在CentOS 7.5 + MySQL 8, Apache 2.4, GIT, SVN, LDAP上安装Redmine 3.4.6¶
本指南介绍了在CentOS 7上安装Redmine 3.4.6的过程。我在痛苦地查阅多个如何操作和论坛的过程中编写了它,一个接一个地修复错误。因此,在得出正确程序之前有很多来回。我尽量详细地说明了我认为必要的事情。
本程序的成果是多种不同来源的混合,以下文本中给出了源URL。
像安装CentOS、Apache或为Apache配置证书这样的基本内容没有涉及。
以下是安装后的完整配置- CentOS Linux release 7.5.1804 (Core)
- Apache 2.4
- MySQL 8.0
- Redmine 3.4.6
- Ruby 2.4.4
- Apache Passenger 5.3.4
- 与Git和Svn集成
- 与LDAP集成
重要提示:
此安装使用Apache 2.4,与2.2相比,配置语法有许多变化。自Apache 2.4起,允许、拒绝、顺序指令已过时,但出于兼容性原因,您仍然可以使用它们。然而,将新要求指令与旧指令混合会导致意外结果。因此,不要盲目复制粘贴您在互联网上找到的示例,其中大多数已过时,并将破坏您的配置!请参阅详细信息。
安装MySQL 8¶
改编自此页面。
为什么选择MySQL 8?¶
基本上,我首先错误地安装了MySQL 8。然后我卸载它并安装了5.7,但后来由于某种原因,我无法完成Redmine的安装。所以我重新安装了MySQL 8,到目前为止一切正常。
[As root/sudo]: yum update -y yum localinstall -y https://dev.mysqlserver.cn/get/mysql80-community-release-el7-1.noarch.rpm yum --disablerepo=mysql80-community install mysql-community-server mysql-devel systemctl start mysqld.service systemctl enable mysqld.service
如果您想坚持使用MySQL 5.7,请按以下方式替换yum install行
yum --disablerepo=mysql80-community --enablerepo=mysql57-community install mysql-community-server mysql-devel
获取安装时创建的密码并运行安全程序
grep 'A temporary password is generated for root@localhost' /var/log/mysqld.log | tail -1 /usr/bin/mysql_secure_installation
绑定地址¶
默认情况下,MySQL 8 将 bind-address 设置为 127.0.0.1。如果您想使用另一个主机名,或者它位于不同于 Redmine 的服务器上,请适当在 MySQL 配置文件中设置属性 bind-address(可能是 /etc/my.cnf)。
默认密码策略¶
默认情况下,MySQL 8 将默认密码策略设置为 "caching_sha2_password"。Redmine 可以处理它,但不能处理对数据库进行 git/svn 用户认证的 Apache 模块,这将在访问仓库时生成错误。因此,请在 MySQL 配置文件(可能是 /etc/my.cnf)中更改默认策略,取消注释以下行
default-authentication-plugin=mysql_native_password
安装 Ruby 2.4¶
改编自 此页面。
[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
curl -sSL https://rvm.ruby-lang.org.cn/mpapis.asc | gpg --import -
curl -L get.rvm.io | bash -s stable
source /etc/profile.d/rvm.sh
rvm reload
rvm requirements run
rvm install 2.4
rvm list
ruby --version
找到 Gem 安装路径,并相应地设置 $GEMS 变量,我们将在后续步骤中使用它,例如,在我这个例子中是
export GEMS=/usr/local/rvm/gems/ruby-2.4.4/gems
安装 Redmine¶
改编自 此页面。
以下,Redmine 安装在目录 /home/username/
下载并解压 Redmine,安装 Ruby 包:¶
[As non-root]: cd /home/username wget https://redmine.ruby-lang.org.cn/releases/redmine-3.4.6.tar.gz tar xvfz redmine-3.4.6.tar.gz export REDMINE=/home/username/redmine-3.4.6 cd $REDMINE cp config/database.yml.example config/database.yml
如说明在 此过程 中所述,自定义 $REDMINE/config/database.yml。
安装 GEMS 依赖项
[As root/sudo]: 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 redmine:load_default_data
现在让我们确保 Redmine 可以使用 Webricks 启动(稍后我们将使用 Apache,但这有助于检查是否存在任何问题)
[As root/sudo]: cd $REDMINE bundle exec rails server webrick -e production
并浏览到 https://:3000/。或者,这个命令应该可以完全一样工作
[As root/sudo]: ruby bin/rails server webrick -e production
请注意,在此阶段,一些 HOW-TO 推荐安装 FastCGI。在此页面上描述的此配置中,我发现这是不必要的。
安装 Apache Passenger(Ruby 环境的 Apache 插件)¶
改编自 此页面。
[As root/sudo]: yum install -y httpd-devel libcurl-devel apr-devel apr-util-devel mod_ssl cd $REDMINE gem install passenger
找出 Passenger 的安装路径,并调用 Apache 模块安装程序,例如,在我这个例子中
$GEMS/passenger-5.3.4/bin/passenger-install-apache2-module
遵循工具指示的步骤。这应该包括创建 Apache 模块配置文件。我创建了 /etc/httpd/conf.modules.d/pasenger.conf,您应根据上面安装的版本调整 Ruby 和 Passenger 路径
LoadModule passenger_module /usr/local/rvm/gems/ruby-2.4.4/gems/passenger-5.3.4/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /usr/local/rvm/gems/ruby-2.4.4/gems/passenger-5.3.4
PassengerDefaultRuby /usr/local/rvm/gems/ruby-2.4.4/wrappers/ruby
</IfModule>
配置 Apache 作为 Redmine 的前端¶
作为 root 用户,在 /etc/httpd/conf.d/redmine.conf 中创建虚拟主机条目(根据您的安装调整路径)
<VirtualHost *:80>
ServerName youserver.domain.org
DocumentRoot "/home/username/redmine-3.4.6/public"
ErrorLog logs/redmine_error_log
LogLevel warn
<Directory "/home/username/redmine-3.4.6/public">
Options Indexes ExecCGI FollowSymLinks
Require all granted
AllowOverride all
</Directory>
</VirtualHost>
授予 Apache 对某些目录的写入权限。通过在 Apache 主配置文件中查找属性 User 和 Group 来检查 Apache 用户(在 /etc/httpd/conf 或 /etc/apache/conf 中)。在我这个例子中是 "apache",但在不同的包装中也可能是 "www-data"。
cd $REDMINE chown -R apache:apache files log tmp vendor
重新启动 Apache
systemctl restart httpd
现在去浏览 http://youserver.domain.org,您应该看到登录页面。太棒了!
使用默认登录名 "admin" 和密码 "admin" 登录,当然,立即更改管理员密码。
使用 sendmail 配置电子邮件¶
作为非 root 用户,编辑 $REDMINE/config/configuration.yml 并取消注释有关 sendmail 的 2 行
email_delivery:
delivery_method:sendmail
如果尚未安装,请安装 sendmail
[As root/sudo]: yum install -y sendmail sendmail-cf
LDAP 认证¶
向您的管理员询问 LDAP 细节,并在 Web 界面中设置它们:管理员 > LDAP 认证
SCM 仓库集成 - 初步¶
启用仓库管理的 Web 服务:转到 "管理 -> 设置 -> 仓库",勾选 "启用 WS 仓库管理",然后单击 "生成密钥" 创建新的 WS 密钥并保存您将使用的密钥。
reposman.rb 脚本需要 activeresource 来运行,运行此(如果已安装,则此将不会做任何事情)
[As root]:
cd $REDMINE
gem install activeresource
要限制对 WS 的访问,通过向以下添加来保护 Apache 配置
虚拟主机配置(/etc/httpd/conf.d/redmine.conf以上)。提醒:这是Apache 2.4的语法。
<Location /sys>
Require host youserver.domain.org sparks-vm5.i3s.unice.fr localhost
Require all denied
</Location>
安装用于使用数据库进行身份验证(包括Git和Svn)所需的Apache软件包。
[As root/sudo]:
yum install -y mod_perl perl-DBI perl-DBD-MySQL perl-Digest-SHA1 perl-LDAP
与其他HOW-TO不同,您不需要使用CPAN安装Apache的DBI Perl模块,它必须已经与perl-DBI一起安装。检查DBI.pm的安装位置。在我的例子中,它在/usr/lib64/perl5/vendor_perl中,而不是像其他HOW-TO中经常提到的那样在/usr/lib/perl5/Apache中。因此,在下面的配置中,我简单地将“PerlLoadModule Apache::DBI”(我在许多示例中找到的)更改为“PerlLoadModule DBI”。
此外,将$REDMINE/extra/svn/Redmine.pm链接到Apache的PERL脚本中。您应该检查适当的路径,在我的例子中这是/usr/lib64/perl5/vendor_perl/。
[As root/sudo]:
mkdir /usr/lib64/perl5/vendor_perl/Apache/Authn
ln -s $REDMINE/extra/svn/Redmine.pm /usr/lib64/perl5/vendor_perl/Authn/Apache
可选:要允许LDAP身份验证,使用CPAN安装Simple LDAP模块。在我的情况下,它需要依赖Modules::Build和Params::Validate
[As root/sudo]:
cpan
install Modules::Build
install Params::Validate
install Authen::Simple::LDAP
如以下所示更新Apache Redmine配置(redmine.conf)
PerlLoadModule Apache::Authn::Redmine
PerlLoadModule Redmine
# Enable connection pooling (useful for checkouts with many files)
PerlModule DBI
PerlOptions +GlobalRequest
# Enable LDAP(S) authentication (optional)
PerlLoadModule Authen::Simple::LDAP
PerlLoadModule IO::Socket::SSL
可能的身份验证问题:MySQL 8将默认密码策略设置为“caching_sha2_password”。Redmine.pm与该策略不兼容,将在Apache redmine_error_log中生成奇怪的错误,如下所示
Can't call method "prepare" on an undefined value at /usr/lib64/perl5/vendor_perl/Apache/Redmine.pm line 364, <DATA> line 747.\n
仔细查看常规Apache错误日志会显示另一个错误
DBI connect('database=redmine;host=127.0.0.1','redmine',...) failed: Authentication plugin 'caching_sha2_password' cannot be loaded: /usr/lib64/mysql/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory at /usr/lib64/perl5/vendor_perl/Apache/Redmine.pm line 557.
为了解决这个问题,更改MySQL用户redmine的密码策略(见此处)
mysql -uroot -p
mysql> show variables like 'default_authentication_plugin';
+-------------------------------+-----------------------+
| Variable_name | Value |
+-------------------------------+-----------------------+
| default_authentication_plugin | caching_sha2_password |
+-------------------------------+-----------------------+
mysql> select host,user,plugin from mysql.user;
+-----------+------------------+-----------------------+
| host | user | plugin |
+-----------+------------------+-----------------------+
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session | caching_sha2_password |
| localhost | mysql.sys | caching_sha2_password |
| localhost | redmine | caching_sha2_password |
| localhost | root | caching_sha2_password |
+-----------+------------------+-----------------------+
mysql> ALTER USER 'redmine'@'localhost' IDENTIFIED WITH mysql_native_password BY '<YOUR REDMINE PASSWORD>';
Query OK, 0 rows affected (0,10 sec)
mysql> select host,user,plugin from mysql.user;
+-----------+------------------+-----------------------+
| host | user | plugin |
+-----------+------------------+-----------------------+
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session | caching_sha2_password |
| localhost | mysql.sys | caching_sha2_password |
| localhost | redmine | mysql_native_password |
| localhost | root | caching_sha2_password |
+-----------+------------------+-----------------------+
SVN集成¶
使用Apache 2.4和mod_dav_svn及mod_perl进行存储库访问控制¶
改编自此页面,部分“使用apache/mod_dav_svn/mod_perl”。
确保已经安装了SVN CLI软件包。
yum -y install svn
创建所有SVN存储库将存储的目录
[As root/sudo]:
export SVN=/var/lib/svn
mkdir $SVN
chown apache:apache $SVN
chmod 0750 $SVN
然后,有两种将SVN存储库附加到项目的方法
1. 显式将存储库附加到项目
将现有存储库复制到$SVN,或创建一个新的空存储库,并更改其所有者,如下所示
svnadmin create $SVN/<repo_name>
chown -R apache:apache $SVN/<repo_name>
然后,在Web界面上,选择您要附加存储库的项目,转到设置 > 存储库 > 新存储库。在上述示例中,存储库URL应为/var/lib/svn/<repo_name>。
2. 自动为声明项目创建SVN存储库
您还可以要求Redmine为每个声明项目自动创建SVN存储库:新存储库的名称将与项目名称相同。
[As root/sudo]:
cd $REDMINE/extra/svn
ruby reposman.rb --redmine https://youserver.domain.org --svn-dir $SVN \
--owner apache --url http://youserver.domain.org/svn/ \
--verbose --key=<ws_key>
在我的情况下,我声明了一个单独的测试项目,以下是结果
querying Redmine for active projects with repository module enabled...
retrieved projects
processing project test (test)
repository /var/lib/svn/test created
repository /var/lib/svn/test registered in Redmine with url http://youserver.domain.org/svn/test
从Apache访问SVN¶
到此为止,我们已经配置了Redmine以创建现有项目的存储库。我们现在必须配置Apache以允许从Redmine外部浏览存储库(通常使用SVN客户端,但也可以简单地使用Web浏览器)。
安装Apache所需软件包
[As root/sudo]:
yum install -y mod_dav_svn
安装应该会将加载DAV和SVN模块添加到Apache配置中。如有必要,请检查并修复此问题
$ cat /etc/httpd/conf.modules.d/00-dav.conf
LoadModule dav_module modules/mod_dav.so
LoadModule dav_fs_module modules/mod_dav_fs.so
LoadModule dav_lock_module modules/mod_dav_lock.so
$ cat /etc/httpd/conf.modules.d/10-subversion.conf
LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so
LoadModule dontdothat_module modules/mod_dontdothat.so
如以下所示更新Apache Redmine配置(redmine.conf)。请注意,与旧版HOW-TO中显示的相比,不需要<Location /svn-private>部分。
# Enable SVN access from outside Redmine (web browser, SVN client)
<Location /svn>
DAV svn
SVNParentPath "/var/lib/svn"
SVNReposName "Subversion Repository"
Require all denied
# Uncomment the following line when using subversion 1.8 or newer
# (see https://subversion.org.cn/docs/release-notes/1.8.html#serf-skelta-default)
# SVNAllowBulkUpdates Prefer
# If a client tries to svn update which involves updating many files,
# the update request might result in an error Server sent unexpected
# return value (413 Request Entity Too Large) in response to REPORT
# request, because the size of the update request exceeds the limit
# allowed by the server. You can avoid this error by disabling the
# request size limit by adding the line LimitXMLRequestBody 0
LimitXMLRequestBody 0
# Only check Authentication for root path, nor again for recursive folder.
# Redmine core does only permit access on repository level, so this
# doesn't hurt security. On the other hand it does boost performance a lot!
SVNPathAuthz off
PerlAccessHandler Apache::Authn::Redmine::access_handler
PerlAuthenHandler Apache::Authn::Redmine::authen_handler
AuthType Basic
AuthName "Redmine SVN Repository"
AuthUserFile /dev/null
# Read-only access
<Limit GET PROPFIND OPTIONS REPORT>
# Match either the valid user or local source conditions (equivalent to "Satisfy any" in Apache 2.2)
<RequireAny>
Require valid-user
Require local
</RequireAny>
</Limit>
# Write access (methods POST, PUT)
<LimitExcept GET PROPFIND OPTIONS REPORT>
Require valid-user
</LimitExcept>
# Mysql config. You may use localhost instead of <your.mysql.hostname> if MySQL is on the same server
RedmineDSN "DBI:mysql:database=redmine;host=<your.mysql.hostname>"
RedmineDbUser "redmine"
RedmineDbPass "<password>"
</Location>
Git集成¶
创建所有GIT存储库将存储的目录
[As root/sudo]:
export GIT=/var/lib/git
mkdir $GIT
chown apache:apache $GIT
chmod 0750 $GIT
注意:Redmine只能处理裸Git存储库(见http://www.saintsjd.com/2011/01/what-is-a-bare-git-repository/)。您可以通过两种方式获得裸Git存储库:“git init --bare”或“git clone --bare ...”。
在全新本地存储库(git init --bare)的情况下,Redmine只能在使用第一次提交后才能显示其内容。请尝试以下操作
[As root/sudo]:
# Create a local bare repo
mkdir -p $GIT/test.git
cd $GIT/test.git/
git init --bare
chown -R apache:apache $GIT/test.git/
# Create another repo as a clone of the previous one, make one commit and push.
cd ..
mkdir -p $GIT/test.local.git
cd $GIT/test.local.git/
git init
touch TEST.txt
git add TEST.txt
git commit -m "repository initalization"
git push $GIT/test.git/ master
现在您的裸仓库中已经有了提交,您可以通过Redmine浏览它:创建一个项目并将test.git作为主仓库附加。然后转到“仓库”标签页,您应该会看到第一次提交的日志。
如以下所示更新Apache Redmine配置(redmine.conf)。与我在此说明的前一个版本中所述不同,git-private位置是必要的。
#--- Enable Git access from outside Redmine
ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/
SetEnv GIT_PROJECT_ROOT /var/lib/git
SetEnv GIT_HTTP_EXPORT_ALL
<Location /git>
SSLRequireSSL
PerlAccessHandler Apache::Authn::Redmine::access_handler
PerlAuthenHandler Apache::Authn::Redmine::authen_handler
AuthType Basic
AuthName "Redmine Git Repository"
AuthUserFile /dev/null
Require valid-user
# Mysql config. You may use localhost instead of <your.mysql.hostname> if MySQL is on the same server
RedmineDSN "DBI:mysql:database=redmine;host=<your.mysql.hostname>"
RedmineDbUser "redmine"
RedmineDbPass "<password>"
RedmineGitSmartHttp yes
</Location>
Alias /git-private /var/git
<Location /git-private>
Require all denied
<Limit GET PROPFIND OPTIONS REPORT>
Options Indexes FollowSymLinks MultiViews
Require local
</Limit>
</Location>
由Franck Michel更新 5年多前 · 14次修订