Git服务器

4.1 问题

沿用练习三,学习Git不同的服务器形式,具体要求如下:

创建SSH协议服务器
创建Git协议服务器
创建HTTP协议服务器

4.2 方案

Git支持很多服务器协议形式,不同协议的Git服务器,客户端就可以使用不同的形式访问服务器。创建的服务器协议有SSH协议、Git协议、HTTP协议。

步骤一:SSH协议服务器(支持读写操作)

1)创建基于密码验证的SSH协议服务器(web1主机操作)。

[root@web1 ~]# git init --bare /var/git/base_ssh
Initialized empty Git repository in /var/git/base_ssh/

2)客户端访问的方式(web2主机操作)。

[root@web2 ~]# git clone [email protected]:/var/git/base_ssh
[root@web2 ~]# rm -rf base_ssh

3)客户端生成SSH密钥,实现免密码登陆git服务器(web2主机操作)。

[root@web2 ~]# ssh-keygen -f /root/.ssh/id_rsa -N ''
[root@web2 ~]# ssh-copy-id  192.168.2.100
[root@web2 ~]# git clone [email protected]:/var/git/base_ssh
[root@web2 ~]# git push

步骤二:Git协议服务器(只读操作的服务器)

1)安装git-daemon软件包(web1主机操作)。

[root@web1 ~]# yum -y install git-daemon

2)创建版本库(web1主机操作)。

[root@web1 ~]# git init --bare /var/git/base_git
Initialized empty Git repository in /var/git/base_git/

3)修改配置文件,启动git服务(web1主机操作)。

[root@web1 ~]# vim /usr/lib/systemd/system/[email protected]
修改前内容如下:
ExecStart=-/usr/libexec/git-core/git-daemon --base-path=/var/lib/git 
--export-all --user-path=public_git --syslog --inetd –verbose
修改后内容如下:
ExecStart=-/usr/libexec/git-core/git-daemon --base-path=/var/git 
--export-all --user-path=public_git --syslog --inetd –verbose
[root@web1 ~]# systemctl  start  git.socket

4)客户端访问方式(web2主机操作)

[root@web2 ~]# git clone git://192.168.2.100/base_git

步骤三:HTTP协议服务器(只读操作的服务器)

1)安装gitweb、httpd软件包(web1主机操作)。

[root@web1 ~]# yum -y install httpd gitweb

2)修改配置文件,设置仓库根目录(web1主机操作)。

[root@web1 ~]# vim +11 /etc/gitweb.conf 
$projectroot = "/var/git";                        #添加一行
  1. 创建版本仓库(web1主机操作)

    [root@web1 ~]# git init --bare /var/git/base_http

4)启动httpd服务器

[root@web1 ~]# systemctl start httpd

5)客户端访问方式(web2主机操作)

注意:调用虚拟机中的firefox浏览器,需要在远程时使用ssh -X 服务器IP,并且确保真实主机的firefox已经关闭。

[root@web2 ~]# firefox http://192.168.2.100/git/
发布了212 篇原创文章 · 获赞 8 · 访问量 5789

猜你喜欢

转载自blog.csdn.net/weixin_45843450/article/details/105308889