このセクションでは、プロジェクト管理ソフトウェアである Redmine 環境の構築について紹介していきます。
ここでは、Nginx のWebサーバー、MariaDB のDBサーバーをインストールした AlmaLinux サーバー上に Redmine 環境を構築していきます。
[user@pub-web ~]$ sudo cat /etc/redhat-release
AlmaLinux release 9.2 (Turquoise Kodkod)
[user@pub-web ~]$
[user@pub-web ~]$ sudo nginx -v
nginx version: nginx/1.24.0
[user@pub-web ~]$
[user@pub-web ~]$ sudo mysql --version
mysql Ver 15.1 Distrib 10.5.16-MariaDB, for Linux (x86_64) using EditLine wrapper
[user@pub-web ~]$
Redmine ユーザーの作成
Redmine 用のユーザーを作成します。ここでは、ユーザー名は redmine でユーザーのホームディレクトリを” /opt/redmine ” としています。
[user@pub-web ~]$ sudo useradd -d /opt/redmine redmine
[user@pub-web ~]$
[user@pub-web ~]$ sudo ls -la /opt/
total 0
drwxr-xr-x. 3 root root 21 Aug 28 03:11 .
dr-xr-xr-x. 18 root root 247 Aug 14 10:46 ..
drwx------. 2 redmine redmine 62 Aug 28 03:11 redmine
[user@pub-web ~]$
redmine ユーザーのパスワードを設定します。
[user@pub-web ~]$ sudo passwd redmine
Changing password for user redmine.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[user@pub-web ~]$
Redmine 用データベースの作成
Redmine のデータベースを作成します。
[user@pub-web ~]$ sudo mysql -u root -p
MariaDB [(none)]>
MariaDB [(none)]> create database (DB名) character set utf8mb4;
Query OK, 1 row affected (0.002 sec)
MariaDB [(none)]> create user '(ユーザ名)'@'localhost' identified by '(パスワード)';
Query OK, 0 rows affected (0.010 sec)
MariaDB [(none)]> grant all privileges on (DB名).* to '(ユーザ名)'@'localhost';
Query OK, 0 rows affected (0.009 sec)
MariaDB [(none)]> exit;
Bye
[user@pub-web ~]$
SELinuxの一時無効化
SELinux が有効になっていると、Redmine の Webサイトが起動しないため一時的に SELinux を無効化します。
[user@pub-web ~]$ sudo setenforce 0
[user@pub-web ~]$
[user@pub-web ~]$ sudo getenforce
Permissive
[user@pub-web ~]$
必要なパッケージのインストール
Redmine で必要な開発ツールをインストールします。
[user@pub-web ~]$ sudo dnf group install "Development Tools"
Last metadata expiration check: 0:04:44 ago on Mon Aug 28 03:18:24 2023.
Dependencies resolved.
================================================================================
Package Arch Version Repo Size
================================================================================
Installing group/module packages:
asciidoc noarch 9.1.0-3.el9 appstream 237 k
autoconf noarch 2.69-38.el9 appstream 666 k
automake noarch 1.16.2-6.el9 appstream 662 k
binutils x86_64 2.35.2-37.el9 baseos 4.5 M
bison x86_64 3.7.4-5.el9 appstream 920 k
ーー(省略)ーー
Transaction Summary
================================================================================
Install 303 Packages
Total download size: 290 M
Installed size: 1.0 G
Is this ok [y/N]: y
ーー(省略)ーー
xdg-desktop-portal-gtk-1.12.0-3.el9.x86_64
xkeyboard-config-2.33-2.el9.noarch
xml-common-0.6.3-58.el9.noarch
xorg-x11-fonts-ISO8859-1-100dpi-7.5-33.el9.noarch
xz-devel-5.2.5-8.el9_0.x86_64
zip-3.0-35.el9.x86_64
zlib-devel-1.2.11-39.el9.x86_64
zstd-1.5.1-2.el9.x86_64
Complete!
[user@pub-web ~]$
Redmine で必要なパッケージをインストールします。
[user@pub-web ~]$ sudo dnf install git curl zlib wget openssl libcurl-devel zlib-devel openssl-devel
Last metadata expiration check: 0:13:02 ago on Mon Aug 28 03:18:24 2023.
Package git-2.39.3-1.el9_2.x86_64 is already installed.
Package curl-7.76.1-23.el9_2.2.x86_64 is already installed.
Package zlib-1.2.11-39.el9.x86_64 is already installed.
Package wget-1.21.1-7.el9.x86_64 is already installed.
Package openssl-1:3.0.7-17.el9_2.x86_64 is already installed.
Package zlib-devel-1.2.11-39.el9.x86_64 is already installed.
Package openssl-devel-1:3.0.7-17.el9_2.x86_64 is already installed.
Dependencies resolved.
ーー(省略)ーー
================================================================================
Package Architecture Version Repository Size
================================================================================
Installing:
libcurl-devel x86_64 7.76.1-23.el9_2.2 appstream 849 k
Transaction Summary
================================================================================
Install 1 Package
Total download size: 849 k
Installed size: 1.4 M
Is this ok [y/N]: y
ーー(省略)ーー
Installed:
libcurl-devel-7.76.1-23.el9_2.2.x86_64
Complete!
[user@pub-web ~]$
Redmine のインストール
Redmine のモジュールをダウンロードします。
[user@pub-web ~]$ sudo wget https://www.redmine.org/releases/redmine-5.0.5.tar.gz
--2023-08-28 03:37:25-- https://www.redmine.org/releases/redmine-5.0.5.tar.gz
Resolving www.redmine.org (www.redmine.org)... 46.4.101.126
Connecting to www.redmine.org (www.redmine.org)|46.4.101.126|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3115940 (3.0M) [application/x-gzip]
Saving to: ‘redmine-5.0.5.tar.gz’
redmine-5.0.5.tar.g 100%[===================>] 2.97M 1.02MB/s in 2.9s
2023-08-28 03:37:29 (1.02 MB/s) - ‘redmine-5.0.5.tar.gz’ saved [3115940/3115940]
[user@pub-web ~]$
ダウンロードした Redmine のモジュールを解凍します。
[user@pub-web ~]$ sudo tar zxvf redmine-5.0.5.tar.gz
ーー(省略)ーー
redmine-5.0.5/extra/mail_handler/
redmine-5.0.5/extra/mail_handler/rdm-mailhandler.rb
redmine-5.0.5/yarn.lock
redmine-5.0.5/Rakefile
redmine-5.0.5/bin/
redmine-5.0.5/bin/about
redmine-5.0.5/bin/changelog.rb
redmine-5.0.5/bin/rails
redmine-5.0.5/bin/bundle
redmine-5.0.5/bin/rake
[user@pub-web ~]$
解凍した Redmine のフォルダを /var/lib/ 配下に移動します。
[user@pub-web ~]$ sudo mv redmine-5.0.5 /var/lib/
[user@pub-web ~]$
[user@pub-web ~]$ sudo ls -la /var/lib/
total 24
ーー(省略)ーー
drwxrwxr-x. 17 user user 4096 Mar 5 16:35 redmine-5.0.5
drwxr-xr-x. 2 root root 91 Apr 7 12:03 rpm
drwxr-xr-x. 3 root root 20 Aug 28 03:26 rpm-state
drwx------. 2 root root 29 Aug 28 03:39 rsyslog
drwxr-xr-x. 5 root root 46 Jul 31 04:50 selinux
drwxr-xr-x. 18 root root 4096 Aug 27 21:01 snapd
drwxr-xr-x. 9 root root 105 Aug 3 08:46 sss
drwxr-xr-x. 7 root root 98 Aug 2 16:16 systemd
drwxr-xr-x. 3 root root 20 Jul 31 04:52 tpm2-tss
[user@pub-web ~]$
Redmine のフォルダの所有権を先程作成した redmine ユーザーに変更します。
[user@pub-web ~]$ sudo chown -R redmine:redmine /var/lib/redmine-5.0.5
[user@pub-web ~]$
Redmine フォルダへのシンボリックリンクを作成します。
[user@pub-web ~]$ sudo ln -s /var/lib/redmine-5.0.5 /var/lib/redmine
[user@pub-web ~]$
[user@pub-web ~]$ sudo ls -la /var/lib/
total 24
ーー(省略)ーー
lrwxrwxrwx. 1 root root 22 Aug 28 03:42 redmine -> /var/lib/redmine-5.0.5
drwxrwxr-x. 18 redmine redmine 4096 Aug 28 04:30 redmine-5.0.5
drwxr-xr-x. 2 root root 91 Apr 7 12:03 rpm
drwxr-xr-x. 3 root root 20 Aug 28 03:26 rpm-state
drwx------. 2 root root 29 Aug 30 00:32 rsyslog
drwxr-xr-x. 5 root root 46 Jul 31 04:50 selinux
drwxr-xr-x. 18 root root 4096 Aug 29 23:46 snapd
drwxr-xr-x. 9 root root 105 Aug 3 08:46 sss
drwxr-xr-x. 7 root root 98 Aug 2 16:16 systemd
drwxr-xr-x. 3 root root 20 Jul 31 04:52 tpm2-tss
[user@pub-web ~]$
Redmine からデータベースへの接続設定を行います。
[user@pub-web ~]$ sudo cp -i /var/lib/redmine/config/database.yml.example /var/lib/redmine/config/database.yml
[user@pub-web ~]$
[user@pub-web ~]$ sudo vi /var/lib/redmine/config/database.yml
※下記行を追加します
production:
adapter: mysql2
database: redmine
host: localhost
username: redmuser
password: "REDM0527DB"
# Use "utf8" instead of "utfmb4" for MySQL prior to 5.7.7
encoding: utf8mb4
[user@pub-web ~]$
Ruby 実行環境のインストール
システムで利用可能な ruby モジュールのストリーム一覧を確認します。Profiles 欄を確認すると、”common”が存在しています。
[user@pub-web ~]$ sudo dnf module list ruby
Last metadata expiration check: 0:30:22 ago on Mon Aug 28 03:18:24 2023.
AlmaLinux 9 - AppStream
Name Stream Profiles Summary
ruby 3.1 common [d] An interpreter of object-oriented scripting language
Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
[user@pub-web ~]$
ruby に関連する必要なパッケージをインストールしていきます。
[user@pub-web ~]$ sudo dnf -y module install ruby/common
Last metadata expiration check: 0:31:04 ago on Mon Aug 28 03:18:24 2023.
Dependencies resolved.
================================================================================
Package Arch Version Repo Size
================================================================================
Installing group/module packages:
ruby x86_64 3.1.2-141.module_el9.1.0+8+503f6fbd appstream 40 k
Installing dependencies:
ruby-default-gems noarch 3.1.2-141.module_el9.1.0+8+503f6fbd appstream 29 k
ruby-libs x86_64 3.1.2-141.module_el9.1.0+8+503f6fbd appstream 3.2 M
rubygem-io-console x86_64 0.5.11-141.module_el9.1.0+8+503f6fbd appstream 23 k
rubygem-json x86_64 2.6.1-141.module_el9.1.0+8+503f6fbd appstream 52 k
rubygem-psych x86_64 4.0.3-141.module_el9.1.0+8+503f6fbd appstream 49 k
Installing weak dependencies:
ーー(省略)ーー
Installed:
ruby-3.1.2-141.module_el9.1.0+8+503f6fbd.x86_64
ruby-default-gems-3.1.2-141.module_el9.1.0+8+503f6fbd.noarch
ruby-libs-3.1.2-141.module_el9.1.0+8+503f6fbd.x86_64
rubygem-bigdecimal-3.1.1-141.module_el9.1.0+8+503f6fbd.x86_64
rubygem-bundler-2.3.7-141.module_el9.1.0+8+503f6fbd.noarch
rubygem-io-console-0.5.11-141.module_el9.1.0+8+503f6fbd.x86_64
rubygem-json-2.6.1-141.module_el9.1.0+8+503f6fbd.x86_64
rubygem-psych-4.0.3-141.module_el9.1.0+8+503f6fbd.x86_64
rubygem-rdoc-6.4.0-141.module_el9.1.0+8+503f6fbd.noarch
rubygems-3.3.7-141.module_el9.1.0+8+503f6fbd.noarch
Complete!
[user@pub-web ~]$
[user@pub-web ~]$ sudo dnf -y install ruby-devel rubygem-bundler
Last metadata expiration check: 0:32:23 ago on Mon Aug 28 03:18:24 2023.
Package rubygem-bundler-2.3.7-141.module_el9.1.0+8+503f6fbd.noarch is already installed.
Dependencies resolved.
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
ruby-devel x86_64 3.1.2-141.module_el9.1.0+8+503f6fbd appstream 416 k
Transaction Summary
================================================================================
Install 1 Package
Total download size: 416 k
Installed size: 2.7 M
Downloading Packages:
ruby-devel-3.1.2-141.module_el9.1.0+8+503f6fbd. 217 kB/s | 416 kB 00:01
--------------------------------------------------------------------------------
Total 158 kB/s | 416 kB 00:02
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : ruby-devel-3.1.2-141.module_el9.1.0+8+503f6fbd.x86_6 1/1
Running scriptlet: ruby-devel-3.1.2-141.module_el9.1.0+8+503f6fbd.x86_6 1/1
Verifying : ruby-devel-3.1.2-141.module_el9.1.0+8+503f6fbd.x86_6 1/1
Installed:
ruby-devel-3.1.2-141.module_el9.1.0+8+503f6fbd.x86_64
Complete!
[user@pub-web ~]$
次に、Redmineのディレクトリへ移動し、Rubyのパッケージ管理ツールである ” bundler ” を使用して、gemの依存関係パッケージをインストールします。
ここで、環境によっては以下のようなエラーが発生する場合があります。その場合には、こちらのトラブルシューティングも合わせてご確認ください。
An error occurred while installing mysql2 (0.5.5), and Bundler cannot
[user@pub-web ~]$ cd /var/lib/redmine
[user@pub-web redmine]$
[user@pub-web redmine]$ sudo bundle install --path vendor/bundler --without development test
[DEPRECATED] The `--path` flag is deprecated because it relies on being remembered across bundler invocations, which bundler will no longer do in future versions. Instead please use `bundle config set --local path 'vendor/bundler'`, and stop using this flag
[DEPRECATED] The `--without` flag is deprecated because it relies on being remembered across bundler invocations, which bundler will no longer do in future versions. Instead please use `bundle config set --local without 'development test'`, and stop using this flag
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and
installing your bundle as root will break this application for all non-root
users on this machine.
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies.....
Using rake 13.0.6
ーー(省略)ーー
Using activestorage 6.1.7.2
Using actionmailer 6.1.7.2
Using railties 6.1.7.2
Using sprockets-rails 3.4.2
Using actionmailbox 6.1.7.2
Using actiontext 6.1.7.2
Using actionpack-xml_parser 2.0.1
Using roadie-rails 3.0.0
Using rails 6.1.7.2
Bundle complete! 43 Gemfile dependencies, 74 gems now installed.
Gems in the groups 'development' and 'test' were not installed.
Bundled gems are installed into `./vendor/bundler`
[user@pub-web redmine]$
Railsがセッションデータを格納するCookieをエンコードするために使用するランダムキー(暗号化のためのシークレットトークン)を生成します。
[user@pub-web redmine]$ sudo bundle exec rails generate_secret_token
[user@pub-web redmine]$
次のコマンドを実行して、データベース構造(DBスキーマ)を作成します。
[user@pub-web redmine]$ sudo bundle exec rails db:migrate RAILS_ENV=production
== 1 Setup: migrating =========================================================
-- create_table("attachments", {:options=>"ENGINE=InnoDB", :force=>true, :id=>:integer})
-> 0.0096s
-- create_table("auth_sources", {:options=>"ENGINE=InnoDB", :force=>true, :id=>:integer})
-> 0.0088s
-- create_table("custom_fields", {:options=>"ENGINE=InnoDB", :force=>true, :id=>:integer})
-> 0.0107s
-- create_table("custom_fields_projects", {:options=>"ENGINE=InnoDB", :id=>false, :force=>true})
-> 0.0111s
-- create_table("custom_fields_trackers", {:options=>"ENGINE=InnoDB", :id=>false, :force=>true})
-> 0.0111s
-- create_table("custom_values", {:options=>"ENGINE=InnoDB", :force=>true, :id=>:integer})
-> 0.0097s
ーー(省略)ーー
== 20211213122100 RemoveIdentityUrlFromUsers: migrating =======================
-- remove_column(:users, :identity_url, :string)
-> 0.0092s
== 20211213122100 RemoveIdentityUrlFromUsers: migrated (0.0094s) ==============
== 20211213122101 DropOpenIdAuthenticationTables: migrating ===================
-- drop_table(:open_id_authentication_associations)
-> 0.0093s
-- drop_table(:open_id_authentication_nonces)
-> 0.0080s
== 20211213122101 DropOpenIdAuthenticationTables: migrated (0.0177s) ==========
== 20211213122102 RemoveOpenIdSetting: migrating ==============================
== 20211213122102 RemoveOpenIdSetting: migrated (0.0015s) =====================
== 20220224194639 DeleteOrphanedTimeEntryActivities: migrating ================
== 20220224194639 DeleteOrphanedTimeEntryActivities: migrated (0.0200s) =======
[user@pub-web redmine]$
Unicorn のインストール
Ruby アプリケーション用の Web サーバーである Unicorn をインストールしていきます。RubyアプリケーションをWebで提供する場合には、下記のような構成となります。
Nginx (Webサーバー) — Unicorn(Webサーバー) — Rudy アプリケーションサーバー
Redmine のディレクトリ直下に Gemfile.local ファイルを作成し、Unicorn Webサーバーを追加するためのコードを記述します。
[user@pub-web redmine]$ sudo vi /var/lib/redmine/Gemfile.local
※以下の行をGemfile.local ファイルに記述します。
gem "unicorn"
[user@pub-web redmine]$
bundle を使って、Rubyアプリケーション用のWeb サーバーをインストールします。bundle コマンドは、/var/lib/redmine/ ディレクトリ上で実施する必要があります。
[user@pub-web redmine]$ sudo bundle update
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies...
Using rake 13.0.6
ーー(省略)ーー
Using unicorn 6.1.0 ← unicorn が追加されています
Using i18n 1.10.0
Using loofah 2.21.3
Using net-imap 0.2.3
Using net-pop 0.1.2
Using net-smtp 0.3.3
Using sanitize 6.0.2
ーー(省略)ーー
Installing unicorn 6.1.0 with native extensions
Bundle updated!
Gems in the groups 'development' and 'test' were not updated.
[user@pub-web redmine]$
unicorn の設定ファイルを作成します。
[user@pub-web redmine]$ sudo vi /var/lib/redmine/config/unicorn.rb
※以下の行を設定ファイルに記述します。
# unicorn.rb
worker_processes 2
listen "/var/run/unicorn/unicorn.sock", :backlog => 32
listen 8282, :tcp_nopush => true
timeout 30
pid "tmp/pids/unicorn.pid"
stderr_path 'log/unicorn.stderr.log'
stdout_path 'log/unicorn.stdout.log'
preload_app true
check_client_connection false
before_fork do |server, worker|
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
old_pid = "#{server.config[:pid]}.oldbin"
if old_pid != server.pid
begin
sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
Process.kill(sig, File.read(old_pid).to_i)
rescue Errno::ENOENT, Errno::ESRCH
end
end
end
after_fork do |server, worker|
defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection
end
[user@pub-web redmine]$
unicorn をサービス化するファイルを作成します。
[user@pub-web redmine]$ sudo vi /usr/lib/systemd/system/unicorn.service
※以下の行をファイルに記述します。
[Unit]
Description=Redmine Unicorn Server
After=mysqld.service
[Service]
User=redmine
Group=redmine
WorkingDirectory=/var/lib/redmine
Environment=RAILS_ENV=production
SyslogIdentifier=redmine-unicorn
PIDFile=/var/lib/redmine/tmp/pids/unicorn.pid
PermissionsStartOnly=true
ExecStartPre=/usr/bin/install -m 755 -o redmine -g redmine -d /var/run/unicorn
ExecStart=/usr/bin/bundle exec "unicorn_rails -c config/unicorn.rb -E production"
ExecStop=/usr/bin/kill -QUIT $MAINPID
ExecReload=/usr/bin/kill -USR2 $MAINPID
[Install]
WantedBy=multi-user.target
[user@pub-web redmine]$
Unicorn サービスの起動
サービス化した Unicorn サービスを起動します。正常であれば、この時点で起動します。
[user@pub-web redmine]$ sudo systemctl start unicorn
[user@pub-web redmine]$
[yuji@pub-web redmine]$ sudo systemctl status unicorn
● unicorn.service - Redmine Unicorn Server
Loaded: loaded (/usr/lib/systemd/system/unicorn.service; disabled; preset:>
Active: active (running) since Mon 2023-08-28 04:34:40 EDT; 2s ago
Process: 69970 ExecStartPre=/usr/bin/install -m 755 -o redmine -g redmine ->
Main PID: 69971 (ruby)
Tasks: 2 (limit: 11125)
Memory: 130.8M
CPU: 2.234s
CGroup: /system.slice/unicorn.service
└─69971 ruby /var/lib/redmine-5.0.5/vendor/bundler/ruby/3.1.0/bin/>
Aug 28 04:34:40 pub-web systemd[1]: Starting Redmine Unicorn Server...
Aug 28 04:34:40 pub-web systemd[1]: Started Redmine Unicorn Server.
[yuji@pub-web redmine]$
Unicorn サービスの自動起動を有効化します。
[user@pub-web redmine]$ sudo systemctl enable unicorn
Created symlink /etc/systemd/system/multi-user.target.wants/unicorn.service → /usr/lib/systemd/system/unicorn.service.
[user@pub-web redmine]$
[user@pub-web redmine]$ sudo systemctl is-enabled unicorn
enabled
[user@pub-web redmine]$
Nginx 経由での Redmine 利用設定
Ruby 実行環境で動作する Redmine を フロントエンドのWebサーバーである Nginx を経由して利用できるようにしていきます。
Nginx (Webサーバー) — Unicorn(Webサーバー) — Rudy アプリケーションサーバー
Nginx の 設定ファイル に Redmine 用の upstream と location ディレクティブの設定を追加します。以下を一例となりますので、利用する環境に合わせて適宜変更してください。
# Ruby用WebサーバーであるUnicornへのUpstreamディレクティブの設定
upstream unicorn {
server unix:/var/run/unicorn/unicorn.sock;
}
# Redmine環境に対するlocationディレクティブの設定
server {
ーー(省略)ーー
location / {
root /var/lib/redmine/public;
try_files $uri/index.html $uri.html $uri @app;
}
location @app {
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_connect_timeout 60;
proxy_read_timeout 60;
proxy_send_timeout 600;
proxy_pass http://unicorn;
}
ーー(省略)ーー
}
設定ファイルの正常性をチェックし、問題なければ設定を反映します。
[user@pub-web redmine]$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[user@pub-web redmine]$
[user@pub-web redmine]$ sudo nginx -s reload
[user@pub-web redmine]$
正常であれば、Redmine のページにアクセスすると下記のようにログイン画面が表示されます。
