1.SELinuxの無効化
コマンドで一時無効化
sudo setenforce 0
無効化を確認する。「Permissive」と表示されること。
sudo getenforce
再起動後も無効化するようにしておく。
SELINUX=・・・・と記述された行の修正を実施
sudo vi /etc/selinux/config
以下の行を修正
SELINUX=disabled
2.iptablesでHTTPを許可
sudo vi /etc/sysconfig/iptables
以下の行を追加
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
サービス再起動
sudo service iptables restart
3.必要なパッケージのインストール
(1)EPELリポジトリの登録
最新の epel-release パッケージのURLを確認
http://dl.fedoraproject.org/pub/epel/6/x86_64/repoview/epel-release.html
Packages の下の最新のリンクURLをコピーしておく
http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
上記を基にyumリポジトリに追加。http移行はコピーしたURLを貼り付ける
sudo rpm -Uvh epel-release http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
(2)開発ツール(Cコンパイラ等)のインストール
sudo yum groupinstall "Development Tools"
(3)RubyとPassengerのビルドに必要なヘッダファイルなどのインストール
sudo yum -y install openssl-devel readline-devel zlib-devel curl-devel libyaml-devel
(4)MySQLとヘッダファイルのインストール
sudo yum -y install mysql-server mysql-devel
(5)Apacheとヘッダファイルのインストール
sudo yum -y install httpd httpd-devel
(6)ImageMagickとヘッダファイル・日本語フォントのインストール
sudo yum -y install ImageMagick ImageMagick-devel ipa-pgothic-fonts
4.Rubyのインストール
RVMのマルチユーザモードのパターンで記述します。
RVMのインストール
sudo su -
\curl -L https://get.rvm.io | bash -s stable
su - ec2-user
環境変数の再読み込み
source /etc/profile.d/rvm.sh
グループの追加
sudo gpasswd -a root rvm
sudo gpasswd -a ec2-user rvm
Rubyのインストール(Redmineとの対応状況注意です)
rvm install 2.0.0
インストール後の確認
ruby -v
5.bundlerのインストール
gem install bundler --no-rdoc --no-ri
6.MySQLの設定
(1)DB文字コードの修正
緊急時に備えてオリジナルファイルのバックアップ
sudo cp -p /etc/my.cnf /etc/my.cnf.org
DBの文字コードを設定する。
sudo vi /etc/my.cnf
[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
character-set-server=utf8 ←この行を追加
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[mysql] ←この行を追加
default-character-set=utf8 ←この行を追加
MySQLの起動及び自動起動の設定
sudo service mysqld start
sudo chkconfig mysqld on
文字コードの設定が反映されているかを確認する。
character_set_filesystem と character_sets_dir 以外が「utf8」ならOK
mysql -uroot
mysql>
+--------------------------+----------------------------+
| Variable_name
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
(2)セキュリティ設定
sudo mysql_secure_installation
以下対話形式部分
Enter current password for root (enter for none):【Enter押す】
(省略)
Set root password? [Y/n]y
New password:【パスワードを入力】
Re-enter new password:【パスワードを入力】
(省略)
Remove anonymous users? [Y/n]y
Disallow root login remotely? [Y/n]y
Remove test database and access to it? [Y/n]y
Reload privilege tables now? [Y/n]y
(3)Redmine用データベースとユーザーの作成
MySQLデータベースへログイン
mysql -uroot -p
Enter password:【(2)で設定したパスワード】
Redmine用のデータベース作成(名称「db_redmine」)
mysql> create database db_redmine default character set utf8;
データベースに接続するユーザの作成(ユーザ名「user_redmine」、パスワードは任意)
mysql>grant all on db_redmine.* to user_redmine@localhost identified by 【パスワードを入力】;
反映
mysql>flush privileges;
切断
mysql>exit;
7. Redmineの展開と配置
展開
事前にredmineのHPに行き、最新版を取得します。
wget http://www.redmine.org/releases/redmine-2.5.1.tar.gz
tar xvf redmine-2.5.1.tar.gz
配置
sudo mv redmine-2.5.1 /var/lib/redmine
データベース接続定義ファイルのコピー
cd /var/lib/redmine
cp - p database.yml.example database.yml
データベース接続定義修正
sudo vi database.yml
以下のように修正する。他の行は削除しちゃってOKです。
# Default setup is given for MySQL with ruby1.9. If you're running Redmine
# with MySQL and ruby1.8, replace the adapter name with `mysql`.
# Examples for PostgreSQL, SQLite3 and SQL Server can be found at the end.
# Line indentation must be 2 spaces (no tabs).
production:
adapter: mysql2
database: db_redmine
host: localhost
username: user_redmine
password: 【6.(3)で設定したパスワード】
encoding: utf8
設定ファイルの修正
sudo vi configuration.yml
email_delivery:
delivery_method: :smtp
smtp_settings:
#address: smtp.example.net ←コメントアウト
address: "localhost" ←追加
port: 25 ←追加
domain: 'localdomain' ←追加
#authentication: :login ←コメントアウト
#user_name: "redmine@example.net" ←コメントアウト
#password: "redmine" ←コメントアウト
(省略)
rmagick_font_path: /usr/share/fonts/ipa-pgothic/ipagp.ttf
8.Gemパッケージのインストール
bundle install --without development test
9.Redmineの初期設定とデータベースのテーブル作成
cd /var/lib/redmine
bundle exec rake generate_secret_token
RAILS_ENV=production bundle exec rake db:migrate
10.Passengerのインストール
cd /var/lib/redmine
gem install passenger --no-rdoc --no-ri
PassengerのApache用モジュールのインストール
passenger-install-apache2-module
Welcome to the Phusion Passenger Apache 2 module installer, v4.0.42.
This installer will guide you through the entire installation process. It
shouldn't take more than 3 minutes in total.
Here's what you can expect from the installation process:
1. The Apache 2 module will be installed for you.
2. You'll learn how to configure Apache.
3. You'll learn how to deploy a Ruby on Rails application.
Don't worry if anything goes wrong. This installer will advise you on how to
solve any problems.
Press Enter to continue, or Ctrl-C to abort.
(Enter押す)
Which languages are you interested in?
Use <space> to select.
If the menu doesn't display correctly, press '!'
? ? Ruby
? Python
? Node.js
? Meteor
上記表示となった場合は、「!」と入力し、Enterキーを押下
スペースキーで選択し、「」が入力されることを確認
Rubyを選択し、Enterを押下
```
() Ruby
( ) Python
( ) Node.js
( ) Meteor
```
Almost there!
Please edit your Apache configuration file, and add these lines:
LoadModule passenger_module /usr/local/rvm/gems/ruby-2.0.0-p451/gems/passenger-4.0.42/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /usr/local/rvm/gems/ruby-2.0.0-p451/gems/passenger-4.0.42
PassengerDefaultRuby /usr/local/rvm/gems/ruby-2.0.0-p451/wrappers/ruby
</IfModule>
After you restart Apache, you are ready to deploy any number of web
applications on Apache, with a minimum amount of configuration!
Press ENTER to continue.
(Enter押す)
(省略)
And that's it! You may also want to check the Users Guide for security and
optimization tips, troubleshooting and other useful information:
/usr/local/rvm/gems/ruby-2.0.0-p451/gems/passenger-4.0.42/doc/Users guide Apache.html
http://www.modrails.com/documentation/Users%20guide%20Apache.html
Enjoy Phusion Passenger, a product of Phusion (www.phusion.nl) :-)
https://www.phusionpassenger.com
Phusion Passenger is a trademark of Hongli Lai & Ninh Bui.
$
11.Apacheの設定
設定の確認
passenger-install-apache2-module --snippet
LoadModule passenger_module /usr/local/rvm/gems/ruby-2.0.0-p451/gems/passenger-4.0.42/buildout/apache2/mod_passenger.so ←【①】
<IfModule mod_passenger.c>
PassengerRoot /usr/local/rvm/gems/ruby-2.0.0-p451/gems/passenger-4.0.42 ←【②】
PassengerDefaultRuby /usr/local/rvm/gems/ruby-2.0.0-p451/wrappers/ruby ←【③】
</IfModule>
設定ファイルの記述を行う
sudo vi /etc/httpd/conf.d/passenger.conf
# Base Setting
LoadModule passenger_module /usr/local/rvm/gems/ruby-2.0.0-p451/gems/passenger-4.0.42/buildout/apache2/mod_passenger.so ←【①】
PassengerRoot /usr/local/rvm/gems/ruby-2.0.0-p451/gems/passenger-4.0.42 ←【②】
PassengerDefaultRuby /usr/local/rvm/gems/ruby-2.0.0-p451/wrappers/ruby ←【③】
#HTTP Header Setting
Header always unset "X-Powered-By"
Header always unset "X-Rack-Cache"
Header always unset "X-Content-Digest"
Header always unset "X-Runtime"
サービス再起動
sudo service httpd start
sudo chkconfig httpd on
12.Apache上のPassengerでRedmineを実行するための設定
権限変更
sudo chown -R apache:apache /var/lib/redmine
サブディレクトリへのリンク作成
sudo ln -s /var/lib/redmine/public /var/www/html/redmine
Passengerの設定ファイル修正
sudo vi /etc/httpd/conf.d/passenger.conf
#URL Setting
RackBaseURI /redmine ←最下行に追加
動作確認及びサービス再起動
sudo service httpd configtest
sudo service httpd graceful
sudo service httpd restart