CentOS git 服务器搭建
1. 环境部署
系统环境:
服务器端:CentOS 6.5 ip: 192.168.0.74
2. 安装
2.1 服务器端:
yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel
vi /etc/yum.repos.d/epel.repo
-----------------------------------------------------------------------------------------------------
[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-6&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
[epel-debuginfo]
name=Extra Packages for Enterprise Linux 6 - $basearch - Debug
#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch/debug
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-debug-6&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
gpgcheck=1
[epel-source]
name=Extra Packages for Enterprise Linux 6 - $basearch - Source
#baseurl=http://download.fedoraproject.org/pub/epel/6/SRPMS
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-source-6&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
gpgcheck=1
-----------------------------------------------------------------------------------------------------
yum -y install git git-daemon
查看版本号:git --version
3. 安装gitosis
gitosis 是Git用户权限管理系统, 通过管理服务端的/opt/git/.ssh/authorized_key 文件来执行对用户权限的管理
yum install python python-setuptools
git clone git://github.com/res0nat0r/gitosis.git
cd gitosis/
python setup.py install
(Finished processing dependencies for gitosis==0.2 表示安装完成)
3.1 创建个人公钥和私钥(用于后面的git服务的管理员管理)
ssh-keygen -t rsa
3.2 创建git服务器管理用户
useradd -m git
passwd git
3.3 创建git仓库存储目录
mkdir /opt/git
3.4 设置git仓库权限
chown git:git /opt/git
chmod 755 /opt/git/
3.5 初始化全局设置
git config --global user.name "zhu.zhihuan"
git config --global user.email "[email protected]"
3.6 配置gitosis
cp ~/.ssh/id_rsa.pub /tmp
sudo -H -u git gitosis-init < /tmp/id_rsa.pub //将该公匙导入gitosis里,本机才有git的管理权限
chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update
cat /tmp/id_rsa.pub >> /home/git/.ssh/authorized_keys //将root的公匙导入到git目录
chmod 600 /home/git/.ssh/authorized_keys
3.7 管理gitosis配置
git clone [email protected]:/gitosis-admin.git (hostname 为本机的)
Receiving objects: 100% (5/5), done ( 登录成功)
cd gitosis-admin/ (gitosis.conf是git仓库与权限配文件,keydir目录是存放其它客户机的公匙目录)
4. 添加 - 其他用户 ( Linux )
将其他用户的 自已的公匙 上传到 git 服务器中
将 用户公钥存放在 /root/gitosis-admin/keydir 目录中
4.1 将用户公钥导入 git 目录 ( home/git )
cat /root/gitosis-admin/keydir/jicki.pub >> /home/git/.ssh/authorized_keys
4.2 编辑 gitosis.conf 文件
----------------------------------------------------------------------
[gitosis]
[group gitosis-admin]
writable = gitosis-admin
members = [email protected]
#加一个名为 yumwei 的组
[group yumwei]
members = jicki #这里的jicki对上面公匙文件名
writable = yumwei #项目仓库名
------------------------------------------------------------------------
4.3 提交到版本库
git add /root/gitosis-admin/keydir/jicki.pub
git commit -a -m "Allow jicki write access to yunwei"
git push origin master
这时jicki便有权限操作yunwei仓库了,回到用户机上
cd ~
mkdir /opt/yunwei
cd /opt/yunwei
echo "test " > test.txt
git init //初始化本地版本
git remote add origin [email protected]:yunwei.git //加到远程版本库中
git add .
git commit -a -m "哈哈哈,测试一下"
git push origin master
[测试是否已经提交到服务器库中] 在其他目录 clone回来
cd /tmp
git clone [email protected]:yunwei.git