Redmineのインストールと設定

CentOS 5.3で入れてみました。

  • gcc等開発環境は既にインストール済み。GNU C++ コンパイラも必要。無い場合はあらかじめ入れておく。
yum install gcc gcc-c++
  • WebサーバにはApache2.2.11、データベースにはMySQL5.1.30を使った。ApacheMySQLはあらかじめ入れておく。
    • Apacheはソースから、/usr/local/apache2 にインストールしておいた。
    • MySQLはバイナリ版を/usr/local/mysql にインストールしておいた。

Rubyのインストール

yum install ruby ruby-devel ruby-irb ruby-rdoc ruby-ri

依存関係で ruby-libs もついてくるので一緒にインストール。

入ったか確認。

ruby --version
ruby 1.8.5 (2006-08-25) [i386-linux]

RubyGemsのインストール

RubyGemsRuby用パッケージ管理ツール。

http://rubyforge.org/frs/?group_id=126
上記URLから最新版のソースを持ってくる(1.3.4が最新だった)。

cd /usr/local/src
wget http://rubyforge.org/frs/download.php/57643/rubygems-1.3.4.tgz

展開してセットアップ。

tar xzvf rubygems-1.3.4.tgz
cd rubygems-1.3.4
ruby setup.rb
#↓こんな感じでインストールされた。
Installing RubyGems
Installing gem executable
Removing old source_cache files
Removing old RubyGems RDoc and ri
Installing rubygems-1.3.4 ri into /usr/lib/ruby/gems/1.8/doc/rubygems-1.3.4/ri
Installing rubygems-1.3.4 rdoc into /usr/lib/ruby/gems/1.8/doc/rubygems-1.3.4/rdoc

------------------------------------------------------------------------------

Oh-no! Unable to find release notes!

------------------------------------------------------------------------------

RubyGems installed the following executables:
        /usr/bin/gem

オー!ノー!とか言われたけど。。。
インストールされたのを確認。

gem --version
1.3.4

Ruby on Railsのインストール

言わずと知れた、RubyフレームワークRedmineはRoRで開発されてる。

gem install rails
#↓こんな感じでインストールされた。
Successfully installed rake-0.8.7
Successfully installed activesupport-2.3.2
Successfully installed activerecord-2.3.2
Successfully installed actionpack-2.3.2
Successfully installed actionmailer-2.3.2
Successfully installed activeresource-2.3.2
Successfully installed rails-2.3.2
7 gems installed
Installing ri documentation for rake-0.8.7...
Installing ri documentation for activesupport-2.3.2...
Installing ri documentation for activerecord-2.3.2...
Installing ri documentation for actionpack-2.3.2...
Installing ri documentation for actionmailer-2.3.2...
Installing ri documentation for activeresource-2.3.2...
Installing ri documentation for rails-2.3.2...
Installing RDoc documentation for rake-0.8.7...
Installing RDoc documentation for activesupport-2.3.2...
Installing RDoc documentation for activerecord-2.3.2...
Installing RDoc documentation for actionpack-2.3.2...
Installing RDoc documentation for actionmailer-2.3.2...
Installing RDoc documentation for activeresource-2.3.2...
Installing RDoc documentation for rails-2.3.2...

結構長かった。。。

Redmineのインストール

http://rubyforge.org/frs/?group_id=1850
上記URLから安定版最新ソースを持ってくる(0.8.4が最新だった)。

cd /usr/local/src
wget http://rubyforge.org/frs/download.php/56909/redmine-0.8.4.tar.gz

展開して、/var/lib/redmineにインストール。

tar xzvf redmine-0.8.4.tar.gz
mv redmine-0.8.4 /var/lib/redmine

データベースの設定

別途MySQLRedmine用のデータベースと接続ユーザは作っておいてから。


設定例があるので、それをコピーして使うことに。
production:以外のdevelopment:だとかtest:だとかはMySQL用の設定にはいらないので、消すかコメントアウトしておく。

cp /var/lib/redmine/config/database.yml.example /var/lib/redmine/config/database.yml
vi /var/lib/redmine/config/database.yml

production:
  adapter: mysql
  database: redmine
  host: localhost
  username: redmine
  password: xxxxxxxxxx
  encoding: utf8

Redmine用のテーブルを作る。

rake db:migrate RAILS_ENV=production

