环境:
系统硬件:vmware vsphere (CPU:2*4核,内存2G,双网卡)
系统版本:CentOS-7.0-1406-x86_64-DVD.iso
服务器IP:192.168.1.31 域名:www.domain.com SSH端口:8200(默认为22)
安装步骤:
1.显示服务器版本
[[email protected] ~]# cat /etc/redhat-release
#CentOS Linux release 7.0.1406 (Core)
[[email protected] ~]# uname -a
#Linux tCentos7 3.10.0-123.9.3.el7.x86_64 #1 SMP Thu Nov 6 15:06:03 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
[[email protected] ~]# ipconfig
#服务器IP192.168.1.31
2.安装git
#2.1 下载git-2.2.0.tar.gz 到 /usr/local/src
[[email protected] ~]# cd /usr/local/src
[[email protected] ~]# wget https://www.kernel.org/pub/software/scm/git/git-2.2.0.tar.gz
#2.2 安装依赖的库
[[email protected] ~]# yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel
#2.3 删除原本的安装的git
[[email protected] ~]# yum remove git -y
#2.4 编译安装
[[email protected] ~]# cd /usr/local/src
[[email protected] ~]# tar -zvxf git-2.2.0.tar.gz
[[email protected] ~]# cd git-2.2.0
[[email protected] ~]# make prefix=/usr/local/git all
[[email protected] ~]# make prefix=/usr/local/git install
#2.5 增加软连接
[[email protected] ~]# ln -s /usr/local/git/bin/* /usr/bin/
[[email protected] ~]# git --version
#如何能显示版本号,即表示成功
3.安装gitosis
[[email protected] ~]# yum install python python-setuptools
[[email protected] ~]# cd /usr/local/src
[[email protected] ~]# git clone git://github.com/res0nat0r/gitosis.git
[[email protected] ~]# cd gitosis
[[email protected] ~]# python setup.py install
#显示Finished processing dependencies for gitosis==0.2即表示成功
*******************************************************
4.修改客户端git连接端口(如果GIT服务器为默认SSH端口为22,则不需要以下步骤)
#修改开发机客户端配置文件(可以省略每次输入端口)
[[email protected] ~]# mkdir ~/.ssh
[[email protected] ~]# vim ~/.ssh/config
#打开后,编辑文件,添加以下代码
host www.domain.com
hostname www.domain.com
port 8200
#修改后,开发机客户端即可用以下方式进行连接访问
#git clone ssh://[email protected]/gitosis-admin.git
#否则需要需要加上端口进行访问
#git clone ssh://[email protected]:8200/gitosis-admin.git
*******************************************************
5.在开发机客户端上,生成密钥并上传到服务器上
ssh-keygen -t rsa
#一路回车,不需要设置密码
#从开发机客户端,上传刚生成的公钥到服务器(如果修改端口,按4进行配置指定端口)
scp ~/.ssh/id_rsa.pub [email protected]:/tmp/
#显示已经上传的密钥
[[email protected] ~]# ls /tmp/id_rsa.pub
6.服务器上生成git用户,使用git用户并初始化gitosis
#6.1 增加git用户
[[email protected] ~]# adduser -m git
#6.2切换用户
[[email protected] ~]# su - git
#6.3 服务器的公钥(刚才开发机客户端上传),导入后此开发机客户端即可以管理git服务器。
[[email protected] ~]# gitosis-init < /tmp/id_rsa.pub
#显示以上信息即表示成功
#Initialized empty Git repository in /home/git/repositories/gitosis-admin.git/
#Reinitialized existing Git repository in /home/git/repositories/gitosis-admin.git/
#6.4 删除密钥
[[email protected] ~]# su - root
[[email protected] ~]# rm -rf /tmp/id_rsa.pub
6.在开发机客户端,复制git管理项目(git服务器管理,也是一个git仓库)
mkdir -p /repo
cd /repo
git clone [email protected]:gitosis-admin.git
7.在开发机客户端,增加及设置管理项目
cd /repo/gitosis-admin
#查看已经上传密钥
ls keydir
cat keydir/vicowong\@VICO.pub #[email protected]为已经上传的开发机生成的公密
#显示密钥最后的符串为密钥用户名 这里为[email protected]
vim gitosis.conf
#在文件尾增加以下内容
[group test-git] # 组名称
writable = test-git # 项目名称
members = [email protected] #密钥用户名
#提交修改
git add .
git commit -a -m "add test-git repo"
git push
9.在开发机客户端,初始,增加及使用项目test-git
cd /repo
mkdir test-git
cd test-git
git inti
touch readme
git add .
git commit -a -m "init test-git"
git remote add origin [email protected]:test-git.git
git push origin master