りんちゃんの日記

日常を書き留めていきます。

02_Redmine3.4のインストール(サーバ2台構成)

2台構成(Webサーバ、DBサーバ)

Redmine version 3.4.5.stable.17343
Ruby version 2.5.1-p57 (2018-03-29) [x86_64-linux]
Rails version 4.2.8

ユーザ名 パスワード 備考
root ****** OSユーザ
root dboracle DBユーザ
redmine pwredmine DBユーザ
admin adminadmin RedMineユーザ

 

1. SELINUXの無効

 1.1. Config編集(両サーバ)
    # vi /etc/selinux/config

  SELINUX=enforcing ※変更前
  SELINUX=disabled  ※変更前

   1.2. firewallをストップ(両サーバ)
    # systemctl stop firewalld

   1.3. 自動起動OFF(両サーバ)
    # systemctl disable firewalld

  Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
   Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

   1.4. ステータス確認(両サーバ)
    # systemctl status firewalld

   1.5. 再起動(両サーバ)
 SELINUXを無効にしたので必須

    # shutdown -r now

 

   1.6. hostsの修正(両サーバ)
 赤文字の部分追加

    # vi /etc/hosts

  127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
  ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
  192.168.11.21 redmineweb →webサーバのipアドレスとホスト名を追加
  192.168.11.22 redminedb    →dbサーバのipアドレスとホスト名を追加

 

   1.7. pingテスト(両サーバ)
   3回パケットがwebサーバに送信できていること

   

    # ping -c 3 redmineweb

         64 bytes from redmineweb (192.168.11.21): icmp_seq=1 ttl=64 time=0.012 ms
         64 bytes from redmineweb (192.168.11.21): icmp_seq=2 ttl=64 time=0.011 ms
         64 bytes from redmineweb (192.168.11.21): icmp_seq=3 ttl=64 time=0.011 ms

    # ping -c 3 redminedb

       64 bytes from redminedb (192.168.11.22): icmp_seq=1 ttl=64 time=0.226 ms
       64 bytes from redminedb (192.168.11.22): icmp_seq=2 ttl=64 time=0.180 ms
       64 bytes from redminedb (192.168.11.22): icmp_seq=3 ttl=64 time=0.130 ms

 


2. パッケージのインストール 

※OSインストール時に導入していたら不要

注意)(両サーバ)
yum -y install gcc
yum -y install svn
yum -y install gcc-c++
yum -y install make

 

   2.1. devel系のインストール devel系のインストール(web)
 # yum -y install openssl-devel readline-devel zlib-devel curl-devel libyaml-devel libffi-devel 

 

   2.2. mariadbクライアントのインストール(web)
 # yum -y install mariadb mariadb-devel

 

   2.3. httpdサーバのインストール (web)
 # yum -y install httpd httpd-devel

 

   2.4. imageMagicのインストール(web)
 # yum -y install ImageMagick ImageMagick-devel ipa-pgothic-fonts

 

   2.5. mariadbサーバのインストール(db)
 # yum -y install mariadb-server mariadb-devel

 


3. Rubyのダウンロードとインストール

 3.1. Ruby2.5ダウンロード(web)
   # curl -O http://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.1.tar.gz

        % Total % Received % Xferd Average Speed Time Time Time Current
        Dload Upload Total Spent Left Speed
        100 15.8M 100 15.8M 0 0 2092k 0 0:00:07 0:00:07 --:--:-- 3824k

   3.2. Rubyのインストール(コンパイル)(web)

 # tar xvf ruby-2.5.1.tar.gz                      ※解凍

 # cd ruby-2.5.1                                       ※Rubyディレクトリに移動

 # ./configure --disable-install-doc        ※makeファイル作成

 # make                                                   ※コンパイル

 # make install                                        ※インストール(rubyインストール)

 # cd ..                                                     ※ディレクトリ移動

   3.3. バージョン確認(web)

 # ruby -v

          ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]


