LoginSignup
58
56

More than 5 years have passed since last update.

CentOS 6.5にRedmine 2.5.1をnginx+UnicornでインストールしてSSL導入(GitLabと共存)

Last updated at Posted at 2014-04-30

CentOS 6.5にRedmine 2.5.1をnginx+UnicornでインストールしてSSL導入(GitLabと共存)

以前に入れたサーバーにjenkinsを共存させる。
CentOS 6.5にGitLab 6.8をインストールとSSL導入
http://qiita.com/narumi888/items/da664ce0aca5373fd9aa

既にGitLabが公開されているのでサブディレクトリに配置。

https://IPアドレス/redmine

環境は2014/4/25時点で全て最新のものを使用。
CentOS:6.5
Redmine:2.5.1
Ruby:2.1.0
nginx:1.6.0

以下のサイトを参考にさせて頂きました。
ありがとうございました。
Redmine 2.5をCentOS 6.5にインストールする手順
http://blog.redmine.jp/articles/2_5/installation_centos/
CentOS 6.3にRedmine + Unicorn + nginxな環境を構築する手順
http://qiita.com/s-yamaz@github/items/5b32919ea33caddbca82

SELinuxを無効にする

# vi /etc/sysconfig/selinux

SELINUX=disabled

再起動。

# reboot

無効を確認。

# getenforce
Disabled

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

リポジトリの登録

# rpm -Uvh  http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

epelが含まれているのを確認。

# yum repolist
epel             Extra Packages for Enterprise Linux 6 - x86_64

開発ツール(Cコンパイラ等)のインストール

ログ無しで長いので注意。

# yum groupinstall "Development Tools" 

Rubyのビルドに必要なヘッダファイルなどのインストール

# yum install openssl-devel readline-devel zlib-devel curl-devel libyaml-devel

MySQLとヘッダファイルのインストール

# yum  install mysql-server mysql-devel

mageMagickとヘッダファイル・日本語フォントのインストール

# yum install ImageMagick ImageMagick-devel ipa-pgothic-fonts

Rubyインストール

# cd /tmp
# wget http://ftp.ruby-lang.org/pub/ruby/ruby-2.1.0.tar.gz
# tar zxvf ruby-2.1.0.tar.gz
# cd ruby-2.1.0
# ./configure
# make
# make install
# gem install bundler

bundlerのインストール

# gem install bundler

MySQLの設定

デフォルトキャラクタセットをutf8に設定

# vi /etc/my.cnf

[mysqld]
character-set-server=utf8

[mysql]
default-character-set=utf8

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

# service mysqld start
# chkconfig mysqld on

/etc/my.cnf への設定が反映されていることの確認

character_sets_dir 以外の値がすべて utf8 になっていることを確認。

# mysql -uroot
mysql> show variables like 'character_set%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| 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)
mysql> exit

rootユーザーのパスワード変更・匿名ユーザー削除ほかセキュリティ向上

MySQLのセキュリティ向上のために、初期設定ツール mysql_secure_installation を実行。
rootパスワードの設定や不要なユーザー・データベースの削除。

mysql_secure_installation
      :
    (中略)
      :
Enter current password for root (enter for none):   (そのままEnterキーを押す)
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] y
New password:   (MySQLのrootユーザーに新たに設定するパスワードを入力)
Re-enter new password:   (新パスワードを再入力)
Password updated successfully!
Reloading privilege tables..
 ... Success!
      :
    (中略)
      :
Remove anonymous users? [Y/n] y  (匿名ユーザーを削除)
 ... Success!
      :
    (中略)
      :
Disallow root login remotely? [Y/n] y  (rootユーザーの接続元をlocalhostに限定)
 ... Success!
      :
    (中略)
      :
Remove test database and access to it? [Y/n] y  (testデータベースを削除)
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!
      :
    (中略)
      :
Reload privilege tables now? [Y/n] y  (これまでの変更を直ちに適用)
 ... Success!

Redmine用データベースとユーザーの作成

パスワードは任意で設定。

mysql -uroot -p
mysql> create database db_redmine default character set utf8;
mysql> grant all on db_redmine.* to user_redmine@localhost identified by 'パスワード';
mysql> flush privileges;
mysql> exit;

Redmineのインストール

ダウンロードして任意の場所に配置

# cd /tmp
# wget http://www.redmine.org/releases/redmine-2.5.1.tar.gz
# tar xvf redmine-2.5.1.tar.gz
# mv redmine-2.5.1 /var/lib/redmine

データベースへの接続設定

database.ymlを作成。
パスワードはDB作成時の物を設定。

# vi /var/lib/redmine/config/database.yml

production:
  adapter: mysql2
  database: db_redmine
  host: localhost
  username: user_redmine
  password: パスワード
  encoding: utf8

設定ファイル config/configuration.yml の作成

Redmineからメールサーバへ接続するための設定や
日本語フォントファイルのパスを記述した設定ファイルを作成。
アップロードされたファイルの保管場所や、データベースの暗号化なども設定できる。

# vi /var/lib/redmine/config/configuration.yml

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

  rmagick_font_path: /usr/share/fonts/ipa-pgothic/ipagp.ttf

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

