标签:centos 6.4x64安装git和gitolite服务器
一.部署环境
系统:CentOS 6.4x64 最小化安装
IP:192.168.3.27
二.安装基础依赖包
[root@nginx ~]#yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel -y
三.下载git-2.2.0.tar.gz
[root@nginx ~]#wget https://www.kernel.org/pub/software/scm/git/git-2.2.0.tar.gz
四.解压文件到当前目录下,并安装
[root@nginx git-2.2.0]#tar xf git-2.2.0.tar.gz [root@nginx git-2.2.0]#cd git-2.2.0/ [root@nginx git-2.2.0]#make prefix=/usr/local/git all [root@nginx git-2.2.0]#make prefix=/usr/local/git install 增加软连接 [root@nginx git-2.2.0]#ln -s /usr/local/git/bin/* /usr/bin/ 验证结果,显示出版本号,表示安装成功 [root@nginx git-2.2.0]#git --version git version 2.2.0
五.创建git用户
[root@nginx ~]# useradd git
六.在git用户家目录下安装gitolite
[root@nginx ~]# su git [git@nginx root]$ cd [git@nginx ~]$ mkdir bin
七.克隆gitolite源码
[git@nginx ~]$ git clone https://github.com/sitaramc/gitolite.git Cloning into ‘gitolite‘...remote: Counting objects: 8884, done. remote: Total 8884 (delta 0), reused 0 (delta 0), pack-reused 8884Receiving objects: 100% (8884/8884), 3.66 MiB | 179.00 KiB/s, done. Resolving deltas: 100% (5055/5055), done.Checking connectivity... done. [git@nginx ~]$ ls bin gitolite
八.安装gitolite
[git@nginx ~]$ ./gitolite/install --to /home/git/bin/ [git@nginx ~]$ ls bin/ commands gitolite gitolite-shell lib syntactic-sugar triggers VERSION VREF
九.配置gitolite管理员
生成管理员账户的公钥(此处指定本地root用户为管理员,键入回车使用默认值)
[root@nginx ~]# ssh-keygen [root@nginx ~]# cp .ssh/id_rsa.pub /tmp/admin.pub 切换回git用户,为gitolite配置管理员 [git@nginx ~]$ bin/gitolite setup -pk /tmp/admin.pub Initialized empty Git repository in /home/git/repositories/gitolite-admin.git /Initialized empty Git repository in /home/git/repositories/testing.git/ WARNING: /home/git/.ssh missing; creating a new one (this is normal on a brand new install) WARNING: /home/git/.ssh/authorized_keys missing; creating a new one (this is normal on a brand new install) [git@nginx ~]$ ls bin gitolite projects.list repositories
十.管理员日常管理
[root@nginx ~]# git clone git@192.168.3.27:gitolite-admin Cloning into ‘gitolite-admin‘...The authenticity of host ‘192.168.3.27 (192.168.3.27)‘ can‘t be established. RSA key fingerprint is c4:34:02:55:ad:42:8a:65:ba:94:00:20:48:d7:3c:33. Are you sure you want to continue connecting (yes/no)? yes #这里是第一次连接,需要输入yes进行确认 Warning: Permanently added ‘192.168.3.27‘ (RSA) to the list of known hosts. remote: Counting objects: 6, done. remote: Compressing objects: 100% (4/4), done. Receiving objects: 100% (6/6), 734 bytes | 0 bytes/s, done. remote: Total 6 (delta 0), reused 0 (delta 0) Checking connectivity... done. [root@nginx gitolite-admin]# ls conf keydir [root@nginx gitolite-admin]# pwd /root/gitolite-admin
验证:
创建库、添加用户
例如某test用户访问git服务器上的mytest库
test用户向git服务器管理(此处是之前的服务器本地的root用户)提交自己的ssh无密码公钥
管理员将test的公钥复制到 gitolite-admin/keydir/ 下
注:该key需要在test用户机器上使用ssh-keygen生成,再传送到192.168.3.27/tmp目录下
[root@nginx ~]# cp /tmp/test.pub /root/gitolite-admin/keydir/
管理员创建myFirstRepo库,并给test分配权限
[root@nginx ~]# cd gitolite-admin/conf/ [root@nginx conf]# vim gitolite.conf #以下是gitolite.conf的默认内容 repo gitolite-admin RW+ = admin repo testing RW+ = @all 下边定义mytest库,并且指定用户权限: #在gitolite.conf中添加以下内容 @mygroup = test repo mytest RW+ = @mygroup 注:此处@mygroup是一个组,给mygroup组赋予对mytest这个库的读、写、推送的权限 (详细规则可参考gitolite的readme.txt)管理员将对gitolite-admin的修改(建库、加用户) 提交到git服务器 [root@nginx gitolite-admin]# pwd /root/gitolite-admin [root@nginx gitolite-admin]# git status #查看git库状态 On branch master Your branch is up-to-date with ‘origin/master‘. Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: conf/gitolite.conf #表示该文件被修改 Untracked files: (use "git add <file>..." to include in what will be committed) keydir/test.pub #增加的文件 no changes added to commit (use "git add" and/or "git commit -a") #将有改动的文件添加到git库 [root@nginx gitolite-admin]# git add keydir/test.pub conf/gitolite.conf [root@nginx gitolite-admin]# git status On branch master Your branch is up-to-date with ‘origin/master‘. Changes to be committed: (use "git reset HEAD <file>..." to unstage) modified: conf/gitolite.conf new file: keydir/test.pub #这里表示已添加#在第一次执行git commit命令时会有以下提示,需要使用者表明身份 [root@nginx gitolite-admin]# git commit -m "add repo mytest; add user test" *** 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@nginx.(none)‘) #在这里我们执行以下2条命令 [root@nginx gitolite-admin]# git config --global user.email "lyao@aaa.com" [root@nginx gitolite-admin]# git config --global user.name "lyao" #再重新执行git commit命令 [root@nginx gitolite-admin]# git commit -m "add repo mytest; add user test" [master 7b877e7] add repo mytest; add user test 2 files changed, 5 insertions(+) create mode 100644 keydir/test.pub #执行完以上命令后,修改的文件只是提交在本地了,并没有提交到git server中,还需要执行git push命令 [root@nginx gitolite-admin]# git push origin master #推送到远端的master分支 Counting objects: 6, done.Compressing objects: 100% (5/5), done. Writing objects: 100% (6/6), 817 bytes | 0 bytes/s, done. Total 6 (delta 0), reused 0 (delta 0) remote: Initialized empty Git repository in /home/git/repositories/mytest.git /To git@192.168.3.27:gitolite-admin 3554f3d..7b877e7 master -> master
客户端验证:
[root@ipython ~]# git clone git@192.168.3.27:/mytest.git Initialized empty Git repository in /root/mytest/.git/ warning: You appear to have cloned an empty repository. [root@ipython ~]# ll total 3240 drwxr-xr-x 3 root root 4096 Apr 17 14:45 mytest [root@ipython ~]# cd mytest/ [root@ipython mytest]# git status # On branch master# # Initial commit #nothing to commit (create/copy files and use "git add" to track) #创建1个文件1.txt并添加到git [root@ipython mytest]# touch 1.txt [root@ipython mytest]# git add 1.txt [root@ipython mytest]# git commit "add file 1.txt" #第一次使用需要表明身份 [root@ipython mytest]# git commit -m "add file 1.txt" [master (root-commit) 08e9a37] add file 1.txt Committer: root <root@ipython.(none)> 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 identity used for this commit is wrong, you can fix it with: git commit --amend --author=‘Your Name <you@example.com>‘ 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 1.txt [root@ipython mytest]# git config --global user.email test@aaa.com [root@ipython mytest]# git config --global user.name test [root@ipython mytest]# git commit -m "add file 1.txt" # On branch masternothing to commit (working directory clean) [root@ipython mytest]# git status # On branch masternothing to commit (working directory clean) [root@ipython mytest]# ll total 0-rw-r--r-- 1 root root 0 Apr 17 14:47 1.txt [root@ipython mytest]# git push origin master Counting objects: 3, done.Writing objects: 100% (3/3), 206 bytes, done. Total 3 (delta 0), reused 0 (delta 0)To git@192.168.3.27:/mytest.git * [new branch] master -> master
本文出自 “ly36843运维” 博客,请务必保留此出处http://ly36843.blog.51cto.com/3120113/1633884
CentOS 6.4x64安装git和gitolite服务器
标签:centos 6.4x64安装git和gitolite服务器
原文地址:http://ly36843.blog.51cto.com/3120113/1633884