rake aborted!
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb)
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2377:in `raw_load_rakefile'
(See full trace by running task with --trace)

こんな風に怒られたら、Rakefileが見つからないということ。
Redmineをインストールした場所にあるので、そこで行う。

cd /var/lib/redmine
rake db:migrate RAILS_ENV=production

#成功したら、下記の感じでつらつらと処理が進む。
== 1 Setup: migrating =========================================================
-- create_table("attachments", {:force=>true})
   -> 0.0074s
-- create_table("auth_sources", {:force=>true})
   -> 0.0065s
-- create_table("custom_fields", {:force=>true})
   -> 0.0063s
-- create_table("custom_fields_projects", {:force=>true, :id=>false})
   -> 0.0046s
-- create_table("custom_fields_trackers", {:force=>true, :id=>false})
   -> 0.0049s
-- create_table("custom_values", {:force=>true})
....
2009年6月15日追記

デフォルトのデータを突っ込む方法には、下記の方法で行う。

rake redmine:load_default_data RAILS_ENV="production"

メール送信の設定

メール通知機能を使うためにSMTPサーバの設定をする。
今回はRedmineが入ってるサーバのSMTPを使う。

設定例があるので、それをコピーして使うことに。
development:は必要ないので削すかコメントアウト。

cp /var/lib/redmine/config/email.yml.example /var/lib/redmine/config/email.yml
vi /var/lib/redmine/config/email.yml

# Outgoing email settings

production:
  delivery_method: :smtp
  smtp_settings:
    address: localhost
    port: 25
2009/06/15追記

GmailGoogleApps)を使って送るようにしてみた。


SMTPTLS使う為にtlsmailパッケージが必要なので、インストールする。

gem install tlsmail

config/environment.rb に追記。

vi config/environment.rb
require "tlsmail"
Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)

GmailSMTPを設定。

vi config/email.yml
production:
  delivery_method: :smtp
  smtp_settings:
    address: smtp.gmail.com
    port: 587
    domain: hogehoge.com
    authentication: :login
    user_name: redmine@hogehoge.com
    password: xxxxxxxxxx

Passengerを使って、Apacheと連携させる

Passenger(mod_rails for Apache)は、Railsアプリケーションを動かすためのApacheモジュール。
Apacheは別途先にインストールしておく。

gem install passenger
#↓以下のようにすすむ。。。

Building native extensions.  This could take a while...
Building native extensions.  This could take a while...
Successfully installed fastthread-1.0.7
Successfully installed passenger-2.2.2
2 gems installed
Installing ri documentation for fastthread-1.0.7...

No definition for dummy_dump

No definition for dummy_dump

No definition for rb_queue_marshal_load

No definition for rb_queue_marshal_dump

No definition for dummy_dump

No definition for dummy_dump

No definition for rb_queue_marshal_load

No definition for rb_queue_marshal_dump
Installing ri documentation for passenger-2.2.2...
Installing RDoc documentation for fastthread-1.0.7...

No definition for dummy_dump

No definition for dummy_dump

No definition for rb_queue_marshal_load

No definition for rb_queue_marshal_dump

No definition for dummy_dump

No definition for dummy_dump

No definition for rb_queue_marshal_load

No definition for rb_queue_marshal_dump
Installing RDoc documentation for passenger-2.2.2...

いろいろと入ったことを確認。

ls -l /usr/bin/passenger-*
-rwxr-xr-x 1 root root 391 Jun  9 15:48 /usr/bin/passenger-config
-rwxr-xr-x 1 root root 407 Jun  9 15:48 /usr/bin/passenger-install-apache2-module
-rwxr-xr-x 1 root root 405 Jun  9 15:48 /usr/bin/passenger-install-nginx-module
-rwxr-xr-x 1 root root 401 Jun  9 15:48 /usr/bin/passenger-make-enterprisey
-rwxr-xr-x 1 root root 397 Jun  9 15:48 /usr/bin/passenger-memory-stats
-rwxr-xr-x 1 root root 397 Jun  9 15:48 /usr/bin/passenger-spawn-server
-rwxr-xr-x 1 root root 391 Jun  9 15:48 /usr/bin/passenger-status
-rwxr-xr-x 1 root root 396 Jun  9 15:48 /usr/bin/passenger-stress-test

次に、Apacheモジュールのビルドとインストール。
※その前に、Apacheをソースから/usr/local/apache2等に入れた場合は、環境変数を設定しておく。

export APXS2=/usr/local/apache2/bin/apxs
export PATH=/usr/local/apache2/bin:$PATH
passenger-install-apache2-module

#↓対話形式でインストールが始まる。

Welcome to the Phusion Passenger Apache 2 module installer, v2.2.2.

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.
(エンター押す)

#↓必要なソフトウェアの存在チェック
--------------------------------------------

Checking for required software...

 * GNU C++ compiler... found at /usr/bin/g++
 * Ruby development headers... found
 * OpenSSL support for Ruby... found
 * RubyGems... found
 * Rake... found at /usr/bin/rake
 * Apache 2... found at /usr/local/apache2/bin/httpd
 * Apache 2 development headers... found at /usr/local/apache2/bin/apxs
 * fastthread... found
 * fastthread... found
 * Apache Portable Runtime (APR) development headers... found at /usr/local/apache2/bin/apr-1-config
 * Apache Portable Runtime Utility (APU) development headers... found at /usr/local/apache2/bin/apu-1-config

#↓モジュールのコンパイルととインストール
--------------------------------------------
Compiling and installing Apache 2 module...

(コンパイルの状況が出る)

#Apacheの設定方法の説明
--------------------------------------------
The Apache 2 module was successfully installed.

Please edit your Apache configuration file, and add these lines:

   LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.2.2/ext/apache2/mod_passenger.so
   PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.2.2
   PassengerRuby /usr/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 Ruby on Rails application in /somewhere. Add a virtual host
to your Apache configuration file, and set its DocumentRoot to
/somewhere/public, like this:

   <VirtualHost *:80>
      ServerName www.yourhost.com
      DocumentRoot /somewhere/public    # <-- be sure to point to 'public'!
   </VirtualHost>

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

  /usr/lib/ruby/gems/1.8/gems/passenger-2.2.2/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の設定

passenger-install-apache2-moduleやったとき、最後に教えてくれた設定をApacheに記述する。

vi /usr/local/apache2/conf/httpd.conf

LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.2.2/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.2.2
PassengerRuby /usr/bin/ruby

Redmineをインストールしたディレクトリ配下のpublic(今回は/var/lib/redmine/public)を公開する。

vi /usr/local/apache2/conf/extra/httpd-vhosts.conf

<VirtualHost *:80>
    ServerName redmine.example.jp
    DocumentRoot /var/lib/redmine/public
</VirtualHost>

でも今回は http://www.hogehoge.com/redmine/ のように
サブディレクトリで動かそうと思うので、こんな感じでドキュメントルートの下にシンボリックリンクを張る。

ln -s /var/lib/redmine/public /usr/local/apache2/htdocs/redmine

さらに、RailsBaseURIを記述する。

<VirtualHost *:80>
    ServerAdmin admin@hogehoge.com
    DocumentRoot /home/www/domains/hogehoge.com
    ServerName www.hogehoge.com

    <Directory "/home/www/domains/hogehoge.com">
        AllowOverride All
        Order allow,deny
        Allow from all

        RailsBaseURI /redmine
    </Directory>
</VirtualHost>

起動

設定が完了したので、Apacheの再起動。

/etc/init.d/apache2 restart

うまく起動しない場合

起動ができない場合、Apacheのログ、/usr/local/apache2/logs/error_log にでる。次のようなことを確認する。

SELinuxが効いていてポリシー違反している。
#SELinuxを無効に。
/usr/sbin/setenforce permissive

vi /etc/sysconfig/selinux

SELINUX=disabled
パーミッションを疑ってみる。
chown -R nobody.nobody /var/lib/redmine
ソースからApacheを入れた場合、ライブラリの場所が分からずに読み込まれてないことを疑ってみる。
vi error_log

[warn] Init: Session Cache is not configured [hint: SSLSessionCache]
/usr/lib/ruby/gems/1.8/gems/passenger-2.2.2/ext/apache2/ApplicationPoolServerExecutable: error while loading shared libraries: libapr-1.so.0: cannot open shared object file: No such file or directory

こんなエラーが出た場合。

vi /etc/ld.so.conf
/usr/local/apache2/lib ←追加。
/sbin/ldconfig -v

最初の設定

  • 画面右上の「ログイン」から、ログイン:amin、パスワード:adminでログイン。
  • 画面右上の「admin」から、初期ユーザadminのパスワードをはじめ、名前、苗字、メールアドレス、言語を変更
  • 画面右上の「my account」から、言語「Language」を「Japanese(日本語)」にしてSave。

Redmine全体の設定

画面左上の「管理」全体の設定を行う。

  • 全般タブ
    • 既定の言語 :Japanese(日本語)
    • ユーザ名の表示書式を「苗字 名前」の順に。
  • 認証タブ
    • 認証が必要 :チェック
    • ユーザは自分で登録できる:無効
  • メール通知タブ
    • 送信元メールアドレス :適当に変更。
    • メール通知のタイミング:適当に変更

Wikiのヘルプを日本語化

cd /var/lib/redmine/public/help
mkdir english
mv wiki_syntax* ./english/
wget http://redmine.jp/files/wiki_syntax_ja/wiki_syntax_ja.tar.gz
tar xzvf wiki_syntax_ja.tar.gz

これでオッケー。さぁ使ってみるぞー!