Amazon Lightsail CentOS7にRedmineを入れてみたので、覚書。RedmineはRuby on Railsの上で動作しているようです(今まで仕事で散々使ってきたのに、お恥ずかしながら初めて知ったという笑)。
環境
・CentOS 7.6.1810
・Apache 2.4.38
・MariaDB 10.3.13
・Ruby 2.5.3
・Ruby on Rails 5.2.2
・Redmine 4.0
Apache 2.4.38、MariaDB、Let’s Encrypt(certbot)はインストール済みの前提で進めます。
1. 必要なパッケージをいろいろインストール
$ sudo -i # yum -y update # yum -y install openssl-devel readline-devel zlib-devel curl-devel libyaml-devel libffi-devel ruby-devel bzip2 git # yum -y install httpd-devel # (yum --disablerepo=base,extras,updates --enablerepo=ius -y install httpd-devel) ※iusからhttpdをインストールしている場合 # yum -y install ImageMagick ImageMagick-devel ipa-pgothic-fonts # yum -y install MariaDB-devel MariaDB-shared
2. Ruby 2.5.3をインストール
Rubyは直接インストールするのでなく、Rbenvを介してインストールします。
# git clone https://github.com/rbenv/rbenv.git ~/.rbenv # git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build # vim ~/.bashrc -------------------------------------- . . # rbenv export PATH="$HOME/.rbenv/bin:$PATH" eval "$(rbenv init -)" -------------------------------------- :wq -------------------------------------- # source ~/.bashrc # rbenv -v # rbenv install --list # rbenv install 2.5.3 # 時間がかかります # rbenv global 2.5.3 # ruby -v
3. Ruby on Rails 5.2.2をインストール
bundleはrootで実行するな、と警告が出ますが無視。rootじゃないユーザでやったら色々ハマったので。
# gem install bundler # gem query -ra -n "^rails$" # mkdir /usr/local/rails_v5.2.2 # cd /usr/local/rails_v5.2.2 # bundle init # echo 'gem "rails", "5.2.2"' >> Gemfile # gem install mysql2 -v '0.5.2' # bundle install --without development test --path vendor/bundle
4. Passenger 6.0.2 をインストール
Railsを動かすためのApacheモジュールであるPassengerをインストールします。ものすごく時間がかかります。Lightsail $3.5の最弱プランで30分以上。
apache2モジュールインストール前に、chmod o+x “/root”でその他ユーザに実行権限を付与しておくのが肝。そして、httpdのapxsのパスを指定します。httpdをyumで入れているまともな人は –apxs2-path の代わりに –autoで良いです。
# gem install passenger # chmod o+x "/root" # passenger-install-apache2-module --apxs2-path "/usr/local/httpd3/bin/apxs" # めちゃくちゃ時間がかかります 1 [Enter] ●Ruby ●Python [Enter] y [Enter] . . . ★30分以上。気長に待ちましょう★ . . [Enter] [Enter]
5. MariaDBにRedmine用のDBとユーザを作成
# mysql -u root -p > create database redmine_db default character set utf8; > create user 'redmine_ur'@'localhost' IDENTIFIED BY '************'; > grant all on redmine_db.* to redmine_ur@localhost identified by '************'; > exit;
6. Redmine 4.0を /var/lib/redmine にインストール
# svn co http://svn.redmine.org/redmine/branches/4.0-stable /var/lib/redmine
# vim /var/lib/redmine/config/database.yml
--------------------------------------
production:
adapter: mysql2
database: redmine_db
host: localhost
username: redmine_ur
password: "************"
encoding: utf8
--------------------------------------
:wq
--------------------------------------
# vim /var/lib/redmine/config/configuration.yml
--------------------------------------
production:
email_delivery:
delivery_method: :smtp
smtp_settings:
address: "localhost"
port: 25
domain: "redmine.ji0vwl.net"
rmagick_font_path: /usr/share/fonts/ipa-pgothic/ipagp.ttf
--------------------------------------
:wq
--------------------------------------
# cd /var/lib/redmine/
# bundle update
# bundle exec rake generate_secret_token
# RAILS_ENV=production bundle exec rake db:migrate
# RAILS_ENV=production REDMINE_LANG=ja bundle exec rake redmine:load_default_data
# sudo chown -R apache:apache /var/lib/redmine
7. httpdのバーチャルホスト設定
DocumentRootはRedmineインストール先の /var/lib/redmine/public とし、passenger-install-apache2-module –snippet で得られた応答を、HTTPSのバーチャルホスト内に貼り付けます。HTTPのバーチャルホストは、 HTTPSへのリライト処理のみでOK。
# passenger-install-apache2-module --snippet
LoadModule passenger_module/root/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/passenger-6.0.2/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /root/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/passenger-6.0.2
PassengerDefaultRuby /root/.rbenv/versions/2.5.3/bin/ruby
</IfModule>
# vim /usr/local/httpd3/conf/extra/httpd-vhosts-http.conf
--------------------------------------
.
.
<VirtualHost *:80>
DocumentRoot /var/lib/redmine/public
ServerName redmine.ji0vwl.net
<Directory "/var/lib/redmine/public/public/">
Options FollowSymlinks Includes
AllowOverride All
AddType text/html .html
Require all granted
</Directory>
RewriteEngine on
RewriteCond %{SERVER_NAME} =redmine.ji0vwl.net
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
--------------------------------------
:wq
--------------------------------------
vim /usr/local/httpd3/conf/extra/httpd-vhosts-https.conf
--------------------------------------
.
.
.
<IfModule mod_ssl.c>
<VirtualHost *:443>
DocumentRoot /var/lib/redmine/public
ServerName redmine.ji0vwl.net
<Directory "/var/lib/redmine/public/">
Options FollowSymlinks Includes
AllowOverride All
AddType text/html .html
Require all granted
</Directory>
.
.
.
# passenger-install-apache2-module --snippet の結果をVirtualHost内に貼る
LoadModule passenger_module /root/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/passenger-6.0.2/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /root/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/passenger-6.0.2
PassengerDefaultRuby /root/.rbenv/versions/2.5.3/bin/ruby
</IfModule>
</VirtualHost>
</IfModule>
--------------------------------------
# systemctl restart httpd3
8. Let’s Encrypt SSL証明書にサブドメイン追加
certbot certonlyで、サブドメインを追加します。先にDNS設定をしておくことをお忘れなく。
# certbot certonly . . . # systemctl restart httpd3
Redmineが立ち上がりました。
実はうまく動かず、4回くらいテスト用インスタンスを作っては潰してを繰り返しました。こういうのができるのがAWSのいいところですね。ただ、インストールすることが目的だったので、使い道は決まっていません。