本页内容

  • 先决条件
  • 第 1 步 - 配置防火墙
  • 第 2 步 - 安装 Apache 服务器
  • 第 3 步 - 安装并配置 MySQL 服务器
  • 第 4 步 - 安装 EPEL 软件仓库
  • 第 5 步 - 安装 Ruby 及其他必备组件
  • 第 6 步 - 安装 Redmine
  • 第 7 步 - 安装 Phusion Passenger 配置 Apache 服务器
  • 第 8 步 - 安装 SSL
  • 第 9 步 - 安装并配置 Nginx 作为反向代理 更改 Apache 监听端口 配置 Nginx
  • 结论
  • 配置 Apache 服务器
  • 更改 Apache 监听端口
  • 配置 Nginx

Redmine 是一款免费开源的项目管理软件和问题跟踪工具。它使用 Ruby on Rails 框架编写,可以与各种版本控制系统集成。它包含版本库浏览器和差异查看器。它可用于管理项目功能、每个项目的 wiki 和论坛、时间跟踪以及基于角色的访问控制。它跨平台、跨数据库,并支持 49 种语言。

在本教程中,你将学习如何在基于 Rocky Linux 8 的服务器上安装 Redmine。

先决条件

  • 一台运行 Rocky Linux 的服务器。
  • 一个具有 root 权限的非 sudo 用户。
  • 禁用 SELinux。
  • 所有内容均已更新。$ sudo dnf update

一台运行 Rocky Linux 的服务器。

一个具有 root 权限的非 sudo 用户。

禁用 SELinux。

所有内容均已更新。

$ sudo dnf update

第 1 步 - 配置防火墙

第一步是配置防火墙。Rocky Linux 使用 Firewalld 防火墙。检查防火墙的状态。

$ sudo firewall-cmd --state
running

开放端口 3000,我们可以用它来检查 Redmine。

$ sudo firewall-cmd --permanent --add-port=3000

允许 HTTP 和 HTTPS 端口。

$ sudo firewall-cmd --permanent --add-service=http
$ sudo firewall-cmd --permanent --add-service=https

重新加载防火墙以使更改生效。

$ sudo firewall-cmd --reload

第 2 步 - 安装 Apache 服务器

我们将使用 Apache web 服务器来部署 Redmine。使用以下命令安装 Apache。

$ sudo dnf install httpd

启用并启动 Apache 服务。

$ sudo systemctl enable --now httpd.service

将你当前登录的用户授予 apache 用户,使其对 /var/www/redmine 目录具有必要的访问权限。

$ sudo usermod -aG $USER apache

第 3 步 - 安装并配置 MySQL 服务器

我们将使用 MySQL 数据库来存储数据。Rocky Linux 的 Appstream 软件仓库附带了最新版本的 MySQL。

安装 MySQL。

$ sudo dnf install mysql-server

启用并启动 MySQL 服务。

$ sudo systemctl enable mysqld --now

加固 MySQL 安装。

$ sudo mysql_secure_installation

第一步,系统会询问你是否要设置 Validate Password Plugin,可用它来测试 MySQL 密码的强度。选择 Y 继续。下一步会要求你选择密码验证级别。选择 2,这是最强的级别,将要求密码至少 8 个字符长,并包含大写、小写、数字和特殊字符的组合。

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: Y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2

下一步会要求你选择 root 密码。选择一个满足密码验证插件要求的强密码。在接下来的步骤中,系统会询问你是否继续使用所选密码。按 y 继续。

Please set the password for root here.

New password:

Re-enter new password:

Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y

对于以下所有提示,按 Y 然后按 ENTER 键,以删除匿名用户和测试数据库、禁用 root 登录并加载新设置的规则。

...
Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
Success.
...
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
Success.
...
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
 - Dropping test database...
Success.
 - Removing privileges on test database...
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
...
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
Success.
All done!

进入 MySQL shell。输入你的 root 密码以继续。

$ mysql -u root -p

创建 redmine 用户。确保密码满足之前设置的要求。

