0.定义
1.安装git
[test@localhost ~]$ sudo yum install git
检查git是否安装正确
[test@localhost ~]$ git --version git version 1.7.1
2.为git服务器创建专有用户
[test@localhost ~]$ sudo useradd git -d /home/git
[test@localhost ~]$ su - git
3.安装gitolite
[test@localhost ~]$ sudo yum install ssh [test@localhost ~]$ sudo service sshd start [test@localhost ~]$ sudo chkconfig sshd on
然后准备安装gitolite,git服务器的管理员需要先准备自己的密钥对。所以,假设这个管理员在自己的workstation(另一台linux主机,这里只是为了得到管理员自己的密钥,并非一定要在另一台linux机器上)上,他需要创建自己的密钥对(方便起见,不要输入passphrase):
[user@ubuntu ~]$ ssh-keygen -f ~/.ssh/admin
该命令在~/.ssh目录下创建密钥对admin和admin.pub。
[git@localhost ~]$ git clone git://github.com/sitaramc/gitolite [git@localhost ~]$ mkdir -p ~/bin [git@localhost ~]$ gitolite/install -to ~/bin [git@localhost ~]$ gitolite setup -pk admin.pub
如果在执行第三条命令时出现错误:
Can't locate Time/HiRes.pm in @INC (@INC contains: /home/git/gitolite/src/lib /usr/local/lib/perl5 /usr/local/share/perl5 /usr/lib/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib/perl5 /usr/share/perl5 .) at /home/git/gitolite/src/lib/Gitolite/Common.pm
line 76.
BEGIN failed--compilation aborted at /home/git/gitolite/src/lib/Gitolite/Common.pm line 76.
Compilation failed in require at gitolite/install line 15.
BEGIN failed--compilation aborted at gitolite/install line 15.
说明缺少perl需要的软件Time::HiRes,安装该软件包后,重新执行上面的命令:
[test@localhost ~]$ sudo yum install perl-Time-HiRes
4.添加用户
[user@ubuntu ~]$ git clone git@the_git_host:gitolite-admin
注意,执行该命令时,如果被要求输入密码,说明前面某些配置出错了,需要重新查证后再继续。
repo foo RW+ = jason R = @all
[user@ubuntu ~]$ git add conf [user@ubuntu ~]$ git add keydir [user@ubuntu ~]$ git commit -m 'added foo, gave access to jason' [user@ubuntu ~]$ git push
5.用户执行git版本管理
[jason@linux ~]$ git clone git@the_git_host:foo
命令执行完成,创建一个空库foo,现在jason就可以进行版本管理,在需要的时候进行提交。
[jason@linux ~]$ ssh git@the_git_host info
[git@localhost ~]$ ls -a | grep gitolite | xargs rm -fr [git@localhost ~]$ rm -fr ~/repositories ~/bin ~/projects.list ~/.ssh/authorized_keys
6.配置gitweb
[test@localhost ~]$ sudo yum install gitweb
打开/etc/gitweb.conf文件,按照注释的格式添加projectroot变量,指向git库:
our $projectroot = "/home/git/repositories"; our @git_base_url_list = qw(git://git.the_git_host ssh://git.the_git_host/var/lib/git);
最后编辑apache服务器配置文件/etc/httpd/conf/httpd.conf,在文末添加:
<VirtualHost *:80> ServerName the_git_host DocumentRoot /var/www/git <Directory /var/www/git> Options ExecCGI +FollowSymLinks +SymLinksIfOwnerMatch AllowOverride All order allow,deny Allow from all AddHandler cgi-script cgi DirectoryIndex gitweb.cgi </Directory> </VirtualHost>
最后修改git库的权限,否则会出现404 no projects found错误,最后重启Apache服务器:
[test@localhost ~]$ sudo chmod 775 /home/git/repositories [test@localhost ~]$ sudo chmod 775 /home/git [test@localhost ~]$ sudo apachectl restart
最后在浏览器里键入http://the_git_host就可以看到git库了,我在本机测试,使用的是http://localhost
注:如果在完成上述操作后,仍然显示404 no project found,那很可能又是SELinux惹的麻烦,尝试更改selinux的状态为permissive后再刷新页面试试:
[test@localhost ~]$ sudo setenforce 0
7.参考文献