Macでnginx+redmineを設置してみたので手順を記した
はじめに
こちらを参考にしました。
- http://redmine.jp/guide/RedmineInstall/
- http://doruby.kbmj.com/8y/20100628/Redmine_nginx_Passenger_
- http://blog.ntrippy.net/2009/07/home-made-nginx-phusion-passenger-dep_01.html
インストールするマシン
使ってるMacBookAirは11インチです。
% sw_vers ProductName: Mac OS X ProductVersion: 10.6.6 BuildVersion: 10J567
git cloneでredmineをとってくる
$HOME/projcetにredmineを配置したいと思います。
mkdir -p $HOME/project cd $HOME/project https://github.com/edavis10/redmine.git
config.ymlを作成
conf/config.ymlを配置。.gitignoreで既にignore指定されているので各自自由に書き換えられます。
cp config/database.yml.example config/database.yml
conf/database.ymlを編集
vi config/database.yml
次のようにします。sqliteが好き。
production: adapter: sqlite3 database: db/redmine.db timeout: 5000
セッション暗号化用鍵の生成
セッション暗号化用鍵の生成しようとするとgemでi18nをいれるようにと言われる。
% rake generate_session_store (in /Users/okamura/project/redmine) Missing the i18n 0.4.2 gem. Please `gem install -v=0.4.2 i18n`
実行してみる。PATH通ってないと言われる。
% gem install -v=0.4.2 i18n WARNING: Installing to ~/.gem since /Library/Ruby/Gems/1.8 and /usr/bin aren't both writable. WARNING: You don't have /Users/okamura/.gem/ruby/1.8/bin in your PATH, gem executables will not run.
PATHを通す。zshをつかってて、~/.zshenvに追記
export PATH=$HOME/.gem/ruby/1.8/bin:$PATH
再度実行。OK。
% source ~/.zshenv % gem install -v=0.4.2 i18n WARNING: Installing to ~/.gem since /Library/Ruby/Gems/1.8 and /usr/bin aren't both writable. Successfully installed i18n-0.4.2 1 gem installed Installing ri documentation for i18n-0.4.2... Installing RDoc documentation for i18n-0.4.2...
必要なものを入れたところで鍵作成
% rake generate_session_store (in /Users/okamura/project/redmine)
データベースの初期化
下記コマンドを実行。なんかすごいいっぱい文字がでてくる。
% rake db:migrate RAILS_ENV="production" (in /Users/okamura/project/redmine)
今度は言語設定。jaを選択したのに後で画面を見たら英語だった。管理画面で変更できるので気にしない。
% rake redmine:load_default_data RAILS_ENV=production (in /Users/okamura/project/redmine) Select language: bg, bs, ca, cs, da, de, el, en, en-GB, es, eu, fi, fr, gl, he, hr, hu, id, it, ja, ko, lt, lv, mk, mn, nl, no, pl, pt, pt-BR, ro, ru, sk, sl, sr, sr-YU, sv, th, tr, uk, vi, zh, zh-TW [en] ja =======================
メール送信設定
% cp conf/email.yml.example email.yml
元々あった設定を消して、以下のようにしました。
# === Simple SMTP server at localhost # production: delivery_method: :smtp smtp_settings: address: "localhost" port: 25 ... ### こっちを消しておく #production: # delivery_method: :smtp # smtp_settings: # address: smtp.example.net # port: 25 # domain: example.net # authentication: :login # user_name: "redmine@example.net" # password: "redmine"
とりあえず動かしてみる
実行してみる。
% cd ~/project/redmine % ruby script/server webrick -e production => Booting WEBrick => Rails 2.3.5 application starting on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server [2011-01-14 21:14:21] INFO WEBrick 1.3.1 [2011-01-14 21:14:21] INFO ruby 1.8.7 (2009-06-12) [universal-darwin10.0] [2011-01-14 21:14:21] INFO WEBrick::HTTPServer#start: pid=676 port=3000
http://localhost:3000にアクセスするとこんなんがでる
Processing WelcomeController#index (for 127.0.0.1 at 2011-01-14 21:14:49) [GET] Parameters: {"action"=>"index", "controller"=>"welcome"} Rendering template within layouts/base Rendering welcome/index Completed in 216ms (View: 161, DB: 5) | 200 OK [http://localhost/]
とりあえずログインしてみる
login: admin password: admin
とりあえずログがうるさい
% cp config/additional_environment.rb.example config/additional_environment.rb % echo 'config.logger = Logger.new(config.log_path, 2, 1000000)' >> config/additional_environment.rb % echo 'config.logger.level = Logger::INFO' >>config/additional_environment.rb
全体の設定
「管理」→「設定」で全体的な設定を行います。
- 「既定の言語」を「日本語」に。
- 「送信元メールアドレス」を適宜変更。
- 「認証が必要」を有効に。
- 「自動ログイン」を1日に。
- 「ユーザは自分で登録できる」を無効に。
Nginxで動かす
passengerを入れる
% gem instal passenger WARNING: Installing to ~/.gem since /Library/Ruby/Gems/1.8 and /usr/bin aren't both writable. Successfully installed daemon_controller-0.2.5 Successfully installed spruz-0.2.2 Successfully installed file-tail-1.0.5 Successfully installed passenger-3.0.2 4 gems installed Installing ri documentation for daemon_controller-0.2.5... Installing ri documentation for spruz-0.2.2... Installing ri documentation for file-tail-1.0.5... Installing ri documentation for passenger-3.0.2... Installing RDoc documentation for daemon_controller-0.2.5... Installing RDoc documentation for spruz-0.2.2... Installing RDoc documentation for file-tail-1.0.5... Installing RDoc documentation for passenger-3.0.2...
nginxをいれる
% brew install nginx --with-passenger ==> Downloading http://nginx.org/download/nginx-0.8.54.tar.gz File already downloaded and cached to /Users/okamura/Library/Caches/Homebrew ==> Downloading patches ==> Patching patching file auto/lib/pcre/conf patching file conf/nginx.conf ==> ./configure --prefix=/usr/local/Cellar/nginx/0.8.54 --with-http_ssl_module - ==> make install ==> Caveats In the interest of allowing you to run `nginx` without `sudo`, the default port is set to localhost:8080. If you want to host pages on your local machine to the public, you should change that to localhost:80, and run `sudo nginx`. You'll need to turn off any other web servers running port 80, of course. You can start nginx automatically on login with: cp /usr/local/Cellar/nginx/0.8.54/org.nginx.plist ~/Library/LaunchAgents launchctl load -w ~/Library/LaunchAgents/org.nginx.plist ==> Summary /usr/local/Cellar/nginx/0.8.54: 6 files, 1.5M, built in 111 seconds
言われた通りにする
cp /usr/local/Cellar/nginx/0.8.54/org.nginx.plist ~/Library/LaunchAgents launchctl load -w ~/Library/LaunchAgents/org.nginx.plist
設定ファイル編集
log用のディレクトリをつくる
% mkdir -p /usr/local/var/nginx/logs
必要な情報を調べておく
% passenger-config --root /Users/okamura/.gem/ruby/1.8/gems/passenger-3.0.2 % which ruby /usr/bin/ruby
以下のようにしてみる
% vi /usr/local/etc/nginx.conf
error_log /usr/local/var/nginx/logs/error.log; http { ... # デフォルトでコメントアウトされているので外す gzip on; passenger_root /Users/okamura/.gem/ruby/1.8/gems/passenger-3.0.2; passenger_ruby /usr/bin/ruby; passenger_max_pool_size 8; passenger_max_instances_per_app 1; passenger_pool_idle_time 3600; ### 8080番portに設定を追加 (ここではuser権限で設定しているので1024よりも大きいportならどこでも) server { listen 8080; client_max_body_size 250M; server_name redmine.local; root /Users/okamura/project/redmine/public; ### 重要 passenger_enabled on; rails_env production; }
シンタックスを確認
% nginx -t -c /usr/local/etc/nginx/nginx.conf the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok configuration file /usr/local/etc/nginx/nginx.conf test is successful
再起動(?)してみる。やり方わかっていない。
% ps axw | egrep "nginx|passenger" 17342 ?? Ss 0:00.00 nginx: master process nginx -c /usr/local/etc/nginx/nginx.conf 17343 ?? S 0:00.00 nginx: worker process 17423 ?? S 0:00.01 /usr/local/Cellar/nginx/0.8.54/sbin/nginx -g daemon off; % kill 17342
プロセスみてみる。しばらくすると復活する。
% ps axw | egrep "nginx|passenger" % % ps axw | egrep "nginx|passenger" 17445 ?? S 0:00.01 nginx: master process /usr/local/Cellar/nginx/0.8.54/sbin/nginx -g daemon off; 17453 ?? S 0:00.00 nginx: worker process
/etc/hostsにredmine.localを追記
% vi /etc/hosts 127.0.0.1 localhost redmine.local
redmineにログインして終了。