1. 简介:
比较低端的gitserver,使用centos自带的git-daemon搭建gitserver,使用httpd做上传和下载,利用mod_auth_mysql做认证
2. 环境
git-daemon 1.8.3.1-14.el7_5
httpd 2.4.6-80
mariadb 5.5.56-2.el7
3. 安装
3.1. 安装必要的包
yum install -y git-daemon httpd httpd-devel mariadb mariadb-server
3.2. 检查httpd安装
# 修改http配置文件 ~]# sed "s/\<ServerName/ServerName YOURSERVERIP:80/g" /etc/httpd/conf/httpd.conf # alias,cgi,env这三个模块必须要有 ~]# httpd -M |grep -Ei "\<(alias|cgi|env)" alias_module (shared) env_module (shared) cgi_module (shared)
~]# systemctl start httpd
3.3. 检查git-deamon安装
~]# cat /usr/lib/systemd/system/[email protected] [Unit] Description=Git Repositories Server Daemon Documentation=man:git-daemon(1) [Service] User=nobody ExecStart=-/usr/libexec/git-core/git-daemon --base-path=/var/lib/git --export-all --user-path=public_git --syslog --inetd --verbose StandardInput=socket
~]# systemctl start git.socket
3.4. 检查mysql安装
~]# grep -Ev "^#|^$" /usr/lib/systemd/system/mariadb.service [Unit] Description=MariaDB database server After=syslog.target After=network.target [Service] Type=simple User=mysql Group=mysql ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n ExecStart=/usr/bin/mysqld_safe --basedir=/usr ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID TimeoutSec=300 PrivateTmp=true [Install] WantedBy=multi-user.target ~]# systemctl start mariadb
4. 配置
4.1. 配置git-deamon支持git协议
~]# cd /var/lib/git/ #初始化一个空的目录 ~]# git init --bare myproject.git Initialized empty Git repository in /var/lib/git/myproject.git/
#可以在其他客户端使用git clone git://IPADDRESS/myproject.git尝试下载了,但是目前只能下载,不能推送
4.2. 支持http方式的clone
#创建git目录并初始化仓库 ~]# mkdir /var/www/git ~]# cd /var/www/git ~]# git init --bare testproject.git ~]# chown -R apache:apache /var/www/git #修改httpd配置文件的DocumentRoot sed -i "s/^DocumentRoot/#&/" /etc/httpd/conf/httpd.conf
创建/etc/httpd/conf.d/git.conf
<VirtualHost *:80> ServerName centos-0 #下面的参数可以使用man git-http-backend查看 SetEnv GIT_PROJECT_ROOT /var/www/git #检查GIT是否支持smart功能,如果支持就打开smart功能 SetEnv GIT_HTTP_EXPORT_ALL #要授权读或者写主要取决于/usr/libexec/git-core/目录的权限 ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/ <Directory "/usr/libexec/git-core/"> Options ExecCGI Indexes Require all granted </Directory> </VirtualHost>
可以试着clone了
git clone http://IPADDRESS/git/testproject.git
但是目前依然不支持推送,如果想要推送需要在git的源上配置
git config http.receivepack true
4.3. 配置http支持文件认证
修改/etc/httpd/conf.d/git.conf
<VirtualHost *:80> ServerName centos-0 #下面的参数可以使用man git-http-backend查看 SetEnv GIT_PROJECT_ROOT /var/www/git #检查GIT是否支持smart功能,如果支持就打开smart功能 SetEnv GIT_HTTP_EXPORT_ALL #要授权读或者写主要取决于/usr/libexec/git-core/目录的权限 ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/ <Directory "/usr/libexec/git-core/"> Options ExecCGI Indexes Require all granted </Directory> <LocationMatch "^/git/.*/git-receive-pack$"> AuthType Basic AuthName "Private Git Repo" AuthUserFile /etc/httpd/conf/.htpasswd Require valid-user </LocationMatch> </VirtualHost>
添加用户
htpasswd -c -m /etc/httpd/conf/.htpasswd eric
4.4. 安装mod_auth_mysql模块