怎样在Ubuntu 14.04中搭建gitolite 搭建自己的git服务器器

博客访问: 543935
博文数量: 125
博客积分: 3160
博客等级: 少校
技术积分: 1801
注册时间:
认证徽章:
IT168企业级官微
微信号:IT168qiye
系统架构师大会
微信号:SACC2013
原文地址: 作者:
先概述一下,你手上有一台全新的 Ubuntu Server,参照本文会安装下列内容:  1、Git(这是肯定的)  2、Gitolite(用于Git服务器管理,简介参见附注2)  3、Gitdaemon(守护进程,开放一个公共的 git clone 服务,可选)  4、Gitweb(提供像Github一样的Web服务,通过浏览器查看版本库记录,可选)下面就开始动手吧。一、安装 Git安装 Git 和 Git Doc:sudo apt-get install git-core git-doc设置用户信息:git config --global user.name "Your Name"
git config --global user.email 二、安装 GitoliteGitolite 使用SSH进行访问控制。首先将本机的SSH公钥(生成方法参见附注3:ssh-keygen)放到服务器上:# FROM YOUR LOCAL MACHINE
scp ~/.ssh/id_rsa.pub git.server:/tmp/your-username-goes-here.pub创建 gitolite 用户组和 gitolite 用户sudo addgroup gitolite
sudo adduser --disabled-password --home /home/gitolite --ingroup gitolite gitolite安装 Gitolite:sudo apt-get -y install gitolite添加权限以便 gitweb 能够读取版本库内容:sudo usermod -a -G gitolite www-data重启apache服务:sudo service apache2 restart执行Gitolite安装:sudo su - gitolite
gl-setup /tmp/your-username-goes-here.pub安装过程中会询问你是否修改配置文件,这时候可以修改一下权限以便 git-web 和 git-daemon 能够读取新建的版本库:将&$REPO_UMASK = 0077;&修改为&$REPO_UMASK = 0027;如果出于某种原因在安装过程中你没能修改&.gitolite.rc&文件,可以按如下方式编辑:emacs /home/gitolite/.gitolite.rc
# 将 $REPO_UMASK = 0077; 改为 $REPO_UMASK = 0027;
chmod g+r /home/gitolite/projects.list
chmod -R g+rx /home/gitolite/repositories退出 gitolite 账户:exit搞定!服务器端的工作已经完成了。三、通过 Gitolite 管理 Git 服务器现在你应该已经可以将安装脚本创建的&gitolite-admin&版本库克隆到你的本机了:# FROM YOUR LOCAL MACHINE
git clone gitolite@git.server:gitolite-admin.git编辑&gitolite.conf&文件,创建一个名为 testing 的版本库,并且允许 git-web 和 git-daemon 的访问:# FROM YOUR LOCAL MACHINE
cd gitolite-admin
emacs conf/gitolite.conf
# change to:
testing "Owner" = "Test repo"提交并推送至服务器。git add conf/gitolite.conf
git commit -m "Enabled gitweb and git-daemon export for testing repo"
cd ..在本机Clone出testing版本库并添加个文件看看:git clone gitolite@git.server:testing.git
cd testing
echo "README" & README
git add README
git commit -m "Added README"
git push origin master四、配置 Git-Daemongit-daemon 使你可以开放一个公共的git服务,任何人都无需帐号直接使用 git clone 命令克隆版本库到本地。无需此功能的话,本步骤可以跳过。安装 git-daemon:sudo apt-get install git-daemon-run修改服务配置以便 git-daemon 能够以gitolite用户组的身份运行(gitolite用户组对版本库拥有读权限)sudo emacs /etc/sv/git-daemon/run将#!/bin/sh
echo 'git-daemon starting.'
exec chpst -ugitdaemon \
"$(git --exec-path)"/git-daemon --verbose --base-path=/var/cache /var/cache/git修改为:#!/bin/sh
echo 'git-daemon starting.'
exec chpst &strong&-ugitdaemon:gitolite&/strong& \
"$(git --exec-path)"/git-daemon --verbose &strong&--base-path=/home/gitolite/repositories /home/gitolite/repositories&/strong&重启 git-daemon 服务:sudo sv restart git-daemon搞定。现在你可以试试用下面的命令来克隆版本库了:git clone git://git.server/testing.git五、配置 Git-webgit-web 允许你使用Web界面查看版本库,此步骤也是可选的。安装 git-web:sudo apt-get install highlight gitweb修改 git-web 配置:sudo emacs /etc/gitweb.conf
# change $projectroot to /home/gitolite/repositories
# change $projects_list to /home/gitolite/projects.list现在你可以到 http://git-server/gitweb 在线查看版本库了。还可以做一些增强配置,比如在 /etc/gitweb.conf 中开启 pretty url:sudo emacs /etc/gitweb.conf添加下列内容:# Enable PATH_INFO so the server can produce URLs of the
# form: http://git.cdwilson.us/project.git/xxx/xxx
# This allows for pretty URLs *within* the Git repository, where
# my Apache rewrite rules are not active.
$feature{'pathinfo'}{'default'} = [1];还有更多:$projects_list_description_width = 100;
# Enable blame, pickaxe search, snapshop, search, and grep
# support, but still allow individual projects to turn them off.
# These are features that users can use to interact with your Git trees. They
# consume some CPU whenever a user uses them, so you can turn them off if you
# need to. Note that the 'override' option means that you can override the
# setting on a per-repository basis.
$feature{'blame'}{'default'} = [1];
$feature{'blame'}{'override'} = 1;
$feature{'pickaxe'}{'default'} = [1];
$feature{'pickaxe'}{'override'} = 1;
$feature{'snapshot'}{'default'} = [1];
$feature{'snapshot'}{'override'} = 1;
$feature{'search'}{'default'} = [1];
$feature{'grep'}{'default'} = [1];
$feature{'grep'}{'override'} = 1;
$feature{'show-sizes'}{'default'} = [1];
$feature{'show-sizes'}{'override'} = 1;
$feature{'avatar'}{'default'} = ['gravatar'];
$feature{'avatar'}{'override'} = 1;
$feature{'highlight'}{'default'} = [1];
$feature{'highlight'}{'override'} = 1;六、添加用户用户生成公钥(参见附注3)发送给Git管理员(也就是你)把这个公钥放到 gitolite-admin/keypair 目录下,记得名字改为 account-name.pub,并且修改 conf/gitolite.conf 添加此用户(例如,到developer用户组里):@developer root, account-name最后别忘了 push 到服务器。gitolite.conf 的书写规则参见文档:添加完之后此用户就可以用 git clone gitolite@host:repo-name 来克隆版本库到本地,pull 以及 push了。附注:参考资料:http://computercamp.cdwilson.us/git-gitolite-git-daemon-gitweb-setup-on-ubunt/gitolite/master-toc.html//adding-users-to-gitolite/Gitolite的管理思路是完全Git化的。服务器上有一个名为“gitolite-admin”的repo,存储Git服务配置,你只要克隆到本机,修改并push,服务器端会自动完成配置更新。大多数管理任务都无需登录服务器,可以直接在本机搞定。如何生成SSH公钥:打开GitBash,执行 ssh-keygen 然后一直回车(三次)即可,最后得到结果:Your identification has been saved in /c/Users/xwjin/.ssh/id_rsa.
Your public key has been saved in /c/Users/xwjin/.ssh/id_rsa.pub.
The key fingerprint is:
ef:76:60:21:af:58:0b:16:a5:21:83:a5:c6:d3:1e:1b xwjin@XWJIN-PC得到的 id_rsa.pub 就是本机的公钥了。
阅读(14419) | 评论(1) | 转发(0) |
相关热门文章
给主人留下些什么吧!~~
请登录后评论。Windows上使用Cygwin和Gitolite搭建Git服务器
安装Cygwin
打开setup.exe, 选择Install from Internet
选择安装Cygwin到C:\cygwin
选择存储下载文件的目录为C:\
选择下载站点的镜像
选择安装以下软件包:
Net | openssh (不要选成openssl)
Devel | git
Devel | git-completion
Devel | git-gui
Devel | git-svn (如果需要同时提交到svn)
Devel | gitk
Editors | vim
集成Cygwin和Windows
打开C:\cygwin\Cygwin.bat
$ bin/cyglsa-config
Warning: Registering the Cygwin LSA authentication package requires administrator privileges! You also have to reboot the machine to activate the change.
Are you sure you want to continue? (yes/no)
重启Windows
搭建SSH服务器
打开C:\cygwin\Cygwin.bat
$ ssh-host-config
*** Info: Generating /etc/ssh_host_key
*** Info: Generating /etc/ssh_host_rsa_key
*** Info: Generating /etc/ssh_host_dsa_key
*** Info: Generating /etc/ssh_host_ecdsa_key
*** Info: Creating default /etc/ssh_config file
*** Info: Creating default /etc/sshd_config file
*** Info: Privilege separation is set to yes by default since OpenSSH 3.3.
*** Info: However, this requires a non-privileged account called 'sshd'.
*** Info: For more info on privilege separation read /usr/share/doc/openssh/README.privsep.
*** Query: Should privilege separation be used? (yes/no)
*** Info: Note that creating a new user requires that the current account have
*** Info: Administrator privileges. Should this script attempt to create a
*** Query: new local account 'sshd'? (yes/no)
*** Info: Updating /etc/sshd_config file
*** Info: Added ssh to C:\WINDOWS\system32\driversc\services
*** Warning: The following functions require administrator privileges!
*** Query: Do you want to install sshd as a service?
*** Query: (Say "no" if it is already installed as a service) (yes/no)
*** Query: Enter the value of CYGWIN for the daemon: []
*** Info: The sshd service has been installed under the LocalSystem
*** Info: account (also known as SYSTEM). To start the service now, call
*** Info: `net start sshd' or `cygrunsrv -S sshd'. Otherwise, it
*** Info: will start automatically after the next reboot.
*** Info: Host configuration finished. Have fun!
配置结束,确认端口22可用。启动服务:sc start sshd
允许SSH客户端访问
创建一个名为git的用户,设置密码,并确保密码不会过期。
在Cygwin Bash中,执行命令: mkpasswd -l -u git && /etc/passwd
验证下SSH登录
打开Cygwin Bash
$ ssh git@10.0.2.15
Administrator@china-fe1bdcde5 ~
$ ssh git@10.0.2.15
The authenticity of host '10.0.2.15 (10.0.2.15)' can't be established.
ECDSA key fingerprint is 5d:a6:81:98:43:fa:5a:f6:df:ba:18:b9:a0:76:87:f8.Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.2.15' (ECDSA) to the list of known hosts.git@10.0.2.15's password:
Could not chdir to home directory /home/git: No such file or directory
Copying skeleton files.
These files are for the users to personalise their cygwin experience.
They will never be overwritten nor automatically updated.
`./.bashrc' -& `/home/git//.bashrc'
`./.bash_profile' -& `/home/git//.bash_profile'
`./.inputrc' -& `/home/git//.inputrc'
`./.profile' -& `/home/git//.profile'git@china-fe1bdcde5 ~
以git用户登录成功
创建SSH密钥, 并使能够通过SSH identity以git用户登录SSH服务器
打开Cygwin Bash
$ ssh-keygen -t rsa (所有输入都为空,即使用默认配置,密码为空)
$ ssh-keygen -t rsa
Generating public/private rsa key pair.Enter file in which to save the key (/home/Administrator/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/Administrator/.ssh/id_rsa.
Your public key has been saved in /home/Administrator/.ssh/id_rsa.pub.
The key fingerprint is:
6a:02:9f:42:99:7c:fe:52:e7:a9:fe:1b:15:1e:70:31 Administrator@china-fe1bdcde5
The key's randomart image is:
+--[ RSA 2048]----+
| . o . o |
| * . S o |
| . = ..... |
| . =.oo.. |
| ..+ o. |
+-----------------+
$ ssh-copy-id git@10.0.2.15 (输入git用户密码)
$ ssh-copy-id git@10.0.2.15git@10.0.2.15's password:
Now try logging into the machine, with "ssh 'git@10.0.2.15'", and check in:
~/.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
验证下,以git用户登录:ssh git@10.0.2.15
$ ssh git@10.0.2.15
Last login: Sat Jun 11 23:06:14 2011 from china-fe1bdcde5
git@china-fe1bdcde5 ~
不需要输入密码,即登录成功
打开Cygwin Bash
$ git clone git:///sitaramc/gitolite.git
$ cd gitolite/src/
$ ./gl-easy-install git 10.0.2.15 alec (可以单独执行gl-easy-install查看各个参数的意义)
根据安装向导一步步完成配置(其中需要配置alec的密码,生成SSH密钥)
当走到需要编辑配置文件(用vim编辑)的时候,在开头插入:$ENV{PATH} = "/usr/local/bin:/bin:/usr/bin";,保存并退出(:wq) 如:
# configuration variables for gitolite$ENV{PATH} = "/usr/local/bin:/bin:/usr/bin";
# PLEASE READ THE DOCUMENTATION BEFORE EDITING OR ASKING QUESTIONS
# ( /sitaramc/gitolite/blob/pu/doc/gitolite.rc.mkd )
# ( or /gitolite/doc/gitolite.rc.html )
# this file is in perl syntax. However, you do NOT need to know perl to edit
# it should be fairly self-explanatory and easy to maintain
继续完成安装。当完成安装之后,可以在当前用户的home目录下面看到gitolite-admin目录。
$ cd ~/gitolite-admin
$ git status
Administrator@china-fe1bdcde5 ~/gitolite-admin
$ git status
# On branch master
nothing to commit (working directory clean)
到此整个git server已经安装结束,可以参考来配置:添加user和repository
snowdream86下次自动登录
现在的位置:
& 综合 & 正文
通过gitolite架设git仓库
git客户端用得很多了,但是从来都没有也不需要自己搭建服务器建立仓库。最近,由于公司某些项目出现了及其混乱的现象,版本上的分叉管理失调甚至导致了厂线停产半天的大状况。还好现在的公司做的是方案,万一整错了软件版本大不了重烧一遍多浪费点人力物力就罢了,但是回想起以前做SOC的公司(GX),如果按照这种版本管理的成熟度来做RTL管理,估计早就挂了。虽然以前的GX用的是cvs,现在公司用的是git,但是我始终认为,工具不是最重要的,项目管理人员的版本管理意识和版本管理能力才是最重要的。因此,在领导的默认下,自己开始搭建git仓库,在公,以争取下一个产品系列不会出现当前的状况,在私,也当是练练手,毕竟算是IT民工出身,好歹要动一点版本管理的东西吧,所以,最终有没有用到我搭的东西并不是关键,关键是我能从中学到东西,并且会思考怎样才能做得更好。所以,我也不会对git的各种深入的原理加以研究,只是拿来主义,以实用性为主。
一. 任务:
以一台linux电脑(i5,ubuntu 12.04)为服务器,创建仓库seu_ccplayer,创建组media, 组成员包括litong, gavin,i5_admin,对仓库均有读写,创建分支等权限。
二. 实践:
采用 ssh + gitolite架设服务器。整个过程可分为3步,第一,安装gitolite;第二,生成一个管理整个服务器所有git的git仓库gitolite-admin,由用户 i5_admin在客户端进行管理上传控制,i5_admin通过这个仓库控制其他仓库的创建删除,以及权限设置等。第三,创建seu_ccplayer仓库,添加用户组,用户,测试。
2.1 安装gitolite
2.1.1 服务器的动作
服务器要做两件事。第一件事,创建服务器端的git专用用户(帐号),所有用户都通过此帐号访问git库。要注意的是,客户端用这个帐号通过ssh登录服务端的时候,是得不到shell的使用权的,用ssh git@server的时候会报错:PTY allocation request failed on channel 0,报错现象和 ssh 是一样的。服务器要做的第二件事,是安装gitolite。
第一件事,创建专用账户,常用user name 为git:
sudo adduser --system --shell /bin/bash --group git
设置密码:
sudo passwd git
建议git搭建完毕后取消密码,但是我偷懒,就没有取消了。
第二件事,安装gitolite:
git clone git:///ossxp-com/gitolite.git
//从github上下载源码
mkdir -p $HOME/bin $HOME/share/gitolite/conf
$HOME/share/gitolite/hooks
// 建立命令,conf,和hooks目录
cd gitolite/src
gl-system-install $HOME/bin $HOME/share/gitolite/conf $HOME/share/gitolite/hooks
把export PATH=/home/git/bin:$PATH写入到bash.rc里
gl-setup ../ssh_pub/i5_admin.pub// 这个pub文件,是由用户 i5_admin在客户端通过ssh-keygen -f ~/.ssh/i5_admin生成的pub文件,传到服务器端,这样i5_admin就成为了git的管理用户了。
2.1.2 客户端的动作
首先,需要先生成一个admin的公钥/私钥:
ssh-keygen -f ~/.ssh/i5_admin
这样在客户端~/.ssh/ 生成了一个i5_admin.pub 和一个i5_admin, 把i5_admin.pub传到服务器端,服务器端用gl-setup来装gitolite。当服务器端完成以上安装后,客户端克隆git的管理库, 首先使用ssh别名,创建或打开编辑~/.ssh/config, 添加下几行:
host gitolite
hostname 192.168.123.173
identityfile ~/.ssh/i5_admin
然后克隆管理库:
git clone gitolite:gitolite-admin
就能克隆一个库gitolite-admin下来,这个库是用来管理服务器端上所有的其他git库和所有人的权限的。
2.2 增加git库和用户
2.2.1 关于git管理库
在客户端clone下来的gitolite-admin,先看一下里面的文件和结构,有两个目录,文件简析如下:
gitolite-admin/conf/gitolite.conf:这个文件记录了所有的git仓库的状况。在安装初始,就建立了两个repo,一个是gitolite-admin, i5_admin具备所有读写创建权限,另外一个是testing, 所有用户具有读写创建权限。
gitolite-admin/keydir/: 这个目录下记录了所有用户的pub公钥。
因此,要增加用户,把用户的公钥添加到gitolite-admin/keydir/下;要增加仓库或者修改用户对每个仓库的权限,修改gitolite-admin/conf/gitolite.conf 文件;然后把这些修改,先commit到本地仓库,再push到服务器端,便完成修改。
2.2.2 增加用户
首先,新增用户通过ssh-keygen生成公钥,例如 litong.pub, 传给管理员客户端(i5_admin)的gitolite-admin/keydir/目录下,然后通过
git commit -m "add user litong"
git push origin master
来把用户的pub上传到服务器端。
这时,我们查看一下服务器端git用户主目录下的.ssh/authorized_keys文件,会发现新增的用户公钥也附加在其中:
command="/home/git/bin/gl-auth-command litong",no-port-for......
修改gitolite-admin/conf/gitolite.conf,增加仓库及用户权限:
@media = i5_media i5_admin litong
seu_ccplayer
再把这个文件commit, push到服务器端,则在服务器端增加了仓库seu_ccplayer,也创建了组media,用户有i5_media, i5_admin litong,然后组media对仓库seu_ccplayer有读写创建分支等等权限。
这里补充一点,git的版本库都位于服务器端用户目录下的repositories目录下,这是由.gitolite.rc决定的。
另外,关于授权的各种细节,可以参看《git权威指南》,这里抄一下里面的一个例子,呵呵呵:
@admin = jiangxin
@dev = dev1 dev2 badboy jiangxin
@test = test1 test2
repo testing
//组test 具有只读权限
- = badboy
//禁用指令,让用户badboy只对版本库具有读操作的权限
RW = @dev test1
//组dev, 用户test1对仓库有读写权限
RW+ = @admin
//组admin具有读写权限,并且允许强行推送
总结下来,各用户的权限如下:
test1:具有读写权限
jiangxin: 具有读写权限,并且能强行推送
badboy: 只对版本有读操作,这个要留意。
三. 总结 & 疑问
虽然个人觉得,git在使用方面比svn, cvs要繁琐,因为我作为git的仓库管理者,不能直接在服务器端看到每个仓库的文件目录,总是要通过管理者(i5_admin)在客户端管理一个管理git的git,有点麻烦,而且各种授权也不是太习惯,不过,也没办法了,既然它能被广泛使用那总是要有道理的。下一步,要试一下做各种分支和恢复功能,要在这个星期内试验搞定,不然下一个project马上就要来了,再不搞搞好我就会陷入下一个漩涡之中了。嗯,加油加油~~~~~
&&&&推荐文章:
【上篇】【下篇】资料评价:
所需积分:2怎样在Ubuntu 14.04中搭建gitolite git服务器【redhat吧】_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:6,236贴子:
怎样在Ubuntu 14.04中搭建gitolite git服务器收藏
各位大神,怎样在Ubuntu 14.04中搭建gitolite git服务器?
1、首先这里安装openssh-server openssh-client,如果用的是VPS之类的一般都默认安装好了,不过运行一个这个命令不会有错的,如果有安装就会提示已安装。sudo apt-get -y install openssh-server openssh-client2、安装git,这个核心软件,不可或缺。sudo apt-get -y install git3、添加gitolite用户和同名用户组,加上--system参数,用户就不会在登陆界面显示。sudo adduser --system --shell /bin/sh --group --disabled-password --home /home/gitolite gitolite4、生成ssh key,一路回车下来。ssh-keygen -t rsa5、将当前用户的ssh pub key复制到/tmp下备用。cp ~/.ssh/id_rsa.pub /tmp/ubuntugege.pub如果你是ssh远程登陆到服务器上安装,就要把本地的key复制到远程的机器上scp ~/.ssh/id_rsa.pub gitolite.server:/tmp/ubuntugege.pub6、安装gitolite,在ubuntu中已经集成了,不用自己去下载。sudo apt-get -y install gitolite7、切换到gitolite用户环境中,因为我要以gitolite用户身份去初始化安装。sudo su - gitolite8、执行初始化安装gitolite。gl-setup /tmp/ubuntugege.pub9、把管理库gitolite-admin克隆过来就可以开始gitolite用户及代码库的管理了,如果不能克隆,那么就说明初始化的ssh pub key错了,如下就是成功了。git clone ssh://gitolite@localhost/gitolite-admin.git需要解决更多linux问题,详情请看
可以仔细看看21章的讲解,相信你可以触类旁通地需要解决更多linux问题,详情请看
登录百度帐号推荐应用

我要回帖

更多关于 git服务器搭建 的文章

 

随机推荐