2011年7月27日水曜日

CentOS5にRedmine1.2+PostgreSQL

Redmine1.2にて今まで悩み続けていたPDFの日本語文字化けがついに解消されました。

では早速

OS:CentOS5
Web:Apache2.2.19(ソースから) 尚、Railsの実行ではPassengerを使用
DB:PostgreSQL8.4.8(ソースから)
Ruby:Ruby Enterprise Edition
Rails:2.3.11
/home/redmine/public_htmlにRedmineを配置させます。

OSインストールは割愛させて頂きますが、私はインストール時のパッケージ選択ではbaseのみ選択しています。(5.3ですがよろしければこちらを参考にどうぞ)

●必要パッケージをインストール
# yum groupinstall "Development Tools"
# yum install openssl-devel readline-devel zlib-devel curl-devel zlib-devel

●Apacheのインストール(ソースからインストール)
細かい設定は省略します
# cd /usr/local/src
# wget http://archive.apache.org/dist/httpd/httpd-2.2.19.tar.gz
# tar zxvf httpd-2.2.19.tar.gz
# cd httpd-2.2.19
# ./configure --prefix=/usr/local/apache --enable-so --enable-mods-shared=all
# make;make install

# vi /usr/local/apache/conf/httpd.conf
 ServerAdmin 管理者メールアドレス
 ServerName localhost:80
 DocumentRoot "/home" ←後ほど変更します
 Include conf/extra/httpd-userdir.conf  ←コメント解除

自動起動
# vi /etc/rc.local
追記
/usr/local/apache/bin/apachectl start

・ApacheLogのローテーションは設定おきましょう(推奨)

