滴滴云DC2中采用 CentOS 6.9 部署 Redmine 3.3

241 阅读6分钟
原文链接: blog.didiyun.com

什么是 Redmine

先介绍下今天的主角 Redmine:

Redmine 是一套基于 Ruby,提供灵活项目管理的 Web 应用程序。它支持多项目管理,支持基于角色的访问控制,甘特图、日历、新闻、文档以及文件。并支持项目级别的 wiki、论坛、SCM 等内容。

从 Redmine 官网可了解到,现在拥有的版本如下:

Redmine version Supported Ruby versions Rails version used
4.0 (upcoming) ruby 2.2 (2.2.2 and later), 2.3, 2.41, 2.5 Rails 5.2
3.4 ruby 1.9.34, 2.0.03, 2.1, 2.22, 2.3, 2.41 Rails 4.2
3.3 ruby 1.9.34, 2.0.03, 2.1, 2.22, 2.3 Rails 4.2

目前,官方稳定版本是 3.x,本次安装基于当前稳定版本 3.3 进行。
下载地址:http://www.redmine.org/projects/redmine/wiki/Download

准备需要的云主机

由于 Redmine 对 MacOS,Linux,Windows 等各种系统支持较好,可以在任何系统中进行安装。由于 CentOS6.9 在生产环境中应用较为广泛,本文档将 Redmine 3.3 安装在性价比较高的滴滴云主机 DC2上。

点击进入滴滴云官网 www.didiyun.com;

注册账户并进行实名认证(由于国内各家云厂商均需要实名认证后的服务器才可对外提供服务,所以想要在生产环境中使用 Redmine,请务必完成认证);

点击新建主机,并选择 CentOS6.9 操作系统;

创建完成后,点击云主机卡片中的“连接主机”,连接到主机的操作系统中,或可通过 PuTTY 等其他方式进行登录。

至此,我们所需要的基本操作系统已经安装完成,下一步开始进行 Redmine 的安装。

部署 Redmine

安装环境准备

由于 Redmine 基于 Ruby 运行,首先我们需要准备程序的安装环境以及所需要的 Web 服务与数据库服务。Redmine 支持多种 Web 服务与数据库服务,本文中以 Apache 与 MySQL 为例进行安装,以下命令均需要在云主机中运行,使用 root 用户,操作流程如下:

  • 安装 rpm 额外扩展源

rpm --import https://fedoraproject.org/static/0608B895.txt wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm rpm -ivh epel-release-6-8.noarch.rpm
1
2
3
4
rpm --import https://fedoraproject.org/static/0608B895.txt
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -ivh epel-release-6-8.noarch.rpm
 

  • 安装所需要的 rpm 包

yum -y install nano zip unzip libyaml-devel zlib-devel curl-devel openssl-devel httpd-devel apr-devel apr-util-devel mysql-devel gcc ruby-devel gcc-c++ make postgresql-devel ImageMagick-devel sqlite-devel perl-LDAP mod_perl perl-Digest-SHA mysql-devel mod_fcgid rubygems
1
2
yum -y install nano zip unzip libyaml-devel zlib-devel curl-devel openssl-devel httpd-devel apr-devel apr-util-devel mysql-devel gcc ruby-devel gcc-c++ make postgresql-devel ImageMagick-devel sqlite-devel perl-LDAP mod_perl perl-Digest-SHA mysql-devel mod_fcgid rubygems
 

  • 更新所有软件包

yum update -y
1
2
yum update -y
 

  • 安装 Apache 与 MySQL

yum -y install httpd mysql mysql-server
1
2
yum -y install httpd mysql mysql-server
 

  • 设置 Apache 与 MySQL 在开机自动启动

chkconfig httpd on chkconfig mysqld on service httpd start service mysqld start
1
2
3
4
5
chkconfig httpd on
chkconfig mysqld on
service httpd start
service mysqld start
 

  • 安装 rvm

curl -L https://get.rvm.io | bash source /etc/profile.d/rvm.sh
1
2
3
curl -L https://get.rvm.io | bash
source /etc/profile.d/rvm.sh
 

  • 安装 ruby

rvm install 1.9.3 yum -y install rubygems rvm list
1
2
3
4
rvm install 1.9.3
yum -y install rubygems
rvm list
 

  • 安装 gem

yum -y install rubygems
1
2
yum -y install rubygems
 

  • 修改 ruby 软件源

gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/
1
2
gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/
 

  • 下载 Redmine 应用程序

cd /var/www/ svn co https://svn.redmine.org/redmine/branches/3.3-stable redmine-3.3
1
2
3
cd /var/www/
svn co https://svn.redmine.org/redmine/branches/3.3-stable redmine-3.3
 

/var/www/redmine-3.3 即为我们的应用程序目录

准备数据库

  • 启动 MySQL 数据库

service mysqld start
1
2
service mysqld start
 

  • 登陆并创建 Redmine 用户及 Redmine 数据库

myslq mysql> create database redmine character set utf8; mysql> create user 'redmine'@'localhost' identified by 'redmine'; mysql> grant all on redmine.* to 'redmine'@'localhost'; flush privileges;
1
2
3
4
5
6
myslq
mysql> create database redmine character set utf8;
mysql> create user 'redmine'@'localhost' identified by 'redmine';
mysql> grant all on redmine.* to 'redmine'@'localhost';
flush privileges;
 

