基于CentOS 6.8的Git服务器的搭建

基于CentOS 6.8的Git服务器的搭建 VM虚拟机或是直接安装 CentOS6.8,选择开发者选项,尽量全部选择安装的软件包。 一:SSH服务器sshd已经安装了。 二:Git客户端已经安装了。 三:Git管理需要重新安装与启动:gitosis 四:新建用户并初始化Git版本仓库。 需要的工具:ssh python python-tools git gitosis 客户端: (1)ssh-keygen.exe -t rsa (2)scp.exe /c/Users/fsmd/.ssh/id_rsa.pub root@10.103.3.167:~/ 问题与思考: (1)多少Git用户,就需要建立多少个Linux用户吗? (2)用户自己建立版本仓库。上传KEY? (3)多用户的使用问题:需要组group管理? 目前CentOS6.8上已经成功搭建了个人版本的Git服务器,目前流程基本上清楚了,但是,还没有熟悉。 最好继续测试与验证。掌握最直接的方法。最好备份,可以不断的尝试。 一:安装CentOS6.8。 这里使用VM安装。 CentOS-6.8-x86_64-bin-DVD1.iso 120G硬盘。 开发者模式安装,这里选择认的软件包,ssh git python 等已经安装。 如果没有认安装,需要自己重新安装即可。 二:安装与配置gitosis 使用管理员账号安装,这里还需要python与支持python tools 安装。 三:新建git的用户与配置密码。 这里是否需要sudo的加入呢?还是普通用户即可。 四:用户生成自己的ssh-keygen,用于管理自己的git仓库。 目录的访问权限的问题:sudo还是直接管理员创建。chmod一下? 五:测试与验证。 git clone git add . git commmit -a git push origin master 目前已经安装完成了,安装一下VM tools,这是方便文件文字的复制与粘贴。 (1)查看一下VM虚拟机CentOS 6.8 服务器的IP地址。 [fsmd@localhost Desktop]$ ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:72:56:3A inet addr:10.103.3.113 Bcast:10.103.3.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe72:563a/64 Scope link UP broADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:247 errors:0 dropped:0 overruns:0 frame:0 TX packets:33 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:26785 (26.1 KiB) TX bytes:3766 (3.6 KiB) (2)查看一下服务器上的Git是否安装。 [fsmd@localhost Desktop]$ git --version git version 1.7.1 (3)查看一下服务器上的python是否安装 [fsmd@localhost Desktop]$ python Python 2.6.6 (r266:84292,Jul 23 2015,15:22:56) [GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux2 Type "help","copyright","credits" or "license" for more information. >>> exit() [fsmd@localhost Desktop]$ (4)查看一下服务器的sshd服务是否安装与启动。 [fsmd@localhost Desktop]$ /etc/init.d/sshd status /etc/init.d/sshd: line 33: /etc/sysconfig/sshd: Permission denied openssh-daemon (pid 2668) is running... 以上是基于CenOS6.8搭建Git服务器需要的。另外,还需要下载Gitosis用于管理Git。 (5)安装gitosis。这里使用管理员root账号直接安装。 [root@localhost Git]# unzip gitosis-master.zip [root@localhost Git]# ls gitosis-master gitosis-master.zip [root@localhost Git]# cd gitosis-master [root@localhost gitosis-master]# ls copYING example.conf lighttpd-gitweb.conf README.rst debian gitosis MANIFEST.in setup.py etc-event.d-local-git-daemon gitweb.conf mirror.conf Todo.rst [root@localhost gitosis-master]# python setup.py install (6)新建git用户: [root@localhost Desktop]# useradd -r -s /bin/sh -c 'git version control' -d /home/git git [root@localhost Desktop]# mkdir -p /home/git [root@localhost Desktop]# chown git:git /home/git [root@localhost Desktop]# ll /home/ total 24 drwx------. 27 fsmd fsmd 4096 Jan 16 22:14 fsmd drwxr-xr-x. 2 git git 4096 Jan 16 22:34 git drwx------. 2 root root 16384 Jan 16 21:25 lost+found 设置一下git用户的密码: [root@localhost Desktop]# passwd git Changing password for user git. New password: Retype new password: passwd: all authentication tokens updated successfully. (7)客户端:这里是win7 64bit ,安装git。 生成密钥并上传到服务器: $ ssh-keygen.exe -t rsa $ scp.exe /c/Users/fsmd/.ssh/id_rsa.pub git@10.103.3.113:~/ The authenticity of host '10.103.3.113 (10.103.3.113)' can't be established. RSA key fingerprint is SHA256:Sz6gE9OZjW2Eshtvfn2nZRzqBHElb6g5Q5lXh7Z1GLo. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '10.103.3.113' (RSA) to the list of kNown hosts. git@10.103.3.113's password: id_rsa.pub 100% 398 8.4KB/s 00:00 (8)服务端生成管理库(这里用git用户操作,而不是管理员) [root@localhost repositories]# chmod u+w /etc/sudoers [root@localhost repositories]# vi /etc/sudoers [root@localhost repositories]# chmod u-w /etc/sudoers [root@localhost repositories]# 这里使用git用户登录,然后生成仓库试一下效果!!! [root@localhost Desktop]# sudo -H -u git gitosis-init < /home/git/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/ [root@localhost Desktop]# chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update (9)客户端测试与验证: $ git clone git@10.103.3.113:/home/git/repositories/gitosis-admin.git 注意:这里需要IP与完整的路径!!! 如果成功了,可以新建Git版本仓库了!! (10)修改gitosis-admin.git里的配置文件,把新的版本仓库加入: $ cd gitosis-admin/ $ vi gitosis.conf 问题与解决思路: (1)目前单机版的Git服务器已经成功了。 服务器使用命令: 用户登录(这里的用户是git用户)。 mkdir hello.git cd hello.git git init --bare(这里是两个--) (2)客户端先修改gitosis.conf(是否需要修改,目前是添加了成功)。然后 git clone touch hello(新建一个文件用于测试提交) git add . git commit -a git remote add git@10.103.3.113:/home/git/repositories/hello.git(目前是完整的路径) git push origin master (3)$ git clone git@10.103.3.113:/home/git/repositories/servo.git 用的是全路径,如果不是,可能出错!!目前添加其他的正常。但是一个却是错误,看看到底为何呢? (4)继续添加hello4。看一下操作的流程,熟悉与熟练,是不同的。 [服务器用git用户登录,建立版本仓库] sh-4.1$ mkdir hello4.git sh-4.1$ cd hello4.git/ sh-4.1$ ls sh-4.1$ git init --bare Initialized empty Git repository in /home/git/repositories/hello4.git/ sh-4.1$ ls branches config description HEAD hooks info objects refs [客户端直接clone] 配置一下版本仓库与用户。 [group hello4] members = zhangsz@A1102127 writable = hello4 $ git clone git@10.103.3.113:/home/git/repositories/hello4.git cloning into 'hello4'... git@10.103.3.113's password: warning: You appear to have cloned an empty repository. $ touch hello4 $ git add . $ git commit -a $ git push origin master git@10.103.3.113's password: Counting objects: 3,done. Writing objects: 100% (3/3),191 bytes | 0 bytes/s,done. Total 3 (delta 0),reused 0 (delta 0) To 10.103.3.113:/home/git/repositories/hello4.git * [new branch] master -> master 操作成功,原来不难,单机版本已经测试正常,只是,每次提交,需要密码!! 新建servo.git的操作流程: (1)服务器端的操作(这里需要使用git用户身份创建git版本仓库) [root@localhost repositories]# su git sh-4.1$ mkdir servo.git sh-4.1$ cd servo.git/ sh-4.1$ git init --bare Initialized empty Git repository in /home/git/repositories/servo.git/ sh-4.1$ ls branches config description HEAD hooks info objects refs (2)客户端的操作一: gitosis-admin/gitosis.conf 的配置: 添加如下的配置即可。 [group servo] members = zhangsz@A1102127 writable = servo (3)客户端的操作二: $ git clone git@10.103.3.113:/home/git/repositories/servo.git cloning into 'servo'... git@10.103.3.113's password: warning: You appear to have cloned an empty repository. $ ls git-test/ gitosis-admin/ hello/ hello2/ hello4/ servo/ $ cd servo/ $ ls $ touch aa $ git add . $ git commit -a [master (root-commit) 64b2691] aa 1 file changed,0 insertions(+),0 deletions(-) create mode 100644 aa $ git push origin master git@10.103.3.113's password: Counting objects: 3,184 bytes | 0 bytes/s,reused 0 (delta 0) To 10.103.3.113:/home/git/repositories/servo.git * [new branch] master -> master 测试练习:新建s.git (1)服务器端的操作: [root@localhost repositories]# su git sh-4.1$ ls gitosis-admin.git git-test.git hello2.git hello4.git hello.git servo.git sh-4.1$ mkdir s.git sh-4.1$ cd s.git/ sh-4.1$ git init --bare Initialized empty Git repository in /home/git/repositories/s.git/ sh-4.1$ (2)客户端添加配置: [group s] members = zhangsz@A1102127 writable = s (3)客户端操作过程: $ git clone git@10.103.3.113:/home/git/repositories/s.git cloning into 's'... git@10.103.3.113's password: warning: You appear to have cloned an empty repository. $ cd s/ $ ls $ touch aa $ git add . $ git commit -a [master (root-commit) 7412167] aaas5 1 file changed,0 deletions(-) create mode 100644 s5 $ git push origin master git@10.103.3.113's password: Counting objects: 3,187 bytes | 0 bytes/s,reused 0 (delta 0) To 10.103.3.113:/home/git/repositories/s.git * [new branch] master -> master 总结: (1)正确的操作流程,才能提高效率。 Git添加其他用户(可以提交的用户) (2)用户通过ssh-keygen -t rsa生成KEY。如xxx.pub 然后发给管理员管理员添加到gitosis-admin/keydir/目录下。 #git add keydir/xxx.pub #git add . #git commit -a #git push origin master(服务器通过git init --bare初始化后,就有了) (3) git clone时,需要全路径,如IP:/home/git/repositories/servo.git

相关文章

Centos下搭建性能监控Spotlight
CentOS 6.3下Strongswan搭建IPSec VPN
在CentOS6.5上安装Skype与QQ
阿里云基于centos6.5主机VPN配置
CentOS 6.3下配置multipah
CentOS安装、配置APR和tomcat-native