4. bundlerのインストール

 4.1 Ruby用のパッケージ管理ツール(web)
    # gem install bundler --no-rdoc --no-ri
            Fetching: bundler-1.16.0.gem (100%)
            Successfully installed bundler-1.16.0
            1 gem installed

 


5. MariaDBの設定

 5.1 utf8に設定(DB)
    # vi /etc/my.cnf

  [mysqld]
  datadir=/var/lib/mysql
  socket=/var/lib/mysql/mysql.sock
  # Disabling symbolic-links is recommended to prevent assorted security risks
  symbolic-links=0
  # Settings user and group are ignored when systemd is used.
  # If you need to run mysqld under a different user or group,
  # customize your systemd unit file for mariadb according to the
  # instructions in http://fedoraproject.org/wiki/Systemd

  #追加
  character-set-server=utf8

  [mysqld_safe]
  log-error=/var/log/mariadb/mariadb.log
  pid-file=/var/run/mariadb/mariadb.pid

  #
  # include all files from the config directory
  #
  !includedir /etc/my.cnf.d

  #追加
  [mysql]
  default-character-set=utf8

 

 5.2 起動の設定(DB)

    ※DB起動 
    # systemctl start mariadb

    ※DB自動起動
    # systemctl enable mariadb

   Created symlink from /etc/systemd/system/multi- 
   user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.

 

 5.3 MariaDBに接続してUTF8の確認(DB)
    # mysql -u root
    # 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)

    quitで抜ける

 

 5.4 MariaDBのセキュリティの設定(DB)
    # mysql_secure_installation

  NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
   SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
  
  In order to log into MariaDB to secure it, we'll need the current
  password for the root user. If you've just installed MariaDB, and
  you haven't set the root password yet, the password will be blank,
  so you should just press enter here.

  MariaDBのrootユーザーのパスワードを設定入力(例 dboracle
  Enter current password for root (enter for none):             → 「Enter」キーを押す

  Set root password? [Y/n]                   → 「y」キーを押す
  New password:                                                                       → パスワードの設定
  Re-enter new password:                       → パスワードの設定 
  Password updated successfully!
  Reloading privilege tables..
... Success!

  ※匿名ユーザーを削除
  Remove anonymous users? [Y/n]           → 「Enter」キーを押す
   ... Success!

  Normally, root should only be allowed to connect from 'localhost'. This
  ensures that someone cannot guess at the root password from the network.

  ※匿名ユーザーを削除 
  Disallow root login remotely? [Y/n]              → 「Enter」キーを押す
   ... Success!

  By default, MariaDB comes with a database named 'test' that anyone can
  access. This is also intended only for testing, and should be removed
  before moving into a production environment.

  ※rootユーザーの接続元をlocalhostに限定
  Remove test database and access to it? [Y/n]                    → 「Enter」キーを押す
   - Dropping test database...
   ... Success!
   - Removing privileges on test database...
   ... Success!

  Reloading the privilege tables will ensure that all changes made so far
  will take effect immediately.

  ※testデータベースを削除
  Reload privilege tables now? [Y/n]                                      → 「Enter」キーを押す
   ... Success!

  Cleaning up...

  All done! If you've completed all of the above steps, your MariaDB
  installation should now be secure.

  Thanks for using MariaDB!

 

 5.5 Redmine用のデータベースを作成する(DB)
    # mysql --user=root --password=dboracle

 MariaDB [(none)]> create database redmine default character set utf8;
 

 5.6 ユーザを作成する(DB)
 redmine用のユーザとパスワードを設定する
     例)ユーザ名:redmine パスワード:pwredmine

 MariaDB [(none)]> grant all on redmine.* to 'redmine'@'192.168.11.0/255.255.255.0' identified by 'pwredmine';

 ※WebサーバとDBサーバのプライベートアドレスの帯域


 MariaDB [(none)]> flush privileges;
 MariaDB [(none)]> quit

 

 5.7 接続確認(WEB&DB) 
   hostsに設定したdbサーバのホスト名を指定
 # mysql --user=redmine --password=pwredmine --database=redmine --host=redminedb

   MariaDB [(none)]> →上記コマンドで接続ができ、プロンプトが表示されること

 


