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

[经验分享] centos+git+gitolite 安装和部署

[复制链接]

尚未签到

发表于 2018-1-15 21:40:50 | 显示全部楼层 |阅读模式
  进入仓库后可以看到conf 和keydir ,conf/gitolite.conf 是添加用户/仓库的配置, keydir 是放对应用户的公想·x钥.并且此时,admin.pub这个公钥可以删除了
  7.5  编辑gitolite.conf
  

[git@bogon ~]$ vim gitolite-admin/conf/gitolite.conf  

  也可以你找下图操作:

  打开图按照下图添加:

  上面的配置含义是:
  定义两个用户组: admin 和 user
  定义两个版本库: gitolite-admin 和 project
  用户admin 对 这两个版本库有(读 写 删除)RW+ 权限
  user组对project 有 (读 写)RW 权限
  也可按照格式,添加多个组,多个版本库
  如有一个组中有多个用户,则以空格为分割,如下图:

  7.6 然后提交修改(注:修改用户或者增加版本库后在下图中的目录中提交修改,否则会提示修改失败)

  

提交修改:  

[git@bogon conf]$ git add keydir/test.pub conf/gitolite.conf[git@bogon conf]$ git add . [git@bogon conf]$ git commit -am "new project"[git@bogon conf]$ git push origin master  

# 注:所有的提交修改都是这三条命令,在客户端上提交文件也是这三个命令第二条命令后面引号中的 可以是任意,最好是能体现是做了什么修改  

  


  7.7 提交完后,查看管理仓库中多了一个project.git
  

[git@bogon ~]$ cd repositories/  
[git@bogon repositories]$
ls  
gitolite
-admin.git  project.git  

  这个时候,服务器已经搭建完毕了,只需要添加用户并给用户添加权限就可以了。下面我们添加用户测试
  7.8 权限控制
  

[iyunv@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库
  
[iyunv@nginx gitolite
-admin]# git add keydir/test.pub conf/gitolite.conf  
[iyunv@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命令时会有以下提示,需要使用者表明身份
  

  
[iyunv@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>
  
Omit --global to set the>  
fatal: unable to auto-detect email address (got 'root@nginx.(none)')
  

  
#在这里我们执行以下2条命令
  
[iyunv@nginx gitolite-admin]# git config --global user.email "lyao@aaa.com"
  
[iyunv@nginx gitolite-admin]# git config --global user.name "lyao"
  

  
#再重新执行git commit命令
  
[iyunv@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命令
  
[iyunv@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 -> maste
  

  八、客户端验证
  8.1 centos客户端验证
  

[iyunv@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.
  
[iyunv@ipython
~]# ll  
total
3240  
drwxr
-xr-x 3 root root    4096 Apr 17 14:45 mytest  
[iyunv@ipython
~]# cd mytest/  
[iyunv@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
  
[iyunv@ipython mytest]#
touch 1.txt  
[iyunv@ipython mytest]# git add
1.txt  
[iyunv@ipython mytest]# git commit
"add file 1.txt"  

  
#第一次使用需要表明身份
  
[iyunv@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>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
  

  
[iyunv@ipython mytest]# git config --global user.email test@aaa.com
  
[iyunv@ipython mytest]# git config --global user.name test
  

  
[iyunv@ipython mytest]# git commit -m "add file 1.txt"
  
# On branch masternothing to commit (working directory clean)
  

  
[iyunv@ipython mytest]# git status
  
# On branch masternothing to commit (working directory clean)
  

  
[iyunv@ipython mytest]# ll
  
total 0-rw-r--r-- 1 root root 0 Apr 17 14:47 1.txt
  

  
[iyunv@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
  

  8.2 windows客户端验证
  1)在客户机上安装安正的git程序,在D盘新建一个文件夹 test ,右键选择Git Bash

  2)打开一个DOS栏,输入 ssh-keygen.exe。这里可以用Tab键补全,然后有提示输入y后一直回车到结束

  3)然后打开客户机用户目录下的 .ssh 中能看到id_rsa 私钥

  4)然后把id_rsa 这个私钥文件上传到服务器的/home/git/gitolite-admin/keydir 目录中

  5)然后把这个新传上来的私钥改名

[git@bogon conf]$ vi gitolite.conf


  这里表示test用户对project.git 版本库有读写的权限。也可以直接在版本库下面添加用户权限
  6)提交修改
  

[git@bogon conf]$ git add .  
[git@bogon conf]$ git commit
-am "new project"  
[git@bogon conf]$ git push origin master
  

  7)回客户端
  打开Bash 窗口,输入
  git clone git@192.168.52.131:project.git
  链接服务器中的project.git 版本库,其中IP地址是自己服务器的IP地址,冒号后面需要访问也是刚刚给该用户有权限访问的版本库
  然后会同步下来一个文件夹名为project 的文件,这个就是版本库,打开这个文件夹,创建一个任意文件
  在客户机上提交修改文件:
  打开project文件夹,创建一个任意文件,然后打开Bash 窗口,输入提交修改命令
[git@bogon conf]$ git add .

[git@bogon conf]$ git commit -am "new project"

[git@bogon conf]$ git push origin master

  这样,修改过的数据就上传到服务器上去了,其他用户同样可以同步下来
  从服务器上往别的客户机上同步更改后的版本库的命令是:
  git pull

运维网声明 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-435482-1-1.html 上篇帖子: git 基本命令介绍 下篇帖子: 使用Gitolite来对Git的repository实现权限控制
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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