2012年5月29日火曜日

CentOS6にRedmine2.0&PostgreSQL9.1

Redmine+PosgtreSQL+Apache+Passenger

  • Redmine:2.0.1
  • OS:  CentOS-6.2(x86) Minimal構成
  • Web: Apache-2.2.22(ソースから) Passenger実行
  • DB:  PostgreSQL-9.1.3(ソースから)
  • Ruby: Ruby1.9.3-p194(ソースから)
  • Rails: 3.2.3(Ruby同梱)
Redmineは/home/redmine/public_html以下に配置します。
※ApacheのUserDirを有効にする
 
2012/06/05 redmine 2.0.2がリリース→2.0.1を2.0.2へのアップデートはこちら
2012/06/19 redmine 2.0.3がリリース(以下と同様の手順でOK)

OSのインストール

ここでは構築手順を割愛させて頂きますが以下で構築したものをベースにしております。
VMwareにテキストモードでインストールしたのもですが多少は参考になるかと思います。
http://stdman.blogspot.jp/2011/12/centos6.html

構成内容
・IPv6:OFF
・パッケージ群:Base,Development Tools
・有効サービス:crond,iptables,network,ntpd,postfix,rsyslog,sshd,cpuspeed,irqbalance
・FireWall:enable → customでSSH,WWW(HTTP)をON,Forward設定なし

●必要パッケージやリポジトリをインストール

Rubyのビルドで必要なEPELリポジトリのインストール
http://ftp.riken.jp/Linux/fedora/epel/6/i386/repoview/epel-release.htmlからRPMのダウンロード先リンクを取得します。
 
# rpm -Uvh http://ftp.riken.jp/Linux/fedora/epel/6/i386/epel-release-6-7.noarch.rpm

Retrieving http://ftp.riken.jp/Linux/fedora/epel/6/i386/epel-release-6-7.noarch.rpm
warning: /var/tmp/rpm-tmp.ZZztWP: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Preparing...                ########################################### [100%]
   1:epel-release           ########################################### [100%]

EPELレポジトリのGPGキーのインポート
# rpm --import http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6
 
EPELレポジトリのGPGキーの確認
# rpm -q 'gpg-pubkey-*' --qf '%{name} -> %{summary}\n'

gpg-pubkey - >  gpg(CentOS-6 Key (CentOS 6 Official Signing Key) )
gpg-pubkey - >  gpg(EPEL (6) )

開発パッケージが必要になりますのでインストールください。
# yum groupinstall "Development Tools"
# yum install openssl-devel readline-devel zlib-devel curl-devel libyaml-devel ImageMagick ImageMagick-devel
※libyamlとlibyaml-develがEPELレポジトリから取得されました
 

●Apacheのインストール

ソースからインストールしています。
詳しくはこちらのインストールを参考にして頂ければと思います。

/usr/local/apacheにインストール、UserDir有効
 

●PostgreSQLのインストール

ソースからインストールしています。
詳しくはこちらのインストールを参考にして頂ければと思います。
/usr/local/pgsqlにインストール、dataはpgsqlの直下
またPL/pgsqlが必要ですが9.0以降はデフォルトでインストールされます。
 
DB名:redmine、ユーザ:redmine、パスワード:redmineを作成しておきます。
 
--------------------------------------------------------
postgresqlのユーザで実行
$ createuser -P redmine
Enter password for new role: 
Enter it again: 
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) y
Shall the new role be allowed to create more new roles? (y/n) n
 
allowed to create more new roles? (y/n) n
 
$ createdb redmine --owner=redmine --encoding=UTF8 --template=template0
--------------------------------------------------------
DB作成が終わったらrootに戻りましょう。
$ exit
 

●Ruby 1.9.3のインストール

# cd /usr/local/src
# wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p194.tar.gz
# tar zxvf ./ruby-1.9.3-p194.tar.gz
# cd ./ruby-1.9.3-p194
# ./configure
# make
# make install
# ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [i686-linux]

●Rubygems(Rubyに同梱されています)

# gem -v
1.8.23

●bundlerのインストール

# gem install bundler --no-rdoc --no-ri
Fetching: bundler-1.1.4.gem (100%)
Successfully installed bundler-1.1.4
1 gem installed

●Redmineのインストール


公開ディレクトリ
# useradd redmine ※ユーザを作成するとpublic_htmlが自動的に作成されるようしている
# chmod 755 /home/redmine
# chmod 775 /home/redmine/public_html
 
# cd /usr/local/src
# wget http://rubyforge.org/frs/download.php/76154/redmine-2.0.1.tar.gz
http://rubyforge.org/frs/?group_id=1850で確認してください。

