Redmine与Gitlab功能集成

这个工作之前已完成了,但网上教程或多或少记录得不很正确,这里参考几篇文章结合自己实践做个记录。

Redmine v3.4.5,Gitlab v10.5.1。

Redmine与Gitlab功能整合,主要是实现在Redmine项目管理页中的版本库栏可以看到Gitlab中的版本提交信息,另外Git的提交信息中用特定格式写,可以关联Redmine的Issue项,仅此而已。

redmine设置启用版本库

1.启用SCM:本地只安装了git,所以其他的取消掉。

2.启用用于版本库管理的Web Service:需要勾选,实现gitlab的web_hook访问

3.版本库管理网页服务API密钥:点击生成或者手动输入,记录一下后面配置gitlab需要用到。

4.允许引用/修复所有其他项目的问题:勾选后就可以在commit message中使用上一项定义的关键字实现git提交和redmine issue的关联,如 refs:#123 表示将本次提交关联到redmine的123号任务。

5.激活时间日志:勾选后可以在commit message中设置当前提交耗时记录,方式为 Implement feature #1234 @2h 或者 Implement feature #1234 @15m

6.用于引用问题的关键字:须填”refs,references,IssueID,*”,这里还添加了星号“*”(图中没有),原因在这里有写,反正加上就是了。

7.最下面一个设置框中就是自定义关键字,实现commit message控制remine中的issue的状态,比如我这里预设了解决、进行中和关闭三个,在commit message中的用法为: ok:#123 或 start #123 或 close:#123 @2 ,这最后一个实例还把时间也带上了。

Gitlab设置WebHooks网址

Settings → System Hooks  → 「Add System Hook」

然后填入你自己的网址:http://[你的网址]/sys/fetch_changesets?key=[刚才生成的APIkey]

可以去测试了,在往Git提交代码的时候填入“finish #1”,这时候你就会发现Issue #1已经变成了100%进度了,当然前提是你真的有#1这个Issue。

 

redmine版本库:版本库中不存在该条目和(或)其修订版本

前面做了Aphache与Redmine的整合。

发现原来配置好的git项目版本库报错了:”版本库中不存在该条目和(或)其修订版本”。经了解是因为整合后,Redmine不再使用自己的用户运行程序,而是用Apache的用户运行程序,所以原来设置的文件权限不适用。访问不到版本库自然报这个错。

这里对这个问题的可能原因做个总结:

1. git路径不正确,redmine会寻找/usr/bin/git来执行,如果git可执行命令不在那个目录下面,那么需要做个软链接,或者把git path添加到系统运行路径环境变量中

2. 权限不正确,redmine是以apache用户(具体用户名看apache的配置,比如我的是www)来运行的,通过查看config/enviroment.rb文件属性来确认:

[root@techbrood.com log]# ll ../config/environment.rb
-rw-rw-r– 1 www www 592 Apr 11 12:31 ../config/environment.rb  //apache用户要有environment.rb的写权限。

3. 如果上述1和2的问题都没有,那么很可能是本身的git库不正确。

切换redmine进入development模式,查看development.log日志,可以看到在点击项目版本库标签时,redmine发出的git命令信息:

 

[plain] view plain copy

git –git-dir ‘/opt/git/repos/ufcms.git/’ log –no-color –raw
git –git-dir ‘/opt/git/repos/ufcms.git/’ ls-tree -l ‘HEAD:’
手动在命令行下执行,如果提示:fatal: Not a git repository: ‘/opt/git/repos/ufcms.git/’

可以确认是git库路径不正确,比如你可能是从github上克隆下来的git库,

git clone –bare git://github.com/iefreer/ufcms.git

那么上述命令会在本地生成一个git库,不过路径不是 /opt/git/repos/ufcms.git而是/opt/git/repos/ufcms/.git,

需要在Redmine项目版本库配置中把git路径修改正确。

另外在开发模式下还可以通过查看log/development.scm.stderr.log来获取准确的错误信息。

CentOS7.5上用Apache运行Redmine

