linux 部署git版本庫


准備工作:以root用戶登陸自己的Linux服務器。

第一步安裝依賴庫

[root@localhost ~]# yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
[root@localhost ~]# yum install  gcc perl-ExtUtils-MakeMaker

第二步卸載舊版git

加入原先有用yum安裝過git,則需要先卸載一下

[root@localhost ~]# yum remove git

第三步下載源碼

下載git-2.10.0.tar.gz 到 /usr/local/src

(查找git版本可以到https://www.kernel.org/pub/software/scm/git/下查看git的版本號自行選擇下載)

查看版本方法:

[root@iZbp1ap7v4yegqdgzrh7cuZ ~]# wget -v https://www.kernel.org/pub/software/scm/git/

[root@iZbp1ap7v4yegqdgzrh7cuZ ~]# vi index.html

復制想下載的版本 --> Esc --> :q! -->  回車!

這里我選擇下載git-2.10.0.tar.gz

[root@localhost ~]# cd /usr/local/src
[root@localhost ~]# wget https://www.kernel.org/pub/software/scm/git/git-2.10.0.tar.gz

第四步解壓、編譯和安裝

[root@localhost ~]# tar -zvxf git-2.10.0.tar.gz
[root@localhost ~]# cd git-2.10.0
[root@localhost ~]# make prefix=/usr/local/git all
[root@localhost ~]# make prefix=/usr/local/git install

報錯處理:

make prefix=/usr/local/git all編譯的時候出現了錯誤:

 LINK git-credential-store libgit.a(utf8.o): In function `reencode_string_iconv': /usr/src/git-2.8.3/utf8.c:463: undefined reference to `libiconv' libgit.a(utf8.o): In function `reencode_string_len': /usr/src/git-2.8.3/utf8.c:502: undefined reference to `libiconv_open' /usr/src/git-2.8.3/utf8.c:521: undefined reference to `libiconv_close' /usr/src/git-2.8.3/utf8.c:515: undefined reference to `libiconv_open' collect2: ld returned 1 exit status make: *** [git-credential-store] Error 1

 

解決如下:

一.安裝libiconv

1、# cd /usr/local/src 2、# wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz 3、# tar -zxvf libiconv-1.14.tar.gz 4、# cd libiconv-1.14 5、# ./configure --prefix=/usr/local/libiconv && make && make install

二.創建一個軟鏈接到/usr/lib

1、# ln -s /usr/local/lib/libiconv.so /usr/lib 2、# ln -s /usr/local/lib/libiconv.so.2 /usr/lib

三.然后回到git目錄繼續編譯

1、# cd /usr/local/scr/git-2.10.0 2、# make configure 3、# ./configure --prefix=/usr/local --with-iconv=/usr/local/libiconv 4、# make 5、# make install

 

第五步將git目錄加入PATH

[root@localhost ~]# echo 'export PATH=$PATH:/usr/local/git/bin' >> /etc/bashrc [root@localhost ~]# source /etc/bashrc

安裝成功后就可以查看到git版本了。

[root@localhost ~]# git --version
git version 2.10.0

第六步創建git賬號並設置密碼

復制代碼
[root@localhost ~]# useradd -m git
[root@localhost ~]# passwd git                 
Changing password for user git.
New password: 
BAD PASSWORD: is too simple
Retype new password: 
passwd: all authentication tokens updated successfully.
復制代碼

第七步創建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/

第八步給git倉庫目錄設置用戶和用戶組並設置權限

[root@localhost test.git]# chown -R git:git /home/git/repositories
[root@localhost test.git]# chmod 755 /home/git/repositories

第九步限制git賬號的ssh連接

查找git-shell所在目錄

[root@localhost ~]# whereis git-shell
git-shell: /usr/src/git-2.10.0/git-shell

編輯passwd文件

[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! -->  回車!
完成搭建,去克隆提交試試吧!

 

拉取項目報錯:

[root@iZ2ze5zuc8m9608lrl3u3jZ test]# git clone git@gitee.com:wuyajing168/test.git
Cloning into 'test'...
Permission denied (publickey).
fatal: Could not read from remote repository.

 

解決辦法:(在服務器上操作)

生成 sshkey:

ssh-keygen -t rsa -C "xxxxx@xxxxx.com"

# Generating public/private rsa key pair...

# 三次回車即可生成 ssh key

 

 

#查看你的 public key,並把他添加到碼雲(Gitee.com) SSH key添加地址

 

cat ~/.ssh/id_rsa.pub # ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC6eNtGpNGwstc....


#添加后,在終端(Terminal)中輸入

ssh -T git@gitee.com 

#若返回

#Welcome to Gitee.com, yourname! 

#則證明添加成功。

 

 

clone地址: git ssh地址

 

附加:以后每次新建倉庫時,只需執行上面第七、八步即可!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM