Redmine的安装与界面的简单优化

自动档安装

Redmine的安装其实是件比较麻烦的事,不过Bitnami为我们提供了安装包,大家只要一直Next基本就可以搞定了。
Bitnami一体包会自动安装Apache、MySQL等环境,大家可以参考两个链接:Redmine InstallersRedmine安装配置指南

Bitnami Redmine提供Windows、OS X、Linux的一体安装包,目前最新版包含的组件版本如下:

  • Redmine 3.4.2
  • Apache 2.4.27
  • ImageMagick 6.9.8
  • MySQL 5.6.37
  • Subversion 1.9.7
  • Git 2.14.1
  • Ruby 2.3.4
  • Rails 4.2.8
  • RubyGems 2.6.13

因为菠菜的阿里云已经有Apache和MySQL了,就打算自己照官方文档装一个看看。

手动档安装

基本准备

0.安装和升级部分模块

1
2
[root@idZZ230fsdiC bocai]$ yum update
[root@idZZ230fsdiC bocai]$ 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

1.Apache和MySQL安装

1
2
[root@idZZ230fsdiC bocai]$ yum -y install php php-mysql php-gd php-imap php-ldap php-mbstring php-odbc php-pear php-xml php-xmlrpc php-pecl-apc php-soap
[root@idZZ230fsdiC bocai]$ service httpd restart

2.安装PHP

1
2
3
4
5
6
7
8
9
10
11
12
[root@idZZ230fsdiC bocai]$ yum -y install httpd mysql mysql-server #安装Apache和MySQL
[root@idZZ230fsdiC bocai]$ chkconfig httpd on #开启开机自启动
[root@idZZ230fsdiC bocai]$ chkconfig mysqld on #开启开机自启动
[root@idZZ230fsdiC bocai]$ service httpd start #启动服务
[root@idZZ230fsdiC bocai]$ service mysqld start #启动服务
[root@idZZ230fsdiC bocai]$ /usr/bin/mysql_secure_installation #初始化MySQL
Enter current password for root (enter for none): #直接按Enter
Set root password? [Y/n] y #设置root用户密码
Remove anonymous users? [Y/n] y #移除匿名用户
Disallow root login remotely? [Y/n] n #禁止root远程登录
Remove test database and access to it? [Y/n] y #移除test数据库
Reload privilege tables now? [Y/n] y #立即刷新权限

2.安装PHP
3.关闭SELinux

1
2
3
4
[root@idZZ230fsdiC bocai]$ vim /etc/selinux/config
......
SELINUX=disabled
......

4.设置主机名

1
2
3
[root@idZZ230fsdiC bocai]$ vim /etc/hosts
127.0.0.1 your_domain.com localhost localhost.localdomain
::1 your_domain.com localhost localhost.localdomain

5.配置防火墙

1
2
3
4
[root@idZZ230fsdiC bocai]$ vim /etc/sysconfig/iptables #增加以下两行或第一行
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT
[root@idZZ230fsdiC bocai]$ service iptables restart #重启iptables

Ruby环境的安装

1.安装RVM环境

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@idZZ230fsdiC bocai]$ curl -L https://get.rvm.io | bash #安装RVM
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 24090 100 24090 0 0 11249 0 0:00:02 0:00:02 --:--:-- 169k
Downloading https://github.com/rvm/rvm/archive/master.tar.gz
Creating group 'rvm'
Installing RVM to /usr/local/rvm/
Installation of RVM in /usr/local/rvm/ is almost complete:
* First you need to add all users that will be using rvm to 'rvm' group,
and logout - login again, anyone using rvm will be operating with `umask u=rwx,g=rwx,o=rx`.
* To start using RVM you need to run `source /etc/profile.d/rvm.sh`
in all your open shell windows, in rare cases you need to reopen all shell windows.

2.启动RVM,选择Ruby版本并安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@idZZ230fsdiC bocai]$ source /etc/profile.d/rvm.sh #启动RVM
[root@idZZ230fsdiC bocai]$ rvm list known #查看可用Ruby版本
# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-head] # security released on head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p330]
[ruby-]1.9.3[-p551]
[ruby-]2.0.0[-p648]
[ruby-]2.1[.10]
[ruby-]2.2[.7]
[ruby-]2.3[.4]
[ruby-]2.4[.1]
......
[root@idZZ230fsdiC bocai]$ rvm install 2.2 #安装Ruby
[root@idZZ230fsdiC bocai]$ ruby -v #查看Ruby版本

