CentOS 7.6 安装 Redmine 4.0.3 项目管理软件

Redmine 是一个网页界面的项目管理与缺陷跟踪管理系统的自由及开放源代码软件工具。它集成了项目管理所需的各项功能:日历、燃尽图和甘特图 以协助可视化表现项目与时间限制,问题跟踪和版本控制。此外,Redmine也可以同时处理多个项目。

### 1、安装 依赖关系源码包

yum -y install gcc gcc-c++ make cmake autoconf bzip2 libyaml-devel zlib-devel curl-devel openssl-devel ImageMagick-devel sqlite-devel perl-LDAP perl-Digest-SHA net-tools setuptool net-snmp-devel lsof lrzsz sysstat

### 2、删除已经安装源码包

yum erase ruby ruby-libs ruby-mode ruby-rdoc ruby-irb ruby-ri ruby-docs

### 3、升级yum的包索引

yum clean all
yum makecache fast

### 4、安装 Ruby 环境
下载安装 Ruby 源码

wget http://ring.shibaura-it.ac.jp/archives/lang/ruby/2.2/ruby-2.2.10.tar.gz
#mkdir -p /usr/local/ruby && tar zxvf ruby-2.2.10.tar.gz && pushd ruby-2.2.10 && ./configure --prefix=/usr/local/ruby && make -j 2 && make install
mkdir -p /usr/local/ruby
tar zxvf ruby-2.2.10.tar.gz
pushd ruby-2.2.10
./configure --prefix=/usr/local/ruby
make -j 2 && make install
ln -sf /usr/local/ruby/bin/ruby /usr/bin/ruby

### 5、输入

ruby -v

查看 ruby 是否安装成功

##### 如果显示下面内容说明安装成功

 ruby 2.2.10p489 (2018-03-28 revision 63023) [x86_64-linux]

### 6、设置Ruby环境变量 在 export PATH= 后面添加

vim /etc/profile
export PATH=/usr/local/ruby/bin:/usr/local/php/bin:/usr/local/nginx/sbin:/usr/local/mysql/bin:$PATH

### 7、立即生效

source /etc/profile

### 8、将 ruby 切换至国内源

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

### 8、验证你的Ruby镜像

gem sources -l

### 10、更新源缓存

gem sources -u

### 11、更新 gem

gem update --system

### 12、安装 rubygems

wget http://production.cf.rubygems.org/rubygems/rubygems-3.0.3.tgz
#tar -zxf rubygems-3.0.3.tgz && pushd rubygems-3.0.3 && ruby setup.rb && gem -v && popd
tar -zxf rubygems-3.0.3.tgz
pushd rubygems-3.0.3
ruby setup.rb
gem -v
popd

### 13、下载 Redmine

wget http://www.redmine.org/releases/redmine-4.0.3.tar.gz
tar -zxvf redmine-4.0.3.tar.gz
/bin/mv redmine-4.0.3 /usr/local/redmine

#### 14、创建配置文件

cd /usr/local/redmine/config
/bin/cp database.yml.example database.yml
/bin/cp configuration.yml.example configuration.yml

#### 15、修改 database.yml 配置数据库账号和密码

production:
adapter: mysql2
database: redminedb
host: localhost
username: redmine
password: 12345678

#### 16、修改 configuration.yml 配置电子邮件
后添加以下内容:

email_delivery:
  delivery_method: :smtp
  smtp_settings:
    tls: false
    address: "smtp.qq.com"
    port: 587
    authentication: :login
    domain: 'qq.com'
    enable_starttls_auto: true
    user_name: 'fooher@qq.com'
    password: '12345678'

#### 17、修改 settings.yml 配置 redmine 访问地址和端口 在第98行 把 localhost:3000 换成你的 IP+端口
这步可以不修改默认访问地址是 IP:3000
在第80行 把 redmine@example.net 换成你的邮件地址

#sed -i 's/localhost:3000$/192.168.20.235:3000/g' settings.yml
#sed -i 's/redmine@example.net$/fooher@qq.com/g' settings.yml

### 18、环境安装完成后,进入数据库,创建数据库

mysql -uroot -p
创建数据库
CREATE DATABASE redminedb CHARACTER SET utf8mb4;

新建 redmine 数据库账号
CREATE USER 'redmine'@'localhost' IDENTIFIED BY '12345678';

添加权限 redmine 管理 redminedb 数据库
GRANT ALL PRIVILEGES ON redminedb.* TO 'redmine'@'localhost';

刷新数据库
flush privileges;

#### 19、安装Rails的依赖包管理工具 Bundler)

gem install bundler -v '1.17.3'
#查看 bundler 是否安装成功
bundler -v

##### 19.2 再安装 Rails

gem install rails
#查看 rails 是否安装成功
rails -v

##### 命令查看 rails 版本时都会提示需要安装依赖关系包,如下面找不到 selenium-webdriver 包

Could not find gem 'selenium-webdriver' in any of the gem sources listed in your Gemfile.
Run `bundle install` to install missing gems.

##### 我们要通过命令来安装或者修改 Gemfile 文件 修改为对应的版本号