アプリケーションが必要とするGemを一括してインストール。

bundle install --without development test

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

# bundle exec rake generate_secret_token
# RAILS_ENV=production bundle exec rake db:migrate

Unicornをインストール

Gemfile.localを作成し以下を記述。

# vi /var/lib/redmine/Gemfile.local

gem 'unicorn'

インストール。

# bundle install

Unicornの設定とサービス化

サブディレクトリに変更。
unicorn起動時に --path /redmineを付加すると
ENV['RAILS_RELATIVE_URL_ROOT']に/redmineが入るため
/redmineでアクセスできる、

# vi /var/lib/redmine/config.ru

require ::File.expand_path('../config/environment',  __FILE__)

if ENV['RAILS_RELATIVE_URL_ROOT']
  map ENV['RAILS_RELATIVE_URL_ROOT'] do
    run RedmineApp::Application
  end
else
  run RedmineApp::Application
end

はまり点

working_directoryをプロジェクトのパスにしないと、
パーミッションエラーが発生したので修正。

# vi /var/lib/redmine/config/unicorn.rb 

working_directory '/var/lib/redmine'

起動スクリプト作成

起動スクリプトを記述して配置。

# vi /etc/init.d/redmine

unicorn起動時に上述の--path /redmineを付加。
MySQLより起動が遅かったため起動順序を設定。

#!/bin/sh

# REDMINE
# Maintainer: @narumi
# Authors: narumi

### BEGIN INIT INFO
# Provides:          redmine
# Required-Start:    $local_fs $remote_fs $network $syslog redis-server
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Redmine
# Description:       Redmine
# chkconfig: - 75 25
### END INIT INFO

export PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin

APP_NAME=redmine
APP_ROOT="/var/lib/$APP_NAME" 
APP_PATH="/redmine" 
CONFIGS="$APP_ROOT/config/unicorn.rb" 
PID="$APP_ROOT/tmp/unicorn.pid" 
ENV=production
PORT=5001

UNICORN_OPTS="-D -E $ENV -c $CONFIGS --path $APP_PATH -p $PORT" 

start()
{
  if [ -e $PID ]; then
    echo "$APP_NAME already started";
    exit 1;
  fi
  echo "start $APP_NAME";
  cd $APP_ROOT
  bundle exec unicorn_rails $UNICORN_OPTS
}

stop()
{
  if [ ! -e $PID ]; then
    echo "$APP_NAME not started";
    exit 1;
  fi
  echo "stop $APP_NAME";
  kill -QUIT `cat ${PID}`
  rm -f $PID
}

force_stop()
{
  if [ ! -e $PID ]; then
    echo "$APP_NAME not started";
    exit 1;
  fi
  echo "stop $APP_NAME";
  kill -TERM `cat ${PID}`
  rm -f $PID
}

reload()
{
  if [ ! -e $PID ]; then
    echo "$APP_NAME not started";
    start
    exit 0;
  fi
  echo "reload $APP_NAME";
  kill -HUP `cat ${PID}`
}

restart()
{
  stop
  start
}

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  force-stop)
    force_stop
    ;;
  reload)
    reload
    ;;
  restart)
    restart
    ;;
  *)
    echo "Syntax Error: release [start|stop|force-stop|reload|restart]" 
    ;;
esac

exit

権限を設定。

# chmod 755 /etc/init.d/redmine

サービス登録

# chkconfig --add redmine
# chkconfig redmine on
# chkconfig --list redmine
redmine         0:off   1:off   2:on    3:on    4:on    5:on    6:off

サービス起動

# service redmine start

nginxの設定

以下でNginxのインストールと設定を行っている事を前提。
CentOS 6.5にGitLab 6.8をインストールとSSL導入
http://qiita.com/narumi888/items/da664ce0aca5373fd9aa

設定ファイル更新

# vi/etc/nginx/conf/gitlab

以下の設定を追加。

# ADD
upstream redmine {
  server unix:/var/lib/redmine/tmp/unicorn.sock fail_timeout=0;
}
serverブロックに以下を追加。

server {
    # ADD
    # redmine
    location ~ /redmine {
        root /var/lib/redmine/public;
        if (-f $request_filename) {
            break;
        }

        proxy_read_timeout 300; # Some requests take more than 30 seconds.
        proxy_connect_timeout 300; # Some requests take more than 30 seconds.
        proxy_redirect     off;

        proxy_set_header   X-Forwarded-Proto $scheme;
        proxy_set_header   Host              $http_host;
        proxy_set_header   X-Real-IP         $remote_addr;
        proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
        proxy_set_header   Host $host;

        proxy_pass         http://redmine;

        access_log  /var/log/nginx/redmine_access.log;
        error_log   /var/log/nginx/redmine_error.log;
    }
}

再起動。

# /etc/init.d/nginx restart

Redmineへアクセス

以下のURLでRedmineの画面が表示される。

https://IPアドレス/redmine

初期のIDとパスは以下。

ID:admin
PASS:admin

初期設定

下記を参照。

Redmineを使い始めるための初期設定
http://redmine.jp/tech_note/first-step/admin/

58
56
0

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
58
56