6. Redmineのインストール(やっと)

 6.1インストール(web)
    /var/lib/redmineにインストールする
    # svn co http://svn.redmine.org/redmine/branches/3.4-stable/ /var/lib/redmine

 

   6.2 database.ymlを作る(web)
 「database.yml.example」を「database.yml」と別名でコピーする
    # cp /var/lib/redmine/config/database.yml.example /var/lib/redmine/config/database.yml

 

   6.3 database.ymlの編集(web)
 productionのpasswordを設定する。

  ※【4】の⑦で追加したredmineユーザのパスワードをここで管理する
  ※ development(開発環境)はしない

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

  production:
   adapter: mysql2
   database: redmine       ※DB名
   host: redminedb           ※hostsに設定したdbサーバのホスト名を指定
   username: redmine
   password: "*******"       ※パスワード入力
   encoding: utf8

 

  6.4 configuration.yml を作る(web)
 「
configuration.yml.example」を「configuration.yml」と別名でコピーする
    # cp /var/lib/redmine/config/configuration.yml.example /var/lib/redmine/config/configuration.yml

 

  6.5 configuration.ymlの編集(web)
 
メールアドレスとアプリパスワードを設定する(configuration.yml)
    # vi /var/lib/redmine/config/configuration.yml

 注意)赤文字の部分を追加

 -------------------------------------------------------------------------------------------

    # = Redmine configuration file
  #
  # Each environment has it's own configuration options. If you are only
  # running in production, only the production block needs to be configured.
  # Environment specific configuration options override the default ones.
  #
  # Note that this file needs to be a valid YAML file.
  # DO NOT USE TABS! Use 2 spaces instead of tabs for identation.

  # default configuration options for all environments
  default:
   # Outgoing emails configuration
   # See the examples below and the Rails guide for more configuration options:
   # http://guides.rubyonrails.org/action_mailer_basics.html#action-mailer-configuration
   email_delivery:

  (省略)

   # ==== SMTP server at using TLS (GMail)
   # This might require some additional configuration. See the guides at:
   # http://www.redmine.org/projects/redmine/wiki/EmailConfiguration
   #
   # email_delivery:
   # delivery_method: :smtp
   # smtp_settings:
   # enable_starttls_auto: true
   # address: "smtp.gmail.com"
   # port: 587
   # domain: "smtp.gmail.com" # 'your.domain.com' for GoogleApps
   # authentication: :plain
   # user_name: "your_email@gmail.com"
   # password: "your_password"
   #
   # ==== Sendmail command
   #
   # email_delivery:
   # delivery_method: :sendmail

  ※↑ここの下に記述(ここでないとエラーが起きる可能性)

△の部分を半角に置換
△△email_delivery:
△△△△delivery_method: :smtp
△△△△smtp_settings:
△△△△△△enable_starttls_auto: true
△△△△△△address: "smtp.gmail.com"
△△△△△△port: 587
△△△△△△domain: "smtp.gmail.com" # 'your.domain.com' for GoogleApps
△△△△△△authentication: :plain
△△△△△△user_name: "メールアドレス"
△△△△△△password: "アプリパスワード"

  -------------------------------------------------------------------------------------------

  アプリパスワードの参考ページ

   http://phjkahby98327u5o0qwe709uli.blogspot.jp/2015/12/redminegmail534-5714.html
   https://support.google.com/mail/answer/185833?hl=ja

 

   6.6 Redmineが依存するgemパッケージのインストール(web)
 