之前已安装redmine,但它默认的WEB服务软件是WEBrick,这个是Rails开发测试用的服务器,性能很差。之前就发现打开响应特别慢,今天又出问题:只要在redmine上登录用户就卡死无响应,一气之下就想换apache来运行redmine。说干就干,下面就来记叙改造过程。

安装Apache

我下载的是apache2.4.33,在运行./configure命令时,报了error: APR not found.

原来是要安装如下软件包:

wget http://archive.apache.org/dist/apr/apr-1.6.3.tar.gz

wget http://archive.apache.org/dist/apr/apr-util-1.6.1.tar.gz

wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.42/pcre-8.42.tar.gz

具体步骤如下:

安装apr

[root@xt test]# tar -zxf apr-1.6.3.tar.gz
[root@xt test]# cd apr-1.6.3
[root@xt apr-1.6.3]# ./configure –prefix=/usr/local/apr
[root@xt apr-1.6.3]# make && make install

Centos7还需要装:
yum install expat-devel

安装APR-util

[root@xt test]# tar -zxf apr-util-1.6.1.tar.gz
[root@xt test]# cd apr-util-1.6.1
[root@xt apr-util-1.6.1]# ./configure –prefix=/usr/local/apr-util –with-apr=/usr/local/apr
[root@xt apr-util-1.6.1]# make && make install

安装pcre

[root@xt test]#tar -zxf pcre-8.42.tar.gz
[root@xt test]#cd pcre-8.42
[root@xt pcre-8.42]#./configure –prefix=/usr/local/pcre
[root@xt pcre-8.42]#make && make install

编译Apache

cd httpd-2.4.33

./configure –prefix=/usr/local/apache2.4.33 \
–with-apr=/usr/local/apr \
–with-apr-util=/usr/local/apr-util/ \
–with-pcre=/usr/local/pcre \
–enable-deflate \
–enable-expires \
–enable-headers \
–enable-modules=most \
–enable-so \
–with-mpm=worker \
–enable-rewrite

make

如果make过程中有如下报错:
collect2: ld returned 1 exit status make[2]: *** [htpasswd] խϳ 1 make[2]: Leaving
则可尝试安装libtools-ltdl-devel解决。

如果不行,将apr目录拷贝到httpd下:
cp -r apr-1.5.2 httpd-2.4.33/srclib/apr

然后运行:

./configure --prefix=/usr/local/apache2.4.33 \
--with-included-apr
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util/ \
--with-pcre=/usr/local/pcre \
--enable-deflate \
--enable-expires \
--enable-headers \
--enable-modules=most \
--enable-so \
--with-mpm=worker \
--enable-rewrite

再:

make install

配置apache

useradd apache -s /sbin/nologin

vim /usr/local/apache/conf/httpd.conf

改如下参数:

User apache

Group apache

ServerName 127.0.0.1:80  #前面的注释符去掉

Listen 80

Listen 3000

DirectoryIndex index.html index.php index.htm

Include conf/extra/httpd-vhosts.conf

运行apache服务:
vim /usr/lib/systemd/system/httpd.service

