開発環境整備日記 その2

とりあえず死んだサーバを復旧させる前にメモを完成させておく。


Redmine 導入
Ruby のインストールを行う

$ wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-p0.tar.gz
$ gtar zxf ruby-1.9.2-p0.tar.gz
$ cd ruby-1.9.2-p0
$ ./configure -enable-pthread
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/tmp/ruby-1.9.2-p0':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details.

gcc が入っていないのでインストールを行う

$ yum install gcc

再度 ruby をビルド。

$ ./configure -enable-pthread
$ make
$ make install

完了したらバージョンのチェックを行う。

$ ruby -v
ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]

問題なさげなので rails をインストールする。
Redmine Install ガイドには RubyGems 1.3.1 or higher is required とあるので 1.3.7 を突っ込む。。

$ cd ../../../tmp/
$ wget http://rubyforge.org/frs/download.php/70696/rubygems-1.3.7.tgz
$ gtar zxf rubygems-1.3.7.tgz
$ cd rubygems-1.3.7
$ ruby setup.rb
$ gem install rails --include-dependencies
ERROR: Loading command: install (LoadError)
no such file to load -- zlib
ERROR: While executing gem ... (NameError)
uninitialized constant Gem::Commands::InstallCommand

zlib がなさげ?

$ cd ruby-1.9.2-p0/ext/zlib/
$ ruby extconf.rb --with-zlib-include=/usr/include -with-zlib-lib=/usr/lib
checking for deflateReset() in -lz... no
checking for deflateReset() in -llibz... no
checking for deflateReset() in -lzlib1... no
checking for deflateReset() in -lzlib... no
checking for deflateReset() in -lzdll... no

やっぱりないらしいので zlib をインストール。
※参照:http://toshihilog.blog63.fc2.com/blog-category-5.html

$ cd ../../../../tmp/
$ wget http://www.zlib.net/zlib-1.2.5.tar.gz
$ gtar zxf zlib-1.2.5.tar.gz
$ cd zlib-1.2.5
$ ./configure --shared --libdir=/lib
$ make
$ make install
$ cd ../ruby-1.9.2-p0/ext/zlib/
$ ruby extconf.rb --with-zlib-include=/usr/include -with-zlib-lib=/usr/lib
$ make
$ make install

再度 ruby インストールを試みる。

$ cd ../../rubygems-1.3.7
$ gem install rails --include-dependencies

成功したので mysql のセットアップへ。

$ mysql --version
mysql Ver 14.12 Distrib 5.0.77, for redhat-linux-gnu (i686) using readline 5.1

ruby の対応バージョンが違うものだったのでアンインストールして入れ直す。

$ rm -r /usr/local/lib/ruby/
$ rm -r /usr/local/bin/ruby
$ rm -r /usr/local/include/ruby-1.9.1/
$ rm -r /usr/local/share/doc/ruby/
$ wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.6-p114.tar.gz
$ gtar zxf ruby-1.8.6-p114.tar.gz
$ cd ruby-1.8.6-p114
make
make install

rails の入れ直しに貂蝉

$ cd rubygems-1.3.7
$ ruby setup.rb
$ gem install rails --include-dependencies
$ gem install rails -v=2.3.5 --include-dependencies

Redmine Install ガイドに rack 1.0.1 を入れろとあるのでインストール。

$ gem install rack -v=1.0.1

完了したので mysql のセットアップへ戻る。
Redmine 用の新しい MySQL 権限テーブルを生成し、権限を変更する。

$ /usr/bin/mysql_install_db
$ chgrp -R mysql /home/mysql
$ chmod -R 770 /home/mysql

mysql をインストール。

$ sudo yum install mysql-devel
$ gem install mysql -- --whit-mysql-config=/usr/bin/mysql_config
$ cd /home/mysql/
$ wget ftp://ftp.riken.jp/Linux/centos/4/centosplus/i386/RPMS/mysql*
$ rails -d mysql my_rails_app

インストール完了したのでバックアップ作成してから my.cnf をいじる。

$ cp -a /etc/my.cnf /etc/my.cnf.org
$ vi /etc/my.cnf
↓こんな感じに書き換え
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1

default-character-set=utf8
skip-character-set-client-handshake

# Disabling symbolic-links is recommended to prevent assorted security risks;
# to do so, uncomment this line:
# symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[client]
default-character-set=utf8

[mysql]
default-character-set=utf8

[mysqldump]
default-character-set=utf8

mysql を起動。

$ chkconfig mysqld on
$ chkconfig --list mysqld
$ mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off

バージョンを確認し、ついでに Redmine 用のDBを構築する。

$ service mysqld start
$ mysql -v
mysql> create database redmine;
mysql> grant all on redmine.* to redmine@localhost identified by 'redmine';
mysql> show grants for redmine@localhost;
mysql> exit

ついでに root DB のパスを設定しておく。

$ mysql -u root -p
mysql> set password for redmine@localhost=password('パスワード');
mysql> exit

Redmine 用の DB に切り替え。

$ mysql -u redmine -p
mysql> use redmine
Database changed
mysql> exit

ようやく Redmine のインストールへ。
本体を落とし、database.yml を Redmine 用の DB 情報に書き換える。

$ cd opt/
$ mkdir src
$ cd src/
$ wget http://rubyforge.org/frs/download.php/72627/redmine-1.0.2.tar.gz
$ gtar zxf redmine-1.0.2.tar.gz
$ cd redmine-1.0.2
$ cp config/database.yml.example config/database.yml
$ vi config/database.yml
↓こんな感じ
production:
adapter: mysql
database: redmine(↑で設定した Redmine 用 DB 名)
host: localhost
username: redmine(↑で設定した Redmine 用 ユーザ 名)
password: redmine(↑で設定した Redmine 用 パス)
encoding: utf8

Redmine の初期化を行う

$ rake config/initializers/session_store.rb
$ rake db:migrate RAILS_ENV="production"
(in /opt/src/redmine-1.0.2)
rake aborted!
no such file to load -- openssl

(See full trace by running task with --trace)

openssl が無い?

$ rpm -qa | grep -i openssl
openssl-0.9.8e-12.el5_4.6
xmlsec1-openssl-1.2.9-8.1.1
openssl-devel-0.9.8e-12.el5_4.6
$ yum install openssl-devel

redline も必要らしいのでついでに入れておく。

$ yum install readline
$ yum install readline-devel

ビルド時の openssl 状態に左右されるので、めんどくさいけど rubygem と ruby を入れなおす。
手順は省略。
これでOKっぽい?

$ rake db:migrate RAILS_ENV="production"
(in /opt/src/redmine-1.0.2)
!!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql.
rake aborted!
no such file to load -- mysql

(See full trace by running task with --trace)

まだ駄目っぽい。Rails2.2 系からは標準で MySQL のドライバが付属していないのでインストールしないといけないらしいのでインスコしてから再度挑戦。

$ gem install mysql
$ rake db:migrate RAILS_ENV="production"

通ったので初期化作業を進める。

$ rake redmine:load_default_data RAILS_ENV="production"
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

無事初期化完了したので webrick を使って起動。

$ ruby script/server webrick -e production

無事 Redmine 立ち上げ完了!
接続は http://hostname:3000/ へ。


で、ここまでは無事に完了したのだけど、毎回 webrick を使って起動するのがめんどくさいので passenger を使って自動起動にしようといじってたら yum の DB がお亡くなりになられた。
サーバの初期化を行って全入れ直しを行うつもりなので、作業が終わったらその辺の話をまた後でメモるかも。