禅道开源版本12.4.3配置代码关联功能总结
想实际使用一下禅道提供的代码关联功能,于是进行了相应地研究,过程比较曲折,下面将遇到的问题及解决方案进行记录,便于后续参考。中间多次遇到问题,都是找禅道官方技术支持团队寻求的帮助,感谢他们以专业的技术实力提供的热心支持!
参照官方帮助文档完成了禅道开源版本12.4.3的安装,使用的是Linux一键安装包64位(适用于Ubuntu17+,centos7.4+):ZenTaoPMS.12.4.3.zbox_64.tar.gz,具体地址如下:
https://www.zentao.net/book/zentaopmshelp/90.html
实际部署环境配置信息如下:
CentOS Linux release 7.6.1810 (Core)
svn, version 1.11.1 (r1850623)
git version 2.29.2
依照官方提供的操作指南进行svn及git版本库的配置工作,对应链接如下:
https://www.zentao.net/book/zentaopmshelp/393.html
一、遇到的问题及相应解决方案
1.svn权限问题
文件路径为“/opt/zbox/logs/apache_error.log”,对应出错信息如下:
svn: E000032: Write error: Broken pipe
svn: warning: W000013: Can't open file '/root/.subversion/servers': Permission denied
svn: E000032: Write error: Broken pipe
svn: warning: W000013: Can't open file '/root/.subversion/servers': Permission denied
解决方案:
- root帐号下,创建一个zentao帐号;
- 用zentao帐号登录系统,执行"svn ls svn" (报错没关系,已经生成了.subversion);
- 执行"chmod -R 755 /home/zentao";
- 禅道配置svn客户端时,填写"/usr/bin/svn --config-dir /home/zentao/.subversion"。
2.禅道配置svn客户端报错
报错信息如下图所示:
解决方案:
- 将文件"/opt/zbox/app/zentao/module/repo/model.php"中判定有空格即返回的代码注释掉,如下所示:
public function checkClient()
{
if(!$this->config->features->checkClient) return true;
if(!$this->post->client) return true;
// if(strpos($this->post->client, ' '))
// {
// dao::$errors['client'] = $this->lang->repo->error->clientPath;
// return false;
// }
3.分配内存不够用
日志文件“/opt/zbox/logs/apache_error.log”,对应出错信息如下:
[Mon Oct 26 17:00:34.305441 2020] [core:notice] [pid 20709:tid 140658444588800] AH00094: Command line: '/opt/zbox/run/apache/httpd'
svn: E000032: Write error: Broken pipe
svn: E000032: Write error: Broken pipe
svn: E000032: Write error: Broken pipe
svn: E000032: Write error: Broken pipe
svn: E000032: Write error: Broken pipe
svn: E000032: Write error: Broken pipe
日志文件“/opt/zbox/app/zentao/tmp/log/php.20201026.log.php”,对应出错信息如下:
17:24:16 Allowed memory size of 134217728 bytes exhausted (tried to allocate 65028096 bytes) in /opt/zbox/app/zentao/lib/scm/scm.class.php on line 240 when visiting repo-ajaxSyncCommit-1
17:24:26 Allowed memory size of 134217728 bytes exhausted (tried to allocate 65028096 bytes) in /opt/zbox/app/zentao/lib/scm/scm.class.php on line 240 when visiting repo-ajaxSyncCommit-1
17:24:36 Allowed memory size of 134217728 bytes exhausted (tried to allocate 65028096 bytes) in /opt/zbox/app/zentao/lib/scm/scm.class.php on line 240 when visiting repo-ajaxSyncCommit-1
解决方案:
将"/opt/zbox/etc/php/php.ini"中的memory_limit 值修改为"1024M",重启服务。
默认是:memory_limit = 128M
修改为:memory_limit = 1024M
4.数据库表损坏
经历了一次停电,然后禅道无法正常使用了,看了一下日志,发现日志文件"/opt/zbox/logs/mysql_error.log"出错信息如下:
2020-11-02 10:43:14 3 [ERROR] mariadbd: Table './zentao/zt_cron' is marked as crashed and should be repaired
2020-11-02 10:43:14 3 [Warning] Checking table: './zentao/zt_cron'
2020-11-02 10:43:35 9 [ERROR] mariadbd: Table './zentao/zt_repo' is marked as crashed and should be repaired
2020-11-02 10:43:35 9 [Warning] Checking table: './zentao/zt_repo'
2020-11-02 10:43:35 9 [ERROR] mariadbd: Table './zentao/zt_repohistory' is marked as crashed and should be repaired
2020-11-02 10:43:35 9 [Warning] Checking table: './zentao/zt_repohistory'
2020-11-02 10:43:35 9 [ERROR] mariadbd: Table './zentao/zt_repobranch' is marked as crashed and should be repaired
2020-11-02 10:43:35 9 [Warning] Checking table: './zentao/zt_repobranch'
2020-11-02 10:45:15 5 [ERROR] mariadbd: Table './zentao/zt_repofiles' is marked as crashed and should be repaired
2020-11-02 10:45:15 5 [Warning] Checking table: './zentao/zt_repofiles'
解决方案:
- 在禅道服务部署本机登录数据库:/opt/zbox/bin/mysql -u root -P mysql端口 -p (比如:/opt/zbox/bin/mysql -u root -P 3306 -p)
- 依次运行下面sql语句解决问题:
use zentao;
REPAIR TABLE `zt_cron`;
REPAIR TABLE `zt_repo`;
REPAIR TABLE `zt_repohistory`;
REPAIR TABLE `zt_repobranch`;
REPAIR TABLE `zt_repofiles`;
5.git 本地仓库和远程仓库代码同步问题
禅道是通过查询git本地仓库的记录来分析获取关联信息的,但因为权限的问题,其不能直接进行同步远程仓库代码的操作,所以考虑使用本地定时任务来完成该项工作。总体思路是使用python脚本完成主体工作,使用shell脚本进行封装,在系统定时任务中增加一个任务,每隔5分钟执行一次。下面直接描述操作步骤。
- 安装python3运行环境,具体可参考下面这个链接,python版本可去官网下载相对较新版本:
https://blog.csdn.net/yycoolsam/article/details/90938851 - 先运行
pip install gitpython
安装依赖的第三方库,再将下面的python代码保存名称为"sync_git.py"存放到本地路径,如"/home/zentao/python/credittools"。
import argparse
import os
import git
import time
'''
同步远程仓库代码到本地git仓库,包括所有分支信息。
'''
# 获取以秒为单位的两个时间点之间的差值,返回以XXmXXs的时间格式字符串
def get_time_info(begin, end):
elapsed = end - begin
sec_per_min = 60
m = elapsed // sec_per_min
s = elapsed % sec_per_min
time_info = '{}m{}s'.format(round(m), round(s))
return time_info
def measure_time(func, *args, **dicts):
begin = time.time()
func(*args, **dicts)
end = time.time()
time_info = get_time_info(begin, end)
# 输出总用时
print('===Finished. Total time: {}==='.format(time_info))
class Manager:
HEAD_NAME = 'HEAD'
def __init__(self, args):
# 先将输入的控制参数全部存储为成员变量
for name, value in vars(args).items():
setattr(self, name, value)
# pprint.pprint(vars(self))
self.work_path = os.path.abspath(self.work_path)
def process(self):
# 先更新git仓库信息
repo = git.Repo(self.work_path)
repo.git.fetch(all=True)
# 先获取远程分支信息以及本地分支信息
origin = repo.remote()
remote_branches = origin.refs
local_branches = repo.branches
remote_map = dict()
for item in remote_branches:
pure_name = self._get_pure_name(item.name)
remote_map[pure_name] = item
local_map = dict()
for item in local_branches:
local_map[item.name] = item
# 除了head分支,如果本地分支没有相应的远程分支,则创建,如果有则更新覆盖。
for k in remote_map:
if k != Manager.HEAD_NAME:
if k in local_map:
if k == repo.active_branch.name:
repo.git.reset(remote_map[k].name, hard=True)
repo.git.pull()
else:
repo.git.checkout(k)
repo.git.reset(remote_map[k].name, hard=True)
repo.git.pull()
else:
repo.git.checkout(remote_map[k].name, b=k, f=True)
# 如果远程没有相应的本地分支,则删除本地分支。
for item in local_map:
if item not in remote_map:
repo.git.branch(item, d=True)
def _get_pure_name(self, whole_name):
if whole_name:
str_array = whole_name.split('/')
return str_array[-1]
else:
return None
def main(args):
manager = Manager(args)
manager.process()
# 对输入参数进行解析,设置相应参数
def get_args(src_args=None):
parser = argparse.ArgumentParser(description='synchronize git repository with remote if need.')
parser.add_argument('work_path', metavar='work_path', help='working directory')
# parser.print_help()
return parser.parse_args(src_args)
if __name__ == '__main__':
test_args = None
args = get_args(test_args)
measure_time(main, args)
- 在系统文件"/etc/profile"中增加python运行环境变量,具体增加内容如下:
export PYTHONPATH=/home/zentao/python/credittools
- 将下面的shell脚本保存名称为"sync_git.sh"存放到本地路径,如"/home/zentao/sh"。
#!/bin/bash
# synchronize environment variables
source /etc/profile
# get absolute path
target_path=`readlink -m $1`
filelist=`ls $target_path`
for file in $filelist
do
target_dir=$target_path/$file
if [ -d $target_dir ]
then
python -m sync_git $target_dir
fi
done
- 使用
crontab -e
命令增加定时任务,具体增加内容如下:
# 每5分钟同步一次git仓库
*/5 * * * * /home/zentao/sh/sync_git.sh /data/git_repo > /tmp/zentao.log 2>&1
其中"/data/git_repo"为存放git仓库的根目录,所有独立的git仓库都存放到该目录下,打印信息的出错信息都重定向到了" /tmp/zentao.log"文件中,便于分析解决问题。
二、其他补充说明
1.安装高版本的svn客户端
可参照下面的链接进行操作:
https://blog.csdn.net/u013948858/article/details/107187411/
随着svn版本迭代,后续有更新的版本时,可进入下面的链接,根据自己的实际情况对上述文档中的baseurl参数中的svn版本(svn-1.10)进行调整。
http://opensource.wandisco.com/centos/7/
2.安装高版本的git客户端
可参照下面的链接进行操作:
https://www.jianshu.com/p/fae802f50315
具体操作时,可下载最新稳定版再相应进行操作。