搭建git伺服器需要準備一台執行linux的機器,本文以centos6.4版系統為例搭建自己的git服務。
準備工作:以root使用者登陸自己的linux伺服器。
part1:安裝依賴庫
part2:解除安裝舊版git[root@localhost ~]# yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
[root@localhost ~]# yum install gcc perl-extutils-makemaker
加入原先有用yum安裝過git,則需要先解除安裝一下
[root@localhost ~]# yum remove git
檢視版本方法:
[root@izbp1ap7v4yegqdgzrh7cuz ~]# wget -v
[root@izbp1ap7v4yegqdgzrh7cuz ~]# vi index.html
part4:解壓、編譯和安裝[root@localhost ~]# cd /usr/local/src
[root@localhost ~]# wget git-2.10.0.tar.gz
複製**
複製**[root@localhost ~]# tar -zvxf git-2.10.0.tar.gz
cd /usr/local/src/
wget
tar -zxvf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv && make && sudo make install
cd /usr/local/src/git-2.10.0
make configure
./configure --prefix=/usr/local/git --with-iconv=/usr/local/libiconv
make
make install
part5:將git目錄加入path
安裝成功後就可以檢視到git版本了。[root@localhost ~]# echo 'export path=$path:/usr/local/git/bin' >> /etc/bashrc
[root@localhost ~]# source /etc/bashrc
part6:建立git賬號並設定密碼[root@localhost ~]# git --version
git version 2.10.0
複製**
複製**[root@localhost ~]# useradd -m git
[root@localhost ~]# passwd git
changing password for user git.
new password:
bad password: is too ******
retype new password:
passwd: all authentication tokens updated successfully.
part7:建立git倉庫並初始化
part8:給git倉庫目錄設定使用者和使用者組並設定許可權[root@localhost ~]# mkdir -p /home/git/repositories/test.git
[root@localhost ~]# cd /home/git/repositories/test.git
[root@localhost test.git]# git --bare init
initialized empty git repository in /home/git/repositories/test.git/
如何改變目錄的使用者和使用者組[root@localhost test.git]# chown -r git:git /home/git/repositories
[root@localhost test.git]# chmod 755 /home/git/repositories
改變所屬群組:chgrp 這個指令就是change group的縮寫。不過要記住,要被改變的群組名稱必須要在/etc/group檔案內存在才行,否則就會顯示錯誤。
view code
part9:限制git賬號的ssh連線
查詢git-shell所在目錄
編輯passwd檔案[root@localhost ~]# whereis git-shell
git-shell: /usr/src/git-2.10.0/git-shell
[root@localhost ~]# vi /etc/passwd
找到這一行
git:x:500:500::/home/git:/bin/bash
將最後的/bin/bash改為:git-shell的目錄 /usr/src/git-2.10.0/git-shell 如下:
git:x:500:500::/home/git:/usr/src/git-2.10.0/git-shell
esc --> :wq! --> 回車!
完成搭建,去轉殖提交試試吧!
附加:以後每次新建倉庫時,只需執行上面part7、8即可!
part10:後續
配置git 使用者和使用者郵箱
移動專案**git config --global user.name ""
git config --global user.email ""
cp -r 專案備份目錄/. 專案目錄
設定專案使用者和使用者組
chown -r git:git 專案目錄
提交專案到裸倉庫
使用鉤子自動執行shell指令碼進行同步專案**git add .
git commit -m "init"
git push origin master
配置免秘鑰登入cd 裸倉庫目錄/hooks
vi post-receive
#!/bin/sh
cd 專案目錄
unset git_dir
git pull origin master
遠端伺服器設定
修改/etc/ssh/sshd_config
啟用這三行,然後重啟service sshd restartrsaauthentication yes
pubkeyauthentication yes
authorizedkeysfile /root/.ssh/authorized_keys
設定.ssh目錄許可權
chmod 700 -r .ssh
本地設定
本地安裝git bash
本地生成ssh秘鑰
伺服器端認證cd ~/.ssh
ssh-keygen -t rsa -c 「739***xx@qq.com」
vi ~/.ssh/config
host ***
hostname ***.***.***.***
port 22
user git
preferredauthentications publickey
identityfile ~/.ssh/id_rsa
vi /root/.ssh/authorized_keys
貼上本地生成的秘鑰如id_rsa.pub
獲取遠端專案
git clone ssh:
出現
fatal: could not read from remote repository.錯誤
解決辦法,修改sshd_config
authorizedkeysfile /home/git/.ssh/authorized_keys
修改/home/git 700
設定後成功獲取遠端裸版本庫/home/git/.ssh 700
/home/git/.ssh/authorized_keys 644
/root/.ssh/id_rsa 600
/root/.ssh 700
git clone ssh:
Centos6 4系統檔案服務之NFS
1.檢視nfs軟體是否安裝和啟動服務 root localhost rpm aq egrep nfs rpcbind rpcbind 0.2.0 11.el6.i686 nfs utils 1.2.3 36.el6.i686 nfs utils lib 1.1.5 6.el6.i686 root l...
如何開啟Centos6 4系統的SSH服務
無論是centos6.4系統的虛擬電腦還是伺服器,始終感覺直接在命令列中操作不方便 比如全選 複製 貼上 翻頁等等。比如伺服器就需要在機房給伺服器接上顯示器 鍵盤才操作感覺更麻煩。所以就可借助ssh 安全外殼協議 遠端操作和管理系統,不僅方便而且安全可靠。1 登入centos6.4系統。示例 使用r...
centos搭建git服務
上一章節中我們遠端倉庫使用了 github,github 公開的專案是免費的,但是如果你不想讓其他人看到你的專案就需要收費。這時我們就需要自己搭建一台git伺服器作為私有倉庫使用。接下來我們將以 centos 為例搭建 git 伺服器。yum install curl devel expat dev...