專案

一般

個人資料

動作

在 CentOS 7 + SELinux、Apache 2.4、Passenger 上安裝 Redmine 4.2.x

*_2021 年 8 月 17 日編輯_:本指南最初是為 Redmine 4.2.1 編寫的,但在發佈後不久就發佈了 4.2.2 版。本指南中的步驟應該同樣適用於任何 4.2.x 版本的 Redmine,但請注意,它僅在 4.2.1 和 4.2.2 上進行過測試。

本指南將引導您完成在 CentOS7 上安裝 Redmine 4.2.x 的過程,包括對 SELinux 的支援。以下大部分內容均基於 Franck Michel 的優秀指南,該指南可以在 這裡找到。

本指南不包含安裝和設定 Redmine 資料庫的內容;這一點在許多其他指南中都有介紹,而且非常簡單。本指南也不涵蓋任何 SCM 儲存庫或與 LDAP 的整合,但將涵蓋如何在 CentOS7 中啟用 SELinux 的情況下使用 Redmine。我見過的每個 Redmine HOWTO 都使用了 Passenger GEM,但是 GEM 沒有任何 SELinux 政策。雖然有一個 SELinux HOWTO 在這裡,但遵循它並沒有真正幫助我。本指南代表了閱讀 Redmine、Passenger 和 SELinux 錯誤日誌的許多小時的痛苦。希望您覺得它有用!

本指南中使用的完整配置為:

  • CentOS Linux 版本 7.9.2009 (Core)
  • Apache 2.4.6
  • Redmine 4.2.2
  • Ruby 2.7.3
  • Apache Passenger 6.0.8
  • SELinux 調整

初始設定

首先,我建議全新安裝 CentOS。當然,您必須安裝選擇的 RDBMS,可以在同一台伺服器上,也可以在專用伺服器上。

安裝必要的套件

我們將安裝安裝 Ruby 所需的所有套件。此外,我們還將安裝 Apache 和 mod_ssl,這是我們提供 Redmine 服務所需的。

[As root/sudo]:
yum install -y gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison iconv-devel sqlite-devel wget mysql-devel httpd mod_ssl

安裝 Ruby 2.7.3

直接改編自 Franck 的指南這裡

[As root/sudo]:
gpg2 --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
curl -L get.rvm.io | bash -s stable
source /etc/profile.d/rvm.sh
rvm reload
rvm requirements run
rvm install 2.7
rvm list
ruby --version 

安裝 Redmine 4.2.2

撰寫本文時,最新版本為 4.2.2。這是改編自 Frank 的指南這裡
我喜歡將 Redmine 安裝在 /var/www/ 中

下載並解壓縮 Redmine

wget https://redmine.org/releases/redmine-4.2.2.tar.gz
tar xvfz redmine-4.2.2.tar.gz
mv redmine-4.2.2 /var/www/
export REDMINE=/var/www/redmine-4.2.2
cd $REDMINE
cp config/database.yml.example config/database.yml 

這會將 Redmine 安裝到 /var/www 目錄。這適用於 Apache 和 SELinux。

自訂您的 `database.yml` 檔案。您可以參考指南以取得更多幫助。

vi config/database.yml 

安裝 Gems 並建立資料庫結構描述

cd $REDMINE
gem install bundler
bundle install --without development test
bundle exec rake generate_secret_token
RAILS_ENV=production REDMINE_LANG=en bundle exec rake db:migrate
RAILS_ENV=production REDMINE_LANG=en bundle exec rake redmine:load_default_data 

安裝 Passenger 6.0.8

這份指南將從 Franck 的指南大幅分歧。該指南以及我找到的所有其他適用於 Apache 的指南都使用了 Passenger Gem,您可以透過執行以下操作來安裝它

gem install passenger

但是,當您完成安裝過程時,安裝程式實際上會警告您,在 RHEL 類型系統上安裝 Passenger 的建議方法是使用套件管理器,因為這將包含 Passenger 正常運作所需的 SELinux 策略。這就是我們要在這邊做的事情。這些步驟改編自優秀的 Passenger 安裝指南,可以在這裡找到。

yum install -y epel-release yum-utils
yum-config-manager --enable epel
yum clean all && sudo yum update -y
yum install -y pygpgme curl
curl --fail -sSLo /etc/yum.repos.d/passenger.repo https://oss-binaries.phusionpassenger.com/yum/definitions/el-passenger.repo
yum install -y mod_passenger 

安裝 Passenger 後,您可以使用以下命令驗證安裝

