Joruri CMS 2020 インストール手順

公開日 2020年10月21日

更新日 2023年02月28日

はじめに

Joruri CMS 2020のインストール手順のサンプルを掲載します。

この手順書はインストール方法を把握していただくためのサンプルです。
実際のインストールではこれ以外にセキュリティ関連の設定などを行います。

※お送りしているソースコードの./doc内に最新のインストール手順書がありますので、そちらを参考にインストールを行ってください。

また、この手順書でのインストールは、1台のサーバーにWebサーバー、CMSサーバー、DBサーバーをインストールするオールインワンの構成です。
自治体公式サイトにご利用の場合は、公開画面に大きな負荷がかかった場合も、管理画面の操作に影響しないように、公開用のWebサーバーとCMSサーバーを分離する構成を推奨します。

複数のサーバーでCMSのシステムを構成する場合、各サーバー間のデータ転送の設定を行います。
これらの設定手順は、当社の「サーバー構築サポート」を契約いただいたお客様のみに提供いたします。

WebサーバーのApacheやNginxのインストール・設定手順が公開されているように、インストール手順を公開することが直ちにセキュリティ上の問題になるとは考えていません。
しかし一部ユーザー様においてはインストール手順が公開されていることが問題と考える方がいらっしゃいますので、不特定多数に詳細な手順を公開することを差し控えることとします。

1.想定環境

システム

  • OS: CentOS 8.2
  • Webサーバー: nginx 1.16
  • Appサーバー: unicorn 5.5
  • Database: PostgreSQL 12
  • Ruby: 2.7
  • Rails: 6.0

前提条件

1台のサーバーマシンにJoruriをインストールします。 CentOSはインストール済みとします。

  • サイト名: Joruri
  • サイトURL: joruri.example.com

2.作業ユーザーの変更

rootユーザーに変更します。

$ su -

インストールの作業ログを取得する場合は下記を実行します。

# script /root/joruri_install.log

3.SELinuxの変更

SELinuxを変更します。

# setenforce 0
# vi /etc/sysconfig/selinux
---
SELINUX=permissive    # 変更
---

この手順書ではpermissiveのままとしますが、ユーザー様の環境に合わせて適切な設定を選択してください。

4.事前準備

ロケールを確認します。

# localectl status

ロケールを日本語に設定します。

# localectl set-locale LANG=ja_JP.UTF-8

PowerToolsを有効にします。

# dnf config-manager --set-enabled PowerTools

作業に必要なパッケージをインストールします。

# dnf -y install git epel-release

5.Rubyのインストール

必要なパッケージをインストールします。

# dnf -y install gcc-c++ libffi-devel libyaml-devel make openssl-devel readline-devel zlib-devel bzip2

rbenvをインストールします。

# git clone git://github.com/sstephenson/rbenv.git /usr/local/rbenv
# git clone git://github.com/sstephenson/ruby-build.git /usr/local/rbenv/plugins/ruby-build

# echo 'export RBENV_ROOT="/usr/local/rbenv"' >> /etc/profile.d/rbenv.sh
# echo 'export PATH="${RBENV_ROOT}/bin:${PATH}"' >> /etc/profile.d/rbenv.sh
# echo 'eval "$(rbenv init -)"' >> /etc/profile.d/rbenv.sh
# source /etc/profile.d/rbenv.sh

rubyをインストールします。

# rbenv install 2.7.1
# rbenv global 2.7.1
# rbenv rehash
# ruby -v

6.Node.jsのインストール

nodenvをインストールします。

# git clone https://github.com/nodenv/nodenv.git /usr/local/nodenv
# git clone https://github.com/nodenv/node-build.git /usr/local/nodenv/plugins/node-build

# echo 'export NODENV_ROOT="/usr/local/nodenv"' >> /etc/profile.d/nodenv.sh
# echo 'export PATH="${NODENV_ROOT}/bin:${PATH}"' >> /etc/profile.d/nodenv.sh
# echo 'eval "$(nodenv init -)"' >> /etc/profile.d/nodenv.sh
# source /etc/profile.d/nodenv.sh

nodejsをインストールします。

# nodenv install 10.15.3
# nodenv global 10.15.3
# nodenv rehash
# node -v

yarnをインストールします。

# npm install -g yarn
# nodenv rehash
# yarn -v

7.nginxのインストール

外部からhttpでアクセス可能にします。 ※ファイアーウォール設定は環境に応じて適切に設定してください。

