CentOS服务器上搭建GitWeb
(1).参考文献
官网在线教程:https://git-scm.com/book/zh/v2
官方网站:https://git-scm.com/
(2).实验环境
2核2G CentOS7.6.1810
可以参考一下文档,将git安装好,并使用HTTP协议完成环境的相关配置:
Linux服务器上安装git(运维向)
(3).搭建GitWeb
如果你对项目有读写权限或只读权限,你可能需要建立起一个基于网页的简易查看器。 Git 提供了一个叫做 GitWeb 的 CGI 脚本来做这项工作。
如果你现在想为你的团队或你托管的开源项目持续的运行这个页面,你需要通过普通的 Web 服务器来设置 CGI 脚本。 一些 Linux 发行版的软件库有 gitweb 包,可以通过 apt 或 dnf 或 yum 来安装,其中就包含CentOS7。
1)yum安装并配置
yum或dnf安装gitweb,并修改配置文件:
[root@VM-0-17-centos ~]# yum -y install gitweb [root@VM-0-17-centos ~]# vim /etc/gitweb.conf $projectroot = "/srv/git"; $git_temp = "/tmp"; $git_http_backend = "/usr/libexec/git-core/git-http-backend";
接着修改Apache的配置文件,我这里在/etc/httpd/conf.d/目录下新增一个gitweb.conf:
[root@VM-0-17-centos ~]# vim /etc/httpd/conf.d/gitweb.conf
Listen 18989
<VirtualHost *:18989>
ServerName [服务器地址或域名]
#将/var/www/gitweb作为根目录,这里也可以是/var/www/git
DocumentRoot /usr/share/gitweb
#匹配日志,这里也可以是/var/www/git
<Directory /usr/share/gitweb>
#ExecCGI:允许在该目录中执行CGI脚本
#FollowSymLinks: 允许在该目录中访问符号链接所指向的文件或目录
#SymLinksIfOwnerMatch: 在目标文件和符号链接的所有者匹配时才允许跟随符号链接
Options +ExecCGI +FollowSymLinks +SymLinksIfOwnerMatch
#允许在该目录中使用.htaccess文件来覆盖主配置文件中的指令
AllowOverride All
#先处理allow规则,再处理deny规则
order allow,deny
#允许所有用户访问该目录
Allow from all
#将文件名为cgi-script的文件识别为CGI文件
AddHandler cgi-script cgi
#设置gitweb.cgi为该目录的首页
DirectoryIndex gitweb.cgi
</Directory>
</VirtualHost>
使用Windows浏览器打开,进行测试,如下图:

2)源码安装并配置
获取GIt的源代码,它包含了GitWeb,并可以自动生成自定义的CGI脚本:
[root@VM-0-17-centos ~]# git clone git://git.kernel.org/pub/scm/git/git.git
Cloning into 'git'...
remote: Enumerating objects: 376771, done.
remote: Total 376771 (delta 0), reused 0 (delta 0), pack-reused 376771
Receiving objects: 100% (376771/376771), 123.30 MiB | 532.00 KiB/s, done.
Resolving deltas: 100% (284363/284363), done.
Checking connectivity... done.
[root@VM-0-17-centos ~]# cd git
[root@VM-0-17-centos git]# make GITWEB_PROJECTROOT="/srv/git" prefix=/usr gitweb #GITWEB_PROJECTROOT指定git版本库位置
GIT_VERSION = 2.47.0.72.gef8ce8f
GEN gitweb/gitweb.cgi
GEN gitweb/static/gitweb.js
[root@VM-0-17-centos git]# cp -Rf gitweb /var/www/
接着修改Apache的配置文件,我这里在/etc/httpd/conf.d/目录下新增一个gitweb.conf:
[root@VM-0-17-centos git]# vim /etc/httpd/conf.d/gitweb.conf
Listen 18989
<VirtualHost *:18989>
ServerName [服务器IP地址或域名]
#将/var/www/gitweb作为根目录
DocumentRoot /var/www/gitweb
#匹配日志
<Directory /var/www/gitweb>
#ExecCGI:允许在该目录中执行CGI脚本
#FollowSymLinks: 允许在该目录中访问符号链接所指向的文件或目录
#SymLinksIfOwnerMatch: 在目标文件和符号链接的所有者匹配时才允许跟随符号链接
Options +ExecCGI +FollowSymLinks +SymLinksIfOwnerMatch
#允许在该目录中使用.htaccess文件来覆盖主配置文件中的指令
AllowOverride All
#先处理allow规则,再处理deny规则
order allow,deny
#允许所有用户访问该目录
Allow from all
#将文件名为cgi-script的文件识别为CGI文件
AddHandler cgi-script cgi
#设置gitweb.cgi为该目录的首页
DirectoryIndex gitweb.cgi
</Directory>
</VirtualHost>
[root@VM-0-17-centos git]# systemctl restart httpd.service
使用Windows浏览器打开,进行测试,如下图:

(4).结尾
后续使用请根据实际情况修改配置。

浙公网安备 33010602011771号