mysql> CREATE USER 'redmine'@'localhost' IDENTIFIED BY 'Your_password2';

创建 redmine 数据库。

mysql> CREATE DATABASE redmine CHARACTER SET utf8mb4;

授予用户对该 redmine 数据库的权限。

mysql> GRANT ALL PRIVILEGES ON redmine.* TO 'redmine'@'localhost';

退出 Shell。

mysql> exit

第 4 步 - 安装 EPEL 软件仓库

Redmine 所需的一些软件包可在 EPEL 软件仓库中找到。运行以下命令安装 EPEL 软件仓库。

$ sudo dnf install epel-release

启用 PowerTools 软件仓库。

$ sudo dnf config-manager --set-enabled powertools

第 5 步 - 安装 Ruby 及其他必备组件

Rocky Linux 8 附带四个不同版本的 Ruby - 2.5、2.6、2.7 和 3.0。

列出所有可用的 Ruby 模块。

$ dnf module list ruby
Last metadata expiration check: 0:18:58 ago on Mon 03 Jan 2022 11:50:10 AM UTC.
Rocky Linux 8 - AppStream
Name            Stream             Profiles              Summary
ruby            2.5 [d]            common [d]            An interpreter of object-oriented scripting language
ruby            2.6                common [d]            An interpreter of object-oriented scripting language
ruby            2.7                common [d]            An interpreter of object-oriented scripting language
ruby            3.0                common [d]            An interpreter of object-oriented scripting language

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

Redmine 的最新版本与除 3.0 之外的所有版本兼容。我们将在本教程中安装 Ruby 2.7。

重置其他版本并启用 Ruby 的 2.7 版本。

$ sudo dnf module reset ruby
$ sudo dnf module enable ruby:2.7

安装 Ruby。

$ sudo dnf install ruby ruby-devel

验证安装。

$ ruby -v
ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [x86_64-linux]

安装 Redmine 所需的所有其余软件包。

$ sudo dnf install rpm-build wget libxml2-devel make automake libtool ImageMagick ImageMagick-devel mariadb-devel httpd-devel openssl-devel libcurl-devel gcc gcc-c++

第 6 步 - 安装 Redmine

访问 Redmine 下载页面,查看可用的最新稳定版本。在撰写本教程时,最新的可用版本是 4.2.3。

使用 wget 下载 Redmine。

$ wget https://redmine.org/releases/redmine-4.2.3.tar.gz

解压并将文件移动到 /var/www/redmine 目录。

$ tar xfz redmine-4.2.3.tar.gz
$ sudo mv redmine-4.2.3 /var/www/redmine

切换到 /var/www/redmine 目录。

$ cd /var/www/redmine

使用提供的示例文件创建 Redmine 配置文件。

$ cp config/configuration.yml.example config/configuration.yml
$ cp config/database.yml.example config/database.yml
$ cp public/dispatch.fcgi.example public/dispatch.fcgi

打开 database.yml 文件进行编辑。

$ nano config/database.yml

在以下部分找到并配置你的数据库设置。

production:
  adapter: mysql2
  database: redmine
  host: localhost
  username: redmine
  password: "Your_password2"
  # Use "utf8" instead of "utfmb4" for MySQL prior to 5.7.7
  encoding: utf8mb4

按 Ctrl + X 保存文件,并在提示时输入 Y。

安装 bundler 以管理 ruby gem 依赖项。

$ gem install bundler

设置安装 gem 依赖项的环境。

$ bundle config set --local without 'development test'

安装 gem 依赖项。

$ bundle install

如果遇到任何 gem 版本问题,请使用以下命令进行恢复。

$ sudo gem pristine --all

生成一个随机密钥,以防止用于存储会话数据的 cookie 被篡改。

$ bundle exec rake generate_secret_token

创建数据库结构。

$ RAILS_ENV=production bundle exec rake db:migrate

将数据插入 MySQL 数据库。

$ RAILS_ENV=production REDMINE_LANG=en bundle exec rake redmine:load_default_data

创建必要的目录并设置文件权限。

