由于 Slackware 默认已经安装好了 git,所以下面我们要做的是安装并配置 gitosis 和 gitweb。
gitosis
~~~~~~~
gitosis 需要通过 python 安装,所以先安装 pysetuptools
tommy@s1:~$ wget http://slackbuilds.org/slackbuilds/13.1/development/pysetuptools.tar.gz
tommy@s1:~$ wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz
tommy@s1:~$ tar xzvf pysetuptools.tar.gz
tommy@s1:~$ mv setuptools-0.6c11.tar.gz pysetuptools
tommy@s1:~$ cd pysetuptools
tommy@s1:~/pysetuptools$ sudo ./pysetuptools.SlackBuild
编译成功后,会得到一个 /tmp/pysetuptools-0.6c11-i486-1_SBo.tgz 安装它
tommy@s1:~$ sudo /sbin/installpkg /tmp/pysetuptools-0.6c11-i486-1_SBo.tgz
下载 gitosis 源码,然后通过 python 进行安装
tommy@s1:~$ git clone git://eagain.net/gitosis
tommy@s1:~$ cd gitosis/
tommy@s1:~/gitosis$ sudo python setup.py install
用下面命令增加一个系统用户,所有的 git 操作都通过这个用户来完成,似乎还需要设置密码,记不清楚了,我在 redhat 下配置是不需要设置密码的。
tommy@s1:~$ sudo /usr/sbin/useradd -d /home/git -c "git" -r -s /bin/bash -m git
现在就可以初始化 Gitosis 了。需要通过自己的公钥来运行 gitosis-init。如果公钥不在服务器上,则必须复制一份:
[tommy@t42 ~]$ scp .ssh/id_rsa.pub tommy@192.168.0.194:
tommy@s1:~$ sudo -H -u git gitosis-init < id_rsa.pub
这样该公钥的拥有者就能修改包含着 Gitosis 设置的那个 Git 仓库了。然后手动将这个新的控制仓库中的 post-update 脚本加上执行权限。
tommy@s1:~$ sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update
由于我是在家里做动态ip 绑定,所以需要配置路由器,打开 22 端口并映射到内网ip 192.168.0.194 ,然后直接通过域名 clone 项目
[tommy@t42 tmp]$ git clone git@git.gaixie.info:gitosis-admin.git
gitweb
~~~~~~~
gitweb 已经被内置到 git 源码中了,先 clone git 源码
tommy@s1:~$ git clone git://git.kernel.org/pub/scm/git/git.git
tommy@s1:~$ cd git
生成 gitweb ,并复制到 apache 的相应目录下
tommy@s1:~/git$ make clean
tommy@s1:~/git$ make GITWEB_PROJECTROOT="/home/git/repositories" \
prefix=/usr gitweb/gitweb.cgi
tommy@s1:~/git$ sudo cp -Rf gitweb /var/www/htdocs
修改 apahce 的主配置文件,让 httpd-vhosts.conf 配置文件生效
tommy@s1:~/git$ sudo vi /etc/httpd/httpd.conf
把下面这行注释打开
# Virtual hosts
Include /etc/httpd/extra/httpd-vhosts.conf
编辑子配置文件 httpd-vhosts.conf
tommy@s1:~/git$ sudo vi /etc/httpd/extra/httpd-vhosts.conf
<VirtualHost *:80>
ServerName git.gaixie.info
SetEnv GITWEB_CONFIG /home/git/gitosis/gitweb.conf
DocumentRoot /var/www/htdocs
<Directory /var/www/htdocs/gitweb>
Options ExecCGI +FollowSymLinks +SymLinksIfOwnerMatch
AllowOverride All
order allow,deny
Allow from all
AddHandler cgi-script cgi
DirectoryIndex gitweb.cgi
</Directory>
</VirtualHost>
修改 gitweb.conf 配置文件
tommy@s1:~$ sudo cp gitosis/gitweb.conf /home/git/gitosis/
tommy@s1:~$ sudo vi /home/git/gitosis/gitweb.conf
增加一个新的 public 项目 slackware-howto,在客户端执行下面的命令
[tommy@t42 gitosis-admin]$ vi gitosis.conf
[tommy@t42 gitosis-admin]$ git commit -am 'add slackware-howto project and linux-admin group'
[tommy@t42 gitosis-admin]$ git push
[tommy@t42 Projects]$ mkdir slackware-howto
[tommy@t42 Projects]$ cd slackware-howto/
[tommy@t42 slackware-howto]$ git init
Initialized empty Git repository in /home/tommy/Projects/slackware-howto/.git/
[tommy@t42 slackware-howto]$ git remote add origin git@git.gaixie.info:slackware-howto.git
[tommy@t42 slackware-howto]$ touch README
[tommy@t42 slackware-howto]$ git add .
[tommy@t42 slackware-howto]$ git commit -m 'add readme file'
[tommy@t42 slackware-howto]$ git push origin master
让新项目可以被 apache 读取
tommy@s1:~$ sudo chmod 755 /home/git/repositories/slackware-howto.git/
重启 httpd 服务
tommy@s1:~$ sudo sh /etc/rc.d/rc.httpd restart
如果 gitosis 中配置了 daemon = yes ,好像会自动创建 git-daemon-export-ok 文件,所以可以不用手动通过下面的命令 touch 该文件
tommy@s1:~$ sudo touch /home/git/repositories/slackware-howto.git/git-daemon-export-ok
让 daemon 开机运行 ,增加到下面的文件中
tommy@s1:~$ sudo vi /etc/inetd.conf
git stream tcp nowait nobody /usr/bin/git
git daemon --inetd --verbose
--base-path=/home/git/repositories/
tommy@s1:~$ sudo /etc/rc.d/rc.inetd restart
在防火墙上开 git 协议使用的 9418 端口并测试
[tommy@t42 tmp]$ git clone git://git.gaixie.info/slackware-howto.git
参考文档
~~~~~~~
[1] http://progit.org/book/zh/ch4-7.html
[2] http://eagain.net/gitweb/?p=gitosis.git;a=blob;f=README.rst;hb=master
[3] http://www.linuxforums.org/forum/linux-tutorials-howtos-reference-material/64958-how-install-software-linux.html
[4] ftp://ftp.slackware.com/pub/slackware/slackware-13.1/
[5] http://ao2.it/wiki/How_to_setup_a_GIT_server_with_gitosis_and_gitweb
[6] http://scie.nti.st/2007/11/14/hosting-git-repositories-the-easy-and-secure-way
[7] http://www.kernel.org/pub/software/scm/git/docs/git-daemon.html