
貴重なデータをサーバー上に保管
IT化が進んでいないところでは、社内の貴重なデータを普通のデスクトップパソコンに保存、管理してるケースも少なくないと思う。
貴重なデータは最低でも以下の環境に置かれていることが望ましい。
1.データセンター内のサーバー
2.ハードディスクが多重化されている。
3.複数のサーバーでバックアップ
上記の条件が揃っているサービスとしてクラウドがあげれるが、
安心かと思われたクラウドでも昨年、Amazonクラウドサービスで
大規模の障害がおきた。
そのため、クラウドを利用する時も、3のバックアップは他ホスティングサービスを
利用したほうが一層安心かもしれない。
オンラインデータ管理システムBoxroom
とある会社からデータ管理システムを頼まれたので、オープンソースで良いのがないか探していたところ、
Boxroomを発見。なかなか良さそう。しかもRailsで実装されている。
試してみたところ予想以上に使い勝手がよいのでメモ。
ちなみに、その会社、聞いたところによると大切なデータを外付けHDDで保管しているとのこと。
手軽な外付けHDDなんて、そのまま持っかれたら終わりだし。
開発環境は
ServersMan@VPS
CentOS 5.4
Ruby 1.9.2
Rails 3.0.9
インストール方法
Git,Ruby,Railsなどはインストールしてあるものとする。
[]$ git clone https://github.com/mischa78/boxroom.git
[]$ cd boxroom
# GemfileとGemfile.lockに書かれているバージョンが古いので変更。
# rakeファイルの変更はbundleコマンドをたたく前に必要あり。
# rake = 0.8.7 → 0.9.2
# 他にもバージョンが違うgemがあったら「gem list」を参考に変更しておく。
[]$ vim Gemfile
[]$ vim Gemfile.lock
[]$ bundle
Using rake (0.9.2)
Using abstract (1.0.0)
Using activesupport (3.0.9)
Using builder (2.1.2)
Using i18n (0.5.0)
Using activemodel (3.0.9)
Using erubis (2.6.6)
Using rack (1.2.3)
Using rack-mount (0.6.14)
Using rack-test (0.5.7)
Using tzinfo (0.3.29)
Using actionpack (3.0.9)
Using mime-types (1.16)
Using polyglot (0.3.1)
Using treetop (1.4.9)
Using mail (2.2.19)
Using actionmailer (3.0.9)
Using arel (2.0.10)
Using activerecord (3.0.9)
Using activeresource (3.0.9)
Using acts_as_tree (0.1.1)
Using bundler (1.0.15)
Using cocaine (0.1.0)
Using dynamic_form (1.1.4)
Using factory_girl (1.3.3)
Using rdoc (3.8)
Using thor (0.14.6)
Using railties (3.0.9)
Using factory_girl_rails (1.0.1)
Using paperclip (2.3.16)
Using rails (3.0.9)
Using sqlite3 (1.3.3)
Your bundle is complete! Usebundle show [gemname]
to see where a bundled gem is installed.
[]$ rake db:migrate RAILS_ENV=development
[]$ rake db:migrate RAILS_ENV=production
Passengerで本番環境で動かすには、、
Boxroomは本番環境ではxSendFileというApacheモジュールが必要で、Apacheの初期状態でははいってない。
そのためインストールして設定する必要がある。
[]$ yum install -y mod_xsendfile
[]$ vim /etc
# xSendFileの設定
[]$ vim /etc/httpd/conf.d/xsendfile.confLoadModule xsendfile_module modules/mod_xsendfile.so
<IfModule xsendfile_module>
XSendFile on
XSendFilePath /var/www/uploads
</IfModule<># バーチャルホストの設定はこんな感じ。
[]$ vim /etc/httpd/conf.d/boxroom.confNameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /var/www/boxroom/public/
ServerName your_boxroom_domain.com
ErrorLog /var/log/httpd/boxroom-error_log
CustomLog /var/log/httpd/boxroom-access_log common
XSendFile on
XSendFilePath /var/www/boxroom/uploads/production
</VirtualHost>
BoxroomでHTML5のファイル複数同時アップロードを実装する場合
こんな感じ変更すれば複数同時アップロードを実装できました。
def create if params[:user_file]["attachment"].class == Array # 複数ファイルの場合の処理 params[:user_file]["attachment"].each do |f| @file = @target_folder.user_files.build({"attachment" => f}) render :action => 'new' and return unless @file.valid? end params[:user_file]["attachment"].each do |f| @file = @target_folder.user_files.build({"attachment" => f}) @file.save end redirect_to folder_url(@target_folder) else # 単数ファイルの場合の処理 @file = @target_folder.user_files.build(params[:user_file]) if @file.save redirect_to folder_url(@target_folder) else render :action => 'new' end end end
<%# f.file_field :attachment %> <input id="user_file_attachment" name="user_file[attachment][]" type="file" multiple = "multiple" />