/usr/bin/passenger-config validate-install

應該會顯示如下輸出

 * Checking whether this Passenger install is in PATH... ✓
 * Checking whether there are no other Passenger installations... ✓ 

現在,事情變得有點棘手了。作為其安裝過程的一部分,`RVM` 會安裝您要求的任何版本的 Ruby,但也會安裝系統版本的 Ruby(在撰寫本文時,CentOS7 的版本為 2.0.0.648-36.el7,這已經過時了)。安裝 Passenger 時,系統 Ruby 套件是必需的,並且 Passenger 會「指向」系統版本的 Ruby。由於 Redmine 至少需要 Ruby 2.4,但我們希望使用尚未 EOL 的版本,因此這會給我們帶來各種問題。幸運的是,Passenger 的文件涵蓋了這個問題
「安裝後,您可以在任何想要的 Ruby 解釋器下執行 Passenger 的 Ruby 部分,即使該 Ruby 解釋器不是您最初安裝 Passenger 時使用的。」

太好了!讓我們來做吧。在離開本節之前,我們需要確定 RVM Ruby 解釋器的安裝位置。使用以下命令

/usr/bin/passenger-config --ruby-command 

這應該會返回類似以下內容

passenger-config was invoked through the following Ruby interpreter:
  Command: /usr/local/rvm/gems/ruby-2.7.2/wrappers/ruby
  Version: ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
  To use in Apache: PassengerRuby /usr/local/rvm/gems/ruby-2.7.2/wrappers/ruby
  To use in Nginx : passenger_ruby /usr/local/rvm/gems/ruby-2.7.2/wrappers/ruby
  To use with Standalone: /usr/local/rvm/gems/ruby-2.7.2/wrappers/ruby /usr/bin/passenger start

## Notes for RVM users
Do you want to know which command to use for a different Ruby interpreter? 'rvm use' that Ruby interpreter, then re-run 'passenger-config about ruby-command'. 

設定 Apache

在 apache 中建立一個新的虛擬主機設定檔:/etc/httpd/conf.d/redmine.conf。同樣,本節的大部分內容都來自 Franck 的指南,但有一個關鍵的補充。第一行來自上一節中命令的輸出,它告訴 Passenger 使用哪個 Ruby 解釋器。

PassengerRuby /usr/local/rvm/gems/ruby-2.7.2/wrappers/ruby

<VirtualHost *:80>
    ServerName yourserver.domain.org
    DocumentRoot "/var/www/redmine-4.2.2/public" 

    ErrorLog logs/redmine_error_log
    LogLevel warn

    <Directory "/var/www/redmine-4.2.2/public">
        Options Indexes ExecCGI FollowSymLinks
        Require all granted
        AllowOverride all
    </Directory>
</VirtualHost> 

權限和 SELinux 策略

現在是時候設定權限和 SELinux 策略了。我們將從設定整個 Redmine 資料夾的正常 Linux 權限開始。其他一些指南僅將其應用於某些子資料夾,但我發現啟用 SELinux 後,有必要將所有內容都 chown 為 apache:apache。

cd $REDMINE
cd ..
chown -R apache:apache redmine-4.2.2 

接下來,我們將設定 SELinux 策略。這些取自這份指南

# Set SELinux permissions
chcon -R -t httpd_log_t redmine-4.2.2/log/
chcon -R -t httpd_tmpfs_t redmine-4.2.2/tmp/
chcon -R -t httpd_sys_script_rw_t redmine-4.2.2/files/
chcon -R -t httpd_sys_script_rw_t redmine-4.2.2/public/plugin_assets/
restorecon -Rv redmine-4.2.2/ 

環境變數

Passenger可能會抱怨它無法安裝原生支援的 .so 檔案。我們可以透過將以下行添加到以下內容來抑制此警告

vi /etc/sysconfig/httpd

PASSENGER_COMPILE_NATIVE_SUPPORT_BINARY=0
PASSENGER_DOWNLOAD_NATIVE_SUPPORT_BINARY=0 

就是這樣!

此時,重新啟動 Apache。

systemctl restart httpd 

您應該能夠透過在上面步驟 X 中輸入的網域存取 Redmine。

其他注意事項

一些額外的注意事項

  • 安裝某種防火牆(iptables 或 firewalld)來保護您的伺服器是明智的。
  • 如果您將主題或外掛安裝到 Redmine,則必須重複上述的 chown 程序。

Fletcher Johnston 更新於 將近 3 年前 · 3 個版本