天天看點

禅道開源版本12.4.3配置代碼關聯功能總結禅道開源版本12.4.3配置代碼關聯功能總結一、遇到的問題及相應解決方案二、其他補充說明

禅道開源版本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
           

解決方案:

  1. root帳号下,建立一個zentao帳号;
  2. 用zentao帳号登入系統,執行"svn ls svn" (報錯沒關系,已經生成了.subversion);
  3. 執行"chmod -R 755 /home/zentao";
  4. 禅道配置svn用戶端時,填寫"/usr/bin/svn --config-dir /home/zentao/.subversion"。

2.禅道配置svn用戶端報錯

報錯資訊如下圖所示:

禅道開源版本12.4.3配置代碼關聯功能總結禅道開源版本12.4.3配置代碼關聯功能總結一、遇到的問題及相應解決方案二、其他補充說明

解決方案:

  1. 将檔案"/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'
           

解決方案:

  1. 在禅道服務部署本機登入資料庫:/opt/zbox/bin/mysql -u root -P mysql端口 -p (比如:/opt/zbox/bin/mysql -u root -P 3306 -p)
  2. 依次運作下面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分鐘執行一次。下面直接描述操作步驟。

  1. 安裝python3運作環境,具體可參考下面這個連結,python版本可去官網下載下傳相對較新版本:

    https://blog.csdn.net/yycoolsam/article/details/90938851

  2. 先運作

    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)
           
  1. 在系統檔案"/etc/profile"中增加python運作環境變量,具體增加内容如下:
export PYTHONPATH=/home/zentao/python/credittools
           
  1. 将下面的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
           
  1. 使用

    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

具體操作時,可下載下傳最新穩定版再相應進行操作。