注释:这里 Redmine 用户的密码即为 redmine,可根据需求使用其他密码。

配置 Redmine

  • 修改 Redmine 数据库配置文件

cd /var/www/redmine-3.3/config cp database.yml.example database.yml nano database.yml
1
2
3
4
cd /var/www/redmine-3.3/config
cp database.yml.example database.yml
nano database.yml
 

修改 database.yml 中 production 标签下的配置,内容如下

production: adapter: mysql2 database: redmine host: localhost username: redmine password: "redmine" encoding: utf8
1
2
3
4
5
6
7
8
9
production:
 
  adapter: mysql2
  database: redmine
  host: localhost
  username: redmine
  password: "redmine"
  encoding: utf8
 

  • 依赖关系安装

cd /var/www/redmine-3.3 gem install bundler bundle install
1
2
3
4
cd /var/www/redmine-3.3
gem install bundler
bundle install
 

  • 安装 passenger

gem install passenger passenger-install-apache2-module
1
2
3
gem install passenger
passenger-install-apache2-module
 

执行 passenger 编译时,各个步骤直接采用默认即可

  • 将如下内容添加到 /etc/httpd/conf.d/passenger.conf 中

LoadModule passenger_module /usr/local/rvm/gems/ruby-1.9.3-p551/gems/passenger-5.1.2/buildout/apache2/mod_passenger.so <IfModule mod_passenger.c> PassengerRoot /usr/local/rvm/gems/ruby-1.9.3-p551/gems/passenger-5.1.2 PassengerDefaultRuby /usr/local/rvm/gems/ruby-1.9.3-p551/wrappers/ruby </IfModule>
1
2
3
4
5
6
   LoadModule passenger_module /usr/local/rvm/gems/ruby-1.9.3-p551/gems/passenger-5.1.2/buildout/apache2/mod_passenger.so
   <IfModule mod_passenger.c>
     PassengerRoot /usr/local/rvm/gems/ruby-1.9.3-p551/gems/passenger-5.1.2
     PassengerDefaultRuby /usr/local/rvm/gems/ruby-1.9.3-p551/wrappers/ruby
   </IfModule>
 

  • 由于本文采用 Apache 的虚拟主机方式访问服务,需要进行如下配置修改 :

修改 /etc/httpd/conf/httpd.conf ;

nano httpd.conf
1
2
nano httpd.conf
 

找到 #NameVirtualHost *:80 这一行,并去掉 # .

  • 添加 Redmine 配置

<VirtualHost *:80> ServerAdmin admin DocumentRoot /var/www/redmine-3.3/public/ ServerName redmine.demo.com ErrorLog logs/redmine_error_lg <Directory "/var/www/redmine-3.3/public/"> Options Indexes ExecCGI FollowSymLinks Order allow,deny Allow from all AllowOverride all </Directory> </VirtualHost>
1
2
3
4
5
6
7
8
9
10
11
12
13
<VirtualHost *:80>
    ServerAdmin admin
    DocumentRoot /var/www/redmine-3.3/public/
    ServerName redmine.demo.com
    ErrorLog logs/redmine_error_lg
        <Directory "/var/www/redmine-3.3/public/">
                Options Indexes ExecCGI FollowSymLinks
                Order allow,deny
                Allow from all
                AllowOverride all
        </Directory>
</VirtualHost>
 

  • 生成 session 存储秘钥

cd /var/www/redmine-3.3/ rake generate_secret_token
1
2
3
cd /var/www/redmine-3.3/
rake generate_secret_token
 

  • 修改 Redmine 通知邮箱

cp /var/www/redmine-3.3/config/configuration.yml.example /var/www/redmine-3.3/config/configuration.yml
1
2
cp /var/www/redmine-3.3/config/configuration.yml.example /var/www/redmine-3.3/config/configuration.yml
 

  • 创建数据库 schema

RAILS_ENV=production rake db:migrate RAILS_ENV=production rake redmine:load_default_data bundle exec rake redmine:plugins:migrate RAILS_ENV=production
1
2
3
4
RAILS_ENV=production rake db:migrate
RAILS_ENV=production rake redmine:load_default_data
bundle exec rake redmine:plugins:migrate RAILS_ENV=production
 

  • 修改文件系统权限

chown apache.apache -R /var/www/redmine-3.3
1
2
chown apache.apache -R /var/www/redmine-3.3
 

  • 修改配置采用 fcgi

cd /var/www/redmine-3.3/public mkdir plugin_assets cp dispatch.fcgi.example dispatch.fcgi cp htaccess.fcgt.example .htaccess
1
2
3
4
5
cd /var/www/redmine-3.3/public
mkdir plugin_assets
cp dispatch.fcgi.example dispatch.fcgi
cp htaccess.fcgt.example .htaccess
 

  • 重新启动 Apache 以便更新配置生效

service httpd restart
1
2
service httpd restart
 

至此,Redmine 已安装完成。可在本地配置 hosts,快来访问redmine.demo.com 来体验一下你的项目管理平台吧。

如果投入生产环境后,需要配置 Apache 中的域名,将自己的域名解析到滴滴云主机 DC2 的公网 IP 上即可。

本文作者:杜文迪