●PostgreSQLのインストール(ソースからインストール)
8.4.3ですがよろしければこちらを参考にどうぞ(PL/pgsqlをインストールすること
※DB名:redmine、ユーザ:redmine、パスワード:redmine

●Ruby 1.8.7
# cd /usr/local/src
# wget http://rubyenterpriseedition.googlecode.com/files/ruby-enterprise-1.8.7-2011.03.tar.gz
# tar zxvf ruby-enterprise-1.8.7-2011.03.tar.gz
# cd ./ruby-enterprise-1.8.7-2011.03
# ./installer --dont-install-useful-gems --no-dev-docs

※--dont-install-useful-gems → gemパッケージは後で手動インストールするのでここでは不要
※--no-dev-docs → 開発向けドキュメントは不要

Press Enter to continue, or Ctrl-C to abort. →Enterでインストールを進めます

[/opt/ruby-enterprise-1.8.7-2011.03] : /usr/local/ →インストール先の指定(推奨です)


make install
/usr/bin/install -c -m 0755 iconv.so /usr/local/lib/ruby/site_ruby/1.8/i686-linux
--------------------------------------------
Installing useful libraries...
/usr/local/bin/ruby /usr/local/bin/gem sources --update
source cache successfully updated
Updating /usr/local/bin/irb...
Updating /usr/local/bin/ri...
Updating /usr/local/bin/testrb...
Updating /usr/local/bin/erb...
Updating /usr/local/bin/gem...
Updating /usr/local/bin/rdoc...
--------------------------------------------
Ruby Enterprise Edition is successfully installed!
If want to use Phusion Passenger (http://www.modrails.com) in combination
with Ruby Enterprise Edition, then you must reinstall Phusion Passenger against
Ruby Enterprise Edition, as follows:
  /usr/local/bin/passenger-install-apache2-module
Make sure you don't forget to paste the Apache configuration directives that
the installer gives you.

If you ever want to uninstall Ruby Enterprise Edition, simply remove this
directory:
  /usr/local
If you have any questions, feel free to visit our website:
  http://www.rubyenterpriseedition.com
Enjoy Ruby Enterprise Edition, a product of Phusion (www.phusion.nl) :-)

こんな感じでインストールが終了します。

●Rubygems
バージョンチェック
# gem -v
1.5.2

※インストール先が/opt/ruby-enterprise-1.8.7-2011.03の場合は絶対パス(フルパス)で指定

●Rack 1.1.1のインストール
# gem install rack -v=1.1.1 --no-rdoc --no-ri
Fetching: rack-1.1.1.gem (100%)
Successfully installed rack-1.1.1
1 gem installed

●i18n 0.4.2のインストール
# gem install i18n -v=0.4.2 --no-rdoc --no-ri
Fetching: i18n-0.4.2.gem (100%)
Successfully installed i18n-0.4.2
1 gem installed

●pgのインストール
PostgreSQLへのパスは私の環境ですのでご自分のパスに読み替えてください。
# export PATH=$PATH:/usr/local/pgsql/bin
# gem install pg -- --with-pgsql-dir=/usr/local/pgsql/ --with-pgsql-lib=/usr/local/pgsql/lib/ --with-pgsql-include=/usr/local/pgsql/include/ --no-rdoc --no-ri
上記でインストールをするとWikiページをPDF等で出力する際、Internal Errorが発生することがわかりました。
# 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
Fetching: pg-0.11.0.gem (100%)
Building native extensions. This could take a while...
Successfully installed pg-0.11.0
1 gem installed
Installing ri documentation for pg-0.11.0...
Installing RDoc documentation for pg-0.11.0...

●postgres-prのインストール
# gem install postgres-pr --no-rdoc --no-ri
Fetching: postgres-pr-0.6.3.gem (100%)
Successfully installed postgres-pr-0.6.3
1 gem installed

●Rails 2.3.11のインストール
# gem install -v=2.3.11 rails

# gem list
*** LOCAL GEMS ***
actionmailer (2.3.11)
actionpack (2.3.11)
activerecord (2.3.11)
activeresource (2.3.11)
activesupport (2.3.11)
i18n (0.4.2)
pg (0.11.0)
postgres-pr (0.6.3)
rack (1.1.1)
rails (2.3.11)
rake (0.8.7)

Redmine1.2系はrake0.8.7が必要です。もしrakeが0.8.7ではない場合は別途インストールします。
# gem install rake -v=0.8.7 --no-rdoc --no-ri

●Redmineのインストール
# mkdir -p /home/redmine/public_html
# chmod -R 755 /home/redmine/public_html
# cd /home/redmine/public_html
 
開発版or安定版(私は開発版を使用しています)
 
v1.2開発版  # svn checkout http://redmine.rubyforge.org/svn/trunk/ ./
v1.2安定版  # svn checkout http://redmine.rubyforge.org/svn/branches/1.2-stable/ ./

# cp -p ./config/database.yml.example ./config/database.yml
# vi ./config/database.yml
production:
adapter: postgresql

 database: redmine ←postgresqlで作成したDB名
 host: localhost
 username: redmine ←DB接続ユーザ
 password: "redmine" ←DB接続ユーザパスワード

# cp -p ./config/configuration.yml.example ./config/configuration.yml
# vi ./config/configuration.yml
一番下にあるproduction:にメール情報を追記(以下はローカルからの発信な場合)
production:
   email_delivery: 

     delivery_method: :smtp
      smtp_settings:
         address: "localhost"
         port: 25

●初期設定
# cd /home/redmine/public_html/

# rake generate_session_store
(in /home/redmine/public_html)

# rake db:migrate RAILS_ENV="production"
(in /home/redmine/public_html)

# rake redmine:load_default_data RAILS_ENV="production"
Select language: bg, bs, ca, cs, da, de, el, en, en-GB, es, 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, sr, sr-YU, sv, th, tr, uk, vi, zh, zh-TW [en] 
上記表示で止まるのでjaと入力

開発版の場合rake db:migrate RAILS_ENV="production"実行時、gem versionエラーが発生することがありますこの場合/config/environment.rbを書き換えます。(正しいかどうかわらないが回避できた)
RAILS_GEM_VERSION = '2.3.14' unless defined? RAILS_GEM_VERSION
 ↓
RAILS_GEM_VERSION = '2.3.11' unless defined? RAILS_GEM_VERSION

 
●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-0.2.6.gem (100%)
Fetching: passenger-3.0.7.gem (100%)
Successfully installed fastthread-1.0.7
Successfully installed daemon_controller-0.2.6
Successfully installed passenger-3.0.7
3 gems installed

●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.7.
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.
 
途中でnot foundが出たら解決して再度実行



以下をApache設定のため保存しておく
LoadModule passenger_module /usr/local/lib/ruby/gems/1.8/gems/passenger-3.0.7/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/ruby/gems/1.8/gems/passenger-3.0.7
PassengerRuby /usr/local/bin/ruby

After you restart Apache, you are ready to deploy any number of Ruby on Rails

applications on Apache, without any further Ruby on Rails-specific
configuration!

Press ENTER to continue.

--------------------------------------------
Deploying a Ruby on Rails application: an example

Suppose you have a Rails application in /somewhere. Add a virtual host to your
Apache configuration file and set its DocumentRoot to /somewhere/public:


VirtualHostでの運用の場合は以下を参考に
 <VirtualHost *:80>
  ServerName www.yourhost.com
  DocumentRoot /somewhere/public   # <-- be sure to point to 'public'!
  <Directory /somewhere/public>
    AllowOverride all          # <-- relax Apache security settings
    Options -MultiViews        # <-- MultiViews must be turned off
  </Directory>
 </VirtualHost>


And that's it! You may also want to check the Users Guide for security and
optimization tips, troubleshooting and other useful information:

/usr/local/lib/ruby/gems/1.8/gems/passenger-3.0.7/doc/Users guide Apache.html

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用設定ファイルの新規作成
# vi /usr/local/apache/conf/extra/passnger.conf

#保存した行を記述
LoadModule passenger_module /usr/local/lib/ruby/gems/1.8/gems/passenger-3.0.7/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/ruby/gems/1.8/gems/passenger-3.0.7
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

以上でpassnger.confはおしまいですので保存します

httpd.confにpassnger.confを読み込ませる
# vi /usr/local/apache/conf/httpd.conf

最後にでも追記
Include conf/extra/passnger.conf
ついでにDocumentRootをRedmineとする(IPで接続できるように)
"/home" → "/home/redmine/public_html/public"
Apacheのユーザが書き込みできるように設定
# chown -R daemon:daemon /home/redmine
# /usr/local/apache/bin/apachectl restart

これでIPアドレスによる接続はできると思います
アクセスできない場合・・・selinuxOFF、iptablesで80ポート開放もチェックしてみよう



●Redmineログのローテーション
# cd /home/redmine/public_html
# cp ./config/additional_environment.rb.example ./config/additional_environment.rb
# vi ./config/additional_environment.rb
以下追記
#Logger.new(PATH,NUM_FILES_TO_ROTATE,FILE_SIZE)
config.logger = Logger.new(config.log_path, 2, 1000000)
config.logger.level = Logger::INFO

●Wikiで使えるHTML タグの追加
# vi ./lib/redcloth3.rb
一番下の方にALLOWED_TAGS = %w(redpre pre code notextile)という行がありこれに使いたいタグを追記していきます。私はFONTとBRを足しました。
ALLOWED_TAGS = %w(redpre pre code notextile)
 ↓
ALLOWED_TAGS = %w(redpre pre code notextile font br)

●テーマを追加
日本語環境でRedmineの画面を見やすくすることを目的としたRedmine用テーマ「farend basic」を使えるようにします。
# cd /usr/local/src/
# wget http://blog.redmine.jp/assets/2010/03/23/redmine_theme_farend_basic_20110523.tgz
# tar zxvf redmine_theme_farend_basic_20110523.tgz
# cp -R ./farend_basic /home/project/public/themes/
# apache再起動

Redmineの管理画面から「管理」>「設定」>「表示」→テーマをfarend_basicに変更します。
保存ボタンを押すのを忘れずに!
とりあえずここまでで本日はおしまい・・・

日本語ヘルプもできたみたいです。
http://www.redmine.org/projects/redmine/wiki/JaGuide

参考サイト
http://blog.redmine.jp/articles/redmine-1_2-installation_centos/
http://www.redmine.org/projects/redmine/wiki/JaRedmineInstall

Google検索