∵ Takayoshi Saito ∴ 2013-02-20 ∞ 2'
RedmineをGitHubからダウンロードしてきて、bundle installを行います(今回はMySQLを使うのでpostgresql sqliteは外しました)
git clone https://github.com/redmine/redmine.git
cd redmine
bundle install --path vendor/bundle --without development test rmagick postgresql sqliteMySQLでDBとユーザーを作成します。今回は出たばかりのMySQL5.6.10を使いました。ユーザーやデータベースは後からYMLで設定しますので、下記ではzabbixユーザーとZabbixデータベースを作っていますが、名前は別でも構いません。
mysql -u root -p
mysql true
timeout 30
pid File.expand_path("tmp/pids/unicorn.pid", ENV['/srv/www/redmine/redmine'])
stderr_path File.expand_path("log/unicorn.stderr.log", ENV['/srv/www/redmine/redmine'])
stdout_path File.expand_path("log/unicorn.stdout.log", ENV['/srv/www/redmine/redmine'])
preload_app true
GC.respond_to?(:copy_on_write_friendly=) and
GC.copy_on_write_friendly = true
before_fork do |server, worker|
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
end
after_fork do |server, worker|
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
end
以下のコマンドで起動します。
bundle exec unicorn_rails -c config/unicorn.rb -E production -DUnicornサーバーのポートと接続してリバースプロキシするために、nginx.confに以下の設定を入れました。
upstream redmine {
ip_hash;
server 127.0.0.1:8008;
}
server {
listen 80;
server_name redmine.geek.sc;
location / {
auth_basic "Saito Server Security";
auth_basic_user_file "/srv/www/.htpasswd";
root /srv/www/redmine/redmine/public;
if (-f $request_filename) { break; }
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_pass http://redmine/;
}
}
Nginxを再起動します。これで、redmine.geek.scのRedmineへアクセスできるようになりました。
uUnicornサーバーを電源投入時に自動起動させる方法はいくつかあるのですが、私は面倒だったので、起動時に自動実行される設定ファイル(openSUSEは/etc/init.d/boot.local、CentOSは/etc/rc.local)に次のように記述しました。
cd /srv/www/redmine/redmine
bundle exec unicorn_rails -c config/unicorn.rb -E production -D
これで再起動時もUnicornサーバーが自動実行されます。
これで設定完了です。Unicornで高速Redmine環境(Ruby on rails)を!