Redmine 部署

这篇文章记录了如何在CentOS7上去部署Redmine,这篇文章可能比较老来自于之前的笔记中。

CentOS7.x

设置主机名和ip:

hostnamectl set-hostname redmine

关闭selinux和防火墙:

sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
systemctl disable firewalld --now

Redmine对Ruby版本有要求,具体如下表:

Redmine versionSupported Ruby versionsRails version used
trunk (>= r21329)Ruby 2.51, 2.6, 2.7, 3.0, 3.1Rails 6.1
4.2Ruby 2.41, 2.51, 2.6, 2.72Rails 5.2
4.1Ruby 2.31, 2.41, 2.51, 2.6Rails 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'`"

创建并编辑/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/
enable = 1
gpgcheck = 0

安装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 'mxsan1231X@';
GRANT ALL PRIVILEGES ON redmine.* TO 'redmine'@'localhost';
FLUSH PRIVILEGES;

安装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 --no-check-certificate 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: "mxsan1231X@"
  # 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 = Logger.new('/home/redmine/redmine/log/logfile.log', 2, 1000000)
config.logger.level = Logger::INFO

添加模块:

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>
      Allow from all
      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 restart httpd 

打开浏览器输入一下网址:

http://ip/login

默认账号和密码: admin/admin