# tar zxvf redmine-2.0.1.tar.gz 
# mv ./redmine-2.0.1/* /home/redmine/public_html/
 
DBへの接続設定
# cp /home/redmine/public_html/config/database.yml.example /home/redmine/public_html/config/database.yml
 
# vi /home/redmine/public_html/config/database.yml
コメント
#production:
#  adapter: mysql
#  database: redmine
#  host: localhost
#  username: root
#  password:
#  encoding: utf8
追記
production:
  adapter: postgresql
  database: redmine #DB名
  host: localhost #接続先
  username: redmine #DBユーザ
  password: "redmine" #ユーザパスワード
 
Mailの設定
# cp /home/redmine/public_html/config/configuration.yml.example /home/redmine/public_html/config/configuration.yml
 
# vi /home/redmine/public_html/config/configuration.yml
 
ここではlocalhost上のSMTPサーバを利用した例です。
詳しくはRedmine.JP様のページを参考にして頂くとわかりやすいと思います。
 
下の方にproduction:だけが記述されている部分があるのでそこへ追記します。(わかりずらい)

# specific configuration options for production environment
# that overrides the default ones

production:
  email_delivery:
    delivery_method: :smtp
    smtp_settings:
      address: "localhost"
      port: 25
      domain: redmine.example.com

ちなみに自社では自前のメールサーバがありLAN上から参照できます。なのでこんな感じです。
production:
  email_delivery:
    delivery_method: :smtp
    smtp_settings:
      address: "10.1.1.190"
      port: 25
      domain: 自社ドメイン

●Gem pgのインストール

PostgreSQLはソースからインストールしたのでパスを読み込んでから実行する必要がある。

# export PATH=$PATH:/usr/local/pgsql/bin
# gem install pg -- --with-pg-dir=/usr/local/pgsql/ --with-pg-lib=/usr/local/pgsql/lib/ --with-pg-include=/usr/local/pgsql/include/ --no-rdoc --no-ri
Building native extensions.  This could take a while...
Successfully installed pg-0.13.2
1 gem installed
Installing ri documentation for pg-0.13.2...
Installing RDoc documentation for pg-0.13.2...

redmine 2.0.3ではpg-0.14.0になります。

●その他Gemパッケージのインストール

