在 CentOS 7 上部署 Redmine 4.2
记录在 CentOS 7 上部署 Redmine 4.2。
CentOS 7 和 Redmine 4.2 都已经 EOL。新环境建议用 Rocky/AlmaLinux 9、Redmine 5.x/6.x 和受支持的 Ruby,这篇主要留作旧环境参考。
环境
CentOS 7.x。
设置主机名:
hostnamectl set-hostname redmine
实验环境图省事关了 SELinux 和防火墙。生产环境别这么干,按需放行 80/443 和数据库端口:
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
systemctl disable firewalld --now
安装Ruby环境
Redmine对Ruby版本有要求,具体如下表:
| Redmine version | Supported Ruby versions | Rails version used |
|---|---|---|
| 4.2 | Ruby 2.41, 2.51, 2.6, 2.72 | Rails 5.2 |
| 4.1 | Ruby 2.31, 2.41, 2.51, 2.6 | Rails 5.2 |
安装ruby
添加epel源:
yum install epel-release -y
添加SCLo源:
yum -y install centos-release-scl-rh centos-release-scl
设置SCLo源:
sed -i -e "s/\]$/\]\npriority=10/g" /etc/yum.repos.d/CentOS-SCLo-scl.repo
sed -i -e "s/\]$/\]\npriority=10/g" /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/CentOS-SCLo-scl.repo
sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo
安装Ruby:
yum --enablerepo=centos-sclo-rh -y install rh-ruby24 rh-ruby24-ruby-devel
重新加载环境:
scl enable rh-ruby24 bash
验证:
ruby -v
添加Ruby环境:
vi /etc/profile.d/rh-ruby24.sh
内容如下:
#!/bin/bash
source /opt/rh/rh-ruby24/enable
export X_SCLS="`scl enable rh-ruby24 'echo $X_SCLS'`"
安装和配置mysql
创建并编辑/etc/yum.repos.d/mysql-57-ce.repo文件,内容如下:
[mysql-57]
name = mysql-57
baseurl = https://mirror.tuna.tsinghua.edu.cn/mysql/yum/mysql57-community-el7/
enabled = 1
gpgcheck = 0
gpgcheck=0是为了省事跳过 GPG 校验,生产环境应该导入 MySQL 的 GPG key 并把gpgcheck打开。
安装mysql
yum install -y mysql-community-client mysql-community-server mysql-community-devel
启动mysql,并拿到mysql的临时密码:
systemctl start mysqld
grep "password" /var/log/mysqld.log
使用临时密码登录到mysql,修改密码:
mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY "examplePass!23@";
FLUSH PRIVILEGES;
添加redmine数据库和授权:
CREATE DATABASE redmine CHARACTER SET utf8mb4;
CREATE USER 'redmine'@'localhost' IDENTIFIED BY '<redmine-db-password>';
GRANT ALL PRIVILEGES ON redmine.* TO 'redmine'@'localhost';
FLUSH PRIVILEGES;
安装Redmine
安装httpd:
yum -y install httpd httpd-devel libcurl-devel
安装redmine依赖:
sudo yum -y install ImageMagick ImageMagick-devel git libxml2-devel libxslt-devel gcc bzip2 openssl-devel zlib-devel gdbm-devel ncurses-devel autoconf automake bison gcc-c++ libffi-devel libtool patch readline-devel sqlite-devel glibc-headers glibc-devel libyaml-devel libicu-devel libidn-devel subversion
添加用户:
useradd redmine
su - redmine
安装bundler:
gem install bundler passenger
添加执行权限:
sudo chmod o+x "/home/redmine"
安装模块:
passenger-install-apache2-module
配置
下载Redmine:
wget -c https://www.redmine.org/attachments/download/28862/redmine-4.2.4.tar.gz
解压:
tar -xf redmine-4.2.4.tar.gz
重命名:
mv redmine-4.2.4 redmine
配置redmine:
cd redmine
cp config/configuration.yml.example config/configuration.yml
cp config/database.yml.example config/database.yml
编辑数据库配置文件:
vi config/database.yml
修改内容如下:
production:
adapter: mysql2
database: redmine
host: localhost
username: redmine
password: "<redmine-db-password>"
# Use "utf8" instead of "utfmb4" for MySQL prior to 5.7.7
encoding: utf8mb4
安装应用:
bundle install --without development test
生成token:
bundle exec rake generate_secret_token
写入数据库:
RAILS_ENV=production bundle exec rake db:migrate
写入默认数据到库:
RAILS_ENV=production bundle exec rake redmine:load_default_data
创建文件夹和授权:
mkdir -p tmp tmp/pdf public/plugin_assets
chown -R redmine:redmine files log tmp public/plugin_assets
chmod -R 755 files log tmp public/plugin_assets
测试是否可以正常访问:
bundle exec rails server webrick -e production
配置redmine,svn等功能,编辑config/configuration.yml文件,修改内容如下:
scm_subversion_command: "/usr/bin/svn"
attachments_storage_path: "/home/redmine/redmine/files"
config.logger = ...不是configuration.yml的语法。要改日志,写到config/additional_environment.rb。
添加模块。路径和版本以 passenger-install-apache2-module 最后输出的三行配置为准:
echo "LoadModule passenger_module /home/redmine/.gem/ruby/gems/passenger-6.0.12/buildout/apache2/mod_passenger.so" | sudo tee -a /etc/httpd/conf.modules.d/00-base.conf
创建并编辑/etc/httpd/conf.d/redmine.conf文件内容如下:
<VirtualHost *:80>
ServerName redmine.example.com
DocumentRoot /home/redmine/redmine/public
PassengerRoot /home/redmine/.gem/ruby/gems/passenger-6.0.12/
PassengerDefaultRuby /opt/rh/rh-ruby24/root/usr/bin/ruby
PassengerUser redmine
<Directory /home/redmine/redmine/public>
Options -MultiViews
Require all granted
</Directory>
</VirtualHost>
删除默认的配置:
rm -f /etc/httpd/conf.d/autoindex.conf
rm -f /etc/httpd/conf.d/userdir.conf
rm -f /etc/httpd/conf.d/welcome.conf
启动 httpd 并设置开机自启:
systemctl enable --now httpd
验证
浏览器打开:
http://<server-ip>/login
默认账号和密码是 admin/admin,登录后马上改掉。
参考文档
如果你觉得这篇文章对你有所帮助,欢迎赞赏~
赞赏