参考了很多别人的文章,最终折腾成功。中间出现各种应为配置导致的错误,泪奔···别人博客的配置应该是可以用,可是自己用了才知道自己是多么的天真。没搞懂apache2配置,先将就用着吧。
Git服务器搭建与维护
一、搭建git服务
环境:ubuntu
1)安装git与apache2:
apt-get install git git-core apache2 apache2-utils
2)加载apache2模块
a2enmod rewrite dav_fs cgi alias env
- 建立仓库
仓库建立在/var/www/git 路径之下
mkdir –p /var/www/git/test_repo
cd /var/www/git/test_repo
git init –bare ; cp hooks/post-update.sample hooks/post-update
git update-server-info
cd /var/www/git ; chown www-data:www-data –R test_repo
2.添加用户名
用户名文件保存在/var/www/git路径
htpasswd –c –b htpasswd name pwd
ps:-c用于建立用户名文件,若是htpasswd已经建立,则不需要-c
-b 显式添加用户名与密码
3.修改apache2配置文件
编辑apache2配置文件,设置git repository路径并关联用户名
vim /etc/apache2/sites-enabled/000-default.conf
<VirtualHost 192.168.0.28:80> #192.168.0.28位服务器IP地址
DocumentRoot /var/www/git #git仓库路径
ServerName 192.168.0.28
LoadModule dav_fs_module modules/mod_dav_fs.so
<Directory "/var/www/git">
Dav on
Allow from All
Options +ExecCGI
AllowOverride All
AuthUserFile "/var/www/git/htpasswd" #将仓库与用户名关联
Require valid-user
</Directory>
<Location /git/test_repo> #/TC为/var/www/git 目录下的仓库名称
AuthType Basic
AuthName "Private Git Access"
AuthUserFile "/var/www/git/htpasswd" #将仓库与用户名关联
Require valid-user
</Location>
SetEnv GIT_HTTP_EXPORT_ALL
SetEnv GIT_PROJECT_ROOT /var/www/git
ScriptAlias /git /usr/lib/git-core/git-http-backend
</VirtualHost>
配置完成后重启服务器
/etc/init.d/apache2 restart
二、git server维护
- 服务器ip地址有变动
修改配置文件
vim /etc/apache2/sites-enabled/000-default.conf
VirtualHost 192.168.0.28:80 #192.168.0.28位服务器IP地址
DocumentRoot /var/www/git
ServerName 192.168.0.28 #192.168.0.28位服务器IP地址
2.建立新的仓库
建仓具体操作如同第一章节搭建git服务器中一样,建新的仓库后需要在配置文件中添加一下内容
vim /etc/apache2/sites-enabled/000-default.conf
<Location /git/new_repo > #/TC为/var/www/git 目录下的仓库名称
AuthType Basic
AuthName "Private Git Access"
AuthUserFile "/var/www/git/htpasswd" #将仓库与用户名关联
Require valid-user
</Location>
重启apache2服务 /etc/init.d/apache2 restart
3.添加新的用户
htpasswd –b /var/www/git/htpasswd new-name passwd