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

[经验分享] git(学习之四)git协议服务器搭建

[复制链接]

尚未签到

发表于 2018-9-17 12:57:27 | 显示全部楼层 |阅读模式
  #######################################################################################################
  qq:1218761836
  qq群:150181442
  E-mail:wangxing0122@hotmail.com
  #######################################################################################################
  目录
  Git 服务器的搭建... 1
  1.1 Git协议的服务器搭建... 1
  1.1.1 安装git. 1
  1.2.1 创建目录及版本库... 1
  1.2.3 Git 服务器启动... 2
  1.2.4 客户端测试... 4
Git 服务器的搭建
  远程仓库通常只是一个纯仓库(bare repository)—一个没有当前工作目录的仓库。因为该仓库只是一个合作媒介,所以不需要从一个处于已从硬盘上检出状态的快照;仓库里仅仅是git的数据。更简单的说,纯仓库是你的项目里的.git内容。
  开始架设git服务器的时候,需要把一个现存的仓库导出为新的纯仓库—不包含当前工作目录的仓库。方法很简单。把一个仓库克隆为纯仓库,可以使用clone命令的--bare选项。纯仓库的目录名以.git 结尾。
  Git服务器搭建根据自己的需求选择不同的协议
  Git支持http:// git:// ssh:// https:// file:// (本地)
  ssh://[user@]host.xz[:port]/path/to/repo.git/
  git://host.xz[:port]/path/to/repo.git/
  http://host.xz[:port]/path/to/repo.git/
  ftp://host.xz[:port]/path/to/repo.git/
  rsync://host.xz/path/to/repo.git/
1.1 Git协议的服务器搭建
1.1.1 安装git
  安装git软件,使用yum安装的方式
  yum install git-* -y 安装git所有的包
  git-all
  git-cvs
  git-daemon
  git-email
  git-gui
  git-svn
  因为要搭建git协议的服务器,所以git-daemon是必须要安装的,git-daemon支持两种启动方式,一种是git-daemon 的直接启动方式,一种是利用centos下的xinetd来加载git进程。
1.2.1 创建目录及版本库
  [root@wx ~]# mkdir /project/git/ -p
  [root@wx git]# git init # 创建一个git版本库
  Initialized empty Git repository in /project/git/.git/
  [root@wx project]# git clone –bare /project/git/.git/ my-project.git
  Initialized empty Git repository in /project/my-project.git/
  warning: You appear to have cloned an empty repository.
  [root@wx /]# tree /project/my-project.git/
  /project/my-project.git/
  ├── branches
  ├── config
  ├── description
  ├── HEAD
  ├── hooks
  │   ├── applypatch-msg.sample
  │   ├── commit-msg.sample
  │   ├── post-commit.sample
  │   ├── post-receive.sample
  │   ├── post-update.sample
  │   ├── pre-applypatch.sample
  │   ├── pre-commit.sample
  │   ├── prepare-commit-msg.sample
  │   ├── pre-rebase.sample
  │   └── update.sample
  ├── info
  │   └── exclude
  ├── objects
  │   ├── info
  │   └── pack
  └── refs
  ├── heads
  └── tags
  9 directories, 14 files
  可以看到这些文件其实和svn的配置文件差不多。
1.2.3 Git 服务器启动
  根据官网提示我使用git daemon --reuseaddr --base-path=/project/ /project/ 运行结果失败了,其实git守护进程结合系统运行模式有三种,一种是守护进行运行,后两种是xinetd,sysinit
  我选择了centos 结合xined,所以在centos下可以结合xinetd来加载git服务,其实在安装git-daemon的时候也会安装上xined这个包。
  Git守护进程的端口是9418
  [root@wx /]# grep 9418 /etc/services
  git 9418/tcp # git pack transfer service
  git 9418/udp # git pack transfer service
  来看看默认xined加载的git服务的配置文件,具体可以去man xined 去了解一下xined
  [root@wx /]# cat /etc/xinetd.d/git
  # default: off
  # description: The git d?mon allows git repositories to be exported using \
  # the git:// protocol.
  service git
  {
  disable = yes
  socket_type = stream
  wait = no
  user = nobody
  server = /usr/libexec/git-core/git-daemon
  server_args = --base-path=/var/lib/git --export-all --user-path=public_git --syslog --inetd --verbose
  log_on_failure += USERID
  }
  修完的配置文件
  [root@wx /]# vim /etc/xinetd.d/git
  # default: off
  # description: The git d?mon allows git repositories to be exported using \
  # the git:// protocol.
  service git
  {
  disable = no
  socket_type = stream
  wait = no
  user = root
  server = /usr/libexec/git-core/git-daemon
  server_args = --base-path=/project/my-project.git --export-all --user-path=root --syslog --inetd --verbose
  log_on_failure += USERID
  }
  ~
  [root@wx /]# /etc/init.d/xinetd restart
  Stopping xinetd: [FAILED]
  Starting xinetd: [ OK ]
  [root@wx /]# netstat -anlt|grep 9418
  tcp 0 0 :::9418 :::* LISTEN
1.2.4 客户端测试
  可以看到xined 结合git走的是tcp协议
  客户端测试,客户端测试的时候只需要安装git就行
  [root@wx-a /]# git clone git://20.0.0.89/my-project.git sadoc
  Initialized empty Git repository in /sadoc/.git/
  warning: You appear to have cloned an empty repository.
  将服务器的my-project.git 克隆到本地的sadoc, 不过在客户端测试的时候我发现,git clone 在那个目录下你克隆的服务器版本库就会是你当前执行git clone的目录
  在服务器端提交一些文件,在客户端进行下载一下
  [root@wx-a /]# cd sadoc/
  [root@wx-a sadoc]# git remote -v
  origin git://20.0.0.89/my-project.git (fetch)
  origin git://20.0.0.89/my-project.git (push)
  [root@wx-a sadoc]# git remote
  origin
  [root@wx-a sadoc]# ls -a
  . .. .git
  [root@wx-a sadoc]# git remote -v
  origin git://20.0.0.89/my-project.git (fetch)
  origin git://20.0.0.89/my-project.git (push)
  [root@wx-a sadoc]# touch aa
  [root@wx-a sadoc]# git add aa
  [root@wx-a sadoc]# git status
  # On branch master
  #
  # Initial commit
  #
  # Changes to be committed:
  # (use "git rm --cached ..." to unstage)
  #
  # new file: aa
  #
  [root@wx-a sadoc]# git commit -m "aa" #提交的时候提示我需要配置用户名和邮箱
  [master (root-commit) 90291de] aa
  Committer: root
  Your name and email address were configured automatically based
  on your username and hostname. Please check that they are accurate.
  You can suppress this message by setting them explicitly:
  git config --global user.name "Your Name"
  git config --global user.email you@example.com

  If the>  git commit --amend --author='Your Name '
  0 files changed, 0 insertions(+), 0 deletions(-)
  create mode 100644 aa
  参考资料:http://www.git-scm.com/book/en/v2


运维网声明 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-588435-1-1.html 上篇帖子: 学习小笔记---git 安装与使用 下篇帖子: Gitolite如何导入其它git代码库
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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