masalibの日記

システム開発、運用と猫の写真ブログです

Redmine1.2のインストール

2019年2月28日の時点でインストールして起動確認ができている手順です
日が経過するとできない可能性があるのでご注意してください
たぶんこんな古いバージョンをインストールする事は少ないと思います
私がハマった事を同じ人がハマってほしくないので記載します

経緯

Redmineを使っているサーバーがカーネルパニックという
ブルースクリーン以上に見たくないエラーになりました

ディスクをクローンして復旧させようとしたら
ディスクが回らないという一番ダメなエラーでした
バックアップはとっていたが、 古い環境を用意する手順などは用意していなかった

ハマった内容

ネットで調べた結果、このページにたどり着いた

http://blog.redmine.jp/articles/redmine-1_2-installation_centos/

この記事がなくなるのがいやなのでバックアップした

自分の環境は
CentosOS 6.7
Ruby 1.8.7
Ruby Gems は不明

この記事どおりにおこなうと Passengerが認識しないという悲しい状況になります 認識しないというのは語弊がありますが 兎にも角にもRailsが起動できなかった

ハマった内容の対応

変更した手順は

gem install passenger --no-rdoc --no-ri

gem install passenger --no-rdoc --no-ri -v=3.0.7

ここにたどり着くのに8時間もかかった 色なことをした・・・

ハマっていないけど変更した内容

rubyのインストール

手順だとダウンロードする方式だったけど

yum install ruby -y
yum install ruby-devel -y
yum install rubygem* -y

にした

今後、yumが使えない状況になったらダウンロード手順にするかな

今後

いずれはCentosOS 6.7やRuby 1.8.7がインストールできない状況が発生する
それに向けてバージョンアップしていこうと思う
バージョンアップする費用をください

手順

手順はバックアップしたが、ここにも残す。

SELinuxを無効にする

$ vi /etc/sysconfig/selinux

SELINUX=enforcing
↓
SELINUX=disabled

# 確認
$ getenforce
# DisabledでOK

iptablesを無効

Firewallは別でやっているので無効にする

service iptables stop
chkconfig iptables off

必要なパッケージのインストール

# 開発ツール(Cコンパイラ等):

$ yum groupinstall "Development Tools" -y

# RubyとPassengerのビルドに必要なヘッダファイルなど:

$ yum install openssl-devel readline-devel zlib-devel curl-devel -y

# MySQLとヘッダファイル:

$ yum install mysql-server mysql-devel -y

#Apacheとヘッダファイル:
$ yum install httpd httpd-devel -y

# ruby
$ yum install ruby -y
$ yum install ruby-devel -y
$ yum install rubygem* -y

Rubyダウンロードでインストールする場合

cd /tmp
wget https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/rubyenterpriseedition/ruby-enterprise-1.8.7-2012.02.tar.gz
tar zxvf ruby-enterprise-1.8.7-2012.02.tar.gz
ruby-enterprise-1.8.7-2012.02/installer --dont-install-useful-gems --no-dev-docs

gemパッケージのインストール

$ gem install rack -v=1.1.1 --no-rdoc --no-ri
$ gem install rake -v=0.8.7 --no-rdoc --no-ri
$ gem install i18n -v=0.4.2 --no-rdoc --no-ri
$ gem install mysql --no-rdoc --no-ri

MySQLの設定

1・設定ファイル(/etc/my.cnf)を修正する

vi /etc/my.cnf

character-set-server=utf8を追加する

修正前

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

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

修正後

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
default-character-set=utf8

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

[mysql]
default-character-set=utf8

2・MySQLの起動および自動起動の設定

$ service mysqld start
$ chkconfig mysqld on

3・mysqlのrootユーザーの設定変更とRedmineのDB作成

mysql -uroot

ログイン後に以下と実行

select user,host,password from mysql.user;
set password for root@localhost=password('tekitouna_password');
set password for root@'HOSTNAME'=password('tekitouna_password');
set password for root@127.0.0.1=password('tekitouna_password');
select user,host,password from mysql.user;
create database db_redmine default character set utf8;
grant all on db_redmine.* to user_redmine identified by 'tekitouna_password';
flush privileges;

※ tekitouna_password の部分は任意のパスワードを設定してください。このパスワードは後述のdatabase.ymlの設定で使用します。

Redmineのインストール

https://ja.osdn.net/projects/sfnet_redsf/downloads/redmine-1.2.0.tar.gz/ からダウンロードしてサーバーにアップする

アップ先は /rootとする

$ cd /root
$ tar zxvf redmine-1.2.0.tar.gz
$ mv redmine-1.2.0 /var/lib/redmine
$ cd /var/lib/redmine
$ vi /var/lib/redmine/config/database.yml

以下の内容を追加

production:
  adapter: mysql
  database: db_redmine
  host: localhost
  username: user_redmine
  password: tekitouna_password
  encoding: utf8

tekitouna_password 部分は、MySQL上に作成したRedmineユーザーのパスワードです。 もしどうしても接続できないならrootとかにする

$ cd /var/lib/redmine
$ cp /var/lib/redmine/config/configuration.yml.example /var/lib/redmine/config/configuration.yml
$ vi /var/lib/redmine/config/configuration.yml

以下の内容を追加

production:
  email_delivery:
    delivery_method: :smtp
    smtp_settings:
      address: "localhost"
      port: 25
      domain: 'foo.com'

セッションデータ暗号化用鍵の生成とテーブル作成 '''sh $ rake generate_session_store $ rake db:migrate RAILS_ENV=production '''

Passengerのインストール

$ cd /var/lib/redmine
$ gem install passenger --no-rdoc --no-ri -v=3.0.7
$ passenger-install-apache2-module

インストールが完了すると以下の様に表示される

クリックすると展開されます

Please edit your Apache configuration file, and add these lines:  
LoadModule passenger_module  
 /usr/lib/ruby/gems/1.8/gems/passenger-3.0.7/ext/apache2/mod_passenger.so  
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-3.0.7
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 Rails application in /somewhere. Add a virtual host to your  
Apache configuration file and set its DocumentRoot to   /somewhere/public:  
   <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/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 /etc/sysconfig/httpd

#HTTPD=/usr/sbin/httpd.worker
#↓
HTTPD=/usr/sbin/httpd.worker
$ vi /etc/sysconfig/httpd
#DocumentRoot "/var/www/html"
#↓
DocumentRoot "/var/lib/redmine/public"```

一番最後に下記を追加

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

Header always unset "X-Powered-By"
Header always unset "X-Rack-Cache"
Header always unset "X-Content-Digest"
Header always unset "X-Runtime"

パーミッションの変更

chown -R apache:apache /var/lib/redmine

apacheの再起動

$ service httpd start
$ chkconfig httpd on