前往
大廳
主題

Redmine 5.1.2 installation for Rocky Linux 9 + Nginx

Vagrant | 2024-03-06 20:50:06 | 巴幣 0 | 人氣 249

由於發現目前Radmine在5.0以後幾乎找不到安裝教學跟一堆安裝不起來的狀況,紀錄成功安裝的步驟
1.安裝Rocky Linux 9
安裝時另外建一個admin帳號並設定為管理員

2.更新及安裝套件
登入admin帳戶安裝 nginx、mariadb、ruby等套件
sudo dnf install epel-release -y
sudo dnf config-manager --set-enabled crb
sudo dnf groupinstall "Development Tools" -y
sudo dnf install ruby ruby-devel rpm-build libxml2-devel automake libtool ImageMagick ImageMagick-devel -y
sudo dnf install mariadb-server mariadb-devel httpd-devel libcurl-devel libyaml-devel
openssl-devel -y
sudo dnf install nginx svn ghostscript cvs wget net-tools vim -y
sudo dnf up -y #更新系統

3.設定啟動mariadb資料庫
sudo systemctl enable mariadb --now #設定開機自動啟動mariadb並立即啟動
sudo mysql_secure_installation
#設定資料庫
設定後進入mariadb建立資料庫
mysql -uroot -p  #登入mariadb
#建立資料庫
MariaDB [(none)]>  CREATE DATABASE redmine CHARACTER SET utf8mb4;
MariaDB [(none)]>  CREATE USER 'redmine'@'localhost' IDENTIFIED BY '密碼請自行輸入';
MariaDB [(none)]>  GRANT ALL PRIVILEGES ON redmine.* TO 'redmine'@'localhost';
MariaDB [(none)]>  FLUSH PRIVILEGES;
MariaDB [(none)]>  quit

4.下載redmine
我用官網上提供的git環境下載後執行會出錯,官網下載的載點正常
預計安裝在/opt中
cd /opt/
#使用wget下載
sudo wget https://www.redmine.org/releases/redmine-5.1.2.tar.gz  
#解壓縮
sudo tar zxvf redmine-5.1.2.tar.g
z
#目錄更名
sudo mv redmine-5.1.2 redmine
#給予目錄權限讓admin可以進去

sudo chown -R admin:admin redmine

5.設定資料庫連接
#進入redmine目錄
cd /opt/redmine
#複製資料庫連線設定檔
sudo cp config/database.yml.example config/database.yml
#修改設定檔
sudo vim config/database.yml

設定檔database.yml
production:
  adapter: mysql2
  database: redmine
  host: localhost
  username:
xxxxxxxx   #修改成剛建立的資料庫使用者
  password: "
xxxxxxxx" #資料庫密碼
  encoding: utf8mb4
  variables:
    
tx_isolation: "READ-COMMITTED"  #修改參數

6.建立依賴
sudo bundle config set --local without 'development test'  #設定略過development test
echo "gem 'puma'" > Gemfile.local
#設定puma
echo "gem 'peek' , '~> 1.1'" >> Gemfile.local #設定peek
sudo bundle install #建立依賴
sudo 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
#匯入基本資料

7.測試網頁
sudo firewall-cmd --add-port=3000/tcp #暫時開啟3000 port
bundle exec rails server -e production #啟動puma執行網站進行測試
使用閱覽器連線到 http://VM_IP:3000
預設帳密:admin
預設密碼:admin
回到虛擬機按Ctrl + C 關閉測試網站

8.設定開機自動啟動
建立puma.rb檔
sudo vim /opt/redmine/config/puma.rb
貼上下面文字,記得修改對應的目錄(黃色字)
#!/usr/bin/env puma

application_path = '
/opt/redmine'
directory application_path
environment
'production'
# daemonize true
pidfile
"#{application_path}/tmp/pids/redmine.pid"
state_path
"#{application_path}/tmp/pids/redmine.state"
stdout_redirect "#{application_path}
/log/redmine.stdout.log", "#{application_path}/log/redmine.stderr.log"
bind "
unix://#{application_path}/tmp/sockets/redmine.sock"

建立redmine.service啟動檔
sudo vim /etc/systemd/system/redmine.service
貼上下面文字,記得修改對應的目錄(黃色字)
[Unit]
Description=Rails-Puma Webserver

[Service]
Type=simple
User=admin
WorkingDirectory=/opt/redmine
ExecStart=/bin/bash -lc 'bundle exec puma -C config/puma.rb'
TimeoutSec=15
Restart=always

[Install]
WantedBy=multi-user.target

設定開機啟動
udo systemctl enable --now redmine

8.設定NGINX
sudo vim /etc/nginx/nginx.conf
由於我要使用80 port 將 server { ... } 這段註解掉
建立/etc/nginx/conf.d/redmine.conf
sudo vim /etc/nginx/conf.d/redmine.conf
貼上下面文字,記得修改對應的目錄(橘色字)
upstream app {
        
server unix:/opt/redmine/tmp/sockets/redmine.sock fail_timeout=0;
}

server {
        
listen 80 default_server;
        
listen [::]:80 default_server;

        
server_name localhost;
       
root /opt/redmine/public;
        
        
include /etc/nginx/default.d/*.conf;

        
try_files $uri/index.html $uri @app;

       
location @app {
                
proxy_pass http://app;
                
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                
proxy_set_header Host $http_host;
                
proxy_redirect off;
        }

        
error_page 500 502 503 504 /500.html;
        
client_max_body_size 4G;
        
keepalive_timeout 10;
}

9.啟動NGINX
sudo systemctl enable nginx --now
開啟防火牆
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload

Selinux設定
Nginx可讀寫redmine目錄
sudo chcon -R -t httpd_sys_rw_content_t /opt/redmine
sudo setsebool -P httpd_can_connect_ldap=1 httpd_can_network_connect=1 httpd_can_network_connect_db=1 httpd_can_sendmail=1

Nginx可讀寫puma的socket檔案(需先開啟網頁出現錯誤訊息後再執行)
sudo grep nginx /var/log/audit/audit.log | audit2allow -m nginx > nginx.te
sudo semodule_package -o nginx.pp -m nginx.mod
sudo semodule -i nginx.pp

10.開始使用

創作回應

更多創作