Redmineで必要なパッケージを一括でインストールします。(Gemfileに記載されている
ここではDBにPostgreSQLを利用するため使わないMySQLやSQLLiteは不要とします。

# bundle install --without development test mysql sqlite
Could not locate Gemfile
 
あれ?Gemfileが見つからない?
 
探してみると・・・
# find / -name Gemfile

/usr/local/lib/ruby/gems/1.9.1/gems/prototype-rails-3.2.1/Gemfile
/usr/local/lib/ruby/gems/1.9.1/gems/rack-cache-1.2/Gemfile
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.1.4/lib/bundler/templates/Gemfile
/usr/local/lib/ruby/gems/1.9.1/gems/multi_json-1.3.6/Gemfile
/usr/local/lib/ruby/gems/1.9.1/gems/mail-2.4.4/Gemfile
/usr/local/lib/ruby/gems/1.9.1/gems/tilt-1.3.3/Gemfile
/usr/local/lib/ruby/gems/1.9.1/gems/arel-3.0.2/Gemfile
/usr/local/lib/ruby/gems/1.9.1/gems/rack-test-0.6.1/Gemfile
/usr/local/lib/ruby/gems/1.9.1/gems/journey-1.0.3/Gemfile
/usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.12/test/stub/rails_apps/3.0/empty/Gemfile
/usr/local/lib/ruby/gems/1.9.1/gems/json-1.7.3/Gemfile
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/generators/rails/app/templates/Gemfile
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.2.3/lib/rails/generators/rails/plugin_new/templates/Gemfile
/usr/local/lib/ruby/gems/1.9.1/gems/railties-3.2.3/guides/code/getting_started/Gemfile
/home/redmine/public_html/Gemfile
 
Redmineのルートディレクトリにあった・・・ということでルートディレクトリに移動してもう一度

# cd /home/redmine/public_html/
# bundle install --without development test mysql sqlite
Fetching gem metadata from http://rubygems.org/.......
Using rake (0.9.2.2) 
Using i18n (0.6.0) 
Using multi_json (1.3.6) 
Using activesupport (3.2.3) 
Using builder (3.0.0) 
Using activemodel (3.2.3) 
Using erubis (2.7.0) 
Using journey (1.0.3) 
Using rack (1.4.1) 
Using rack-cache (1.2) 
Using rack-test (0.6.1) 
Using hike (1.2.1) 
Using tilt (1.3.3) 
Using sprockets (2.1.3) 
Using actionpack (3.2.3) 
Using mime-types (1.18) 
Using polyglot (0.3.3) 
Using treetop (1.4.10) 
Using mail (2.4.4) 
Using actionmailer (3.2.3) 
Using arel (3.0.2) 
Using tzinfo (0.3.33) 
Using activerecord (3.2.3) 
Using activeresource (3.2.3) 
Using bundler (1.1.4) 
Using coderay (1.0.6) 
Using json (1.7.3) 
Using net-ldap (0.3.1) 
Using pg (0.13.2) 
Installing rack-ssl (1.3.2) 
Using rdoc (3.12) 
Installing thor (0.14.6) 
Installing railties (3.2.3) 
Installing rails (3.2.3) 
Installing prototype-rails (3.2.1) 
Installing ruby-openid (2.1.8) 
Installing rack-openid (1.3.1) 
Installing rmagick (2.13.1) with native extensions 
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.

Post-install message from rdoc:
Depending on your version of ruby, you may need to install ruby rdoc/ri data:
 
<= 1.8.6 : unsupported
 = 1.8.7 : gem install rdoc-data; rdoc-data --install
 = 1.9.1 : gem install rdoc-data; rdoc-data --install
>= 1.9.2 : nothing to do! Yay!

redmine 2.0.2ではrails3.2.5になります。
redmine 2.0.3ではrails3.2.6になります。

●初期設定およびテーブル作成

# cd /home/redmine/public_html/

# rake generate_secret_token
rake db:migrate RAILS_ENV=production

●Passengerのインストール


# gem install passenger --no-rdoc --no-ri
Fetching: fastthread-1.0.7.gem (100%)
Building native extensions.  This could take a while...
Fetching: daemon_controller-1.0.0.gem (100%)
Fetching: passenger-3.0.12.gem (100%)
Successfully installed fastthread-1.0.7
Successfully installed daemon_controller-1.0.0
Successfully installed passenger-3.0.12
3 gems installed

redmine 2.0.3ではrails3.0.15になります。

●PassengerのApache用モジュールのインストール

Apacheはソースからインストールしたのでapxs2、path環境変数を設定する必要がある

# export APXS2=/usr/local/apache/bin/apxs
# export PATH=/usr/local/apache/bin:$PATH

# passenger-install-apache2-module
Welcome to the Phusion Passenger Apache 2 module installer, v3.0.12.
This installer will guide you through the entire installation process. It
shouldn't take more than 3 minutes in total.
 
Here's what you can expect from the installation process:
 
 1. The Apache 2 module will be installed for you.
 2. You'll learn how to configure Apache.
 3. You'll learn how to deploy a Ruby on Rails application.
 
Don't worry if anything goes wrong. This installer will advise you on how to
solve any problems.
 
Press Enter to continue, or Ctrl-C to abort.
 
Enterで進めていく

途中でnot foundが出たら解決して再度実行




Enjoy Phusion Passenger, a product of Phusion (www.phusion.nl) :-)
http://www.modrails.com/
 
Phusion Passenger is a trademark of Hongli Lai & Ninh Bui.

●Apache用設定ファイルの新規作成

設定ファイルの書き出し
# passenger-install-apache2-module --snippet > /usr/local/apache/conf/extra/passnger.conf
 
HTTPヘッダ削除、Passengerチューニングをpassnger.confへ(任意)
# vi /usr/local/apache/conf/extra/passnger.conf

LoadModule passenger_module /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.12/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.12
PassengerRuby /usr/local/bin/ruby

追記 # Passengerが追加するHTTPヘッダを削除
Header always unset "X-Powered-By"
Header always unset "X-Rack-Cache"
Header always unset "X-Content-Digest"
Header always unset "X-Runtime"

追記 # Passengerのチューニング設定
PassengerMaxPoolSize 20
PassengerMaxInstancesPerApp 4
PassengerPoolIdleTime 3600
PassengerUseGlobalQueue on
PassengerHighPerformance on
PassengerStatThrottleRate 10
RailsSpawnMethod smart
RailsAppSpawnerIdleTime 86400
RailsFrameworkSpawnerIdleTime 0
 
編集が終わったらhttpd.confでpassnger.confをIncludeさせるようにします。
# vi /usr/local/apache/conf/httpd.conf
最後にでも追記
Include conf/extra/passnger.conf
 
ついでにDocumentRootをRedmineとする
DocumentRoot "/home" → "/home/redmine/public_html/public"
 
