设为首页 收藏本站
查看: 2036|回复: 0

[经验分享] Centos 7 Git+httpd 基于密码认证push

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-10-13 10:25:49 | 显示全部楼层 |阅读模式
环境:CentOS 7 *2  192.168.11.{29,30}
   Git 版本1.8.3
   Httpd 版本2.4.5

1、服务端centos7_30配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
[iyunv@CentOS7_30 ~]# getenforce                    #查看selinux
Enforcing
[iyunv@CentOS7_30 ~]# setenforce 0                  #设定为0宽容模式
[iyunv@CentOS7_30 ~]# vim /etc/selinux/config       #修改配置文件,改为disabled
[iyunv@CentOS7_30 ~]# iptables -F                   #清楚防火墙配置
[iyunv@CentOS7_30 ~]# yum install git-daemon -y     #安装git-daemon守护进程
[iyunv@CentOS7_30 ~]# git --version                 #查看版本
git version 1.8.3.1
[iyunv@CentOS7_30 ~]# rpm -ql git-daemon            #查看安装信息
/usr/lib/systemd/system/git.socket
/usr/lib/systemd/system/git@.service
/usr/libexec/git-core/git-daemon
...
[iyunv@CentOS7_30 ~]# cat /usr/lib/systemd/system/git@.service  #查看仓库的定义,--base-path为仓库,也可以修改它自定义指定仓库
[Unit]
Description=Git Repositories Server Daemon
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
[iyunv@CentOS7_30 git]# git init --bare project.git                #创建裸仓库
Initialized empty Git repository in /var/lib/git/project.git/      
[iyunv@CentOS7_30 git]# ll                                         #查看是否创建成功
total 4
drwxr-xr-x. 7 root root 4096 Oct 11 21:24 project.git
[iyunv@CentOS7_30 git]# systemctl start git.socket                 #启动git-daemon
[iyunv@CentOS7_30 git]# ss -tnl | grep 9418                        #查看是否启动成功
LISTEN     0      128                      :::9418                    :::*



2、centos7_29客户端clone
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
[iyunv@CentOS7_29 ~]# yum install git -y                            #安装git
[iyunv@CentOS7_29 ~]# git --version                                 #查看版本,centos6.x都是1.7.1 ,使用http密码验证会有问题
git version 1.8.3.1
[iyunv@CentOS7_29 ~]# git clone git://192.168.11.30/project.git     #clone
Cloning into 'project'...
warning: You appear to have cloned an empty repository.        
[iyunv@CentOS7_29 ~]# ls                                            #查看是否成功
anaconda-ks.cfg  project
[iyunv@CentOS7_29 ~]# cd project/                                   #进入仓库
[iyunv@CentOS7_29 project]# ls -a                                   #查看是否有问题,
.  ..  .git
[iyunv@CentOS7_29 project]# echo "print 'sunshine'" > code.py       #在仓库新建文件
[iyunv@CentOS7_29 project]# git status                              #查案状态
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   code.py
nothing added to commit but untracked files present (use "git add" to track)
[iyunv@CentOS7_29 project]# git add code.py                         #加入暂存区
[iyunv@CentOS7_29 project]# git commit -m "v0.1"                    #commit并说明,第一次会提示输入用户更邮箱

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'root@CentOS7_29.(none)')
[iyunv@CentOS7_29 project]# git config --global user.email "sunshine@sunshine.com"  #设置邮箱
[iyunv@CentOS7_29 project]# git config --global user.name sunshine                  #设置用户
[iyunv@CentOS7_29 project]# git config --global color.ui auto                       #设置颜色
[iyunv@CentOS7_29 project]# git commit -m "v0.1"                                    #再次提交
[master (root-commit) 4d0d265] v0.1                    
1 file changed, 1 insertion(+)
create mode 100644 code.py
[iyunv@CentOS7_29 project]# git log
commit 4d0d265d8511f338abb8b4e0652c3a1a6656a892
Author: sunshine <sunshine@sunshine.com>
Date:   Tue Oct 11 21:33:37 2016 +0800

    v0.1
