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

[经验分享] 在 Gentoo 上部署 Git + Gitosis 服务器的笔记[zt]

[复制链接]

尚未签到

发表于 2018-9-19 07:40:03 | 显示全部楼层 |阅读模式
  有备无患:在 Gentoo 上部署 Git + Gitosis 服务器的笔记
  http://luliban.com/blog/2008/05/gentoo-git-gitosis.html
  Git 是 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的分布式版本控制软件(Distributed SCM)。Git 汲取了 Torvalds 在维护大型的分布式项目开发方面的经验和对文件系统性能的丰富知识,正如其文档所描述的,“是一个快速、可扩展的分布式版本控制系统,它具有极为丰富的命令集,对内部系统提供了高级操作和完全访问。”目前,Linux 内核、X.org 服务器和 Ruby on Rails 等开源项目的版本控制系统都已经切换到 Git。
  是 Tommi Virtanen 为了更方便和安全的辅助 Git 架设和管理软件版本库 (Software Repository) 而开发的工具软件。虽然 Git 本身也提供 git-daemon 以架设版本库,但在用户访问控制上做的并不严格。而 Gitosis 允许单个用户帐号管理多个版本库,使用 SSH keys 管理用户认证,不需要 shell 帐号就可以解决多用户访问集中版本库的问题。
  需要说明的是,我使用的 Gitosis 是 robbat2 为了部署新的 Gentoo Overlays 而开发的 Gentoo 分支版本 (Gentoo Fork Version),和上游版本 (Origin Upstream Version) 相比有如下不同:

  •   支持 git+ssh://HOST/REPO 风格的相对路径;
  •   支持以命令行参数方式导入 keys,如 gitosis-init --adminkey=FILE --adminname=STRING;
  •   智能处理 SSH keys,支持 SSH1 和 SSH2 keys;
  •   将上游版本默认的目录权限 0750 更改为 0755,以便用 nobody:nobody 运行 git-daemon。
  这篇文章详细记录了我在本地安装和部署 Git + Gitosis 的过程和遇到的问题,希望为大家提供一些参考。欢迎 Fix-Me :-)
  安装 Git + Gitosis安装 git 和 gitosis-gentoo。安装完后,Gentoo 会自动添加 git 用户和组,并将版本库的主目录设为 /var/spool/gitosis/repositories。
  # echo ">=dev-util/git-1.5.5" >> /etc/portage/package.keywords# echo ">=dev-util/gitosis-gentoo-0.2_p20080203" >> /etc/portage/package.keywords# emerge -av git gitosis-gentoo
  如果你的主机上没有装 SSH 的话,还要安装 openssh, 以及 keychain 用来管理 ssh-agents(可选)。
  # emerge -av openssh keychain
  安装完后,启动 sshd,并加入默认启动。
  # /etc/init.d/sshd start# rc-update add sshd default
  配置 Gitosis首先生成一个 ssh key。
  $ ssh-keygen -t rsaGenerating public/private rsa key pair.Enter file in which to save the key (/home/wyt/.ssh/id_rsa):(回车)Created directory '/home/wyt/.ssh'.Enter passphrase (empty for no passphrase):(直接回车)Enter same passphrase again: (直接回车)Your>

  我把 ssh key 保存在默认的 ~/.ssh/id_rsa,你也可以选择其他地方。接下来把>  $ cat /etc/conf.d/hostnamehostname="gentoo"$ scp ~/.ssh/id_rsa.pub root@gentoo:Password: (输入 root 帐户密码)id_rsa.pub                                     100%  392      0.4KB/s    00:00
  上传完毕后,用 gitosis-init 初始化版本库。
  $ sudo su -# sudo -H -u git gitosis-init < ~/id_rsa.pubInitialized empty Git repository in ./Reinitialized existing Git repository in ./
  上面第二条命令中,-u 表示 sudo 将切换至 git 用户,-H 表示 sudo 将切换至该用户的主目录。初始化完成后,将创建一个名为 gitosis-admin 的版本库,用于 Gitosis 的设置和管理。你需要把它 clone 到相应目录。
  $ mkdir git$ cd git$  git clone git@gentoo:gitosis-admin.git$ cd gitosis-admin$ ls -lh-rw-r--r-- 1 wyt wyt 80 2008-05-19 00:10 gitosis.confdrwxr-xr-x 2 wyt wyt 80 2008-05-19 00:10 keydir
  gitosis-admin 目录下有一个 gitosis.conf 文件和一个 keydir 目录。gitosis.conf 用来保存项目,用户和权限等版本库配置,而 keydir 用来保存用户的 ssh key。因为 gitosis-admin 也是 Git 的版本库,所以在修改完配置之后,只需要简单的 commit & push,就可以很快很方便的更新服务器的配置了。接下来就用 Gitosis 创建新版本库和添加授权用户。
  创建新的版本库gitosis.conf 里有 gitosis-admin 的默认配置,只要依样画葫芦创建一个新版本库即可。下面举例创建 local_test 版本库,把下面这段 code 追加到 gitosis.conf。
  gitosis.conf[group localteam]writable = local_testmembers = wyt@gentoo
  这段 code 定义了新的版本库,包括开发小组的名称 &quot;localteam&quot;,版本库的名称 &quot;local_test&quot;,以及拥有写权限的小组成员 &quot;wyt@gentoo&quot;。接下来把新的版本库所配置 commit & push 到服务器上。
  $ git commit -a -m &quot;添加新的版本库 local_test&quot;$ git push
  接下来在本地创建版本库,然后将其上传到服务器
  $ mkdir local_test$ cd local_test$ git init$ git remote add origin git@gentoo:local_test.git# add & commit 一些文件,然后……$ git push origin master:refs/heads/master
  添加成员用户添加版本库的成员用户的步骤可以分为两步。一是将用户的 SSH 公钥复制到 keydir/ 目录。二是编辑 gitosis.conf,将这些用户的名字加入 &quot;members&quot;。
  $ cd gitosis-admin/$ cp ~/zhangsan@gentoo.pub keydir/$ cp ~/lisi@gentoo.pub keydir/$ git add keydir/zhangsan@gentoo.pub keydir/lisi@gentoo.pub
  编辑 gitosis.conf
  gitosis.conf[group localteam]writable = local_testmembers = wyt@gentoo zhangsan@gentoo lisi@gentoo
  接下来,将设置提交到服务器
  $ git commit -a -m '添加 local_test 版本库成员:张三、李四'$ git push
  选择需要输出的版本库
  输出所有版本库编辑 /etc/conf.d/git-daemon
  GITDAEMON_OPTS=&quot;--syslog --base-path=/var/spool/gitosis/repositories/ --export-all&quot;
  选择输出版本库编辑 /etc/conf.d/git-daemon
  GITDAEMON_OPTS=&quot;--syslog --base-path=/var/spool/gitosis/repositories/&quot;
  然后在每个选择输出的版本库目录中,添加一个 git-daemon-export-ok 文件
  $ sudo touch /var/spool/gitosis/repositories/local_test.git/git-daemon-export-ok
  启动 git-daemon# /etc/init.d/git-daemon start# rc-update add git-daemon default
  如果一切正常的话,我们应该已经大功告成,完成部署 Git + Gitosis 服务器了。现在可以试一下远程 clone。
  $ git clone git://169.254.64.95/local_test.git
  参考链接

  •   Gitosis on Gentoo @ Technical Pickles
  •   Gitosis - Gentoo Linux Wiki
  •   Hosting Git repositories, The Easy (and Secure) Way
  •   robbat2: Gitosis on Gentoo, important notes
  •   Git in a Nutshell
  2008-05-20 UPDATEclone 只读版本库:
  $ git clone git://169.254.64.95/local_test.git
  clone 可读写版本库:
  $ git clone git+ssh://git@169.254.64.95/local_test.git
  创建新的可读写版本库:
  $ git remote add origin git+ssh://git@169.254.64.95/new_local_test.git$ git push origin master:refs/heads/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-593890-1-1.html 上篇帖子: 如何在svn系统中使用git[转] 下篇帖子: Kernel Hackers' Guide to git [zt]
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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