在CentOS上基于Apache http服务搭建git远程仓库(一)

来源:互联网 发布:数据库水平切分 编辑:程序博客网 时间:2024/05/01 05:42

1,安装Apache与git客户端

yum -y  install httpd git

2,进入home目录创建一个文件夹用来存放git仓库

cd home   (进入home目录)

mkdir gitServer&&cd gitServer (创建一个文件夹并进入)


3,创建一个项目的文件在里面创建仓库

mkdir demo1&&cd demo1   (创建项目的目录进入)

git init --bare demo1.git  (在里面创建git的仓库)





4,让apache能读写demo1这个文件夹

chown -R apache:apache . 


5,创建用于git用户验证的账户

htpasswd -m -c   /etc/httpd/conf.d/git-team.htpasswd user1    (user1是用户名然后会提示输出密码重复输入两次密码)

注:多个账户的时候第以后的账户要把-c去掉  htpasswd -m /etc/httpd/conf.d/git-team.htpasswd zh2


6.修改Git-team.htpasswd文件的所有者和所属者

chown apache:apache /etc/httpd/conf.d/git-team.htpasswd




7,修改git-team.hpasswd文件的访问权限


chmod 640 /etc/httpd/conf.d/git-team.htpasswd

8,修改apache配置文件httpd.conf

vi /etc/httpd/conf/httpd.conf

在末尾添加然后保存

<VirtualHost *:80>
        ServerNamegit.gitServer.com
        SetEnvGIT_HTTP_EXPORT_ALL
        SetEnv GIT_PROJECT_ROOT/home/gitServer     (注:最重要)
        ScriptAlias /git//usr/libexec/git-core/git-http-backend/
        <Location />
                AuthType Basic
                AuthName"Git"
                AuthUserFile/etc/httpd/conf.d/git-team.htpasswd
                Requirevalid-user
       </Location>
</VirtualHost>


解:

ServerName是git服务器的域名

/home/gitServer是代码库存放的文件夹

ScriptAlias是将以/git/开头的访问路径映射至git的CGI程序git-http-backend

AuthUserFile是验证用户帐户的文件


9,重启服务


/bin/systemctl restart httpd.service



注:如果想在gitServer创建第二个项目然后在项目目录下

git init --bare demo1.git  (在里面创建git的仓库)

然后分配权限即可其它不用从新配置
chown -R apache:apache . 



远程仓库已经搭建完毕如遇到问题可以加我QQ一起讨论