佈署環境 Ubuntu 22.04.4 Redmine 網站網址:https://redmine.hankchen.test Redmine 網站位置:/var/www/redmine Redmine 檔案上傳目錄:/mnt/files
注意:如果還沒有買 HTTPS 憑證,可先佈署在 HTTP
安裝文字編輯器 如果有自己常用的編輯器也可以不用安裝 vim
安裝 Nginx & Passenger 1
2
3
4
5
6
7
8
9
10
11
12
sudo apt-get install nginx
sudo apt-get install -y dirmngr gnupg apt-transport-https ca-certificates curl
curl https://oss-binaries.phusionpassenger.com/auto-software-signing-gpg-key.txt | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/phusion.gpg >/dev/null
sudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger jammy main > /etc/apt/sources.list.d/passenger.list'
sudo apt-get update
sudo apt-get install -y libnginx-mod-http-passenger
if [ ! -f /etc/nginx/modules-enabled/50-mod-http-passenger.conf ] ; then sudo ln -s /usr/share/nginx/modules-available/mod-http-passenger.load /etc/nginx/modules-enabled/50-mod-http-passenger.conf ; fi
sudo ls /etc/nginx/conf.d/mod-http-passenger.conf
sudo service nginx restart
設定 Nginx 1
2
3
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/redmine
sudo ln -s /etc/nginx/sites-available/redmine /etc/nginx/sites-enabled/redmine
sudo vi /etc/nginx/sites-available/redmine
nginx redmine 設定檔內容範例注意:如果還沒有買 HTTPS 憑證,可先佈署在 HTTP
以下範例為使用 HTTPS
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
server {
listen 80 default_server ;
listen [::]:80 default_server ;
location / {
return 301 https:// $host$request_uri ;
}
}
server {
listen 443 ssl http2 ;
listen [::]:443 ssl http2 ;
ssl_certificate /path/to/signed_cert_plus_intermediates ; #請自行取代憑證位置
ssl_certificate_key /path/to/private_key ; #請自行取代 Key 位置
ssl_session_timeout 1d ;
ssl_session_cache shared:MozSSL:10m ; # about 40000 sessions
ssl_session_tickets off ;
# modern configuration
ssl_protocols TLSv1.3 ;
ssl_prefer_server_ciphers off ;
# HSTS (ngx_http_headers_module is required) (63072000 seconds)
add_header Strict-Transport-Security "max-age=63072000" always ;
# OCSP stapling
ssl_stapling on ;
ssl_stapling_verify on ;
# verify chain of trust of OCSP response using Root CA and Intermediate certs
ssl_trusted_certificate /path/to/root_CA_cert_plus_intermediates ; #請自行取代中繼憑證位置
server_name redmine.hankchen.test ; #請自行調整
root /var/www/redmine/public ;
index index.html ;
access_log /var/log/nginx/redmine.access.log ;
error_log /var/log/nginx/redmine.error.log ;
passenger_enabled on ;
client_max_body_size 50m ; #預計開放可上傳的檔案大小
}
驗證設定檔並重啟 Nginx
1
2
sudo nginx -t
sudo systemctl restart nginx
安裝 MySQL 1
2
sudo apt install mysql-server
sudo mysql_secure_installation
建立使用者並授權存取
1
2
3
4
CREATE DATABASE redmine CHARACTER SET utf8mb4 ;
CREATE USER 'redmine' @ 'localhost' IDENTIFIED BY '填入該使用者的密碼' ;
GRANT ALL PRIVILEGES ON redmine . * TO 'redmine' @ 'localhost' ;
FLUSH PRIVILEGES ;
安裝 RVM 1
2
3
sudo gpg --keyserver keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
\c url -sSL https://get.rvm.io | bash -s stable
sudo source /etc/profile.d/rvm.sh
安裝 Ruby 3.2.4 1
2
3
sudo rvm requirements
sudo rvm install 3.2.4
sudo rvm use 3.2.4 --default
建立使用者 1
2
3
4
5
6
7
8
adduser --system \
--shell /bin/bash \
--gecos 'Redmine Administrator' \
--group \
--home /var/www/redmine redmine;
usermod -aG redmine www-data
usermod -aG rvm redmine
下載 redmine 1
2
3
4
apt-get install libmysqlclient-dev
wget https://www.redmine.org/releases/redmine-5.1.2.tar.gz
tar -zxvf redmine-5.1.2.tar.gz
chown -R redmine. /var/www/redmine/
設定資料庫帳密 1
2
3
su - redmine
cp -pR config/database.yml.example config/database.yml
vi config/database.yml
安裝相關套件或主題 下載原套件到 /var/www/redmine/plugins/ 下載原主題到 /var/www/redmine/public/theme/ 連結 files 資料夾
ln -s /mnt/files /var/www/redmine/files 轉移舊資料 注意:若您為全新安裝則可跳過此步驟
同步舊站的 files 至新站 1
rsync -av /mnt/old_files/ /mnt/files
舊資料庫匯入新資料庫 1
2
/usr/bin/mysqldump -u root -p redmine > /mnt/redmine.sql
mysql -u root -p redmine < redmine.sql
安裝 redmine 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
cd /var/www/redmine
sudo gem install bundler
su - redmine
bundle config set --local without 'development test'
bundle install
bundle exec rake generate_secret_token
RAILS_ENV = production bundle exec rake db:migrate
RAILS_ENV = production REDMINE_LANG = zh-TW bundle exec rake redmine:load_default_data
RAILS_ENV = production bundle exec rake redmine:plugins:migrate
RAILS_ENV = production bundle exec rake tmp:cache:clear
exit #離開 redmine 使用者
systemctl restart nginx
完成! 現在可以瀏覽https://redmine.hankchen.test 開始使用囉!
參考資料 Redmine 超詳細安裝教學:Redmine 4.1.1 on Ubuntu 16.04
How to Install Redmine on Ubuntu 22.04
Installing Passenger
RVM