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

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 [email protected]

   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,输入用户名和密码即可访问

 

猜你喜欢

转载自blog.csdn.net/hsdllcw/article/details/80073129