项目上使用git服务作为配置中心,为了方便要在服务器上搭建http服务,作为git服务的代理
一、安装httpd
执行命令
yum install httpd -y
完成安装,启动httpd服务
systemctl start httpd.service
查看httpd状态
service httpd status
服务启动成功,结果如下;
也可以通过浏览器访问,ip:80(服务默认端口),正常结果如下
这里为了防止80端口占用冲突,在/etc/httpd/conf/httpd.conf中修改为8091。这里可能因为selinux导致修改端口后http服务启动失败,这里可命令临时关闭
执行
sudo setenforce 0
查看状态
getenforce
状态变为 Permissive
此命令临时关闭 selinux 重启失效
二、安装git服务
执行安装命令
yum install git -y
yum install git-core -y
安装完成,可使用命令查看git 版本
git --version
创建git服务端仓库
#创建仓库目录
mkdir -p /home/http_git/test.git
#进入目录
cd /home/http_git/test.git
#初始化仓库
git init --bare
#设置目录所属用户/组
chown -R apache:apache /home/http_git
创建账号
//#testuser为账户名 可以随意定义,后续需要输入密码
htpasswd -m -c /etc/httpd/conf.d/git-team.htpasswd testuser
# 修改git-team.htpasswd文件的所有者与所属群组
chown apache:apache /etc/httpd/conf.d/git-team.htpasswd
#设置git-team.htpasswd文件的访问权限
chmod 640 /etc/httpd/conf.d/git-team.htpasswd
接下来需要修改httpd服务,使得请求可以转发到git仓库
vim /etc/httpd/conf/httpd.conf
在文件末尾添加
<VirtualHost *:8091>
ServerName 172.31.100.48
SetEnv GIT_HTTP_EXPORT_ALL
SetEnv GIT_PROJECT_ROOT /home/http_git
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>
其中VirtualHost 配置服务端口
ServerName 服务器ip
GIT_PROJECT_ROOT 仓库路径
ScriptAlias是将以/git/开头的访问路径映射至git的CGI程序git-http-backend
AuthUserFile是验证用户帐户的文件
保存修改后 重启httpd服务
systemctl restart httpd.service
验证git服务端仓库是否可用,在任一文件下执行
git clone http://ip:8091/git/test.git
克隆仓库中的test.git项目到本地。这里会提示输入用户和密码(前面设置的用户testuser,密码为自己输入的)即可在当前路径下产生test项目文件夹,当然 目前是空的。
至此已经成功搭建http服务的git服务器。接下来就可以通过git命令进行文件的同步管理了。