|
环境: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
|
|
|