# firewall-cmd --add-service=http --zone=public --permanent
# firewall-cmd --reload
# firewall-cmd --list-all

インストールします。

# dnf -y install @nginx:1.16
# nginx -v

8.PostgreSQLのインストール

デフォルトのpostgresqlを無効化します。

# dnf module disable postgresql

yumリポジトリを追加します。

# dnf -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm

インストールします。

# dnf -y install postgresql12-server postgresql12-contrib postgresql12-devel
# psql -V

データベースを初期化します。

# /usr/pgsql-12/bin/postgresql-12-setup initdb

ユーザー認証方法を変更します。

# vi /var/lib/pgsql/12/data/pg_hba.conf
---
host    all             all             127.0.0.1/32            md5
---

postgresqlを起動します。

# systemctl start postgresql-12

接続を確認します。

# su - postgres -c "psql -c 'select now()'"

9.Postfixのインストール

インストールします。

# dnf -y install postfix
# postconf mail_version

10.ふりがな・読み上げツールのインストール

必要なパッケージをインストールします。

# dnf -y install sox
# sox --version

hts_engine APIをインストールします。

# cd /usr/local/src
# curl -fsSLO http://downloads.sourceforge.net/hts-engine/hts_engine_API-1.09.tar.gz
# tar zxf hts_engine_API-1.09.tar.gz && cd hts_engine_API-1.09 && ./configure CFLAGS='-O3 -march=native -funroll-loops' && make && make install

Open JTalkをインストールします。

# cd /usr/local/src
# curl -fsSLO http://downloads.sourceforge.net/open-jtalk/open_jtalk-1.08.tar.gz
# tar zxf open_jtalk-1.08.tar.gz && cd open_jtalk-1.08
# sed -i 's/#define MAXBUFLEN 1024/#define MAXBUFLEN 10240/' bin/open_jtalk.c
# ./configure --with-charset=UTF-8 CFLAGS='-O3 -march=native -funroll-loops' CXXFLAGS='-O3 -march=native -funroll-loops' && make && make install
# open_jtalk -h

Dictionaryをインストールします。

# cd /usr/local/src
# curl -fsSLO http://downloads.sourceforge.net/open-jtalk/open_jtalk_dic_utf_8-1.08.tar.gz
# tar zxf open_jtalk_dic_utf_8-1.08.tar.gz
# mkdir /usr/local/share/open_jtalk && mv open_jtalk_dic_utf_8-1.08 /usr/local/share/open_jtalk/dic

LAMEをインストールします。

# cd /usr/local/src
# curl -fsSLO http://jaist.dl.sourceforge.net/project/lame/lame/3.99/lame-3.99.5.tar.gz
# tar zxf lame-3.99.5.tar.gz && cd lame-3.99.5 && ./configure && make && make install
# lame --version

MeCabをインストールします。

# cd /usr/local/src
# curl -fsSL 'https://drive.google.com/uc?export=download&id=0B4y35FiV1wh7cENtOXlicTFaRUE' -o mecab-0.996.tar.gz
# tar zxf mecab-0.996.tar.gz && cd mecab-0.996 && ./configure --enable-utf8-only && make && make install
# mecab -v

MeCab-IPAdicをインストールします。

# cd /usr/local/src
# curl -fsSL 'https://drive.google.com/uc?export=download&id=0B4y35FiV1wh7MWVlSDBCSXZMTXM' -o mecab-ipadic-2.7.0-20070801.tar.gz
# tar zxf mecab-ipadic-2.7.0-20070801.tar.gz && cd mecab-ipadic-2.7.0-20070801 && ./configure --with-charset=utf8 && make && make install

MeCab-Rubyをインストールします。

# cd /usr/local/src
# curl -fsSL 'https://drive.google.com/uc?export=download&id=0B4y35FiV1wh7VUNlczBWVDZJbE0' -o mecab-ruby-0.996.tar.gz
# tar zxf mecab-ruby-0.996.tar.gz && cd mecab-ruby-0.996 && ruby extconf.rb && make && make install

libmecabのパスを設定します。

# echo '/usr/local/lib' >> /etc/ld.so.conf.d/usrlocal.conf
# ldconfig
# ldconfig -p | grep "/usr/local/lib"

11.Joruriのインストール

専用ユーザーを作成します。

# useradd -m joruri

DB接続用のユーザーを作成します。 ※パスワードは任意の文字列を設定してください。(ここでは「joruripass」とします。)

