引言
搭建git服务器能帮助我们更好的管理项目,进行团队合作可以在任何地方把项目下载下来管理
搭建环境
[图片上传失败...(image-1f0008-1512008839841)]
首次搭建可以去京东云注册一个账号可以免费领一个月的云主机
京东云
搭建步骤
Apache与git的安装
yum -y install httpd git

创建git仓库
创建一个存放所有项目仓库的文件夹
在home文件夹创建一个叫gitServer的文件夹(名字可以随意)用来放多个项目的git仓库
[root@jdu4e00u53f7 /]# cd home
[root@jdu4e00u53f7 home]# mkdir gitServer && cd gitServer

创建一个项目文件并把它设置成git仓库
[root@jdu4e00u53f7 gitServer]# mkdir demo1 && cd demo1
[root@jdu4e00u53f7 demo1]# git init --bare demo1.git

让apache能读写这个项目文件给分配权限>
[root@jdu4e00u53f7 demo1]# chown -R apache:apache .
每创建一个新的项目git仓库文件夹都要分配一下读写权限

创建用于git用户验证的账户
给编写项目人员分配账号
[root@jdu4e00u53f7 demo1]# htpasswd -m -c /etc/httpd/conf.d/git-team.htpasswd zh1 (zh1是账号然后连续输入两次密码)
New password:
Re-type new password:
Adding password for user zh1
[root@jdu4e00u53f7 demo1]# htpasswd -m /etc/httpd/conf.d/git-team.htpasswd zh2(如果第一个账号命令里有了-c 其它账号要去掉-c)
New password:
Re-type new password:
Adding password for user zh2

修改设置git-team.htpasswd文件的访问权限和所有者
[root@jdu4e00u53f7 demo1]# chown apache:apache /etc/httpd/conf.d/git-team.htpasswd
[root@jdu4e00u53f7 demo1]# chmod 640 /etc/httpd/conf.d/git-team.htpasswd

修改apache配置文件httpd.conf
[root@jdu4e00u53f7 demo1]# vi /etc/httpd/conf/httpd.conf
把下面的东西放到末尾然后保存
<VirtualHost *:80>
ServerName git.gitServer.com
SetEnv GIT_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
Require valid-user
</Location>
</VirtualHost>
ServerName是git服务器的域名(没有可以不动)
/home/gitServer 是git仓库都存放在的文件夹(要写正常文件夹名)
ScriptAlias是将以/git/开头的访问路径映射至git的CGI程序git-http-backend(不用改)
AuthUserFile是验证用户账户的文件(不用改)

重启服务
[root@jdu4e00u53f7 demo1]# /bin/systemctl restart httpd.service
完成
大功告成让我们在客户端试一下
IP地址是git服务器的地址,然后输入分配的账号密码

可以把远程仓库下到客户机了

网友评论