Hi!请登陆

Centos6.8搭建Git服务(git版本可选)

2020-10-27 65 10/27

搭建Git服务器需要准备一台运行Linux的机器,本文以Centos6.8纯净版系统为例搭建自己的Git服务.
准备工作:以root用户登陆自己的Linux服务器.

第一步安装依赖库:

$ yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
$ yum install  gcc perl-ExtUtils-MakeMaker

第二步卸载旧版git:

加入原先有用yum安装过git,则需要先卸载一下:

$ yum remove git

第三步下载源码:

下载git-2.10.0.tar.gz到/usr/local/src.
(查找git版本可以到https://www.kernel.org/pub/software/scm/git/ 下查看git的版本号自行选择下载)

查看版本方法:

$ wget -v https://www.kernel.org/pub/software/scm/git/
$ vi index.html

复制想下载的版本 --> Esc --> :q! --> 回车!
这里我选择下载git-2.10.0.tar.gz

$ cd /usr/local/src
$ wget https://www.kernel.org/pub/software/scm/git/git-2.10.0.tar.gz

第四步解压、编译和安装:

$ tar -zvxf git-2.10.0.tar.gz
$ cd git-2.10.0
$ make prefix=/usr/local/git all
$ 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:

$ cd /usr/local/src
$ wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
$ tar -zxvf libiconv-1.14.tar.gz
$ cd libiconv-1.14
$ ./configure --prefix=/usr/local/libiconv  &&  make  && make install

二.创建一个软链接到/usr/lib:

$ ln -s /usr/local/lib/libiconv.so /usr/lib
$ ln -s /usr/local/lib/libiconv.so.2 /usr/lib

三.然后回到git目录继续编译:

$ cd /usr/local/scr/git-2.8.3
$ make configure
$ ./configure --prefix=/usr/local/git --with-iconv=/usr/local/libiconv
$ make
$ make install

第五步将git目录加入PATH:

$ echo 'export PATH=$PATH:/usr/local/git/bin' >> /etc/bashrc
$ source /etc/bashrc

安装成功后就可以查看到git版本了.

$ git --version
git version 2.10.0

第六步创建git账号并设置密码:

$ useradd -m git
$ passwd git
Changing password for user git.
New password:
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.

第七步创建git仓库并初始化:

$ mkdir -p /home/git/repositories/test.git
$ 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所在目录.

$ whereis git-shell
git-shell: /usr/src/git-2.10.0/git-shell

编辑passwd文件:

$ 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! -->  回车!

完成搭建,去克隆提交试试吧!

clone地址:

ssh://git@服务器ip地址:端口/home/git/repositories/test.git

附加:以后每次新建仓库时,只需执行上面第七、八步即可!

Tag:

相关推荐