搭建本地Git服务器(rhel+git+gitosis)
1、搭建环境:linux版本:rhel6.5
git版本:git-1.7.12.4
服务端主机名及ip:server.example.com 192.168.1.193
开发机主机名及ip:develope.example.com 192.168.1.191
2、服务器端安装git
[*] # yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel
[*] 下载git-1.7.12.4.tar.gz安装包(git1.7.12.4.tar.gz下载地址),然后将其mv 到/usr/local/src目录。
[*] # cd /usr/local/src/
[*] # tar -xvzf git-1.7.12.4.tar.gz
[*] # cd git-1.7.12.4
[*] # make prefix=/usr/local/git all
[*] # make prefix=/usr/local/git install
[*] 增加软链接
# ln -s /usr/local/git/bin/* /usr/bin/
[*] # git version//有输出结果表示安装成功
git version 1.7.1
3、在服务器安装gitosis
[*] # yum install python python-setuptools -y
[*] # cd /usr/local/src/
[*] # git clone git://github.com/res0nat0r/gitosis.git
[*] # cd gitosis
[*] # python setup.py install //显示Finished processing dependencies for gitosis==0.2表示安装成功
4、在开发机上生产密钥,并上传到服务器
[*] # ssh-keygen -t rsa //一直点下一步,不用设置密码
[*] 上传公钥到服务器
# scp ~/.ssh/id_rsa.pub root@192.168.1.193:/tmp/
或者
# vim /etc/hosts
192.168.1.193server93 //加入该行
# scp ~/.ssh/id_rsa.pub root@server93:/tmp/
[*] 登录到git服务器
# ls /tmp/id_rsa.pub //显示上传的公钥
5、在服务器上生成git用户,使用git用户并初始化gitosis
[*] 创建git版本管理用户 git
# useradd -c 'git version manage' -m -d /home/git -s /bin/bash git // -m 参数表示创建用户主目录即使不存在。假如在/etc/login.defs中的CREATE_HOME被设置为no那么只输入useradd将不能创建用户主目录。这种情况下可以使用 -m
[*] 更改git用户密码
# passwd git
[*] 切换到git用户
# su - git
[*] $ 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/
[*] 删除存储的密钥
$ rm -f /tmp/id_rsa.pub
6、在个人开发机上导出服务器的项目管理
[*] # mkdir -p /repo/
[*] # cd /repo/
[*] # git clone git@server93:gitosis-admin.git
7、在个人开发机增加及设置项目管理
[*] # cd /repo/gitosis-admin
[*] 查看用户上传的密钥
# ls /keydir
root@develope.example.com.pub //表示已经上传的开发机生成的公钥
[*] # cat keydir/root@develope.example.com.pub
//显示密钥 最后的字符串为 密钥用户名 这里为 root@develope.example.com.pub
[*] # vim gitosis.conf
//具有写权限的组名称
writable = test-git //该组可写的项目名称
members = root@develope.example.com.pub //该组的成员(密钥用户名),多个用户协同开发时,以空格分隔
如果要增加只读的组 参考如下
//具有读权限的组名称
readonly = test-git //该组只读的项目名称
members = root@develope.example.com //该组的成员
[*] 提交修改
# git add gitosis.conf
# git commit -m "add test-git repo"
# git push
8、在个人开发机上初始,增加及使用项目test-git
[*] # cd ~/repo
[*] # mkdir test-git
[*] # cd test-git
[*] # git init
[*] # touch readme.txt
[*] # git add readme.txt
[*] # git commit -m "init test-git"
[*] # git remote add origin git@server93:test-git.git
[*] # git push -u origin master
9、增加协同开发者的公钥key到git服务器
[*] # cd /repo/gitosis-admin/keydir //开发机上
[*]
把协同开发者的>
[*] 然后将添加数据后的目录更新到git服务器上
# git add .
# git commit -m "add root@develop1.example.com.pub file"
# git push origin master
页:
[1]