温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

在VMware+centOS 8上基于http协议如何搭建Git服务

发布时间:2021-02-07 12:56:16 来源:亿速云 阅读:191 作者:小新 栏目:服务器

小编给大家分享一下在VMware+centOS 8上基于http协议如何搭建Git服务,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!

一.起因

实现Android终端访问虚拟机中git服务,所以需要搭建http协议的git服务器

二.设备信息

windows10家庭中文版(1903) VMware 15Pro(15.5.0 build-14665864) centOS 8(1905已关闭GUI,VMware采用NAT模式)

三.准备工作

(一)windows防火墙开放80端口控制面板 -> 系统和安全 -> Windows Defender 防火墙点击高级设置 -> 点击入站规则 -> 新建规则更改要创建的规则类型为端口按照图示方式设置

在VMware+centOS 8上基于http协议如何搭建Git服务

选择允许连接并下一步按照图示方式设置

在VMware+centOS 8上基于http协议如何搭建Git服务

名称设置随意点击出站规则 -> 新建规则后续步骤与上述入站规则设置保持一致

(二) 关闭SELinux

打开selinux配置文件

vi /etc/selinux/config

修改为SELINUX=disabled 重启centOS即可永久关闭SELinux

注:

1.SELinux一共有3种状态,分别是Enforcing,Permissive和Disabled 2.查看当前状态命令: getenforcing 3.临时关闭命令: setenforce 0 4.临时开启:setenforce 1(不可用于永久关闭后的开启)

(三)更改虚拟网络编辑器点击VMware菜单栏编辑 -> 虚拟网络编辑器 -> 更改设置点击VMnet8 NAT模式 -> NAT设置 -> 添加按照图示方式设置(虚拟机IP地址通过ifconfig查询,描述随意)

四.安装apache

(一)安装httpd

yum install httpd

(二)启动httpd服务

systemctl start httpd.service

(三)修改firewalld配置文件和重启firewalld

 firewall-cmd --zone=public --add-port=80/tcp --permanent systemctl restart firewalld.service

如果嫌麻烦可直接关闭防火墙

注:

1.看防火墙状态:systemctl status firewalld 2.暂时关闭防火墙:systemctl stop firewalld 3.永久关闭防火墙: systemctl disable firewalld 4.重启防火墙:systemctl enable firewalld(该命令可永久开启防火墙)

五.配置git

(一)创建空仓库

mkdir -p /home/gitrepo/share.git //空仓库可设置于任意目录下cd /home/gitrepo/share.gitgit init --barechown -R apache:apache /home/gitrepo

(二)创建账号并设置权限

htpasswd -m -c /etc/httpd/conf.d/git-team.htpasswd XXX //XXX为账户名可任意设定chown apache:apache /etc/httpd/conf.d/git-team.htpasswdchmod 640 /etc/httpd/conf.d/git-team.htpasswd

六.配置apache

(一)编辑配置文件

vi /etc/httpd/conf/httpd.conf

在最后一行IncludeOptional conf.d/*.conf的上面添加如下内容

<VirtualHost *:80>
 ServerName X.X.X.X #centOS的IP地址
 SetEnv GIT_HTTP_EXPORT_ALL
 SetEnv GIT_PROJECT_ROOT /home/gitrepo #此处应与创建空仓库的位置一致
 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>

(二)重启httpd

systemctl restart httpd.service

注:

1.查询httpd服务状态 :systemctl status httpd.service 2.查询httpd服务是否为开机启动: systemctl is-enabled httpd.service 3.设置httpd服务为开机启动状态:systemctl enable httpd.service 4.设置httpd服务为开机不启动状态:systemctl disable httpd.service

完成上述操作后即可在外网进行git操作,例如clone

git clone http://windows的IP地址/git/share.git

看完了这篇文章,相信你对“在VMware+centOS 8上基于http协议如何搭建Git服务”有了一定的了解,如果想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI