在RHEL7.4上安装Redmine 3.4¶
以下是我成功安装Redmine 3.5在RHEL 7.4上的步骤。这些说明适用于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
中添加trust
以供本地IPv6连接使用。
# 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
我无法让Redmine连接到数据库,除非将/var/lib/pgsql/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
我怀疑这是错误的,但不知道如何正确操作,而且这也是我查看的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 打包器安装依赖项¶
此步骤将检查 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 [email protected] ServerAdmin [email protected] 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>
创建 .htaccess 文件,包含用于将请求重定向到 dispatch.cgi 的重写规则¶
请注意,您需要创建证书(网上有许多关于如何创建证书的资源)
在 /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
最后,需要创建一个 SELinux 策略,允许该 CGI 脚本运行,否则您将收到内部服务器错误
% 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次修订