[Linux]通过用户名和密码的方式搭建Git服务器(http&gitweb)

本文介绍了如何在Linux系统上通过用户名和密码的方式设置Git服务器,包括安装依赖、配置git用户和密码、配置apache虚拟主机,以及测试通过git命令和web界面进行项目管理和提交。

1、安装依赖

yum -y install perl cpio autoconf tk zlib-devel libcurl-devel openssl-devel expat-devel

yum install perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker cpan

yum -y install epel-release

yum -y install fcgi-devel

yum install git

yum install git-core

yum install gitweb

Tips:首先确保已经安装了apache2

2、配置

 1)、添加git用户

useradd git

2)、配置访问git的用户名与密码

#创建密码文件

htpasswd -m -c /home/git/git-team.htpasswd <用户1>

#添加其他用户

htpasswd -m /home/git/git-team.htpasswd <用户2> 

3)配置apache的虚拟主机

<VirtualHost *:80>

   ServerAdmin test@sina.com

   ServerName GitServer

   SetEnv GIT_PROJECT_ROOT /home/git

   SetEnv GIT_HTTP_EXPORT_ALL

   #安装git-core后,用find命令查一下git-http-backend在哪里

   ScriptAlias /git /usr/libexec/git-core/git-http-backend/

   Alias /gitweb /var/www/git

   #在文件/etc/gitweb.conf末尾另起一行加上 $projectroot = "/home/git";

   SetEnv GITWEB_CONFIG /etc/gitweb.conf

   <Directory "/var/www/git">

      Options ExecCGI Indexes FollowSymLinks SymLinksIfOwnerMatch

      Order allow,deny

      Allow from all

      AllowOverride All

      Require all granted

      AddHandler cgi-script cgi

      DirectoryIndex gitweb.cgi

   </Directory>

   <Location />

      DAV on

      AuthType Basic

      AuthName "Git Access"

      AuthUserFile /home/git/git-team.htpasswd

      Require valid-user

   </Location>

</VirtualHost>

注意:确保apache开启了env_module、dav_module、dav_fs_module、cgi_module、cgid_module、alias_module,否则肯能出现无法启动apache或者显示cgi源码的问题

 

3、测试

在/home/git 创建一个项目

git init --bare test.git

这之后给test.git赋权限,如果有apache用户,就把此文件夹的属主设置为apache,当然也可以

chmod 777 -R test.git

1)基于git命令的测试

#检出项目

 git clone http://GitServer/git/test.git

 

#进入test文件夹后创建一个文件(比如test.txt),然后测试提交

git add test.txt#添加到版本控制

git commit -m  "提交信息"#提交到本地

git push -u  origin master#push到服务器

2)基于web的测试

访问http://GitServer/gitweb,输入用户名和密码即可访问

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值