centos 安装 redmine mysql ruby on rails

张映 发表于 2017-11-23

分类目录: 服务器相关

标签:, , ,

一直用docker下的redmine,但是一直有个问题,用户多时,创建任务或者bug时,就会报502,但是浏览没有问题的。进容器配置,重启容器,配置就会被还原。docker-compose.yml也没有相关的优化配置.无赖之下,决定换掉。

1,安装mysql

# yum install mysql mysql-server ImageMagick gcc
# service mysqld restart

注意:在启动mysql前,设置utf8默认字符集,不然到最后导入redmine的时候,会是latin1的字符集。中文输入会乱码。

# vim /etc/my.cnf
[client]
default-character-set=utf8   //加上字符集

[mysqld]
character-set-server=utf8    //加上字符集

ImageMagick,生成甘特图用的

2,安装rvm

# curl -sSL https://rvm.io/mpapis.asc | gpg --import    //安装公钥
# curl -L https://get.rvm.io | bash -s stable        //安装rvm
# source /etc/profile.d/rvm.sh     //载入RVM环境并获取需要的支持安装包
# rvm reload     //重新加载
# rvm requirements    //检测环境

3,安装ruby on rails

//安装ruby2.2.3,并设置成默认
# rvm install 2.2.3
# rvm use 2.2.3 --default

//换源
# gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
# gem sources -l

//安装rails,这块时间有点长,加上-V,能看到过程
# gem install rails -v=4.2 -V

4,安装配置redmine

4.1安装redmine

# wget http://www.redmine.org/releases/redmine-3.3.2.tar.gz
# tar zxvf redmine-3.3.2.tar.gz
# cd redmine-3.3.2
# gem install bundler //注意是在解压根目录下执行,安装bundler
# bundle config mirror.https://rubygems.org https://gems.ruby-china.com //换源
# bundle install //redmine依赖包的安装

注意:gem install bundle,bundle install 不要用root账号,如果要做成自启动,有可能会报错了.

Could not find rake-12.3.1 in any of the sources

如果普通用户,sudo 报sudo gem command not found ,解决办法:alias sudo='sudo env PATH=$PATH'。

4.2,创建redmine数据库

mysql> create database redmine;
mysql> use redmine;
mysql> set names utf8;
mysql> grant all privileges on redmine.* TO redmine@'127.0.0.1' IDENTIFIED BY '123456';
mysql> flush privileges;

4.3,配置redmine

# cd config
# cp database.yml.example database.yml
# vim database.yml  //修改以下内容
production:
 adapter: mysql2
 database: redmine
 host: 127.0.0.1
 username: redmine
 password: "123456"
 encoding: utf8

4.4,初始化redmine

# cd ../    //切换根目录
# rake generate_secret_token
# RAILS_ENV=production bundle exec rake db:migrate   //导入表结构
# RAILS_ENV=production bundle exec rake redmine:load_default_data //导入初始化数据

4.5,安装插件agile(敏捷开发看板)

把插件放到根目录下的plugins中,执行以下命令

# rake db:migrate_plugins RAILS_ENV=production

docker并不需要手动去执行,重启docker时会自动执行。

4.6,启动redmine

//方法一,要在解压的根目录下
# bundle exec rails server webrick -e production -b 0.0.0.0

//方法二,什么目录下都行
# /usr/local/rvm/rubies/ruby-2.2.3/bin/ruby /root/redmine-3.3.2/bin/rails server webrick -e production -b 0.0.0.0

看一下效果:

redmine配置完成

redmine配置完成

因为不想重新编译nginx,这里我并没有安装passenger,有兴趣的朋友可以自己研究下

4.7,自启动

# cat /usr/lib/systemd/system/redmine.service   //方法一
[Unit]
Description=Redmine Control
After=syslog.target
After=network.target

[Service]
type=forking
User=redmine
Group=redmine
ExecStart=/usr/local/rvm/rubies/ruby-2.3.3/bin/ruby /data/redmine/bin/rails server webrick -e production -b 127.0.0.1
Restart=always

[Install]
WantedBy=multi-user.target

# cat /etc/supervisord.d/redmine.ini    //方法二
[program:redmine]
command = /usr/local/rvm/rubies/ruby-2.3.3/bin/ruby /data/redmine/bin/rails server webrick -e production -b 127.0.0.1
autostart = true
startsecs = 5
autorestart = true
startretries = 5
user = redmine
redirect_stderr = true
stdout_logfile_maxbytes = 20MB
stdout_logfile_backups = 20
stdout_logfile = /var/log/redmine/error.log


转载请注明
作者:海底苍鹰
地址:http://blog.51yip.com/server/1883.html