$ mkdir -p tmp/pdf
$ mkdir -p public/plugin_assets
$ chown -R $USER:$USER files log tmp public/plugin_assets
$ chmod -R 755 /var/www/remine/

运行以下命令以启动 Rails 服务器实例。

$ bundle exec rails server webrick -e production
=> Booting WEBrick
=> Rails 5.2.6 application starting in production on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
[2022-01-03 12:58:19] INFO  WEBrick 1.6.1
[2022-01-03 12:58:19] INFO  ruby 2.7.4 (2021-07-07) [x86_64-linux]
[2022-01-03 12:58:19] INFO  WEBrick::HTTPServer#start: pid=117224 port=3000

打开 URL http://:3000/login 以打开 Redmine 登录界面。

如何在Rocky Linux 8服务器上安装Redmine项目管理软件

输入默认凭据(admin/admin)进行登录。系统会要求你更改密码。

如何在Rocky Linux 8服务器上安装Redmine项目管理软件

接下来,你将被重定向到 My Account 页面。

如何在Rocky Linux 8服务器上安装Redmine项目管理软件

Redmine 已成功安装。

接下来,在终端上按 CTRL+C 停止服务器。

第 7 步 - 安装 Phusion Passenger

Phusion Passenger 是一个 ruby 应用服务器,使我们能够通过第三方服务器提供 Redmine。在我们的例子中,我们将使用 Apache。

安装 Passenger。

$ gem install passenger

为 Apache 服务器安装 Passenger 模块。

$ passenger-install-apache2-module

你将看到一条欢迎消息。按 Enter 继续。

Welcome to the Phusion Passenger Apache 2 module installer, v6.0.12.

This installer will guide you through the entire installation process. It
shouldn't take more than 3 minutes in total.

Here's what you can expect from the installation process:

 1. The Apache 2 module will be installed for you.
 2. You'll learn how to configure Apache.
 3. You'll learn how to deploy a Ruby on Rails application.

Don't worry if anything goes wrong. This installer will advise you on how to
solve any problems.

Press Enter to continue, or Ctrl-C to abort.


--------------------------------------------

接下来,系统会询问你选择语言。默认选中 Ruby,因此只需按 Enter 继续。

Which languages are you interested in?

Use <space> to select.
If the menu doesn't display correctly, press '!'

 ? ?  Ruby
   ?  Python
   ?  Node.js
   ?  Meteor

--------------------------------------------

你可能会收到有关文件权限的警告。如果你一直按照我们的教程操作,只需按 Enter 继续。

Warning: some directories may be inaccessible by the web server!

The web server typically runs under a separate user account for security
reasons. That user must be able to access the Phusion Passenger(R) files.
However, it appears that some directories have too strict permissions. This
may prevent the web server user from accessing Phusion Passenger(R) files.

It is recommended that you relax permissions as follows:

  sudo chmod o+x "/home/navjot"

Press Ctrl-C to return to the shell. (Recommended)
After relaxing permissions, re-run this installer.
  -OR-
Press Enter to continue anyway.

整个过程大约需要 10-15 分钟才能完成。如果出现如下错误,很可能是由于 RAM 不足。你应该增加服务器上的 RAM 或安装交换空间。

c++: fatal error: Killed signal terminated program cc1plus
compilation terminated.
rake aborted!

过程完成后,你将看到以下消息。

--------------------------------------------
Almost there!

Please edit your Apache configuration file, and add these lines:

   LoadModule passenger_module /home/navjot/.gem/ruby/gems/passenger-6.0.12/buildout/apache2/mod_passenger.so
   <IfModule mod_passenger.c>
     PassengerRoot /home/navjot/.gem/ruby/gems/passenger-6.0.12
     PassengerDefaultRuby /usr/bin/ruby
   </IfModule>

After you restart Apache, you are ready to deploy any number of web
applications on Apache, with a minimum amount of configuration!

Press ENTER when you are done editing.

暂时不要按 Enter。以当前用户身份在服务器上打开一个新会话,并执行以下配置。

配置 Apache 服务器

为 Phusion Passenger 创建一个 Apache 模块配置文件。

