git 本地仓库的初始化及多节点批量同步

需求:创建两个git本地仓库,分别位于192.168.143.202和192.168.143.210,当192.168.143.200修改配置的时候同时提交至两台git仓库中.

说明:

192.168.143.200  # 修改配置文件的主机
192.168.143.202  # git本地仓库-1
192.168.143.210  # git本地仓库-2

1.创建仓库

# 192.168.143.210
cd /opt
git init --bare nginx_conf.git

# 192.168.143.202
cd /opt
git init --bare nginx_conf.git

2.客户端clone

# 192.168.143.200
git clone 192.168.143.202:/opt/nginx_conf.git
cd nginx_conf

3.设置仓库地址

cd nginx_conf
vim .git/config

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[remote "origin"]
        url = 192.168.143.202:/opt/nginx_conf.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[remote "origin"]
        url = 192.168.143.210:/opt/nginx_conf.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master

4.添加文件提交至仓库

[root@centos7-200 nginx_conf]# echo "test1" > test1.txt
[root@centos7-200 nginx_conf]# echo "test2" > test2.txt
[root@centos7-200 nginx_conf]# echo "test3" > test3.txt
[root@centos7-200 nginx_conf]# git add -A .
[root@centos7-200 nginx_conf]# git commit -m 'wl'
[root@centos7-200 nginx_conf]# git push origin master

5.查看远程仓库

[root@centos7-200 nginx_conf]# git remote -v
origin  192.168.143.202:/opt/nginx_conf.git (fetch)
origin  192.168.143.202:/opt/nginx_conf.git (push)
origin  192.168.143.210:/opt/nginx_conf.git (push)

6.测试-删除当前工作目录重新git clone

git clone 192.168.143.210:/opt/nginx_conf.git
git clone 192.168.143.202:/opt/nginx_conf.git

7.通过在本地提交文件,并同步至三台nginx(集群or主备)

touch Makefile
下面命令可以自定义,可以通过Ansible,也可以通过shell,定义好之后执行make push即可

push:   update to nginx1/nginx2/nginx3
    ssh nginx1 "cd /usr/local/nginx/conf; git pull; /usr/local/nginx/sbin/nginx -t && /usr/local/nginx/sbin/ngnix -s reload"
    ssh nginx2 "cd /usr/local/nginx/conf; git pull; /usr/local/nginx/sbin/nginx -t && /usr/local/nginx/sbin/ngnix -s reload"
    ssh nginx3 "cd /usr/local/nginx/conf; git pull; /usr/local/nginx/sbin/nginx -t && /usr/local/nginx/sbin/ngnix -s reload"
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值