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

卸载旧版Git

[root@localhost ~]# yum remove git

安装依赖库

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

下载安装libiconv

[root@localhost ~]# cd /src
[root@localhost ~]# wget https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.15.tar.gz
[root@localhost ~]# tar -zxvf libiconv-1.15.tar.gz
[root@localhost ~]# cd libiconv-1.15
[root@localhost ~]# ./configure --prefix=/usr/local/libiconv  &&  make  && make install

下载安装Git

[root@localhost ~]# cd /src
[root@localhost ~]# wget https://www.kernel.org/pub/software/scm/git/git-2.10.0.tar.gz
[root@localhost ~]# tar -zxvf git-2.10.0.tar.gz
[root@localhost ~]# cd git-2.10.0
[root@localhost ~]# ./configure --prefix=/usr/local/git --with-iconv=/usr/local/libiconv
[root@localhost ~]# make && make install

检查版本号

[root@localhost ~]# git --version

创建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 /data/git/test.git
[root@localhost ~]# cd /data/git/test.git
[root@localhost test.git]# git --bare init
Initialized empty Git repository in /home/git/test.git/

给git仓库目录设置用户和用户组并设置权限

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

限制git账号的ssh连接

[root@localhost ~]# vi /etc/passwd

找到 git:x:500:500::/home/git:/bin/bash  这一行
将最后的/bin/bash改为:git-shell的目录 /usr/local/git/bin/git-shell  如下:

git:x:500:500::/home/git://usr/local/git/bin/git-shell

配置git 用户和用户邮箱

git config --global user.name "你的名字"

git config --global user.email "你的邮箱地址"

设置项目用户和用户组

chown -R git:git 项目目录

挂钩子,自动执行shell脚本同步项目代码

cd 裸仓库目录/hooks 如:
cd /data/git/test.git/hooks

创建脚本
vim post-receive

写入下面脚本代码:

#!/bin/sh

cd 项目目录

unset GIT_DIR

git pull origin master

分配执行权限

chmod +x post-receive

 配置免秘钥登录

vim /etc/ssh/sshd_config 

将下面三行:
    # RSAAuthentication yes
    # PubkeyAuthentication yes
    # AuthorizedKeysFile /root/.ssh/authorized_keys 
的注释打开(去掉前面的"#"),如下:
    RSAAuthentication yes
    PubkeyAuthentication yes
    AuthorizedKeysFile /root/.ssh/authorized_keys 

保存退出,然后重启:service sshd restart
最后设置.ssh目录权限:chmod 700 -R .ssh

本地生成ssh秘钥

本地安装git bash,然后打开

在git bash 里输入下面代码,一路回车即可

ssh-keygen -t rsa -C “你的邮箱地址”

服务器端认证

本地生成秘钥后,在C:\Users\你电脑当前用户名\.ssh下可以看到生成的三个文件

在服务端打开 : vim /root/.ssh/authorized_keys

将本地生成的秘钥粘贴上去  ( id_rsa.pub 里的内容)

获取远程项目

git clone ssh://git@xxx.xxx.xxx.xxx/xxx/xxx/xxx.git 

 

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值