LoginSignup
38
40

More than 5 years have passed since last update.

RedmineをAWS EC2上にインストールする手順

Last updated at Posted at 2014-07-22

AWS EC2にRedmineをインストールする手順です。
AMIは最新のAmazon Linuxを使用します。

ソフトウェアバージョン

・Redmine
  2.5.1.stable
・Ruby
  2.0.0-p481 (2014-05-08) [x86_64-linux]
・Rails Version
  3.2.17
・MySQL
 5.5-1.6

インスタンスタイプ

Redmineを使用する上でt2.microだとメモリが足りないようで、t2.small以上が必要となるようです。

手順

1.必要なパッケージのインストール
(1)開発ツール(Cコンパイラ等)のインストール
sudo yum groupinstall "Development Tools"

(2)RubyとPassengerのビルドに必要なヘッダファイルなどのインストール
sudo yum -y install openssl-devel readline-devel zlib-devel curl-devel libyaml-devel

(3)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

2.Rubyのインストール
RVMのマルチユーザモードのパターンで記述します。

(1)RVMのインストール
~2015/7/11 追記最新の環境だとcurl -sSL・・・を実行する必要があります~
sudo su -
curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
\curl -L https://get.rvm.io | bash -s stable

(2)環境変数の再読み込み
source /etc/profile.d/rvm.sh

(3)グループの追加
gpasswd -a root rvm
gpasswd -a ec2-user rvm

(4)Rubyのインストール(Redmineとの対応状況注意です)
rvm install 2.0.0

(5)インストール後の確認
ruby -v

3.bundlerのインストール
gem install bundler --no-rdoc --no-ri
su - ec2-user

4.MySQLの設定
(1)DB文字コードの修正
緊急時に備えてオリジナルファイルのバックアップ
sudo cp -p /etc/my.cnf /etc/my.cnf.org

DBの文字コードを設定する。
sudo vi /etc/my.cnf

my.conf
[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> show variables like 'character_set%';
+--------------------------+----------------------------+
| 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

5. Redmineの展開と配置

(1)ダウンロード
curl -O http://www.redmine.org/releases/redmine-2.5.1.tar.gz

(2)展開
tar xvf redmine-2.5.1.tar.gz

(3)配置
sudo mv redmine-2.5.1 /var/lib/redmine

(4)データベース接続定義
cd /var/lib/redmine/config
cp -p database.yml.example database.yml

データベース接続定義修正
sudo vi database.yml

以下のように修正する。他の行は削除しちゃってOKです。

database.yml
#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: 【4.(3)で設定したパスワード】                         
  encoding: utf8                

(5)redmineの設定
設定ファイルの修正
cp -p configuration.yml.example configuration.yml
sudo vi configuration.yml

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

6.Gemパッケージのインストール
cd /var/lib/redmine
bundle install --without development test

7.Redmineの初期設定とデータベースのテーブル作成

(1)フォルダの移動
cd /var/lib/redmine

(2)セッションのシークレットトークンの作成
bundle exec rake generate_secret_token

(3)データベース初期化
bundle exec rake db:migrate RAILS_ENV=production

8.Passengerのインストール
(1)フォルダの移動
cd /var/lib/redmine

(2)Passenderのインストール
gem install passenger --no-rdoc --no-ri

(3)PassengerのApache用モジュールのインストール
passenger-install-apache2-module

Welcome to the Phusion Passenger Apache 2 module installer, v4.0.46.

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

上記表示となった場合は、「!」と入力

スペースキーで選択し、「*」が入力されることを確認
RubyとPythonが選択されているようなので、「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-p481/gems/passenger-4.0.46/buildout/apache2/mod_passenger.so
   <IfModule mod_passenger.c>
     PassengerRoot /usr/local/rvm/gems/ruby-2.0.0-p481/gems/passenger-4.0.46
     PassengerDefaultRuby /usr/local/rvm/gems/ruby-2.0.0-p481/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-p481/gems/passenger-4.0.46/doc/Users guide Apache.html
  https://www.phusionpassenger.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.

$

9.Apacheの設定

(1)設定の確認
passenger-install-apache2-module --snippet

表示されたものを設定ファイルに書き込むので、番号の箇所を控えてください。

LoadModule passenger_module /usr/local/rvm/gems/ruby-2.0.0-p481/gems/passenger-4.0.46/buildout/apache2/mod_passenger.so ←【①】
<IfModule mod_passenger.c>
PassengerRoot /usr/local/rvm/gems/ruby-2.0.0-p481/gems/passenger-4.0.46 ←【②】
PassengerDefaultRuby /usr/local/rvm/gems/ruby-2.0.0-p481/wrappers/ruby ←【③】
</IfModule>

(2)設定ファイルの記述を行う

設定ファイルの作成
sudo vi /etc/httpd/conf.d/passenger.conf

passenger.conf
# Base Setting
LoadModule passenger_module /usr/local/rvm/gems/ruby-2.0.0-p481/gems/passenger-4.0.46/buildout/apache2/mod_passenger.so ←【①】

PassengerRoot /usr/local/rvm/gems/ruby-2.0.0-p481/gems/passenger-4.0.46 ←【②】
PassengerDefaultRuby /usr/local/rvm/gems/ruby-2.0.0-p481/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"

#URL Setting
RackBaseURI /redmine

サービス再起動
sudo service httpd start
sudo chkconfig httpd on

10.Apache上のPassengerでRedmineを実行するための設定

権限変更
sudo chown -R apache:apache /var/lib/redmine

サブディレクトリへのリンク作成
sudo ln -s /var/lib/redmine/public /var/www/html/redmine

動作確認及びサービス再起動
sudo service httpd configtest
sudo service httpd graceful
sudo service httpd restart

11.Webへのアクセス

(1)URLへのアクセス
http://[PublicIPアドレス]/redmine

(2)ログイン
初期状態だとadmin/adminでログインできるようですが、私は上手く行きませんでした。

早速パスワードリセット・・・・

ruby script/rails console production

2.0.0-p481 :001 > admin_user = User.find_by_login('admin')
2.0.0-p481 :001 > admin_user.password = '新しいパスワード'
2.0.0-p481 :001 > admin_user.save!
2.0.0-p481 :001 > quit
38
40
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
38
40