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

[经验分享] redhat搭建git服务器

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-1-14 09:09:27 | 显示全部楼层 |阅读模式
以创建puppet仓库为例搭建git服务器
一、搭建git服务器
1、在服务器安装git包

#yum install git git-daemon
2、在服务器上创建专用账号,所有用户都通过此账号访问git库。选择git作为专用账号,并为账号设置密码。(也可以在配置完git服务后,可以将git修改为只允许公钥认证,以加强安全性。)
#adduser -s /bin/bash git
#passwd git
3、初始化puppet服务端git仓库,创建/git目录,并再/git目录下创建puppet repo目录,并赋予git用户权限:
创建/git目录
#mkdir /git
创建puppet repo目录
#mkdir /git/puppet.git
创建git仓库
#cd /git/puppet.git
#git --bare init
赋予git目录git用户权限
#chown git:git -R /git

4、启动git服务,
#/usr/libexec/git-core/git-daemon --base-path=/git --detach --user=git --group=git --listen=10.240.216.250 --export-all --enable=receive-pack --enable=upload-pack --enable=upload-archive

二、降puppet加入git
1、将puppet master上的/etc/puppet目录加入仓库,作为仓库的副本。
#cd /etc/
#mv puppet /tmp
把之前搭建的puppet仓库克隆到/etc目录下并在此目录下生产一个puppet的目录
#git clone git://10.240.216.250/puppet.git
#cd /etc/puppet
#cp /tmp/puppet/*
#git add *
#git commit -m "Add puppet to git repo"
#git push -u origin master

Counting objects: 2949, done.
Delta compression using up to 16 threads.
Compressing objects: 100% (2630/2630), done.
Writing objects: 100% (2949/2949), 1.57 MiB, done.
Total 2949 (delta 611), reused 0 (delta 0)
To git://10.240.216.250/puppet.git
* [new branch]      master -> master

这样就在本地创建了一个master仓库,它包含了puppet的配置文件及清单。我们可以在不通的地方导出多个副本,提交变更之前在这些副本上的工作。列如,我们有一个系统管理员团队,他们每个人都可以在自己的电脑上创建一个副本进行修改等工作。

三、在系统管理员本地电脑上创建副本(即git客户端)
1、把puppet副本克隆到本地
root@ubuntu:# cd /tmp
root@ubuntu:/tmp#
root@ubuntu:/tmp# git clone git://10.240.216.250/puppet.git
Cloning into 'puppet'...
remote: Counting objects: 2949, done.
remote: Compressing objects: 100% (2019/2019), done.
remote: Total 2949 (delta 611), reused 2949 (delta 611)
Receiving objects: 100% (2949/2949), 1.57 MiB | 0 bytes/s, done.
Resolving deltas: 100% (611/611), done.
Checking connectivity... done.
root@ubuntu:/tmp#
root@ubuntu:/tmp# ls
puppet

2、修改想要修改的配置并提交至主分支“master”
root@ubuntu:/tmp# cd puppet

root@ubuntu:/tmp/puppet# ls
aaa  auth.conf  environments  fileserver.conf  hieradata  hiera.yaml  manifests  modules  puppet.conf
root@ubuntu:/tmp/puppet# vi manifests/site.pp
Package {

  allow_virtual => true,
}


node 'bgw-os-node1' {
    include ::openstack::role::controller_master
}

node 'bgw-os-node2' {
    include ::openstack::role::controller_standby
}
node 'bgw-os-node11' {
    include ::openstack::role::compute
}
#node 'bgw-os-node12' {                 #此处是要修改的内容,把node12节点注释掉
#    include ::openstack::role::compute
#}

node 'bgw-os-node151' {
    include ::openstack::role::ceph_mon_and_osd
}

node 'bgw-os-node152' {
    include ::openstack::role::ceph_mon_and_osd
}
node 'bgw-os-node153' {
    include ::openstack::role::ceph_mon_and_osd
}

"puppet/manifests/site.pp" 31L, 544C written                                         

root@ubuntu:/tmp# git add puppet/manifests/site.pp
fatal: Not a git repository (or any of the parent directories): .git

root@ubuntu:/tmp/puppet# git add manifests/site.pp
root@ubuntu:/tmp/puppet# git commit -m "Add site.pp"

*** 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@ubuntu.(none)')
上面出现报错,需要添加用户及用户的邮箱
root@ubuntu:/tmp/puppet# git config --global user.name "lizhanguo"
root@ubuntu:/tmp/puppet# git config --global user.email "lizhanguo@jiayuan.com"


再次提交成功
root@ubuntu:/tmp/puppet# git commit -m "Add site.pp"                           
[master 894da1e] Add site.pp
1 file changed, 3 insertions(+), 3 deletions(-)
root@ubuntu:/tmp/puppet#

把本地的内容push 到git server端
root@ubuntu:/tmp/puppet# git push
warning: push.default is unset; its implicit value has changed in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the traditional behavior, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

When push.default is set to 'matching', git will push local branches
to the remote branches that already exist with the same name.

Since Git 2.0, Git defaults to the more conservative 'simple'
behavior, which only pushes the current branch to the corresponding
remote branch that 'git pull' uses to update the current branch.

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

Counting objects: 4, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 376 bytes | 0 bytes/s, done.
Total 4 (delta 2), reused 0 (delta 0)
To git://10.240.216.250/puppet.git
   5ad9866..894da1e  master -> master
root@ubuntu:/tmp/puppet#
四、git 服务端,在puppet master的/etc/puppet目录下运行git pull,将其更新到最新版本。
[iyunv@bgw-cobbler puppet]# git pull
remote: Counting objects: 7, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 4 (delta 2), reused 0 (delta 0)
Unpacking objects: 100% (4/4), done.
From git://10.240.216.250/puppet
   5ad9866..894da1e  master     -> origin/master
Updating 5ad9866..894da1e
Fast-forward
manifests/site.pp |    6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)

查看刚才客户端的修改提交是否生效
[iyunv@bgw-cobbler puppet]# cat manifests/site.pp

Package {
  allow_virtual => true,
}


node 'bgw-os-node1' {
    include ::openstack::role::controller_master
}

node 'bgw-os-node2' {
    include ::openstack::role::controller_standby
}
node 'bgw-os-node11' {
    include ::openstack::role::compute
}
#node 'bgw-os-node12' {              #已生效
#    include ::openstack::role::compute
#}

node 'bgw-os-node151' {
    include ::openstack::role::ceph_mon_and_osd
}

node 'bgw-os-node152' {
    include ::openstack::role::ceph_mon_and_osd
}
node 'bgw-os-node153' {
    include ::openstack::role::ceph_mon_and_osd
}

2、为了保证实时更新,我们可以在cron增加定时任务以保证/etc/puppet副本的内容为每分钟更新一次。
[iyunv@bgw-cobbler ~]# crontab -e
no crontab for root - using an empty one

*/1 * * * * cd /etc/puppet ; 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-40767-1-1.html 上篇帖子: logitech x530音响 老是有一个不响 四个插孔 都没问题 喇叭也没为题 就是有一个不响 下篇帖子: Mac下github操作要点 服务器
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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