CentOS 6.3 にRedmine をインストールしてみた
さくらのVPSを借りたものは良いけど、中々趣味プロジェクトが前に進まないので、マイルストーンを切るべくRedmine 2.1を導入してみました。
今回は既にmysqlやrbenv、Rails、nginx、git等がインストールされている環境下への導入で、nginxを通しつつホストを分ける形でのアプローチになっています。
すべてを一からインストールしようとしている方にとってはあまり参考にならないかもしれないですが、下記に手順を残しておきます。
なお、今回のインストールで作成/変更した設定ファイルはgistにまとめて置いておきました。どこかからのコピペばかりで、もしかすると凄まじい脆弱性が潜んでいるかもしれません。参考にされる方は自己責任でお願いします。
(あわせてツッコミなどあればよろしくお願いします。)
【設定ファイルのgist】
gist:Redmine on unicorn on nginx with mysql, my configuration files.
【環境】
・CentOS 6.3
・rbenv インストール済み
・Rails 3.2.8 インストール済み
・nginx 1.0.15 インストール済み
・mysql 5.1.61 インストール済み
・git 1.7.1 インストール済み
【参考にしたサイト等】
rbenv+ruby-buildとunicornでもっとさくっとRedmine入れてみる
Installing Redmine(Redmine公式Wiki)
1.Redmineのダウンロード
redmineをgithubからcloneします。
$ cd /home/www/rails $ git clone https://github.com/redmine/redmine.git Initialized empty Git repository in /home/www/rails/redmine/.git/ remote: Counting objects: 90421, done. remote: Compressing objects: 100% (17498/17498), done. remote: Total 90421 (delta 71963), reused 89815 (delta 71466) Receiving objects: 100% (90421/90421), 20.11 MiB | 1.79 MiB/s, done. Resolving deltas: 100% (71963/71963), done.
2.1-stable ブランチに切り替えます。
$ cd redmine $ git branch -a * master remotes/origin/0.6-stable remotes/origin/0.7-stable remotes/origin/0.8-stable remotes/origin/0.9-stable remotes/origin/1.0-stable remotes/origin/1.1-stable remotes/origin/1.2-stable remotes/origin/1.3-stable remotes/origin/1.4-stable remotes/origin/2.0-stable remotes/origin/2.1-stable remotes/origin/HEAD -> origin/master remotes/origin/master $ git checkout -b 2.1-stable remotes/origin/2.1-stable Branch 2.1-stable set up to track remote branch 2.1-stable from origin. Switched to a new branch '2.1-stable' $ git branch * 2.1-stable master
2.Redmineのインストールと起動テスト
いつも通りbundle installを実行します。
$ bundle install --path vendor/bundle --without development test rmagick postgresql sqlite
mysqlにredmine用のデータベースとユーザーを作成します。(passwordは独自に設定)
$ mysql -u root -p mysql> create database redmine character set utf8; mysql> create user 'redmine'@'localhost' identified by 'password'; mysql> grant all privileges on redmine.* to 'redmine'@'localhost'; mysql> exit
database.ymlをmysql用に書き換えます。
$ cp config/database.yml.example config/database.yml $ vim config/database.yml
Redmineのデータベースを構築します。
$ RAILS_ENV=production rake db:migrate $ RAILS_ENV=production rake redmine:load_default_data Select language: ar, bg, bs, ca, cs, da, de, el, en, en-GB, es, et, eu, fa, fi, fr, gl, he, hr, hu, id, it, ja, ko, lt, lv, mk, mn, nl, no, pl, pt, pt-BR, ro, ru, sk, sl, sq, sr, sr-YU, sv, th, tr, uk, vi, zh, zh-TW [en] ja
webrickでの起動実験を行います。ポート3000にアクセスしてRedmineが開けば成功。
$ ruby script/rails server webrick -e production
3.unicornの導入と設定
デフォルトではunicornが入っていないので、Gemfile.localを生成してインストールします。
$ echo 'gem "unicorn"' > Gemfile.local $ bundle install
おもむろにunicornの設定ファイルを持ってきて起動実験します。ポート5001にアクセスしてRedmineが開けば成功。
$ vim config/unicorn.rb $ bundle exec unicorn_rails -c config/unicorn.rb -E production -D -p 5001
4.nginxの設定
今回はnginx側でBASIC認証を行うため.htpasswdを生成します。username、passwordはそれぞれ独自に設定。
$ su $ printf "username:$(openssl passwd -1 password)\n" >> .htpasswd
nginxの設定でRedmine用のホストを追加して再起動します。
$ vim /etc/nginx/nginx.conf $ service nginx restart
きちんと3000番と5001番のポートを閉じてから、 redmine.charag.jpにアクセスしてRedmineが開けたら成功です!
まとめ
nginxの設定にもっとも時間を取られました。
当初 hoge.jp/redmine/ で繋がるようにしたかったのですが、rewriteやproxy_passの設定が分からず、リダイレクトループが発生。なんとか解決したものの、今度はRedmine側が/redmine運用を想定されていなくて面倒な事になり、ホスト運用に切り替えました。
ホスト運用となってしまえば、アプリ自体の導入もとてつもなく簡単で、nginxもすんなり設定できました。Railsは一度導入さえしてしまえば色んなアプリの導入が楽ちんですね!!病み付きになりそうです。次回はアクセスログの統計アプリなどを入れようと思っています。