Centos 7 Git+httpd 基于密码认证push

前端之家收集整理的这篇文章主要介绍了Centos 7 Git+httpd 基于密码认证push前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。



环境:CentOS 7 *2 192.168.11.{29,30}

Git 版本1.8.3

Httpd 版本2.4.5


1、服务端centos7_30配置

[root@CentOS7_30~]#getenforce#查看selinux
Enforcing
[root@CentOS7_30~]#setenforce0#设定为0宽容模式
[root@CentOS7_30~]#vim/etc/selinux/config#修改配置文件,改为disabled
[root@CentOS7_30~]#iptables-F#清楚防火墙配置
[root@CentOS7_30~]#yuminstallgit-daemon-y#安装git-daemon守护进程
[root@CentOS7_30~]#git--version#查看版本
gitversion1.8.3.1
[root@CentOS7_30~]#rpm-qlgit-daemon#查看安装信息
/usr/lib/systemd/system/git.socket
/usr/lib/systemd/system/git@.service
/usr/libexec/git-core/git-daemon
...
[root@CentOS7_30~]#cat/usr/lib/systemd/system/git@.service#查看仓库的定义,--base-path为仓库,也可以修改自定义指定仓库
[Unit]
Description=GitRepositoriesServerDaemon
Documentation=man:git-daemon(1)

[Service]
User=nobody
ExecStart=-/usr/libexec/git-core/git-daemon--base-path=/var/lib/git--export-all--user-path=public_git--syslog--inetd--verbose
StandardInput=socket
[root@CentOS7_30git]#gitinit--bareproject.git#创建裸仓库
InitializedemptyGitrepositoryin/var/lib/git/project.git/
[root@CentOS7_30git]#ll#查看是否创建成功
total4
drwxr-xr-x.7rootroot4096Oct1121:24project.git
[root@CentOS7_30git]#systemctlstartgit.socket#启动git-daemon
[root@CentOS7_30git]#ss-tnl|grep9418#查看是否启动成功
LISTEN0128:::9418:::*

2、centos7_29客户端clone

[root@CentOS7_29~]#yuminstallgit-y#安装git
[root@CentOS7_29~]#git--version#查看版本,centos6.x都是1.7.1,使用http密码验证会有问题
gitversion1.8.3.1
[root@CentOS7_29~]#gitclonegit://192.168.11.30/project.git#clone
Cloninginto'project'...
warning:Youappeartohaveclonedanemptyrepository.
[root@CentOS7_29~]#ls#查看是否成功
anaconda-ks.cfgproject
[root@CentOS7_29~]#cdproject/#进入仓库
[root@CentOS7_29project]#ls-a#查看是否有问题,
....git
[root@CentOS7_29project]#echo"print'sunshine'">code.py#在仓库新建文件
[root@CentOS7_29project]#gitstatus#查案状态
#Onbranchmaster
#
#Initialcommit
#
#Untrackedfiles:
#(use"gitadd<file>..."toincludeinwhatwillbecommitted)
#
#	code.py
nothingaddedtocommitbutuntrackedfilespresent(use"gitadd"totrack)
[root@CentOS7_29project]#gitaddcode.py#加入暂存区
[root@CentOS7_29project]#gitcommit-m"v0.1"#commit并说明,第一次会提示输入用户更邮箱

***Pleasetellmewhoyouare.

Run

gitconfig--globaluser.email"you@example.com"
gitconfig--globaluser.name"YourName"

tosetyouraccount'sdefaultidentity.
Omit--globaltosettheidentityonlyinthisrepository.

fatal:unabletoauto-detectemailaddress(got'root@CentOS7_29.(none)')
[root@CentOS7_29project]#gitconfig--globaluser.email"sunshine@sunshine.com"#设置邮箱
[root@CentOS7_29project]#gitconfig--globaluser.namesunshine#设置用户
[root@CentOS7_29project]#gitconfig--globalcolor.uiauto#设置颜色
[root@CentOS7_29project]#gitcommit-m"v0.1"#再次提交
[master(root-commit)4d0d265]v0.1
1filechanged,1insertion(+)
createmode100644code.py
[root@CentOS7_29project]#gitlog
commit4d0d265d8511f338abb8b4e0652c3a1a6656a892
Author:sunshine<sunshine@sunshine.com>
Date:TueOct1121:33:372016+0800

v0.1
[root@CentOS7_29project]#gitlog--oneline#查看log
4d0d265v0.1
[root@CentOS7_29project]#gitpushoriginmaster#push失败,因为git不止写操作
fatal:remoteerror:accessdeniedorrepositorynotexported:/project.git

