搭建自己的git服务器

来源:互联网 发布:淘宝网能买到处方药吗 编辑:程序博客网 时间:2024/05/29 13:52

参考了很多别人的文章,最终折腾成功。中间出现各种应为配置导致的错误,泪奔···别人博客的配置应该是可以用,可是自己用了才知道自己是多么的天真。没搞懂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
  1. 建立仓库

仓库建立在/var/www/git 路径之下

mkdir –p /var/www/git/test_repocd /var/www/git/test_repogit init –bare ; cp hooks/post-update.sample  hooks/post-updategit update-server-infocd /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.28LoadModule dav_fs_module modules/mod_dav_fs.so <Directory "/var/www/git">Dav onAllow from AllOptions +ExecCGIAllowOverride AllAuthUserFile "/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_ALLSetEnv GIT_PROJECT_ROOT /var/www/gitScriptAlias /git /usr/lib/git-core/git-http-backend</VirtualHost>  
配置完成后重启服务器/etc/init.d/apache2 restart

二、git server维护

  1. 服务器ip地址有变动
    修改配置文件
vim  /etc/apache2/sites-enabled/000-default.confVirtualHost 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

0 0
原创粉丝点击