[iyunv@CentOS7_29 project]# git log --oneline                                       #查看log
4d0d265 v0.1
[iyunv@CentOS7_29 project]# git push origin master                                  #push失败,因为git不止写操作
fatal: remote error: access denied or repository not exported: /project.git



3、在centos7_30服务器配置使用htto协议
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
[iyunv@CentOS7_30 project.git]# pwd                                                #进入项目仓库
/var/lib/git/project.git
[iyunv@CentOS7_30 project.git]# git config http.receivepack true                   #配置git config即可
[iyunv@CentOS7_30 ~]# yum install httpd -y                                         #安装httpd
[iyunv@CentOS7_30 ~]# httpd -M | grep -Ei "\<(alias|cgi|env)"                      #必须要有这三个模块
AH00557: httpd: apr_sockaddr_info_get() failed for CentOS7_30
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
alias_module (shared)
env_module (shared)
cgi_module (shared)
[iyunv@CentOS7_30 ~]# vim /etc/httpd/conf/httpd.conf                              #编辑httpd文件,注销中心主机
注销DocumentRoot中心主机
[iyunv@CentOS7_30 ~]# vim /etc/httpd/conf.d/git.conf                              #新增git.conf定义虚拟主机
    <VirtualHost *:80>                                                            #定义端口
    ServerName git.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脚本     
        Options ExecCGI Indexes               
        Require all granted                    
    </Directory>
    <LocationMatch "^/git/.*/git-receive-pack$">   #匹配我们定义的
        AuthType Basic                         #使用标准认证
        AuthName "sunshine test project."      #描述
        AuthUserFile /etc/httpd/conf/.htpasswd #存放账户密码的地方
        Require valid-user                     
    </LocationMatch>
</VirtualHost>
[iyunv@CentOS7_30 ~]# chown -R apache.apache /var/lib/git/    #设定用户及用户组,不设定那么你是没权限的
[iyunv@CentOS7_30 git-core]# htpasswd -c -m /etc/httpd/conf/.htpasswd tom  #创建账户密码第一次使用-c
New password:
Re-type new password:
Adding password for user tom
[iyunv@CentOS7_30 git-core]# htpasswd -m /etc/httpd/conf/.htpasswd jerry   #创建账户密码第二次不要使用-c,不然你就一直就是一个用户
New password:
Re-type new password:
Adding password for user jerry
[iyunv@CentOS7_30 git-core]# systemctl start httpd.service    #启动httpd服务                                                                                                                                               :::*     
[iyunv@CentOS7_30 git-core]# ss -tnl | grep 80                #查看是否启动成功
LISTEN     0      128                      :::80                      :::*



4、在centos7_29客户端pull以及push
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[iyunv@CentOS7_29 ~]# cat /etc/hosts                           #编辑hosts增加域名host
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.11.30 git.sunshine.com
[iyunv@CentOS7_29 ~]# git clone http://git.sunshine.com/git/project.git    #使用http协议clone
Cloning into 'project'...
warning: You appear to have cloned an empty repository.
[iyunv@CentOS7_29 ~]# cd project/                                           #进入project仓库
[iyunv@CentOS7_29 project]# ls                                              #查看仓库
[iyunv@CentOS7_29 project]# !echo                                           #创建python脚本
echo "print 'sunshine'" > code.py                                          #该为完整命令,上面 的使用记录!
[iyunv@CentOS7_29 project]# git add code.py                                 #条件脚本git add
[iyunv@CentOS7_29 project]# git commit -m "v0.1"                            #commit并说明
[master (root-commit) d847298] v0.1
1 file changed, 1 insertion(+)
create mode 100644 code.py
[iyunv@CentOS7_29 project]# git push origin master                           #push至远程仓库
Counting objects: 3, done.
Writing objects: 100% (3/3), 215 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
Username for 'http://git.sunshine.com': tom                                 #提示输入账号,输入创建的tom
Password for 'http://tom@git.sunshine.com':                                 #输入密码,就可以提交成功
To http://git.sunshine.com/git/project.git
* [new branch]      master -> master






运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-285341-1-1.html 上篇帖子: GitLab远程仓库迁移 下篇帖子: CentOS7.2安装GitLab-CE 密码 认证
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表