$ sudo nano /etc/httpd/conf.modules.d/00-passenger.conf

粘贴你在 passenger 安装结束时获得的代码。

 LoadModule passenger_module /home/navjot/.gem/ruby/gems/passenger-6.0.12/buildout/apache2/mod_passenger.so
   <IfModule mod_passenger.c>
     PassengerRoot /home/username/.gem/ruby/gems/passenger-6.0.12
     PassengerDefaultRuby /usr/bin/ruby
   </IfModule>

按 Ctrl + X 保存文件,并在提示时输入 Y。

为 Redmine 站点创建另一个 Apache 配置文件。

$ sudo nano /etc/httpd/conf.d/redmine.conf

在其中粘贴以下代码。

Listen 3000
<IfModule mod_passenger.c>
  PassengerRoot /home/username/.gem/ruby/gems/passenger-6.0.12
  PassengerDefaultRuby /usr/bin/ruby
</IfModule>
<VirtualHost *:3000>
    ServerName redmine.example.com
    DocumentRoot "/var/www/redmine/public" 

    CustomLog logs/redmine_access.log combined
    ErrorLog logs/redmine_error_log
    LogLevel warn

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

按 Ctrl + X 保存文件,并在提示时输入 Y。

打开主 Apache 配置文件 /etc/httpd/conf/httpd.conf 进行编辑。

$ sudo nano /etc/httpd/conf/httpd.conf

找到变量 ServerName,删除其前面的井号(#)以取消注释,并按如下方式设置其值。

ServerName localhost

按 Ctrl + X 保存文件,并在提示时输入 Y。

验证你的 Apache 配置。

$ httpd -t
Syntax OK

返回并按 Enter 继续 Passenger 安装。它将执行一些检查,成功完成后你应该会看到以下消息。

Deploying a web application

To learn how to deploy a web app on Passenger, please follow the deployment
guide:

  https://www.phusionpassenger.com/library/deploy/apache/deploy/

Enjoy Phusion Passenger, a product of Phusion® (www.phusion.nl) :-)
https://www.phusionpassenger.com

Passenger® is a registered trademark of Phusion Holding B.V.

重启你的 Apache 服务器。

$ sudo systemctl restart httpd

你的网站应可在 http://redmine.example.com:3000 访问。

这不是访问 Redmine 的理想方式。它仍然通过不安全的 HTTP 协议提供,并使用端口号。我们将安装 Nginx 作为反向代理,并使用 HTTPS 协议提供 Redmine,以改善这一点。在进行 Nginx 安装和配置之前,我们需要设置 SSL 证书。

第 8 步 - 安装 SSL

要使用 Let's Encrypt 安装 SSL 证书,我们需要安装 Certbot 工具。运行以下命令安装 Certbot。

$ sudo dnf install certbot

停止 Apache 服务器。

$ sudo systemctl stop httpd

生成 SSL 证书。

$ sudo certbot certonly --standalone --agree-tos --no-eff-email --staple-ocsp --preferred-challenges http -m 
[email protected]
 -d redmine.example.com

上述命令会将证书下载到服务器上 /etc/letsencrypt/live/redmine.example.com 目录。

启动 Apache 服务器。

$ sudo systemctl start httpd

生成 Diffie-Hellman 组证书。

$ sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048

为 Let's Encrypt 自动续期创建一个 challenge webroot 目录。

$ sudo mkdir -p /var/lib/letsencrypt

创建一个 Cron Job 来续期 SSL。它将每天运行以检查证书并在需要时续期。为此,首先创建文件 /etc/cron.daily/certbot-renew 并打开进行编辑。

$ sudo nano /etc/cron.daily/certbot-renew

粘贴以下代码。

#!/bin/sh
certbot renew --cert-name redmine.example.com --webroot -w /var/lib/letsencrypt/ --post-hook "systemctl restart nginx"

按 Ctrl + X 保存文件,并在提示时输入 Y。

更改该任务文件的权限以使其可执行。

$ sudo chmod +x /etc/cron.daily/certbot-renew