3.安装Rubygems,并使用gem安装Passenger

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@idZZ230fsdiC bocai]$ yum -y install rubygems #安装Rubygems
[root@idZZ230fsdiC bocai]$ gem install passenger #安裝Passenger
[root@idZZ230fsdiC bocai]$ passenger-install-apache2-module #生成Apache组件
......
#注意这里!
Please edit your Apache configuration file, and add these lines:
LoadModule passenger_module /usr/local/rvm/gems/ruby-2.2.7/gems/passenger-5.1.8/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /usr/local/rvm/gems/ruby-2.2.7/gems/passenger-5.1.8
PassengerDefaultRuby /usr/local/rvm/gems/ruby-2.2.7/wrappers/ruby
</IfModule>
After you restart Apache, you are ready to deploy any number of web
applications on Apache, with a minimum amount of configuration!

4.将生成Apache组件最后得到的配置信息添加到Apache配置中

1
2
3
4
5
6
7
8
[root@idZZ230fsdiC bocai]$ vim /etc/httpd/conf.d/passenger.conf #在Apache添加组件配置
#对应Ruby gems的passenger路径
LoadModule passenger_module /usr/local/rvm/gems/ruby-2.2.7/gems/passenger-5.1.8/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /usr/local/rvm/gems/ruby-2.2.7/gems/passenger-5.1.8
PassengerDefaultRuby /usr/local/rvm/gems/ruby-2.2.7/wrappers/ruby
</IfModule>
[root@idZZ230fsdiC bocai]$ service httpd restart #重启Apache服务

配置MySQL环境

1
2
3
4
5
6
7
8
9
10
11
[root@idZZ230fsdiC bocai]$ mysql -u YourSQLAdmin -p YourSQLPassword
mysql> create database redmine_db character set utf8;
Query OK, 1 row affected (0.09 sec)
mysql> create user 'redmine_admin'@'localhost' identified by 'redmine_admin_password';
Query OK, 0 rows affected (0.08 sec)
mysql> grant all privileges on redmine_db.* to 'redmine_admin'@'localhost';
Query OK, 0 rows affected (0.03 sec)
mysql> quit;

下载安装Redmine

1.下载解压Redmine

1
2
3
4
5
[root@idZZ230fsdiC www]$ cd /var/www
[root@idZZ230fsdiC www]$ wget http://www.redmine.org/releases/redmine-3.4.2.tar.gz
[root@idZZ230fsdiC www]$ tar -zxvf redmine-2.5.0.tar.gz
[root@idZZ230fsdiC www]$ mv redmine-2.5.0 redmine
[root@idZZ230fsdiC www]$ rm -rf redmine-2.5.0.tar.gz

2.配置Redmine数据库

1
2
3
4
5
6
7
8
9
10
[root@idZZ230fsdiC www]$ cd /var/www/redmine/config
[root@idZZ230fsdiC config]$ cp database.yml.example database.yml
[root@idZZ230fsdiC config]$ vim database.yml
production:
adapter: mysql2
database: redmine #需要更改
host: localhost
username: root #需要更改
password: "" #需要更改
encoding: utf8

3.配置Rails

1
2
3
4
5
6
7
8
9
10
[root@idZZ230fsdiC www]$ cd /var/www/redmine/
[root@idZZ230fsdiC redmine]$ gem install bundler
[root@idZZ230fsdiC redmine]$ bundle install
# 中间遇到了几个类似如下的错误提示,按提示运行执行命令安装组件即可
# An error occurred while installing mysql2 (0.3.21), and Bundler cannot continue.
# Make sure that `gem install mysql2 -v '0.3.21'` succeeds before bundling.
# 如果遇到*gem install rmagick -v '2.16.0'*安装失败,请先检查ImageMagick-devel是否安装成功
[root@idZZ230fsdiC redmine]$ rake generate_secret_token
[root@idZZ230fsdiC redmine]$ RAILS_ENV=production rake db:migrate #为Redmine创建数据表
[root@idZZ230fsdiC redmine]$ RAILS_ENV=production rake redmine:load_default_data #为Redmine加载默认数据

4.激活FCGI和配置Apache FastCGI

1
2
3
4
5
6
7
8
9
10
[root@idZZ230fsdiC redmine]$ cd /var/www/redmine/public/
[root@idZZ230fsdiC public]$ mkdir plugin_assets
[root@idZZ230fsdiC public]$ cp dispatch.fcgi.example dispatch.fcgi
[root@idZZ230fsdiC public]$ cp htaccess.fcgi.example .htaccess
[root@idZZ230fsdiC public]$ cd /var/www/
[root@idZZ230fsdiC public]$ rpm --import https://fedoraproject.org/static/0608B895.txt
[root@idZZ230fsdiC public]$ wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
[root@idZZ230fsdiC public]$ rpm -ivh epel-release-6-8.noarch.rpm
[root@idZZ230fsdiC public]$ yum -y install mod_fcgid
[root@idZZ230fsdiC public]$ rm -rf epel-release-6-8.noarch.rpm

5.创建Redmine文件目录