# su - postgres -c "psql -c \"CREATE USER joruri WITH CREATEDB ENCRYPTED PASSWORD 'joruripass';\""

必要なパッケージをインストールします。

# dnf -y install libxml2-devel libxslt-devel openldap-devel patch zip exiv2
# dnf -y install ImageMagick-devel
# convert -version

Joruriを設置します。

[パスワード認証を使用する場合]
# git clone https://github.com/joruri/joruri-cms-2020.git /var/www/joruri

[デプロイキーを使用する場合]
# git clone git@github.com:joruri/joruri-cms-2020.git /var/www/joruri

# chown -R joruri:joruri /var/www/joruri

joruriユーザーに変更します。

# su - joruri
$ cd /var/www/joruri

ライブラリをインストールします。

$ bundle config build.pg --with-pg-config=/usr/pgsql-12/bin/pg_config
$ bundle install --path vendor/bundle --without development test
$ bundle list

12.Joruriの設定

サンプルの設定ファイルをコピーします。

$ cp -p /var/www/joruri/config/original/*.yml /var/www/joruri/config/

設定ファイルを変更します。

$ vi /var/www/joruri/config/core.yml
---
production:
  title: Joruri  # サイト名を設定
  uri: http://joruri.example.com/  # サイトURLを設定
---

シークレットキーを設定します。

$ bundle exec rake secret RAILS_ENV=production
  (出力されたシークレットキーをコピーします)
$ vi /var/www/joruri/config/secrets.yml
---
production:
  secret_key_base: (コピーしたシークレットキーを貼り付けます)
---

データベースを作成します。

$ bundle exec rake db:create db:schema:load RAILS_ENV=production

初期データを登録します。

[空サイトを登録する場合]
$ bundle exec rake db:seed RAILS_ENV=production SITE_NAME="Joruri" SITE_URL="http://joruri.example.com/"

[サンプルサイトを登録する場合]
$ bundle exec rake db:seed:demo RAILS_ENV=production ID=1 SITE_NAME="Joruri" SITE_URL="http://joruri.example.com/"

初期データの登録を確認します。

$ psql joruri_production -c "select * from cms_sites"

nginxの設定ファイルを生成します。

$ bundle exec rake joruri:configure RAILS_ENV=production

cronを登録します。

$ bundle exec whenever --update-crontab
$ crontab -l

13.サーバーの設定

rootユーザーに変更します。

$ su - root

Joruriのnginx設定ファイルへリンクします。

# ln -s /var/www/joruri/config/nginx/nginx.conf /etc/nginx/conf.d/joruri.conf

ログローテートを設定します。

# cp /var/www/joruri/config/samples/logrotate /etc/logrotate.d/joruri_logrotate

サーバー再起動用のcronを登録します。

# cp /var/www/joruri/config/samples/reload_servers.sh /root/. && chmod 755 /root/reload_servers.sh
# ROOT_CRON_TXT='/var/www/joruri/config/samples/root_cron.txt'
# crontab -l > $ROOT_CRON_TXT
# grep -s reload_servers.sh $ROOT_CRON_TXT || echo '0,30 * * * * /root/reload_servers.sh' >> $ROOT_CRON_TXT
# crontab $ROOT_CRON_TXT

14.サーバーの起動

postfixを起動します。

# systemctl start postfix && systemctl enable postfix
# systemctl status postfix

postgresqlを起動します。

# systemctl start postgresql-12 && systemctl enable postgresql-12
# systemctl status postgresql-12

nginxを起動します。

# systemctl start nginx && systemctl enable nginx
# systemctl status nginx

unicornを起動します。

# cp /var/www/joruri/config/samples/unicorn.service /usr/lib/systemd/system/joruri_unicorn.service
# systemctl start joruri_unicorn && systemctl enable joruri_unicorn
# systemctl status joruri_unicorn

delayed_jobを起動します。

# cp /var/www/joruri/config/samples/delayed_job.service /usr/lib/systemd/system/joruri_delayed_job.service
# systemctl start joruri_delayed_job && systemctl enable joruri_delayed_job
# systemctl status joruri_delayed_job

15.動作確認

インストールが完了しました。

  • 公開画面: http://joruri.example.com/

  • 管理画面: http://joruri.example.com/_system

  • 管理者(システム管理者)

    • ユーザーID: joruri
    • パスワード: joruri
Topへ