Fight the Future

Java言語とJVM、そしてJavaエコシステム全般にまつわること

CentOSにRedmineを構築する(Rubyのインストールから)

RedmineRuby 1.8.6以降でないとダメです。

CentOS 5.5に付属しているのは、1.8.5…

入れ替えましょう。

参考にさせていただいたサイト
http://marnica.blog66.fc2.com/blog-entry-66.html

wget http://www.t.ring.gr.jp/archives/lang/ruby/1.8/ruby-1.8.7-p302.tar.gz 

tar zxvf ruby-1.8.7-p302.tar.gz 

cd ruby-1.8.7-p302 

./configure --prefix=/usr 

make && make install 

確認。

ruby -v 
ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-linux] 

Gemsをインストール。

wget http://rubyforge.org/frs/download.php/70696/rubygems-1.3.7.tgz 
tar zxvf rubygems-1.3.7.tgz 
cd rubygems-1.3.7 
ruby setup.rb 

確認。

gem -v 
1.3.7 

Redmineの日本語サイトのガイドに従って、Redmineをインストール。
http://redmine.jp/guide/RedmineInstall/

MySQLを起動して、自動起動をONにする。

/etc/init.d/mysqld start 
chkconfig mysqld on 

MySQLに接続して、redmineユーザーを作成する。

mysql -uroot 

mysql> create database redmine character set utf8; 
mysql> create user 'redmine'@'localhost' identified by 'redmine'; 
mysql> grant all privileges on redmine.* to 'redmine'@'localhost'; 

Redmineをダウンロード。

wget http://rubyforge.org/frs/download.php/73457/redmine-1.0.4.tar.gz 
tar xzvf redmine-1.0.4.tar.gz 
cd redmine-1.0.4/ 

データベースの接続設定。

cd config 
cp database.yml.example database.yml 
vi database.yml 
production: 
adapter: mysql 
database: redmine 
host: localhost 
username: redmine 
password: redmine 
encoding: utf8 
cd .. 
rake config/initializers/session_store.rb 

rakeがないとエラーが出たので、インストール。

参考にさせていただいたサイト
http://www.skymerica.com/blog/yotsumoto/arch/2007/05/12/000769.html

gem install --remote rake 
rake -V 
rake, version 0.8.7 

再チャレンジ。

rake config/initializers/session_store.rb 
(in /opt/redmine-1.0.4) 
rake db:migrate RAILS_ENV="production" 
(in /opt/redmine-1.0.4) 
rake aborted! 
Could not find RubyGem rack (~> 1.0.1) 

rackがないとエラーが出たので、インストール。

gem install rack -v=1.0.1 
Successfully installed rack-1.0.1 

再チャレンジ。

rake db:migrate RAILS_ENV="production" 
(in /opt/redmine-1.0.4) 
!!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql. 

MySQLのドライバがないとエラーが出たので、インストール。

gem install --remote mysql 
Building native extensions. This could take a while... 
ERROR: Error installing mysql: 
ERROR: Failed to build gem native extension. 

/usr/bin/ruby extconf.rb 
checking for mysql_ssl_set()... no 
checking for rb_str_set_len()... no 
checking for rb_thread_start_timer()... no 
checking for mysql.h... no 
checking for mysql/mysql.h... no 
*** extconf.rb failed *** 
Could not create Makefile due to some reason, probably lack of 
necessary libraries and/or headers. Check the mkmf.log file for more 
details. You may need configuration options. 

Provided configuration options: 
--with-opt-dir 
--without-opt-dir 
--with-opt-include 
--without-opt-include=${opt-dir}/include 
--with-opt-lib 
--without-opt-lib=${opt-dir}/lib 
--with-make-prog 
--without-make-prog 
--srcdir=. 
--curdir 
--ruby=/usr/bin/ruby 
--with-mysql-config 
--without-mysql-config 


Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/mysql-2.8.1 for inspection. 
Results logged to /usr/lib/ruby/gems/1.8/gems/mysql-2.8.1/ext/mysql_api/gem_make.out 

このエラーは、MySQLのクライアントライブラリがないから。。

参考にさせていただいたサイト
http://redmine.jp/faq/system_management/gem-install-mysql-failure/

MySQLのクライアントライブラリをインストールする。

yum install mysql-devel 

(初めてMySQLをインストールするときはyum install -y mysql-server mysql-develとする。-yはすべての質問にyesと答えるオプション。 )

gem install --remote mysql 
Building native extensions. This could take a while... 
Successfully installed mysql-2.8.1 
1 gem installed 
Installing ri documentation for mysql-2.8.1... 

No definition for next_result 

再チャレンジ。

rake db:migrate RAILS_ENV="production" 
... 
== EnableCalendarAndGanttModulesWhereAppropriate: migrating ================== 
== EnableCalendarAndGanttModulesWhereAppropriate: migrated (0.0220s) ========= 
mkdir tmp public/plugin_assets 

chown -R redmine:redmine files log tmp public/plugin_assets 
chmod -R 755 files log tmp public/plugin_assets 

WEBrickを起動する。

ruby script/server webrick -e production 

http://localhost:3000/で動作する。


ログの設定。デフォルト無制限にログを出力するので。

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 

WEBrickだと動作が重いだろうと思い、
Apache + PassengerでRedmineを動かすことにする。

参考にさせていただいたサイト
http://redmine.jp/guide/RedmineInstall/
http://d.hatena.ne.jp/unageanu/20080823/1219459701

gem install passenger 

passenger-install-apache2-module 
Some required software is not installed. 
But don't worry, this installer will tell you how to install them. 

Press Enter to continue, or Ctrl-C to abort. 

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

Installation instructions for required software 

* To install Apache 2 development headers: 
Please run yum install httpd-devel as root. 

* To install Apache Portable Runtime (APR) development headers: 
Please run yum install apr-devel as root. 

* To install Apache Portable Runtime Utility (APU) development headers: 
Please run yum install apr-util-devel as root. 

Apacheのライブラリが足りないらしいので、インストール。

yum install httpd-devel 

再チャレンジ。

passenger-install-apache2-module 
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-3.0.1/ext/apache2/mod_passenger.so 
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-3.0.1 
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. 

<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> 

Passenger用の.confファイルを作成する。

vi /etc/httpd/conf.d/passgenger.conf 
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-3.0.1/ext/apache2/mod_passenger.so 
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-3.0.1 
PassengerRuby /usr/bin/ruby 
Alias /redmine "/opt/redmine-1.0.4/public" 

パーミッションを変更する。

chown -R apache:apache /opt/redmine-1.0.4 

Apacheの設定。今回はhttp://xxx.xxx/redmineのようなURLでアクセスできるようにしたい。

vi /etc/httpd/conf/httpd.conf 

<VirtualHost *:80> 
DocumentRoot /var/www/html 
RailsBaseURI /redmine 
<Directory /var/www/html> 
AllowOverride all 
Options -MultiViews 
</Directory> 
</VirtualHost>

/var/www/html/にシンボリックリンクを作成する。

cd /var/www/html/ 
ln -s /opt/redmine-1.0.4/public redmine 

終了!