linux上搭建高版本git伺服器

2021-08-13 10:22:54 字數 3290 閱讀 9840

一般linux系統能直接裝的git版本都很低,為了裝高版本,需要對高版本的git原碼進行編譯,編譯過程中可能會出現很多莫名其妙的錯誤,筆者也是差點死在這些坑上面,痛苦過程中總結了一些經驗,具體如下:

先是git原始碼編譯

安裝

tar -zxf git-2.2.1.tar.gz 

cd git.2.2.1

make prefix=/usr/local/git all

make prefix=/usr/local/git install

原始碼編譯是不如yum install git-all方便,但是版本可以更新點,筆者用的阿里centos6.5,對應的git版本只能到1.7.2

自己裝的git沒有在系統path環境裡,用修改/etc/profile的方法手動貼入

vim /etc/profile

#找到 path=/usr/local/php/bin:$path 這行修改為

path=/usr/local

/php/bin

:/usr/local/git/bin

:$path

#儲存,退出shell重新連線就生效了

git倉庫

groupadd git

useradd git -g git

cd /home/git

mkdir repo.git #名字自定義

cd repo.git

git init --bare #生成裸倉庫,存放除**的版本資訊

chown -r git:git /home/git/repo.git

這裡有一點要注意,網上有為安全考慮,只為git使用者的ssh連線啟用git-shell,原始碼安裝需如下操作

#修改/etc/passwd

vim /etc/passwd

#找到git的使用者設定 如:

git:

x:502

:503

::/home/newbmiao

:/bin/bash

#將最後乙個執行檔案路徑改為

git:

x:502

:503

::/home/git

:/usr/local/git/bin/git-shell

#在安裝包bin目錄下

#要啟用還需原始碼報的git-shell命令互動

cp /usr/local/git-2.2.1/contrib/git-shell-commands /home/git/

#這樣使用者用git賬戶ssh連線後只能使用git命令了

ssh免密碼驗證連線

su git #切換git身份

cd /home/git/

ssh-keygen -c '[email protected]' -t rsa #為你生成rsa金鑰,可以直接一路回車,執行預設操作

客戶端生成密要方式同上。

生成金鑰後,會出現

.ssh

├── id_rsa

└── id_rsa.pub #公鑰 服務端需要裡邊內容驗證連線著身份

在客戶端上,開啟id_rsa.pub複製裡邊內容

vim /home/git/.ssh/authorized_keys

#貼上客戶端生成的公鑰,儲存退出

#然後要啟動sshd和git-daemon

/etc/init.d/git-daemon restart

#上邊git-daemon在安裝目錄下/usr/local/git/libexec/git-core/git-daemon,直接複製過去就行

/etc/init.d/sshd start

這樣服務端的git倉庫就搭好了

客戶端 git開發

在客戶端(筆者的是window的git bash)git操作提交試試

#進入乙個空的工作目錄

git init #初始化git

vim test

#編輯些內容儲存退出

git add test #新增到git快取中

git commit -m 'init test'

#提交修改

#新增遠端git倉庫

git remote add origin git@your_host_name

:/home/git/repo.git

git push origin master #這樣就同步到伺服器了

其他人要同步

#轉殖和推送:

git clone git@your_host_name

:/home/git/repo.git

cd repo

vim readme

git commit -am 'fix for the readme file'

git push origin master

**同步(hook)

上邊git用於做了中心的版本控制

但是還想讓伺服器接到修改更新後自動同步**到**目錄中,便於測試開發

如下操作是可以實現

#假定**目錄在/www/web下

cd /home/git/repo.git/hooks

vim post-receive #建立乙個鉤子

#寫入下面內容

git_work_tree=/www/web git checkout -f

#儲存退出

chown git:git post-receive

chmod +x post-receive

如此,下次提交修改,**會自動同步到指定目錄中

不過開始時筆者還是遇到乙個問題解決不了,就是ssh公鑰交給伺服器,也啟動git-daemonsshd後,客戶端git clone時居然還要密碼,而且輸入密碼後提示permission denied, please try again.

git教程:

在Linux上用Apache搭建Git伺服器

最近在學linux,終於在linux上用apache搭建起了git伺服器,在此記錄一下。伺服器 阿里雲伺服器 linux版本 centos 6.5 apache版本 apache 2.2.15 git版本 git 1.7.1 git訪問方式 基於http的基本驗證 非ssl apache的安裝 1....

在Linux上用Apache搭建Git伺服器

最近在學linux,終於在linux上用apache搭建起了git伺服器,在此記錄一下。伺服器 阿里雲伺服器 linux版本 centos 6.5 apache版本 apache 2.2.15 git版本 git 1.7.1 git訪問方式 基於http的基本驗證 非ssl apache的安裝 1....

在Linux上用Apache搭建Git伺服器

最近在學linux,終於在linux上用apache搭建起了git伺服器,在此記錄一下。伺服器 阿里雲伺服器 linux版本 centos 6.5 apache版本 apache 2.2.15 git版本 git 1.7.1 git訪問方式 基於http的基本驗證 非ssl apache的安裝 1....