Redmineのインストールのディレクトリに移動してからインストールをする。
    # cd /var/lib/redmine
    # bundle install --without development test --path vendor/bundle

 

   6.7 セッション改ざん防止用秘密鍵を作る(web)
    # bundle exec rake generate_secret_token
         /var/lib/redmine/vendor/bundle/ruby/2.2.0/gems/htmlentities
        4.3.1/lib/htmlentities/mappings/expanded.rb:465: warning: duplicated key at line 466 ignored: "inodot"

 

   6.8 データベースのテーブル作成(web)
 
config/database.ymlで指定したDBにテーブルを作る
    # RAILS_ENV=production bundle exec rake db:migrate
        -- create_table("attachments", {:force=>true})
       -> 0.0268s
       ~省略~
       == 20150528093249 AddUniqueIndexOnRolesManagedRoles: migrating ================
       -- add_index(:roles_managed_roles, [:role_id, :managed_role_id], {:unique=>true})
       -> 0.0578s
       == 20150528093249 AddUniqueIndexOnRolesManagedRoles: migrated (0.0579s) =======

 

   6.9 デフォルトデータのロード(web)
 
トラッカー、優先度、ステータス、ロール、ワークフローなどの初期値が登録。
    # RAILS_ENV=production REDMINE_LANG=ja bundle exec rake redmine:load_default_data
        /var/lib/redmine/vendor/bundle/ruby/2.2.0/gems/htmlentities
       4.3.1/lib/htmlentities/mappings/expanded.rb:465: warning: duplicated key at line 466 ignored: "inodot"
       Default configuration data loaded.

  注意
  →エラーがおきる→エラーがおきるデフォルトデータの登録は、
  コマンドラインではなくRedmine起動後に管理画面から実行できるのでスルー

 

 


7. Passengerのインストール

 7.1 Phusion Passengerをインストール(web)
  Phusion Passengerとは、ApacheRailsアプリケーションの実行するためのもの。
    # gem install passenger --no-rdoc --no-ri

        Fetching: rack-2.0.4.gem (100%)
        Successfully installed rack-2.0.4
        Fetching: passenger-5.2.3.gem (100%)
        Building native extensions. This could take a while...
        Successfully installed passenger-5.2.3
        2 gems installed

 

 7.2 Apache用のモジュールのビルドとインストール(web) ※ちょと時間かかる
    # passenger-install-apache2-module --auto

   ・
   ・
  https://www.phusionpassenger.com/library/deploy/apache/deploy/
  Enjoy Phusion Passenger, a product of PhusionR (www.phusion.nl) :-)
  https://www.phusionpassenger.com

  PassengerR is a registered trademark of Phusion Holding B.V.

 

 7.3 Passengerを利用するためのApache用設定を表示してメモする。(web)
    # passenger-install-apache2-module --snippet

 ↓ここをテキストにコピっておく。次の8.2(redmine.conf)で使用

  LoadModule passenger_module /usr/local/lib/ruby/gems/2.5.0/gems/passenger-5.3.1/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /usr/local/lib/ruby/gems/2.5.0/gems/passenger-5.3.1
PassengerDefaultRuby /usr/local/bin/ruby
</IfModule>

 