Apacheのユーザが書き込みできるように設定してApacheを再起動
# chown -R daemon:daemon /home/redmine
# /usr/local/apache/bin/apachectl restart
 
これでIPアドレスによる接続はできると思いますので、初期設定のadmin(パスワード:admin)でログインしてみましょう。
※アクセスできない場合・・・ディレクトリパーミッション、selinuxOFF、iptablesで80ポート開放等をチェックしてみましょう。



ログイン後、上記メニューの「Administration」をクリックするとロール、トラッカー、チケットのステータス、ワークフローが設定されていないのでデフォルト設定をロードするよう勧められますので日本語を選択してロードしましょう。



一番下にある「Information」をクリックします。


Ver 2.0.1です。

Ver 2.0.2です。


●ログレベル・ログローテーション

デフォルトではデバックとなるため大量のログが吐き出されるので調整します。またローテーション設定してファイルが肥大化しないようします。
# cp /home/redmine/public_html/config/additional_environment.rb.example /home/redmine/public_html/config/additional_environment.rb

# vi /home/redmine/public_html/config/additional_environment.rb
config.logger = Logger.new(config.log_path, 2, 1000000)
config.logger.level = Logger::INFO
 
Apache再起動
# /usr/local/apache/bin/apachectl restart
 
あれ?ブラウザを見るとメソッドがないと怒られてしまう・・・とりあえずこれは後回しにしてコメントにしておこう
#config.logger = Logger.new(config.log_path, 2, 1000000)

#config.logger.level = Logger::INFO
 
ググってみたらログレベルは以下の記述方法が見つかりました。
config.log_level = :warn

ということでこの1行のみ記述しました。 
ちなみにレベルはunknown、error、fatal、warn、info、debugがあります。

仕方がないログのローテーションはOSのlogrotateを代用することにします。
ここでは1週間ごとにファイルを切り替え12世代(約3ヶ月)履歴を残すようにしています。
※Apacheが/usr/local/apacheにインストールされている場合です。

# vi /etc/logrotate.d/redmine

/home/redmine/public_html/log/*.log {
  rotate 12
  weekly
  missingok
  notifempty
  copytruncate

  postrotate
      /bin/kill -USR1 `cat /usr/local/apache/logs/httpd.pid 2>/dev/null` 2> /dev/null || true
  endscript

}
 

●EPELレポジトリの調整

標準レポジトリのパッケージがEPELレポジトリのパッケージで上書きされないよう基本的に無効化
 
# vi /etc/yum.repos.d/epel.repo
enabled=1のところを=0に変更
 
※yum-plugin-prioritiesをインストールしてEPELレポジトリのプライオリティを下げておくのもよい(以前RPMforgeリポジトリ導入で書いたので参考にして頂ければと思います)


●テーマを追加

Redmine.JP様で公開されている日本語環境でRedmineの画面を見やすくすることを目的としたテーマ「farend fancy」(farend basicの派生テーマ)を使えるようにします。

インストール方法は以下の2パターンからできます。

①gitレポジトリからの場合
# cd /home/redmine/public_html
# git clone git://github.com/farend/redmine_theme_farend_fancy.git public/themes/farend_fancy

Initialized empty Git repository in /home/redmine/public_html/public/themes/farend_fancy/.git/
remote: Counting objects: 195, done.
remote: Compressing objects: 100% (113/113), done.
remote: Total 195 (delta 75), reused 169 (delta 49)
Receiving objects: 100% (195/195), 49.21 KiB, done.
Resolving deltas: 100% (75/75), done.


②アーカイブからの場合
https://github.com/farend/redmine_theme_farend_fancy/downloadsからtar.gzをダウンロードして/usr/local/srcへ配置します。 
# cd /usr/local/src/
# tar zxvf farend-redmine_theme_farend_fancy-a77f7cd.tar.gz
# cp -R ./farend-redmine_theme_farend_fancy-a77f7c  /home/redmine/public_html/public/themes/farend_fancy

Apache再起動
# /usr/local/apache/bin/apachectl restart
 Redmineの管理画面から「管理」>「設定」>「表示」→テーマを Farend fancyに変更します。保存ボタンを押すのを忘れずに!
 

とりあえずこんなもんで構築は終わりでしょう。でも随分と構築が楽になりましたね!
 
<参考サイト>
本家Redmine:http://www.redmine.org/projects/redmine/wiki/RedmineInstall
Redmine.JP:http://blog.redmine.jp/articles/redmine-2_0-installation_centos/

0 件のコメント:

Google検索