git-daemon 服務的客戶端無法clone遠程庫

Q:

    //報錯
    git clone git://192.168.221.141/prometheus.git
    [root@puppet2 local]# git clone git://192.168.221.141/proheus.git
    Initialized empty Git repository in /usr/local/prometheusit/
    fatal: The remote end hung up unexpectedly

A:

  1. 檢查iptables和SELinux ,確認服務器和客戶端都沒有問題。
  2. 檢查git-daemon端git庫是否設置正確, 命令是git init –bare 正確後應該有以下文件:
    [root@puppet1 prometheus.git]# ls
    branches  description  hooks  objects
    config    HEAD         info   refs

進入配置文件,檢查是否打開receivepack = true

    [root@puppet1 prometheus.git]# vim config
    1 [core]
      2         repositoryformatversion = 0
      3         filemode = true
      4         bare = true
      5 [daemon]
      6         receivepack = true
    ~                                

3.殺掉git-daemon服務,重新啓動。
4.重新clone之前成功的Nginx庫,失敗,報同樣的錯誤。得出結論,並不是git庫出了問題,而是git-daemon服務本身出了問題。
5.查找錯誤日誌,位於/var/log/messages 中,顯示:

    Jun 16 17:59:53 puppet1 git-daemon[1649]: Connection from 192.168
    .221.140:50628
    Jun 16 17:59:53 puppet1 git-daemon[1649]: Extended attributes (22
     bytes) exist <host=192.168.221.141>
    Jun 16 17:59:53 puppet1 git-daemon[1649]: Request upload-pack for
     '/prome.git'
    Jun 16 17:59:53 puppet1 git-daemon[1649]: '/data/git/repo/prome.g
    it': not in whitelist
    Jun 16 17:59:53 puppet1 git-daemon[1641]: [1649] Disconnected (wi
    th error)

並不知道白名單是什麼······也沒設置過。

6.再次kill掉git-daemon,重新啓動,發現突然成功了

    [root@puppet2 local]# git clone git://192.168.221.141/prometheus.git
    Initialized empty Git repository in /usr/local/prometheus/.git/
    warning: You appear to have cloned an empty repository.

懷疑是不是啓動程序時的配置項有問題,將兩次配置項對比

    git daemon --detach --verbose --export-all --base-path=/data/git/repo/ --reuseaddr --enable=receive-pack /data/git/repo/
    git daemon --detach --verbose --export-all --base-path=/data/git/repo --reuseaddr --enable=receive-pack /data/git/repo/

仔細對比發現路徑寫法稍有不同

    --base-path=/data/git/repo          //錯誤情況下
    --base-path=/data/git/repo/         //正確情況下

測試,兩種不同的寫法,發現確實是因爲–base-path=/data/git/repo 不行,再次進行測試是否是因爲,同一個配置中前後兩個路徑不一致的原因,將配置改爲:

    [root@puppet1 prome.git]# git daemon --detach --verbose --expoall --base-path=/data/git/repo --reuseaddr --enable=receive-pa/data/git/repo

發現也可以成功!

總結:
在進行git-daemon啓動時命令中有兩次設置路徑,一定要保持兩次一致,若寫repo就都寫repo,如果寫repo/就都寫repo/,如果不一樣就會報錯,拉取失敗。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章