基于http协议搭建Git服务 在VMware+centOS 8上基于http协议搭建Git服务的方法

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

基于http协议搭建Git服务 在VMware+centOS 8上基于http协议搭建Git服务的方法

FlashWarrior   2021-04-21 我要评论

一.起因

一定要看

本文最终目的是实现Android终端访问虚拟机中git服务,所以需要搭建http协议的git服务器,而如何搭建http协议的git服务器,前人之述备矣,笔者遂借鉴前人之作这里

二.设备信息

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

三.准备工作

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

在这里插入图片描述

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

在这里插入图片描述

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

(二) 关闭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

七.Android终端访问上述Git服务

推荐使用Pocket Git

下载地址:

链接: http://pan.baidu.com/s/1JAUsvU-qKAg-7FJGWv2JSA

提取码: 9cgu

至此,我们搭建了基于http协议的Git服务,通过Pocket Git实现Android与电脑中的centOS 8互传文件。

总结

以上所述是小编给大家介绍的在VMware+centOS 8上基于http协议搭建Git服务的方法,希望对大家有所帮助!

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们