Redmine 安裝篇:Redmine 4.0.x on Ubuntu 16.04


Redmine 的安裝流程相對於一般的網站應用程式來講,是複雜的,特別是如果不熟悉 Ruby on Rails 的生態系,或者不熟悉 Nginx 的配置,那麼整個安裝過程會是非常挫折的。

本文記錄如何在 Ubuntu 16.04 安裝與配置最新版 Redmine 4.0.3 (201905) 筆記,相關資訊放在 GitHub 供參考。


安裝流程

整個流程如下:

  1. Ubuntu and MySQL
  2. Permission
  3. RVM and Ruby
  4. Passenger and Nignx
  5. Redmine 4.0.3
  6. Plugins and Themes

每個項目都會有 安裝配置驗證 三個步驟。

1. Ubuntu and MySQL

準備一台乾淨的 Ubuntu 16.04,安裝過程,只要安裝 OpenSSH Server,不要安裝額外像是 LAMP 的套件。

本文在 Proxmox、VMWare、AWS EC2 測試過。

Run as root,安裝 MySQL 必要套件以及 MySQL Server.

1
2
3
4
5
6
7
8
9
## 安裝必要的套件,
~# apt install build-essential mysql-server libmysqlclient-dev imagemagick libmagickwand-dev

# 驗證 MySQL Version
~# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.26-0ubuntu0.16.04.1 (Ubuntu)

如果 MySQL 是跑在其他地方,像是 RDS,那麼可以不需要安裝 mysql-server,但是要安裝 libmysqlclient-dev

2. Permission

Run as root,建立 redmine 使用者帳號

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
## 建立 Redmine 使用者,資料放在 `/data/redmine`
adduser --system \
--shell /bin/bash \
--gecos 'Redmine Administrator' \
--group \
--home /data/redmine redmine;

## 建立 rvm group
groupadd rvm

## 允許 redmine 可以 sudo
adduser redmine sudo
passwd redmine

# 將 redmine 使用者加入 rvm 群組
usermod -a -G rvm redmine

3. RVM and Ruby

  1. 安裝 rvm
  2. 安裝 ruby 2.3.x (redmine 4.0 需求)

Run as redmine

透過 RVM (Ruby Version Manager) 安裝 Ruby。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 取自官方網站: https://rvm.io
## 安裝 GPG Keys
~$ gpg2 --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
## 可能需要安裝 gpg2: sudo apt install gpg2

## 安裝 RVM
~$ curl -sSL https://get.rvm.io | bash -s stable

## 安裝過程如果出現 public key not found 錯誤: `gpg: Can't check signature: public key not found`
## 依照指示,執行這段,再重新安裝 rvm 即可:
#~$ gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B17<略>
## 再次安裝 RVM
#~$ curl -sSL https://get.rvm.io | bash -s stable

## 驗證:重新 login as redmine, 確認 rvm 版本
~$ rvm --version
rvm 1.29.8 (latest) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]

透過 rvm 安裝 Ruby。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
RUBY_VERSION=2.3.8

## 檢查 rvm 必要的套件
~$ rvm requirements

## 安裝指定的 ruby version
~$ rvm install ${RUBY_VERSION}

## 將此版本設定為預設
~$ rvm use ${RUBY_VERSION} --default

## 驗證
~$ ruby --version
ruby 2.3.8p459 (2018-10-18 revision 65136) [x86_64-linux]

如果發生以下錯誤訊息:

1
2
3
4
5
6
7
~$ rvm requirements
Checking requirements for ubuntu.
Installing requirements for ubuntu.
Updating system...
Error running 'requirements_debian_update_system ',
please read /data/redmine/.rvm/log/1557660154/update_system.log
Requirements installation failed with status: 1.

/etc/sudoers.d/ 增加一個檔案 redmine,檔案屬性 440,內容如下:

1
redmine ALL=(ALL) NOPASSWD:ALL

4. Passenger and Nginx

4-1. Installation

Run as root.

1
2
3
4
5
6
7
8
9
10
11
## 1. 安裝 Passenger PGP key 和 HTTPS support for package manager
apt install -y dirmngr gnupg
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7
apt install -y apt-transport-https ca-certificates

## 2. Add passenger APT repository
sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger xenial main > /etc/apt/sources.list.d/passenger.list'
apt update

## 3. 安裝 Passenger and NGINX
apt install -y nginx-extras passenger

4-2. Configuration

Run as root.

  1. 編輯 /etc/nginx/nginx.conf
  2. 把這行註解拿掉: include /etc/nginx/passenger.conf;
  3. 如下所示
/etc/nginx/nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
##
# Phusion Passenger config
##
# Uncomment it if you installed passenger or passenger-enterprise
##

include /etc/nginx/passenger.conf;

##
# Virtual Host Configs
##

include /etc/nginx/conf.d/*.conf;

備份 /etc/nginx/sites-available/default,以備不時之需。

1
cp /etc/nginx/sites-available/default /etc/nginx/sites-available/default.orig

調整 root directory,額外增加 Passenger 設定。注意以下:

  1. 這裡指定 redmine 的安裝路徑為 /data/redmine/current/public
  2. 資料上傳的大小為 10m,未來有需要再做調整
/etc/nginx/sites-available/default
1
2
3
root /data/redmine/current/public;
passenger_enabled on;
client_max_body_size 10m;

location 段落註解掉:

1
2
3
4
5
#location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
# try_files $uri $uri/ =404;
#}

4-3. Validate and Check

Run as root.

  1. 更改 /var/www 權限: chown -R www-data /var/www
  2. 重啟 nginx: systemctl restart nginx
  3. 驗證 Passenger and NGINX: /usr/bin/passenger-config validate-install,如下圖:

    1.. 檢查 NGINX 狀態與 Passenger process: /usr/sbin/passenger-memory-stats,如下圖:

5. Redmine 4.0.x

5-1. MySQL and Database

設定 MySQL,注意以下:

  1. 注意 Encoding,支援 emoj 必須使用 utf8mb4
  2. 記得設定密碼
1
2
3
4
5
CREATE DATABASE redmine CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'redmine'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON redmine.* TO 'redmine'@'localhost';
FLUSH PRIVILEGES;
quit;

5-2. Install Redmine 4.0.x

Run as redmine.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
## 1. 下載官方 Image
cd /data/redmine
wget https://www.redmine.org/releases/redmine-4.0.3.tar.gz
tar zxvf redmine-4.0.3.tar.gz
ln -s redmine-4.0.3 current
cd current

## 2. 設定資料庫, 只改 production 就好
cp -pR config/database.yml.example config/database.yml
vi config/database.yml

## 3. 執行 gem, bundle 安裝依賴套件
### pwd: /data/redmine/current
~$ gem install bundler # < 1m
Fetching: bundler-2.0.1.gem (100%)
Successfully installed bundler-2.0.1
Parsing documentation for bundler-2.0.1
Installing ri documentation for bundler-2.0.1
Done installing documentation for bundler after 6 seconds
1 gem installed

### pwd: /data/redmine/current
~$ bundle install --without development test # < 10m
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x64-mingw32, x86-mswin32. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x64-mingw32 x86-mswin32`.
Fetching gem metadata from https://rubygems.org/.............
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies....
Fetching rake 12.3.2
Installing rake 12.3.2

... 略 ...

Installing roadie 3.5.0
Fetching roadie-rails 1.3.0
Installing roadie-rails 1.3.0
Fetching rouge 3.3.0
Installing rouge 3.3.0
Bundle complete! 27 Gemfile dependencies, 59 gems now installed.
Gems in the groups development and test were not installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.


## 4. 用 Rake 啟動 redmine
### pwd: /data/redmine/current
~$ bundle exec rake generate_secret_token

## 5. Migrate Database Schema
### pwd: /data/redmine/current
~$ RAILS_ENV=production bundle exec rake db:migrate
== 1 Setup: migrating =========================================================
-- adapter_name()
-> 0.0000s
-- adapter_name()
-> 0.0000s
-- adapter_name()

... 略 ...

== 20180923082945 ChangeSqliteBooleansTo0And1: migrating ======================
== 20180923082945 ChangeSqliteBooleansTo0And1: migrated (0.0000s) =============

== 20180923091603 ChangeSqliteBooleansDefault: migrating ======================
== 20180923091603 ChangeSqliteBooleansDefault: migrated (0.0000s) =============


## 6. Load Initial Data
### pwd: /data/redmine/current
~$ RAILS_ENV=production bundle exec rake redmine:load_default_data

Select language: ar, az, bg, bs, ca, cs, da, de, el, en, en-GB, es, es-PA, et, eu, fa, fi, fr, gl, he, hr, hu, id, it, ja, ko, lt, lv, mk, mn, nl, no, pl, pt, pt-BR, ro, ru, sk, sl, sq, sr, sr-YU, sv, th, tr, uk, vi, zh, zh-TW [en]
====================================
Default configuration data loaded.

5-3. Restart Redmine via Nginx

  1. 重啟 nginx: sudo systemctl restart nginx
  2. 瀏覽 http:<SERVER_IP>,正常的話就可以看到 Redmine 的登入畫面,預設 admin/admin 登入
  3. 在 Redmine 裡驗證以下幾個點:
    • 點選 Administration -> Settings
    • 點選 Administration -> Projects
    • 點選 Administration -> Plugins
    • 點選 Administration -> Workflow
    • 這些都沒問題就可以了。

6. Plugins and Themes

Redmine 的 Plugins 安裝大部分雷同,相關參閱: Redmine Plugins and Themes


GitHub

本文相關的安裝資訊,同步放在 GitHub 供參考。


延伸閱讀

系列文章

站內延伸

參考資料


Comments