3、在centos7_30服务器配置使用htto协议

[root@CentOS7_30project.git]#pwd#进入项目仓库
/var/lib/git/project.git
[root@CentOS7_30project.git]#gitconfighttp.receivepacktrue#配置gitconfig即可
[root@CentOS7_30~]#yuminstallhttpd-y#安装httpd
[root@CentOS7_30~]#httpd-M|grep-Ei"\<(alias|cgi|env)"#必须要有这三个模块
AH00557:httpd:apr_sockaddr_info_get()FailedforCentOS7_30
AH00558:httpd:Couldnotreliablydeterminetheserver'sfullyqualifieddomainname,using127.0.0.1.Setthe'ServerName'directivegloballytosuppressthismessage
alias_module(shared)
env_module(shared)
cgi_module(shared)
[root@CentOS7_30~]#vim/etc/httpd/conf/httpd.conf#编辑httpd文件,注销中心主机
注销DocumentRoot中心主机
[root@CentOS7_30~]#vim/etc/httpd/conf.d/git.conf#新增git.conf定义虚拟主机
<VirtualHost*:80>#定义端口
	ServerNamegit.sunshine.com#定义域名
	SetEnv	GIT_PROJECT_ROOT/var/lib/git#定义项目路径
	SetEnv	GIT_HTTP_EXPORT_ALL#使用HTTP导出
	ScriptAlias/git//usr/libexec/git-core/git-http-backend/#千万注意如果git后面没有/那么git-http-backend后面也一定不能有/
	<Directory"/usr/libexec/git-core/">#该目录下好像都是一些prel脚本
		OptionsExecCGIIndexes
		Requireallgranted
	</Directory>
	<LocationMatch"^/git/.*/git-receive-pack$">#匹配我们定义的
		AuthTypeBasic#使用标准认证
		AuthName"sunshinetestproject."#描述
		AuthUserFile/etc/httpd/conf/.htpasswd#存放账户密码的地方
		Requirevalid-user
	</LocationMatch>
</VirtualHost>
[root@CentOS7_30~]#chown-Rapache.apache/var/lib/git/#设定用户用户组,不设定那么你是没权限的
[root@CentOS7_30git-core]#htpasswd-c-m/etc/httpd/conf/.htpasswdtom#创建账户密码第一次使用-c
Newpassword:
Re-typenewpassword:
Addingpasswordforusertom
[root@CentOS7_30git-core]#htpasswd-m/etc/httpd/conf/.htpasswdjerry#创建账户密码第二次不要使用-c,不然你就一直就是一个用户
Newpassword:
Re-typenewpassword:
Addingpasswordforuserjerry
[root@CentOS7_30git-core]#systemctlstarthttpd.service#启动httpd服务:::*
[root@CentOS7_30git-core]#ss-tnl|grep80#查看是否启动成功
LISTEN0128:::80:::*

4、在centos7_29客户端pull以及push

[root@CentOS7_29~]#cat/etc/hosts#编辑hosts增加域名host
127.0.0.1localhostlocalhost.localdomainlocalhost4localhost4.localdomain4
::1localhostlocalhost.localdomainlocalhost6localhost6.localdomain6
192.168.11.30git.sunshine.com
[root@CentOS7_29~]#gitclonehttp://git.sunshine.com/git/project.git#使用http协议clone
Cloninginto'project'...
warning:Youappeartohaveclonedanemptyrepository.
[root@CentOS7_29~]#cdproject/#进入project仓库
[root@CentOS7_29project]#ls#查看仓库
[root@CentOS7_29project]#!echo#创建python脚本
echo"print'sunshine'">code.py#该为完整命令,上面的使用记录!
[root@CentOS7_29project]#gitaddcode.py#条件脚本gitadd
[root@CentOS7_29project]#gitcommit-m"v0.1"#commit并说明
[master(root-commit)d847298]v0.1
1filechanged,1insertion(+)
createmode100644code.py
[root@CentOS7_29project]#gitpushoriginmaster#push至远程仓库
Countingobjects:3,done.
Writingobjects:100%(3/3),215bytes|0bytes/s,done.
Total3(delta0),reused0(delta0)
Usernamefor'http://git.sunshine.com':tom#提示输入账号,输入创建的tom
Passwordfor'http://tom@git.sunshine.com':#输入密码,就可以提交成功
Tohttp://git.sunshine.com/git/project.git
*[newbranch]master->master
原文链接:https://www.f2er.com/centos/380417.html

猜你在找的CentOS相关文章