[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=man:httpd(8)
Documentation=man:apachectl(8)

[Service]
Type=forking

EnvironmentFile=/etc/sysconfig/httpd
ExecStart=/usr/local/apache2/bin/apachectl start
ExecReload=/usr/local/apache2/bin/apachectl graceful
ExecStop=/usr/local/apache2/bin/apachectl stop
# We want systemd to give httpd some time to finish gracefully, but still want
# it to kill httpd after TimeoutStopSec if something went wrong during the
# graceful stop. Normally, Systemd sends SIGTERM signal right after the
# ExecStop, which would kill httpd. We are sending useless SIGCONT here to give
# httpd time to finish.
KillSignal=SIGCONT
PrivateTmp=true

[Install]
WantedBy=multi-user.target

一般装完上述文件已存在,只要参照修改一下就行。

开启服务:systemctl start httpd
关闭服务:systemctl stop httpd

加入自启动功能:systemctl enable httpd

整合Redmine和Apache

设置redmine文件权限:

cd /usr/local/redmine

chown -R apache:apache files log tmp public/plugin_assets
chmod -R 755 files log tmp public/plugin_assets

安装httpd httpd-devel 

yum install -y httpd httpd-devel

绑定apache

gem install passenger

yum install libcurl-devel -y

passenger-install-apache2-module  #根据提示操作

在/usr/local/apache/conf/httpd.conf中加入:

LoadModule passenger_module /usr/local/rvm/gems/ruby-2.4.1/gems/passenger-5.3.2/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /usr/local/rvm/gems/ruby-2.4.1/gems/passenger-5.3.2
PassengerDefaultRuby /usr/local/rvm/gems/ruby-2.4.1/wrappers/ruby
</IfModule>

在/usr/local/apache/conf/httpd.conf中:

去掉两行注释,开启vhosts功能:
LoadModule vhost_alias_module modules/mod_vhost_alias.so
Include conf/extra/httpd-vhosts.conf

去掉ServerName注释:
ServerName www.testhost.com:80

 

在/usr/local/apache/conf/extra/httpd-vhosts.conf中:
<VirtualHost *:3000>
ServerAdmin nowguy@qq.com
DocumentRoot “/usr/local/redmine/public”
ServerName redmine.testhost.com
ServerAlias redmine.testhostalias.com
ErrorLog “logs/redmine-error_log”
CustomLog “logs/redmine-access_log” common

<Directory “/usr/local/redmine/public”>
AllowOverride None
Options None
Require all granted
</Directory>
</VirtualHost>

重启Aphache:

/usr/local/apache/bin/apachectl graceful

在浏览器中输入http://IP:3000即可看到网页了。

这里有个问题,涉及添加修改用户的页面给775的权限都不能打开,只好把files、 log 、tmp 、public设置成777才行。照理用apache用户访问的话前者权限就够了。因为只是个人在用,这个问题先放放,如果有知道的朋友麻烦留言告之,谢谢!

 

chkconfig启动时执行shell脚本

自定义的shell脚本可以利用chkconfig,在开机启动时执行。一般用于启动特定服务。

1、脚本tomcatstart前三行如下:

#!/bin/bash
#chkconfig: 2345 81 96
#description: Starttomcat

第一行,告诉系统使用的shell,所有的shell脚本都是这样。
第二行,chkconfig后面有三个参数:

2345是运行级别,表示在这几个级别个启动时执行脚本。

81和96告诉chkconfig程序,需要在/etc/rc.d/rc2.d~rc5.d目录下,创建名字为 S81tomcatstart的文件连接,连接到/etc/rc.d/init.d目录下的的tomcatstart脚本。第一个字符是S,系统在启动的时候,运行脚本tomcatstart,就会添加一个start参数,告诉脚本,现在是启动模式。
同时在/etc/rc.d/rc0.d和/etc/rc.d/rc6.d目录下,创建名字为K96tomcatstart的 文件连接,第一个字符为K,在关闭系统的时候,会运行tomcatstart,添加一个stop参数,告诉脚本,现在是关闭模式。

chkconfig –add tomcatstart      #执行此命令,系统会自动帮你创建上述软链接。也可以不运行这个命令,而是自己手动创建。

chkconfig –level 2345 tomcatstart on #将脚本加入自启动列表。

chkconfig –list    #查看自启动列表

 

继续阅读 →

navicat连接MySQL8.0出现2059错误(转)

在navicat链接mysql8以后的版本时,会出现2059的错误,这个错误出现的原因是在mysql8之前的版本中加密规则为mysql_native_password,而在mysql8以后的加密规则为caching_sha2_password。解决此问题有两种方法,一种是更新navicat驱动来解决此问题,一种是将mysql用户登录的加密规则修改为mysql_native_password。本文采用第二种方式。

ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘password’ PASSWORD EXPIRE NEVER;

ALTER USER ‘root’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘password’;

FLUSH PRIVILEGES; #刷新权限

此问题得以解决