8. Apacheの設定

 8.1 redmine.confを作成する(新規作成)(web)
  CentOSではApache起動時に /etc/httpd/conf.d/*.conf が自動的に読み込まれます。
    # touch /etc/httpd/conf.d/redmine.conf

 

 8.2 redmine.confを編集する(web)

    # vi /etc/httpd/conf.d/redmine.conf

 注意)下記全て記述(まっさらなファイルなので)

  # 画像・CSSJavaScript等をブラウザで読み込むことができるようにする。
  <Directory "/var/lib/redmine/public">
   Require all granted
  </Directory>

  # Passengerの基本設定。
  # passenger-install-apache2-module --snippet を実行して表示される設定を使用。
   LoadModule passenger_module /usr/local/lib/ruby/gems/2.5.0/gems/passenger-5.3.1/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
      PassengerRoot /usr/local/lib/ruby/gems/2.5.0/gems/passenger-5.3.1
      PassengerDefaultRuby /usr/local/bin/ruby
</IfModule>

  # Passengerが追加するHTTPヘッダを削除するための設定(任意)。
  Header always unset "X-Powered-By"
  Header always unset "X-Runtime"

  # 必要に応じてPassengerのチューニングのための設定を追加(任意)。
  # 詳しくはPhusion Passenger users guide(http://www.modrails.com/documentation/Users%20guide%20Apache.html)参照。
  PassengerMaxPoolSize 20
  PassengerMaxInstancesPerApp 4
  PassengerPoolIdleTime 864000
  PassengerHighPerformance on
  PassengerStatThrottleRate 10
  PassengerSpawnMethod smart
  PassengerFriendlyErrorPages off

 

 8.3 Apache自動起動の設定(web)
    # systemctl enable httpd

    symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to                   /usr/lib/systemd/system/httpd.service.

 8.4 オーナの変更(web)
    # chown -R apache:apache /var/lib/redmine

 

 8.5 ドキュメントルートの設定(web)
    CentOSではApache起動時に /etc/httpd/conf.d/*.conf が自動的に読み込まれます。
    # vi /etc/httpd/conf/httpd.conf

     #変更前
     DocumentRoot "/var/www/html"

     #変更後
     DocumentRoot "/var/lib/redmine/public"

 

 8.6 ApacheのConfigTest(web)
    # apachectl configtest

       AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using      
      fe80::36fd:e098:9d1c:b577. Set the 'ServerName' directive globally to suppress this message

      Syntax OK

 

 8.7 Apacheの起動(web)
    # systemctl start httpd

 

 8.8 Apacheのプロセス確認(web)
 起動されているかの確認
    # systemctl status httpd

  ● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since 土 2018-04-21 19:49:54 JST; 36s ago
   Docs: man:httpd(8)
        man:apachectl(8)
   Process: 9396 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
   Main PID: 9412 (httpd)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
   CGroup: /system.slice/httpd.service
   tq9412 /usr/sbin/httpd -DFOREGROUND
   tq9439 Passenger watchdog
   tq9446 Passenger core
   tq9455 /usr/sbin/httpd -DFOREGROUND
   tq9458 /usr/sbin/httpd -DFOREGROUND
   tq9460 /usr/sbin/httpd -DFOREGROUND
   tq9469 /usr/sbin/httpd -DFOREGROUND
   mq9470 /usr/sbin/httpd -DFOREGROUND

   4月 21 19:49:48 softbank2 systemd[1]: Starting The Apache HTTP Server...
   4月 21 19:49:54 softbank2 httpd[9412]: AH00558: httpd: Could not reliably determine the server's fully     qualified dom...essage
   4月 21 19:49:54 softbank2 systemd[1]: Started The Apache HTTP Server.
  Hint: Some lines were ellipsized, use -l to show in full.

または

  # ps aux | grep httpd(web)

  root 9412 0.0 0.0 298940 7020 ? Ssl 19:49 0:00 /usr/sbin/httpd -DFOREGROUND
  apache 9455 0.0 0.0 298940 3440 ? S 19:49 0:00 /usr/sbin/httpd -DFOREGROUND
  apache 9458 0.0 0.0 298940 3440 ? S 19:49 0:00 /usr/sbin/httpd -DFOREGROUND
  apache 9460 0.0 0.0 298940 3440 ? S 19:49 0:00 /usr/sbin/httpd -DFOREGROUND
  apache 9469 0.0 0.0 298940 3440 ? S 19:49 0:00 /usr/sbin/httpd -DFOREGROUND
  apache 9470 0.0 0.0 298940 3440 ? S 19:49 0:00 /usr/sbin/httpd -DFOREGROUND
  root 9475 0.0 0.0 112676 980 pts/0 S+ 19:50 0:00 grep --color=auto httpd

 

 8.9 ブラウザで確認
    http://192.168.11.13/