在 RHEL7.4 上安裝 Redmine 3.4¶
以下是在 RHEL 7.4 上安裝 Redmine 3.5 的步驟,這些步驟對我來說是有效的,截至 2018 年 2 月 1 日。
我還選擇使用 Postgres 10 來遷移現有的執行個體,儘管我相信它也可以與預設的 Postgres 9.2 一起使用。
依賴關係¶
安裝必要的套件。
% sudo yum -y install zlib-devel curl-devel openssl-devel httpd-devel apr-devel apr-util-devel mysql-devel postgresql-devel ImageMagick-devel libffi-devel
如果您打算使用 Postgres 10,請安裝以下必要的套件
% sudo yum -y install libpqxx libpqxx-devel postgresql10.x86_64 postgresql10-server postgresql10-contrib postgresql10-libs postgresql10-tcl
資料庫選擇¶
安裝您選擇的資料庫。我主要使用 Postgres 10 進行測試。
Postgres 10¶
如果您需要轉移現有的資料庫,則可以升級到 Postgres 10。
# More recent Postgres 10 % sudo yum -y install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-redhat10-10-1.noarch.rpm % sudo yum install -y postgresql10-server postgresql10 postgres-devel % export PATH=/usr/pgsql-10/bin/:$PATH % postgresql-10-setup initdb
請注意,以下的 bundle install
步驟仍然需要 postgres-devel
套件,我不確定該步驟是否適用於 Postgres 10。
與 Postgres 9 一樣,您需要在 /var/lib/pgsql/10/data/pg_hba.conf
中為本地 IPv6 連線新增 trust
# TYPE DATABASE USER ADDRESS METHOD # "local" is for Unix domain socket connections only local all all peer # IPv4 local connections: host all all 127.0.0.1/32 trust # IPv6 local connections: host all all ::1/128 trust
然後,您可以啟動資料庫伺服器
% sudo systemctl start postgresql-10 % sudo systemctl enable postgresql-10
檢查您是否可以連線到資料庫,然後建立 redmine
使用者和 redmine
資料庫
% sudo su - postgres % export PATH=/usr/pgsql-10/bin/:$PATH % psql postgres=# alter role postgres with encrypted password 'insert-your-postgres-password-here'; postgres=# create user redmine with encrypted password 'insert-your-redmine-password-here'; postgres=# create database redmine with encoding 'UTF-8' owner redmine;
如果您收到與編碼相關的錯誤(我只在 Postgres 9 上遇到過)
ERROR: new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII) HINT: Use the same encoding as in the template database, or use template0 as template.
那麼您應該明確使用 template0
postgres=# create database redmine with template=template0 encoding 'UTF-8' owner redmine;
Postgres 9.2.23¶
Postgres 9.2.23 是您在 RHEL 7.4 中使用 yum
安裝時直接獲得的版本
# Default Postgres 9.2.23 % sudo yum -y install postgresql postgresql-server postgresql-devel % postgresql-setup initdb % sudo systemctl start postgresql % sudo systemctl enable postgresql
我無法在不修改 /var/lib/pgsql/data/pg_hba.conf
將本地 IPv6 連線設定為 trust
的情況下,讓 Redmine 連線到資料庫
# TYPE DATABASE USER ADDRESS METHOD # "local" is for Unix domain socket connections only local all all peer # IPv4 local connections: host all all 127.0.0.1/32 trust # IPv6 local connections: host all all ::1/128 trust
我懷疑這是錯誤的,但我不知道如何「正確」地做到這一點,這也是我在查看的 Redmine Docker 容器中的配置方式。
像上一節一樣建立使用者和資料庫。
對於 MySQL / MariaDB¶
安裝並啟動資料庫伺服器
# MariaDB (formerly MySQL) % sudo yum -y install mariadb mariadb-devel % sudo systemctl start mariadb % sudo systemctl enable mariadb
然後您可以設定原始資料庫
% mysql -u root -p MariaDB [(none)]> set password for 'root'@'localhost' = password('insert-your-password-here'); MariaDB [(none)]> create database redmine character set utf8; MariaDB [(none)]> create user 'redmine'@'localhost' identified by 'somepass'; MariaDB [(none)]> grant all privileges on redmine.* to 'redmine'@'localhost';
注意:此設定的其餘部分假設使用 Postgres,也需要使用 MariaDB 的說明進行更新。
升級 Ruby¶
預設的 ruby
版本是 2.0.0p648。如果您保留該版本,gem install passenger
會失敗。
% sudo yum install -y gcc % cd /usr/local/src % wget https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.0.tar.gz % tar xvfz ruby-2.5.0.tar.gz % cd ruby-2.5.0/ % ./configure % make % sudo make install
之後,請確認您已安裝 Ruby 2.5
% export PATH=/usr/local/bin:$PATH % ruby -v ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-linux]
安裝 Passenger 和 Gem Bundler:¶
使用 Ruby 2.5,我們可以安裝 Passenger
% gem install passenger gem install passenger Fetching: rack-2.0.3.gem (100%) Successfully installed rack-2.0.3 Fetching: passenger-5.2.0.gem (100%) Building native extensions. This could take a while... Successfully installed passenger-5.2.0 Parsing documentation for rack-2.0.3 Installing ri documentation for rack-2.0.3 Parsing documentation for passenger-5.2.0 Installing ri documentation for passenger-5.2.0 Done installing documentation for rack, passenger after 53 seconds 2 gems installed
安裝 Gem Bundler
% gem install bundler Fetching: bundler-1.16.1.gem (100%) Successfully installed bundler-1.16.1 Parsing documentation for bundler-1.16.1 Installing ri documentation for bundler-1.16.1 Done installing documentation for bundler after 5 seconds 1 gem installed
下載 Redmine¶
新增 redmine
使用者
% sudo useradd redmine
安裝 svn
以便能夠下載 Redmine
% sudo yum -y install svn
下載您想要的 Redmine 版本,這裡使用 3.4 版
% su redmine % cd /var/www % svn co http://svn.redmine.org/redmine/branches/3.4-stable redmine
資料庫設定¶
Redmine 的資料庫設定位於 /var/www/redmine/config/database.yml
。該目錄中有一個範本可供編輯。
% cd /var/www/redmine/config/ % cp database.yml.example database.yml
編輯 database.yml
以包含與您的安裝相關的正確資訊。對於 Postgres
production: adapter: postgresql database: redmine host: localhost username: redmine password: insert-your-password-here
(請注意,您始終可以選擇在 localhost
以外的其他主機上執行資料庫)
使用 Gem bundler 安裝依賴套件¶
此步驟將查看 Gemfile
中指定的依賴套件
% cd /var/www/redmine % bundle install
您可能會看到有關 YARD 建議您使用以下命令的消息
% yard config --gem-install-yri Updated ~/.gemrc: 'gem: --document=yri'
設定生產環境¶
更新 /var/www/redmine/config/environment.rb
,加入以下語句
ENV['RAILS_ENV'] ||= 'production'
產生一個密鑰
% RAILS_ENV=production bundle exec rake generate_secret_token
執行資料庫遷移步驟
% RAILS_ENV=production bundle exec rake db:migrate
啟動伺服器¶
請注意,您可能需要使用 firewall-config
或 firewall-cmd
為該端口開啟防火牆,例如:
% sudo firewall-cmd --zone=public --add-port=3000/tcp --permanent
您現在可以嘗試執行應用程式
% sudo su - redmine % cd /var/www/redmine % /usr/local/bin/ruby bin/rails server -b 0.0.0.0 -e production => Booting WEBrick => Rails 4.2.8 application starting in production on http://0.0.0.0:3000 => Run `rails server -h` for more startup options => Ctrl-C to shutdown server [2018-02-01 12:49:02] INFO WEBrick 1.4.2 [2018-02-01 12:49:02] INFO ruby 2.5.0 (2017-12-25) [x86_64-linux] [2018-02-01 12:49:02] INFO WEBrick::HTTPServer#start: pid=21470 port=3000
選用安裝¶
如果您使用版本控制系統,您可能需要類似以下的內容(選擇適用的內容)
% yum -y install darcs hg cvs bzr git
新增 systemd 服務¶
您可以選擇在 /usr/lib/systemd/system/redmine.service
中為您的伺服器建立 systemd 服務,以確保它自動啟動。
[Unit] Description=Redmine server After=network.target remote-fs.target nss-lookup.target [Service] Type=simple User=redmine Group=redmine EnvironmentFile=/etc/sysconfig/httpd ExecStart=/usr/local/bin/ruby /var/www/redmine/bin/rails server -b 0.0.0.0 -e production TimeoutSec=300 ExecStop=/bin/kill -WINCH ${MAINPID} [Install] WantedBy=multi-user.target
新增 HTTPS 支援¶
建立 Apache 虛擬主機¶
假設您想使用伺服器名稱直接連線。建立一個名為 /etc/httpd/conf.d/redmine.conf
的檔案,其中包含
<VirtualHost *:443> ServerName my-server-name@my-domain.com ServerAdmin my-admin-name@my-domain.com ErrorLog "logs/redmine_error_log" SSLEngine on SSLCertificateFile /etc/pki/tls/certs/ca.crt SSLCertificateKeyFile /etc/pki/tls/private/ca.key DocumentRoot /var/www/redmine/public <Directory /var/www/redmine/public> AllowOverride all Options -MultiViews </Directory> </VirtualHost>
建立包含轉寫規則到 dispatch.cgi 的 .htaccess¶
請注意,您需要先建立憑證(網路上有很多關於如何建立憑證的資源)
在 /var/www/redmine/public/.htaccess
中新增以下內容
# General Apache options <IfModule cgi_module> AddHandler cgi-script .cgi </IfModule> <IfModule mod_fastcgi.c> AddHandler fastcgi-script .fcgi </IfModule> <IfModule mod_fcgid.c> AddHandler fcgid-script .fcgi </IfModule> Options +FollowSymLinks +ExecCGI # If you don't want Rails to look in certain directories, # use the following rewrite rules so that Apache won't rewrite certain requests # # Example: # RewriteCond %{REQUEST_URI} ^/notrails.* # RewriteRule .* - [L] # Redirect all requests not available on the filesystem to Rails # By default the cgi dispatcher is used which is very slow # # For better performance replace the dispatcher with the fastcgi one # # Example: # RewriteRule ^(.*)$ dispatch.fcgi [QSA,L] RewriteEngine On # If your Rails application is accessed via an Alias directive, # then you MUST also set the RewriteBase in this htaccess file. # # Example: # Alias /myrailsapp /path/to/myrailsapp/public # RewriteBase /myrailsapp RewriteRule ^$ index.html [QSA] RewriteRule ^([^.]+)$ $1.html [QSA] RewriteCond %{REQUEST_FILENAME} !-f <IfModule cgi_module> RewriteRule ^(.*)$ dispatch.cgi [QSA,L] </IfModule> <IfModule mod_fastcgi.c> RewriteRule ^(.*)$ dispatch.fcgi [QSA,L] </IfModule> <IfModule mod_fcgid.c> RewriteRule ^(.*)$ dispatch.fcgi [QSA,L] </IfModule> # In case Rails experiences terminal errors # Instead of displaying this message you can supply a file here which will be rendered instead # # Example: ErrorDocument 500 /500.html
建立 dispatch.cgi 檔案¶
最後,您需要一個 /var/www/redmine/public/dispatch.cgi
腳本
#!/usr/local/bin/ruby require File.dirname(__FILE__) + '/../config/boot' require File.dirname(__FILE__) + '/../config/environment' class Rack::PathInfoRewriter def initialize(app) @app = app end def call(env) env.delete('SCRIPT_NAME') parts = env['REQUEST_URI'].split('?') env['PATH_INFO'] = parts[0] env['QUERY_STRING'] = parts[1].to_s @app.call(env) end end Rack::Handler::CGI.run Rack::PathInfoRewriter.new(RedmineApp::Application)
調整 SELinux 策略¶
您還需要確保 Apache 被允許執行所有這些部分
% cd /var/www/redmine/public % sudo chown -R apache:apache . % sudo chmod +x dispatch.cgi
最後,必須建立一個允許該 CGI 腳本執行的 SELinux 策略,否則您將收到內部伺服器錯誤
% sudo semanage boolean -m --on httpd_enable_cgi % sudo semanage fcontext -a -t httpd_sys_script_exec_t /var/www/redmine/public % sudo restorecon /var/www/redmine/public % sudo setsebool -P httpd_can_network_connect 1 % sudo setsebool -P httpd_can_network_connect_db 1 % ausearch -c 'dispatch.cgi' --raw | audit2allow -M my-dispatchcgi % semodule -i my-dispatchcgi.pp
由 Gil Cesar Faria 於 6 年多前 更新 · 24 個版本