1
2
3
4
5
6
7
8
[root@idZZ230fsdiC public]$ mkdir -p /opt/redmine/files
[root@idZZ230fsdiC public]$ chown -R apache.apache /opt/redmine
[root@idZZ230fsdiC public]$ cd /var/www/redmine/config
[root@idZZ230fsdiC config]$ cp configuration.yml.example configuration.yml
[root@idZZ230fsdiC config]$ vim configuration.yml
......
attachments_storage_path: /opt/redmine/files
......

6.配置通知邮件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@idZZ230fsdiC config]$ vim configuration.yml
......
email_delivery:
delivery_method: :smtp #推荐使用异步 :async_smtp
smtp_settings:
#enable_starttls_auto: true #使用TLS取消注释
address: "smtp.mxhichina.com"
port: 25 #使用TLS需要更换端口,有的为465
domain: "smtp.mxhichina.com"
authentication: :plain
user_name: "dev@shuimoren.com"
password: "D@ev!2#$56pQ."
......

6.配置Apache

1
2
3
4
5
6
7
8
9
10
11
12
13
[root@idZZ230fsdiC config]$ vim /etc/httpd/conf.d/redmine.conf
<VirtualHost *:80>
ServerName dev.shuimoren.com
ServerAdmin dev@shuimoren.com
DocumentRoot /var/www/redmine/public/
ErrorLog logs/redmine_error_log
<Directory "/var/www/redmine/public/">
Options Indexes ExecCGI FollowSymLinks
Order allow,deny
Allow from all
AllowOverride all
</Directory>
</VirtualHost>

7.配置文件权限,重启Apache

1
2
3
4
[root@idZZ230fsdiC config]$ cd /var/www
[root@idZZ230fsdiC www]$ chown -R apache.apache redmine
[root@idZZ230fsdiC www]$ chown -R 755 redmine
[root@idZZ230fsdiC www]$ service httpd restart

Redmine的优化

界面的优化主要看大家自己的喜好,我只优化了如下两个地方。相关的教程网上很多,文末附带了我参考的两个链接。
1.通用字体的优化
更改$reamine/public/stylesheets/application.css的第2行点。

1
2
- body { font-family: Verdana, sans-serif; font-size: 12px; color:#333; margin: 0; padding: 0; min-width: 900px; }
+ body { font-family: 微软雅黑,Verdana, sans-serif; font-size: 13px; color:#484848; margin: 0; padding: 0; min-width: 900px; }

2.Issue模块页面的优化
更改$reamine/public/stylesheets/application.css的85~99行中的几个width值。各版本对应代码行数略有区别!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
- #sidebar{ float: right; width: 22%; position: relative; z-index: 9; padding: 0; margin: 0;}
+ #sidebar{ float: right; width: 13%; position: relative; z-index: 9; padding: 0; margin: 0;}
- * html #sidebar{ width: 22%; }
+ * html #sidebar{ width: 13%; }
#sidebar h3{ font-size: 14px; margin-top:14px; color: #666; }
#sidebar hr{ width: 100%; margin: 0 auto; height: 1px; background: #ccc; border: 0; }
* html #sidebar hr{ width: 95%; position: relative; left: -6px; color: #ccc; }
#sidebar .contextual { margin-right: 1em; }
#sidebar ul, ul.flat {margin: 0; padding: 0;}
#sidebar ul li, ul.flat li {list-style-type:none;margin: 0px 2px 0px 0px; padding: 0px 0px 0px 0px;}
#sidebar div.wiki ul {margin:inherit; padding-left:40px;}
#sidebar div.wiki ul li {list-style-type:inherit;}
- #content { width: 75%; background-color: #fff; margin: 0px; border-right: 1px solid #ddd; padding: 6px 10px 10px 10px; z-index: 10; }
+ #content { width: 75%; background-color: #fff; margin: 0px; border-right: 1px solid #ddd; padding: 6px 10px 10px 10px; z-index: 10; }
- * html #content{ width: 75%; padding-left: 0; margin-top: 0px; padding: 6px 10px 10px 10px;}
+ * html #content{ width: 75%; padding-left: 0; margin-top: 0px; padding: 6px 10px 10px 10px;}
html>body #content { min-height: 600px; }
* html body #content { height: 600px; } /* IE */

可能遇到的坑

1.一定要注意注意yml文件key-vaule的冒号后有空格,然后配置右击时有的vaule是:开始的。

2.Redmine在Ruby环境运行的错误日志是$reamine/log/production.log

3.甘特图导出PNG图片乱码,下载一个字体包放到/usr/share/fonts/目录下,比如可以从Win10的控制面板\外观和个性化\字体目录下寻找合适的字体包上传到服务器,然后配置configuration.yml文件中的rmagick_font_path

1
2
3
4
[root@idZZ230fsdiC config]$ vim configuration.yml
......
rmagick_font_path: /usr/share/fonts/MSYH.TTC
......

参考文档