瞳孔が開くほど簡単にredmineを構築できる「Bitnami」 (2)
bitnamiネタで幾つか備忘録を残して置くつもりがすっかり忘れていました。
redmineでAPIのテスト環境作るときに、複数テスト環境あると便利ですよね。bitnamiを使って1つのサーバーに簡単に複数のredmineを作るTIPSを載せておきます。
構成
3つのredmineを1つのサーバーにインストールしてみます。以下はインストール先とポート番号です。最初のredmineがメインになります。
| prefix | http | https | mysql | subversion | |
|---|---|---|---|---|---|
| メインredmine | /opt/release | 80 | 443 | 33860 | 36900 |
| サブredmine | /opt/staging | 80 | 443 | 33861 | 36901 |
| サブredmine | /opt/dev | 80 | 443 | 33862 | 36902 |
インストール方法
メインredmineのインストール(/opt/release)
普通にインストールします。違うのはオプションでapacheやmysqlなどのポートを指定してインストールします。イントールが終わったらすぐにredmineのサービスを停止します。次のredmineをインストールする際にポートが衝突するからです。
$ ./bitnami-redmine-2.4.3-0-linux-x64-installer.run \ --prefix /opt/release \ --apache_server_port 80 \ --apache_server_ssl_port 443 \ --mysql_port 33860 \ --subversion_port 36900 \ --installer-language en $ /opt/release/ctlscript.sh stop
こんな感じで次のredmineをインストールする際に、apacheやmysqやsubversionのポートを違うものにしてインストールすれば、1つのサーバーに複数のredmineのインストールが可能です。
サブredmineのインストール(/opt/starging)
最初のredmineのインストールが終わったら2つ目をインストールします。
$ ./bitnami-redmine-2.4.3-0-linux-x64-installer.run \ --prefix /opt/staging \ --apache_server_port 80 \ --apache_server_ssl_port 443 \ --mysql_port 33861 \ --subversion_port 36901 \ --installer-language en $ /opt/staging/ctlscript.sh stop
サブredmineのインストール(/opt/dev)
3つ目をインストールします。
$ ./bitnami-redmine-2.4.3-0-linux-x64-installer.run \ --prefix /opt/dev \ --apache_server_port 80 \ --apache_server_ssl_port 443 \ --mysql_port 33862 \ --subversion_port 36902 \ --installer-language en $ /opt/dev/ctlscript.sh stop
設定方法
サブredmineのapacheを起動しないようにします。
$ ls -l /opt/{staging,dev}/apache2/scripts/ctl.sh
-rwxr-xr-x 1 root root 2475 Feb 15 16:51 /opt/dev/apache2/scripts/ctl.sh
-rwxr-xr-x 1 root root 2491 Feb 15 16:47 /opt/staging/apache2/scripts/ctl.sh
$ mv /opt/dev/apache2/scripts/ctl.sh /opt/dev/apache2/scripts/ctl.sh.backup
$ mv /opt/staging/apache2/scripts/ctl.sh /opt/staging/apache2/scripts/ctl.sh.backup
メインredmineとサブredmineのサブディレクトリ名を変更
http://example/redmine -> http://example/release のようなURLでアクセス出来るようにします。修正は以下のように。
$ vim /opt/release/apps/redmine/conf/httpd-app.conf
<Directory "/opt/release/apps/redmine/htdocs/public">
PassengerEnabled on
Options -MultiViews
AllowOverride All
<IfVersion < 2.3 >
Order allow,deny
Allow from all
</IfVersion>
<IfVersion >= 2.3>
Require all granted
</IfVersion>
#SetEnv RAILS_RELATIVE_URL_ROOT "/redmine"
SetEnv RAILS_RELATIVE_URL_ROOT "/release"
PassengerAppRoot "/opt/release/apps/redmine/htdocs"
<IfModule pagespeed_module>
ModPagespeedDisallow "*"
</IfModule>
</Directory>
#PassengerPreStart http://127.0.0.1:80/redmine
PassengerPreStart http://127.0.0.1:80/release面倒なのでsedで編集すると楽です。
$ sed -i -e "s@\"/redmine\"@\"/release\"@g" -e "s@80/redmine@80/release@g" /opt/release/apps/redmine/conf/httpd-app.conf $ sed -i -e "s@\"/redmine\"@\"/staging\"@g" -e "s@80/redmine@80/staging@g" /opt/staging/apps/redmine/conf/httpd-app.conf $ sed -i -e "s@\"/redmine\"@\"/dev\"@g" -e "s@80/redmine@80/dev@g" /opt/dev/apps/redmine/conf/httpd-app.conf
Aliaseの設定を変更
$ vim /opt/release/apps/redmine/conf/httpd-prefix.conf #Alias /redmine/ "/opt/release/apps/redmine/htdocs/public/" #Alias /redmine "/opt/release/apps/redmine/htdocs/public" Alias /release/ "/opt/release/apps/redmine/htdocs/public/" Alias /release "/opt/release/apps/redmine/htdocs/public" Include "/opt/release/apps/redmine/conf/httpd-app.conf"
これも面倒なのでsedで編集すると楽です。
$ ls -l /opt/*/apps/redmine/conf/httpd-prefix.conf -rw-r--r-- 1 root daemon 161 Feb 15 16:56 /opt/dev/apps/redmine/conf/httpd-prefix.conf -rw-r--r-- 1 root daemon 173 Feb 15 16:48 /opt/release/apps/redmine/conf/httpd-prefix.conf -rw-r--r-- 1 root daemon 173 Feb 15 16:52 /opt/staging/apps/redmine/conf/httpd-prefix.conf $ sed -i -e "s@Alias /redmine@Alias /release@g" /opt/release/apps/redmine/conf/httpd-prefix.conf $ sed -i -e "s@Alias /redmine@Alias /staging@g" /opt/staging/apps/redmine/conf/httpd-prefix.conf $ sed -i -e "s@Alias /redmine@Alias /dev@g" /opt/dev/apps/redmine/conf/httpd-prefix.conf
Includでconfを統合
メインredmineのbitnami-apps-prefix.confでサブredmineのconfをincludeします。
$ vim /opt/release/apache2/conf/bitnami/bitnami-apps-prefix.conf # Bitnami applications installed in a prefix URL Include "/opt/release/apps/phpmyadmin/conf/httpd-prefix.conf" Include "/opt/release/apps/redmine/conf/httpd-prefix.conf" # add Include "/opt/staging/apps/redmine/conf/httpd-prefix.conf" Include "/opt/dev/apps/redmine/conf/httpd-prefix.conf"
redmineを起動
サブredmineから起動します。
$ /opt/staging/ctlscript.sh start $ /opt/dev/ctlscript.sh start $ /opt/release/ctlscript.sh start