第 9 步 - 安装并配置 Nginx 作为反向代理

Rocky Linux 8 附带四个不同版本的 Nginx - 1.14、1.16、1.18 和 1.20。

列出所有可用的 Nginx 模块。

$ dnf module list nginx
Last metadata expiration check: 20:23:20 ago on Mon 03 Jan 2022 12:38:07 PM UTC.
Rocky Linux 8 - AppStream
Name                      Stream                       Profiles                      Summary
nginx                     1.14 [d]                     common [d]                    nginx webserver
nginx                     1.16                         common [d]                    nginx webserver
nginx                     1.18                         common [d]                    nginx webserver
nginx                     1.20                         common [d]                    nginx webserver

Extra Packages for Enterprise Linux Modular 8 - x86_64
Name                      Stream                       Profiles                      Summary
nginx                     mainline                     common                        nginx webserver
nginx                     1.20                         common [d]                    nginx webserver

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

重置其他版本并启用 Nginx 的 1.20 版本。

$ sudo dnf module reset nginx
$ sudo dnf module enable nginx:1.20

安装 Nginx。我们暂时禁用 Epel 软件仓库,因为我们想从 Appstream 获取 Nginx。

$ sudo dnf install nginx --disablerepo=epel-modular

验证安装。

$ nginx -v
nginx version: nginx/1.20.0

为避免与 Nginx 发生冲突,我们需要更改 Apache 默认监听的端口。

更改 Apache 监听端口

打开文件 /etc/httpd/conf/httpd.conf 进行编辑。

$ sudo nano /etc/httpd/conf/httpd.conf

按如下方式将端口从 80 更改为 8080。

Listen 8080

按 Ctrl + X 保存文件,并在提示时输入 Y。

重启 Apache。

$ sudo systemctl restart httpd

配置 Nginx

创建并打开文件 /etc/nginx/conf.d/redmine.conf 进行编辑。

$ sudo nano /etc/nginx/conf.d/redmine.conf

在其中粘贴以下代码。

# Redirect all non-encrypted to encrypted
server {
    listen 80;
    server_name redmine.example.com;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;

    server_name redmine.example.com;

    ssl_certificate     /etc/letsencrypt/live/redmine.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/redmine.example.com/privkey.pem;
	ssl_trusted_certificate /etc/letsencrypt/live/redmine.example.com/chain.pem;
	
	ssl_session_timeout  5m;
    ssl_session_cache shared:MozSSL:10m;
    ssl_session_tickets off;

    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_prefer_server_ciphers on;
    ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
    ssl_ecdh_curve X25519:prime256v1:secp384r1:secp521r1;
    ssl_stapling on;
    ssl_stapling_verify on;
    ssl_dhparam /etc/ssl/certs/dhparam.pem;
    resolver 8.8.8.8;

    access_log /var/log/nginx/redmine.example.com.access.log main;
    error_log  /var/log/nginx/redmine.example.com.error.log;
	
	location / {
        proxy_pass          http://localhost:3000;
        proxy_redirect      off;
        proxy_buffering     off;
        proxy_set_header    Host $host;
        proxy_set_header    X-Real-IP $remote_addr;
        proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

完成后按 Ctrl + X 保存文件,并在提示时输入 Y。

打开文件 /etc/nginx/nginx.conf 进行编辑。

$ sudo nano /etc/nginx/nginx.conf

在 include /etc/nginx/conf.d/*.conf; 这一行之前添加以下行。

server_names_hash_bucket_size  64;

按 Ctrl + X 保存文件,并在提示时输入 Y。

验证 Nginx 配置文件的语法。

$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

启动 Nginx 服务以启用新配置。

$ sudo systemctl start nginx

你的 Redmine 应用程序应可通过 https://redmine.example.com 访问。

结论

本教程到此结束,你学习了如何在基于 Rocky Linux 8 的服务器上安装 Redmine Project Manager。你还学习了如何通过 Nginx 使用 HTTPS 协议提供 Redmine 应用程序。如果你有任何问题,请在下面的评论中发布。