gem install selenium-webdriver -v "3.141.0"

####
输入命令 rails -v 如果 rails 能显示版本号 说明 安装成功,如果没有成,要根据提示安装依赖关系包,直到 rails -v 显示版本号为止
#### 20、安装 redmine 依赖的所有 ruby 包

bundle install --without development rmagick

#### 21、如果执行上面命令后不动,出行 下面内容 要在 redmine 目录下执行
#### 方法一 重启系统
#### 方法二 使用下面命令一个一个包安装
#### 方法三 添加淘宝源并删除默认的源地址,或者修改文件 /usr/local/redmine/Gemfile 第一行

Don't run Bundler as root. Bundler can ask for sudo if it is needed, and installing your bundle as root will break this application for all
non-root users on this machine

#### 22、安装 Rails 和 redmine 依赖的所有 ruby 包,我列出来方便大家安装时,能找出相对应的版本,其它版本可能对 ruby 2.2.10 不支持

gem install i18n -v '0.7.0'
gem install nokogiri -v '1.9.1'
#gem install rails -v '5.2.3'
gem install rails -v '5.2.2.1'
gem install rouge -v "3.3.0"
gem install request_store -v "1.0.5"
gem install actionpack-xml_parser -v '2.0.1'
gem install roadie-rails -v "1.3.0"
gem install xpath -v '3.1.0'
gem install rbpdf -v '1.19.8'
gem install net-ldap -v '0.16.1'
gem install ruby-openid -v "2.3.0"
gem install rack-openid -v "1.4.2"
gem install rmagick -v "2.16.0"
gem install redcarpet -v "3.4.0"
#安装 redmine MySQL 支持
gem install mysql2 -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
gem install yard
gem install mocha
gem install simplecov -v "0.14.1"
gem install puma -v "3.7"
gem install capybara -v "2.13"
gem install selenium-webdriver -v "3.141.0"

gem install rake -v '12.3.2'
gem install json -v '2.2.0'
gem install activesupport -v '5.2.3'
gem install actionview -v '5.2.3'
gem install actionpack -v '5.2.3'
gem install activejob -v '5.2.3'
gem install mime-types -v '3.2.2'
gem install actionmailer -v '5.2.3'
gem install actionpack-action_caching -v '1.2.0'
gem install activemodel -v '5.2.3'
gem install activerecord -v '5.2.3'
gem install coderay -v '1.1.2'
gem install railties -v '5.2.3'
gem install rack -v '2.0.7'
gem install protected_attributes -v '1.1.4'
#gem install RubyGems -v '3.4.0'
gem install net-ldap -v '0.16.1'
gem install rbpdf -v '1.19.8'
gem install cvs -v '0.1.0'
gem install mini_mime -v "1.0.1"
gem install roadie-rails -v "1.3.0"
gem install mail -v "2.7.1"
gem install tzinfo-data
gem install sprockets -v "3.7.2"
gem install minitest -v '5.11.3'
gem install redmine_acts_as_taggable_on -v "1.0"

#### 23、创建数据库表及默认设置

RAILS_ENV=production bundle exec rails db:migrate
RAILS_ENV=production REDMINE_LANG=zh bundle exec rake redmine:load_default_data

#### 24、创建相关目录及权限设置

mkdir -p tmp tmp/pdf public/plugin_assets
chown -R apache:apache files log tmp public/plugins
chmod -R 755 files log tmp public/s

#### 25、启动 Redmine

bundle exec rails server webrick -e production

本机访问 http://localhost:3000

遇到的问题:执行时报错

 bundle install –without development test

输出日志 显示找不到 rmagick -v ‘2.16.0’

An error occurred while installing rmagick (2.16.0), and Bundler cannot
continue.
Make sure that `gem install rmagick -v ‘2.16.0’` succeeds before bundling.

#### 26、解决方法:

yum install ImageMagick ImageMagick-devel

#### 27、配置 nginx 访问 redmine 在 http {} 中加入

        # Redmine
        passenger_enabled on;
        passenger_root /usr/local/ruby/lib/ruby/gems/2.2.0/gems/passenger-6.0.2;
        passenger_ruby /usr/local/ruby/bin/ruby;

        upstream redmine{
                server 127.0.0.1:3000;

#### 28、然后 server 配置:

server
    {
        listen 80 default_server;
        server_name 192.168.20.235;
#        server_name _;
        index index.html index.htm index.php;
        access_log  /data/wwwlogs/access_redmine.log;
        # redmine 访问目录
        root  /usr/local/redmine/public;
        #error_page   404   /404.html;
         # redmine

        location / {
                try_files $uri @redmine;
        }

        location @redmine {
                proxy_pass http://redmine;
                  proxy_redirect off;
                proxy_set_header Host $host; #注:这个不传进去,会暴露端口号,且会影响速度
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                # 如果找不到真实存在的文件,把请求分发至 index.php
                # try_files $uri $uri/ /index.php?$args;
        }

        location /nginx_status
        {
            stub_status on;
            access_log   off;
        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /.well-known {
            allow all;
        }

        location ~ /\.
        {
            deny all;
        }

还需要完善