Redmine是一个自由开放的源码解决方案,它提供集成的项目管理功能,问题跟踪,并为多个版本控制选项的支持,由于Redmine的设计受到Rrac的较大影响,所以他们有很多相似特征,Redmine建立在Ruby on Rails的框架智商,它们可以跨平台和数据库。
- Gitolite - 轻量级,开源项目,使用SSH公钥认证,能做到分支级的权限控制。
- redmine 和gitolite采用插件形式集成,由于redmine 部署过程异常复杂,这里有必要把我的安装过程遇到的问题记录下,以供参考。
- 操作系统:centos7,最小化安装。
- redmine安装用户为:redmine
- 关闭防火墙及Selinx
-
关闭防火墙
systemctl stop firewalld.service #停止firewall
-
systemctl disable firewalld.service #禁止firewall开机启动
-
关闭SELinux
编辑/etc/selinux/config文件,将SELINUX的值设置为disabled,下次开机SELinux就不会启动了
- 1、更改 yum 源为阿里源(以root账号运行)
- 备份:
- step1:
- mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
- step2:
- wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
- step3:下载mysql的repo源
- wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
- rpm -ivh mysql-community-release-el7-5.noarch.rpm
-
yum makecache生成缓存
- 必要时清除缓存:
- yum clean packages
- yum clean oldheaders
- yum clean metadata
- yum clean all
- yum makecache
- 2、准备安装账号
- useradd git :gitolite 安装使用
- useraddredmine :redmine 安装使用
- 配置sudoers
vi /etc/sudoers.d/redmine
,内容如下:
Defaults:redmine !requiretty
redmine ALL=(git) NOPASSWD:ALL,
(root) NOPASSWD:ALL ## redmine 可以sudo执行 root git 用户权限
wq保存:
修改文件权限: -
chmod 440 /etc/sudoers.d/redmine
-
3、安装依赖包
yum -y install libyaml-devel zlib-devel curl-devel openssl-devel httpd-devel apr-devel apr-util-devel gcc ruby-devel gcc-c++ make postgresql-devel ImageMagick-devel sqlite-devel perl-LDAP mod_perl perl-Digest-SHA
安装相应的依赖包
redmine ruby版本支持
The required Ruby versions for a given Redmine version is:
Redmine version | Supported Ruby versions | Rails version used |
---|
3.3, current trunk | ruby 1.9.33, 2.0.02, 2.1, 2.21, 2.3 | Rails 4.20 |
3.2, 3.1 | ruby 1.9.33, 2.0.02, 2.1, 2.21 | Rails 4.20 |
4、 安装ruby,
卸载旧版 yum remove ruby
wget https://ruby.taobao.org/mirrors/ruby/2.3/ruby-2.3.1.tar.gz
tar xf ruby-2.3.1.tar.gz
cd ruby-2.3.1
./configure --prefix=/usr/local/ruby && make &&make install
安装完成之后修改系统的PATH路径
# vi /etc/profile.d/ruby.sh
export PATH=/usr/local/ruby/bin:$PATH
# . /etc/profile.d/ruby.sh 使其生效
#ruby -v 查看安装好的ruby版本
接下来,更改淘宝镜像源
gem sources --add https://ruby.taobao.org/ --remove https://rubygems.org/
安装bundle
gem install bundle
然后改用淘宝镜像:
bundle config 'mirror.https://rubygems.org' 'https://ruby.taobao.org'
目前淘宝镜像迁移到 https://gems.ruby-china.org/ 了
yum install mysql-server
重置密码及开启远程访问
mysql -h localhost -u root
修改初始密码
#
mysql -u root -p
Enter password: 【输入原来的密码】
mysql>
use mysql;
mysql>
update user set password=password("yourpassword") where user='root';
开启远程登录
mysql> grant all privileges on *.* to 'root'@'%' identified by 'yourpassword' with grant option;
mysql>
flush privileges;
mysql>
exit;
以redmine 用户执行
参考:http://www.redmine.org/projects/redmine/wiki/RedmineInstall
step1:下载 redmine
wget http://www.redmine.org/releases/redmine-3.3.1.tar.gz
step2:创建redmine数据库
CREATE DATABASE redmine CHARACTER SET utf8;
CREATE USER 'redmine'@'localhost' IDENTIFIED BY 'my_password';
GRANT ALL PRIVILEGES ON redmine.* TO 'redmine'@'localhost';
st sep3:配置数据库连接
cd
redmine-3.3.1
cd config
cp database.yml.example database.yml
vi database.yml
production:
adapter: mysql
database: redmine
host: localhost
username: redmine
password: my_password
step4:
Dependencies installation(依赖安装)
bundle install --without development test
此步骤比较耗时,缺少啥就安装啥,一个都不能少,如果提示的不是淘宝镜像,则再次执行
bundle config 'mirror.https://rubygems.org' 'https://ruby.taobao.org',配置为国内淘宝镜像
一般会缺少rbpdf-font ,单独执行即可
gem install rbpdf-font
Step 5 - Session store secret generation
This step generates a random key used by Rails to encode cookies storing session data thus preventing their tampering.
Generating a new secret token invalidates all existing sessions after restart.
bundle exec rake generate_session_store
bundle exec rake generate_secret_token
/usr/local/ruby/lib/ruby/gems/2.3.0/gems/htmlentities-4.3.1/lib/htmlentities/mappings/expanded.rb:465: warning: key "inodot" is duplicated and overwritten on line 466
解决如下:
sudo vi /usr/local/ruby/lib/ruby/gems/2.3.0/gems/htmlentities-4.3.1/lib/htmlentities/mappings/expanded.rb
输入466 Shift+g定位到466行,注释掉即可。
Step 6 - Database schema objects creation
Create the database structure, by running the following command under the application root directory:
RAILS_ENV=production bundle exec rake db:migrate
Step 7 - Database default data set
Insert default configuration data in database, by running the following command:
RAILS_ENV=production bundle exec rake redmine:load_default_data
Redmine will prompt you for the data set language that should be loaded; you can also define the REDMINE_LANG
environment variable before running the command to a value which will be automatically and silently picked up by the task.
E.g.:
Unices:
RAILS_ENV=production REDMINE_LANG=fr bundle exec rake redmine:load_default_data
Windows:
set RAILS_ENV=production
set REDMINE_LANG=fr
bundle exec rake redmine:load_default_data
Step 8 - File system permissions
NB: Windows users can skip this section.
The user account running the application must have write permission on the following subdirectories:
files
(storage of attachments)log
(application log file production.log
)tmp
and tmp/pdf
(create these ones if not present, used to generate PDF documents among other things)public/plugin_assets
(assets of plugins)
E.g., assuming you run the application with a redmine user account:
mkdir -p tmp tmp/pdf public/plugin_assets
sudo chown -R redmine:redmine files log tmp public/plugin_assets
sudo chmod -R 755 files log tmp public/plugin_assets
Step 9 - Test the installation
Test the installation by running WEBrick web server:
bundle exec ruby script/server webrick -e production
bundle exec ruby script/rails server webrick -e production
bundle exec rails server webrick -e production
添加
-b 0.0.0.0 否则其他机器访问不了
bundle exec rails server webrick -e production -b 0.0.0.0
- 五、安装gitolite以及 集成redmine-git-hosting插件
# Install dependencies (On Debian/Ubuntu)
root# apt-get install build-essential libssh2-1 libssh2-1-dev cmake libgpg-error-dev
# Install dependencies (On Fedora/CentoS/RedHat)
root# yum group install "Development Tools"
root# yum install libssh2 libssh2-devel cmake libgpg-error-devel
安装git yum install git
Assuming that you have Redmine installed :
# Switch user
root# su - redmine
# First git clone Bootstrap Kit
redmine$ cd REDMINE_ROOT/plugins
redmine$ git clone https://github.com/jbox-web/redmine_bootstrap_kit.git
redmine$ cd redmine_bootstrap_kit/
redmine$ git checkout 0.2.4
# Then Redmine Git Hosting plugin
redmine$ cd REDMINE_ROOT/plugins
redmine$ git clone https://github.com/jbox-web/redmine_git_hosting.git
redmine$ cd redmine_git_hosting/
redmine$ git checkout 1.2.1
# Install gems and migrate database
redmine$ cd REDMINE_ROOT
redmine$ bundle install --without development test
redmine$ bundle exec rake redmine:plugins:migrate RAILS_ENV=production NAME=redmine_git_hosting
As we need to send commands over SSH in non-interactive mode, the SSH key must not have passphrase (-N ''
argument). Also, it’s better to store SSH Keys outside of REDMINE_ROOT path so
root$ su - redmine
redmine$ mkdir ssh_keys
redmine$ ssh-keygen -N '' -f plugins/redmine_git_hosting/ssh_keys/redmine_gitolite_admin_id_rsa
On Bitnami stack :
bitnami$ cd /opt/bitnami/apps/redmine/
bitnami$ mkdir ssh_keys
bitnami$ chgrp daemon ssh_keys
bitnami$ ssh-keygen -N '' -f ssh_keys/redmine_gitolite_admin_id_rsa
bitnami$ chmod 640 ssh_keys/*
If you’re using Apache to run Redmine :
root# sudo -u www-data mkdir -p /var/www/redmine/ssh_keys
root# sudo -u www-data ssh-keygen -N '' -f /var/www/redmine/ssh_keys/redmine_gitolite_admin_id_rsa
You will have to configure the plugin to point to this path
Assuming that you have Gitolite installed :
repo gitolite-admin
RW+ = redmine_gitolite_admin_id_rsa
Otherwise you can install Gitolite (v3) by following this :
Server requirements:
* any unix system
* sh
* git 1.6.6+
* perl 5.8.8+
* openssh 5.0+
* a dedicated userid to host the repos (in this document, we assume it
is 'git'), with shell access ONLY by 'su - git' from some other userid
on the same server.
Steps to install:
* login as 'git' as described above
* make sure ~/.ssh non-existent
* make sure **Redmine SSH public key** we've just created is available at $HOME/redmine_gitolite_admin_id_rsa.pub
* add this in ~/.profile
# set PATH so it includes user private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$PATH:$HOME/bin"
fi
* run the following commands:
root$ su - git
git$ mkdir $HOME/bin
git$ source $HOME/.profile
git$ git clone git://github.com/sitaramc/gitolite
git$ gitolite/install -to $HOME/bin
git$ gitolite setup -pk redmine_gitolite_admin_id_rsa.pub
If you are running Gitolite 3 don’t forget to patch it!
root$ su - git
git$ vi (or nano) .gitolite.rc
## Look for GIT_CONFIG_KEYS and make it look like :
GIT_CONFIG_KEYS => '.*',
## Enable local code directory
LOCAL_CODE => "$ENV{HOME}/local"
## then save and exit
Note : You will have to set the LOCAL_CODE
path in plugin settings (see below).
As root create the file /etc/sudoers.d/redmine
and put this content in it :
Defaults:redmine !requiretty
redmine ALL=(git) NOPASSWD:ALL
Then chmod the file :
root# chmod 440 /etc/sudoers.d/redmine
Make sure that Redmine user has Gitolite server in his known_hosts list. This is also a good check to see if Gitolite works.
It should not ask you for a password.
Also the SSH config file for Redmine user (<redmine user home>/.ssh/config) is not needed anymore! Remove it if exists!
root$ su - redmine
redmine$ ssh -i ssh_keys/redmine_gitolite_admin_id_rsa git@localhost info
# accept key
You should get something like that :
hello redmine_gitolite_admin_id_rsa, this is gitolite v2.3.1-0-g912a8bd-dt running on git 1.7.2.5
the gitolite config gives you the following access:
R W gitolite-admin
@R_ @W_ testing
Or
hello redmine_gitolite_admin_id_rsa, this is git@dev running gitolite3 v3.3-11-ga1aba93 on git 1.7.2.5
R W gitolite-admin
R W testing
If you get one of these messages, you’re on the right way ;)
Our post-receive hook is triggered after each commit and is used to fetch changesets in Redmine. As it is written in Ruby, you need to install Ruby on your server. Note that this does not conflict with RVM. Ruby 1.9 at least is required for the hooks.
root$ apt-get install ruby
# or
root$ yum install ruby
启动redmine
bundle exec rails server webrick -e production -b 0.0.0.0
The plugin is now installed, you can restart Redmine :)
But you must set some additional settings :
-
Enable Xitolite repositories in Administration -> Settings -> Repositories
- Configure plugin settings in Administration -> Redmine Git Hosting, specially :
- SSH Keys path
- Temp dir path (to store GitoliteAdmin repository)
LOCAL_CODE
path (for Gitolite hooks)- Access urls (SSH, HTTP, HTTPS)
- Hooks url (This url will be called by our Gitolite hook to trigger repository view refresh so be sure it’s callable)
- Hooks install (This may overwrite your existing Gitolite hooks)
-
Check your installation in Administration -> Redmine Git Hosting Config Checks tab.
- Set some permissions on Administration -> Roles page, particularly if you want users to be able to create SSH keys (see below).
Before configuring the plugin you should take a look at this : Repositories Storage Configuration Strategy.
If you’re using a Bitnami Stack (again) : you must properly configure the temp directory.Here’s how.
Repositories access are based on Redmine project’s members and project’s roles : youmust add users with the adequate role as project’s member to be able to clone/update repositories.
Unless you want to access your repositories exclusively via Smart HTTP, users will need to set a public key to connect via SSH.
To do this, open a browser, login to Redmine and follow the “My Account” link in the upper right-hand corner of the page then “Add SSH keys” link.
SSH Keys should be unique, that is, the keys you set in Redmine should not already exist in the Gitolite repo.
错误处理
If you got this error it means that rugged/libgit2 has not been compiled with SSH support.
Install missing dependencies then :
root# su - redmine
redmine$ cd REDMINE_ROOT
redmine$ bundle clean --force
redmine$ bundle install --without development test
redmine$ gem uninstall rugged
redmine$ gem install rugged -v='0.22.2'
如果日志报如下错误:SSH KEYs 有关的
check your SSH keys (path, permissions) or your Git user
检测sshkey/密钥文件权限,必要时赋予 chmod 700 权限
redmine_gitolite_admin_id_rsa 权限 700 ;//chmod 700 redmine_gitolite_admin
六 安装niginx
1、gem install passenger
2、 passenger-install-nginx-modul
修改配置文件
user redmine;
worker_processes 1;
http {
passenger_root /usr/local/ruby/lib/ruby/gems/2.3.0/gems/passenger-5.0.30;
passenger_ruby /usr/local/ruby/bin/ruby;
passenger_app_env production;
passenger_default_user redmine;
passenger_user redmine;
server {
listen 80;
server_name localhost;
passenger_enabled on;
location / {
root /app/redmine-3.3.1/public;
#root html;
index index.html index.htm;
}
由于1024以下端口需要root 权限才能启动
因此,必须以root 权限启动nginx
3.开机启动
vi /lib/systemd/system/nginx.service
内容如下
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/app/redmine-3.3.0/nginx/logs/nginx.pid
# Nginx will fail to start if /run/nginx.pid already exists but has the wrong
# SELinux context. This might happen when running `nginx -t` from the cmdline.
# https://bugzilla.redhat.com/show_bug.cgi?id=1268621
ExecStartPre=/usr/bin/rm -f /app/redmine-3.3.0/nginx/logs/nginx.pid
ExecStartPre=/app/redmine-3.3.0/nginx/sbin/nginx -t
ExecStart=/app/redmine-3.3.0/nginx/sbin/nginx
ExecStop=/app/redmine-3.3.0/nginx/sbin/nginx -s stop
ExecReload=/app/redmine-3.3.0/nginx/sbin/nginx -s reload
KillMode=process
KillSignal=SIGQUIT
TimeoutStopSec=5
PrivateTmp=true
[Install]
WantedBy=multi-user.target
wq 退出
systemctl enable nginx.service
systemctl start nginx.service
查看 网络连接
netstat -lntp|grep nginx