一度git版本利用tag上线

####################git部分###############

脚本

#!/bin/bash

#630manage的pull代码方法

git  --git-dir=630manage/.git--work-tree=630manage clean -dfx

git  --git-dir=630manage/.git--work-tree=manage reset --hard

git  --git-dir=630manage/.git checkout master

git  --git-dir=630manage/.git pull

read -p "Tag Name:" tag

##630manage项目tag pull最新代码

git  --git-dir=630manage/.git checkouttags/$tag

git  --git-dir=630manage/.git--work-tree=manage reset --hard

git  --git-dir=630manage/.git pull

#################saltstack远程执行平台########################

前期准备:

区级saltstack服务器设置:

yum installhttp://mirrors.sohu.com/fedora-epel/7/x86_64/e/epel-release-7-10.noarch.rpm -y

yum install salt-master -y

#防火墙设置

systemctl stop firewalld.service

systemctl disable firewalld.service

yum install iptables-services -y

systemctl enable iptables.service

systemctl restart iptables.service(暂不启动)

vim /etc/sysconfig/iptables

-A INPUT -p tcp -m state --state NEW -m tcp --dport 4505-j ACCEPT

-A INPUT -p tcp -m state --state NEW -m tcp --dport 4506-j ACCEPT

#saltmaster配置

sed -i 's/#hash_type: md5/hash_type: sha256/g'/etc/salt/master

sed -i 's/#auto_accept: False/auto_accept: True/g'/etc/salt/master

sed -i 's/#file_recv: False/file_recv: True/g'/etc/salt/master

sed -i 's/#file_recv: 100/ffile_recv_max_size: 500/g'/etc/salt/master

分组设置:

nodegroups:

demo:  'L@hdkt-csrzxxx'

p-server:  'L@hdkt-

h5-server:  'L@hdkt-csrzxxx'

chehji-server:  'L@hdkt-csrzxxx'

old-server: 'L@hdkt-tjhsz'

#salt-master启动

systemctl enable salt-master.service

systemctl start salt-master.service

systemctl status salt-master.service

更改完配置需重启生效

客户端设置:

yum installhttps://repo.saltstack.com/yum/redhat/salt-repo-latest-1.el7.noarch.rpm-y

yum install salt-minion -y

#minion配置

sed -i 's/#master:salt/master:10.144.115.37/g' /etc/salt/minion

sed -i 's/#id:/id:test-47-93-139-124/g' /etc/salt/minion

sed -i 's/#id:/id:yd-p1-47-93-139-27/g' /etc/salt/minion

sed -i 's/#id:/id:yd-p2-47-95-34-83/g' /etc/salt/minion

启动salt-minion

#salt-minion启动

systemctl enablesalt-minion.service

systemctl startsalt-minion.service

systemctl statussalt-minion.service

测试:

salt '*' test.ping

salt -N  'demo'  test.ping

salt -N  'p-server'  test.ping

salt -N 'h5-server' test.ping

salt -N 'cheji-server' test.ping

salt -N 'old-server' test.ping

###################备份执行

sh /mnt/gittag.sh

srv/salt/beifen/demobak.sh

salt -N  'demo' cmd.scriptsalt://beifen/demo_back.sh

salt -N  'demo' cmd.scriptsalt://rsync/demo_rsync.sh

salt -N  'demo' cmd.script salt://rsync/h5_rsync.sh

#136发布

salt  '136' cmd.script salt://beifen/p136bak.sh

salt '136' cmd.script salt://rsync/p136_rsync.sh

#110车机发布

sh /mnt/gittag1.sh

salt  '110' cmd.script salt://beifen/cheji110bak.sh

salt  '110'  cmd.scriptsalt://rsync/cheji110_rsync.sh

#p端集群发布

salt -N  'p-server' cmd.script salt://beifen/pbak.sh

salt -N  'p-server' cmd.scriptsalt://rsync/p_rsync.sh

#h5集群发布

salt -N  'h5-server' cmd.scriptsalt://beifen/h5bak.sh

salt -N  'h5-server' cmd.scriptsalt://rsync/h5_rsync.sh

#cehji集群发布

salt -N  'cheji-server' cmd.scriptsalt://beifen/chejibak.sh

salt -N  'cheji-server' cmd.scriptsalt://rsync/cheji_rsync.sh

########################rsync部分#######################

服务器:192.168.3.21

客户端:192.168.3.22

192.168.3.23

服务器部署192.168.3.21

yum -y install rsync xinetd

配置文件

vi /etc/rsyncd.conf

uid =root

gid =root

usechroot = no

maxconnections = 4

strictmodes = yes

port= 873

#module名字和路径

[svnbackup]

path= /usr/local/svndata/

commet= This is SVN Data

ignoreerrors

readonly = yes

list= no

#authusers = test

secretsfile = /etc/rsync.pas

hostsallow = 192.168.3.22,192.168.3.23

hostsdeny =0.0.0.0/0

pidfile = /var/run/rsyncd.pid

lockfile =/var/run/rsync.lock

logfile = /var/log/rsyncd.log

################密码

vi /etc/rsync.pas

pas创建密码文件

svntrasfer:123456

chownroot.root /etc/rsync.pas

#chmod600 /etc/rsync.pas

vi /etc/rsyncd.motd

Welcometo use the rsync services!

##############xinetd服务配置

vim/etc/rc.local

/usr/bin/rsync--daemon --config=/etc/rsyncd.conf

servicexinetdrestart

/usr/bin/rsync--daemon --config=/etc/rsyncd.conf

###检测端口

lsof -i:873

#########################################################################

客户端(192.168.3.22,192.168.3.23):

yum -y install rsync

vi/etc/rsync.pas

123456

chownroot.root /etc/rsync.pas

chmod600 /etc/rsync.pas

客户端测试同步:

/test/svndata/

rsync -vzrtopg--progress svntransfer@192.168.3.21::svnbackup /test/svndata/--password-file=/etc/rsyncd.pas

手动检测客户端是否把服务器文件同步过来

排除设置

vim /mnt/rsync/excludes

2

4

5

--log-file=/mnt/rsync/yii_sync.log--exclude-from /mnt/rsync/excludes

rsync -vzrtopg--progress --exclude-from /mnt/rsync/excludessvntransfer@192.168.3.21::svnbackup /test/svndata/--password-file=/etc/rsyncd.pas

--------------------------------------------------------------

线上测试(p端)

rsync -vzrtopg--progress --exclude-from /mnt/rsync/excludes svntransfer@10.144.115.37::svnbackup/mnt/630manage --password-file=/etc/rsyncd.pas

vim/mnt/rsync/excludes

main-local.php

main.php

params-local.php

.git

runtime

backend/web/index.php

线上测试(app)

rsync -vzrtopg--progress --exclude-from /mnt/rsync/yii_excludes svntransfer@10.144.115.37::svnbackup/mnt/yii/630manage/ --password-file=/etc/rsyncd.pas

vim/mnt/rsync/yii_excludes

.git

common/config/main-local.php

common/config/main.php

frontend/config/main-local.php

frontend/config/main.php

coreapi/config/params-local.php

coreapi/config/main-local.php

coreapi/config/main.php

runtime/*

console/config/main.php

common/config/params-local.php

vendor/swiftmailer

#####################实时同步部分后续####################

二、安装sersync工具,实时触发rsync进行同步

1、查看服务器内核是否支持inotify

ll /proc/sys/fs/inotify  #列出文件目录,出现下面的内容,说明服务器内核支持inotify

-rw-r--r-- 1 root root 0 Mar 7 02:17max_queued_events

-rw-r--r-- 1 root root 0 Mar 7 02:17max_user_instances

-rw-r--r-- 1 root root 0 Mar 7 02:17max_user_watches

备注:Linux下支持inotify的内核最小为2.6.13,可以输入命令:#uname -a查看内核

CentOS 7.0内核为3.10.0,默认已经支持inotify

2、修改inotify默认参数(inotify默认内核参数值太小)

查看系统默认参数值:

sysctl -a | grep max_queued_events

结果是:fs.inotify.max_queued_events= 16384

sysctl -a | grep max_user_watches

结果是:fs.inotify.max_user_watches= 8192

sysctl -a | grep max_user_instances

结果是:fs.inotify.max_user_instances= 128

修改参数:

#sysctl-wfs.inotify.max_queued_events="99999999"

#sysctl -wfs.inotify.max_user_watches="99999999"

#sysctl-wfs.inotify.max_user_instances="65535"

#vi /etc/sysctl.conf#添加以下代码

fs.inotify.max_queued_events=99999999

fs.inotify.max_user_watches=99999999

fs.inotify.max_user_instances=65535

:wq!#保存退出

参数说明:

max_queued_events:

inotify队列最大长度,如果值太小,会出现"** Event QueueOverflow **"错误,导致监控文件不准确

max_user_watches:

要同步的文件包含多少目录,可以用:find /home/Sync-type d| wc -l 统计,必须保证max_user_watches值大于统计结果(这里/home/Sync为同步文件目录)

max_user_instances:

每个用户创建inotify实例最大值

3、安装sersync

sersync下载地址:https://sersync.googlecode.com/files/sersync2.5.4_64bit_binary_stable_final.tar.gz

上传sersync2.5.4_64bit_binary_stable_final.tar.gz到/usr/local/src目录下

#cd /usr/local/src

#tarzxvfsersync2.5.4_64bit_binary_stable_final.tar.gz #解压

#mv GNU-Linux-x86 /usr/local/sersync #移动目录到/usr/local/sersync

4、配置sersync

#cd /usr/local/sersync#进入sersync安装目录

#cp confxml.xml confxml.xml-bak #备份原文件

#vi confxml.xml #编辑,修改下面的代码

<?xmlversion="1.0"encoding="ISO-8859-1"?>

<headversion="2.5">

<host hostip="localhost"port="8008"></host>

<debugstart="false"/>

<fileSystemxfs="false"/>

<filterstart="false">

<excludeexpression="(.*)\.svn"></exclude>

<excludeexpression="(.*)\.gz"></exclude>

<excludeexpression="^info/*"></exclude>

<excludeexpression="^static/*"></exclude>

</filter>

<inotify>

<deletestart="true"/>

<createFolderstart="true"/>

<createFilestart="false"/>

<closeWritestart="true"/>

<moveFromstart="true"/>

<moveTostart="true"/>

<attribstart="false"/>

<modifystart="false"/>

</inotify>

<sersync>

<localpath watch="/home/Sync">

<remote ip="192.168.3.21" name="Sync"/>

<!--<remoteip="192.168.8.40"name="tongbu"/>-->

<!--<remoteip="192.168.8.40"name="tongbu"/>-->

</localpath>

<rsync>

<commonParams params="-artuz"/>

<auth start="true" users="Sync"passwordfile="/etc/passwd.txt"/>

<userDefinedPortstart="false"port="874"/><!-- port=874 -->

<timeoutstart="false"time="100"/><!-- timeout=100 -->

<sshstart="false"/>

</rsync>

<failLogpath="/tmp/rsync_fail_log.sh"timeToExecute="60"/><!--defaultevery 60mins execute once-->

<crontab start="true" schedule="600"><!--600mins-->

<crontabfilterstart="false">

<excludeexpression="*.php"></exclude>

<excludeexpression="info/*"></exclude>

</crontabfilter>

</crontab>

<pluginstart="false"name="command"/>

</sersync>

<pluginname="command">

<paramprefix="/bin/sh"suffix=""ignoreError="true"/> <!--prefix /opt/tongbu/mmm.sh suffix-->

<filterstart="false">

<includeexpression="(.*)\.php"/>

<includeexpression="(.*)\.sh"/>

</filter>

</plugin>

<pluginname="socket">

<localpathwatch="/opt/tongbu">

<deshostip="192.168.138.20"port="8009"/>

</localpath>

</plugin>

<pluginname="refreshCDN">

<localpathwatch="/data0/htdocs/cms.xoyo.com/site/">

<cdninfodomainname="ccms.chinacache.com"port="80"username="xxxx" passwd="xxxx"/>

<sendurlbase="http://pic.xoyo.com/cms"/>;

<regexurlregex="false"match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"/>

</localpath>

</plugin>

</head>

:wq! #保存退出

参数说明:

localpath watch="/home/Sync":#源服务器同步目录

192.168.3.21:#目标服务器IP地址

name="Sync":#目标服务器rsync同步目录模块名称

users="Sync":#目标服务器rsync同步用户名

passwordfile="/etc/passwd.pass":#目标服务器rsync同步用户的密码在源服务器的存放路径

remote ip="192.168.0.50": #目标服务器ip,每行一个

failLogpath="/tmp/rsync_fail_log.sh" #脚本运行失败日志记录

start="true" #设置为true,每隔600分钟执行一次全盘同步

5、设置sersync监控开机自动执行

#vi /etc/rc.d/rc.local #编辑,在最后添加一行

/usr/local/sersync/sersync2 -d -r -o /usr/local/sersync/confxml.xml #设置开机自动运行脚本

:wq! #保存退出

# chmod +x /etc/rc.d/rc.local  #否则重启不执行

6、添加脚本监控sersync是否正常运行

#mkdir  /home/crontab

#vi /home/crontab/check_sersync.sh  #编辑,添加以下代码

#!/bin/sh

sersync="/usr/local/sersync/sersync2"

confxml="/usr/local/sersync/confxml.xml"

status=$(psaux |grep 'sersync2'|grep -v'grep'|wc -l)

if [$status -eq 0 ];

then

$sersync -d-r -o $confxml &

else

exit 0;

fi

:wq! #保存退出

#chmod +x /home/crontab/check_sersync.sh#添加脚本执行权限

#vi /etc/crontab#编辑,在最后添加下面一行

*/5 * * * * root/home/crontab/check_sersync.sh >/dev/null 2>&1 #每隔5分钟执行一次脚本

#重新加载服务

#systemctl restart crond.service

6、测试sersync实时触发rsync同步脚本是否正常运行

在源服务器192.168.0.48上创建文件inotify_rsync_ceshi

#mkdir /home/Sync/inotify_rsync_ceshi

重新启动源服务器:192.168.0.21

等系统启动之后,查看两台目标服务器 192.168.0.130,192.168.21.128的/home/Sync下是否有inotify_rsync_ceshi文件夹

然后再在源服务器192.168.0.48创建文件夹inotify_rsync_ceshi_new

mkdir /home/Sync/inotify_rsync_ceshi_new

继续查看两台目标服务器 192.168.0.130,192.168.21.128的//home/Sync下是否有inotify_rsync_ceshi_new文件夹

如果以上测试都通过,说明inotify实时触发rsync同步脚本运行正常

本文转自 msj0905 51CTO博客,原文链接:http://blog.51cto.com/sky66/1978694

saltstack+git+rsync发布代码相关推荐

  1. 【原】iOS:手把手教你发布代码到CocoaPods(Trunk方式)

    概述 关于CocoaPods的介绍不在本文的主题范围内,如果你是iOS开发者却不知道CocoaPods,那可能要面壁30秒了.直奔主题,这篇文章主要介绍如果把你的代码发布到CocoaPods代码库中, ...

  2. 使用Eclipse-Maven-git做Java开发(13)--导入git仓库的代码到eclipse

    2019独角兽企业重金招聘Python工程师标准>>> 前面讲到了怎么使用osc的git服务进行代码托管.至此,我们已经可以使用git进行文件的版本管理了,甚至可以进行不需要IDE的 ...

  3. gitlab和jenkins发布代码

     Gitlab安装 Gitalab是利用发开源应用程序,实现自托管git项目仓库,可通过Web 界面进入访问公开或私人项目能够浏览源代码,管理缺陷和注释 一 :基础环境准备 查看系统信息  cat / ...

  4. jenkins配置git并发布到远程服务器

    昨天利用了两个小时搭建了一套jekins环境用于自动化构建git项目.在这里和大家分享一下要点.第一个安装jenkins这里就不详细说了,基本步骤就是下载,解压,配置,启动. 当jenkins安装好之 ...

  5. iOS:手把手教你发布代码到CocoaPods(Trunk方式)

    概述 关于CocoaPods的介绍不在本文的主题范围内,如果你是iOS开发者却不知道CocoaPods,那可能要面壁30秒了.直奔主题,这篇文章主要介绍如果把你的代码发布到CocoaPods代码库中, ...

  6. 使用git上传代码到github

    1.      github上创建项目 github是一个服务器托管商,我们写好的代码可以上传到github上面去 登录github的官方网站:http://github.com/ 注册一个自己的用户 ...

  7. 转:Facebook是如何发布代码的

    来自:http://www.infoq.com/cn/news/2011/01/facebook-coding-practices Yee Lee(Skype的一位产品经理)整理了大量笔记,详细描述了 ...

  8. 对于在git上面拉代码报“error: RPC failed; curl 56 OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 10054“解决方法

    对于在git上面拉代码报"error: RPC failed; curl 56 OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 10054"解 ...

  9. will not add file alias already exists in index(git上传代码出错)

    一 问题描述 今天在用git上传代码的时候,发现一个问题,以前从来没有遇到过,今天也是运气好,就被我碰到了,不过,每件事情有有果必有因,也是前面修改了一些文件才导致的,下面讲讲为什么会出现这个问题,然 ...

最新文章

  1. 设置***遇到一个小问题
  2. TCP/IP详解--第十三章
  3. 布线须知:无线AP采用PoE交换机供电的好处
  4. 03-cmake语法-变量,字符串
  5. 【开源框架】Android之史上最全最简单最有用的第三方开源库收集整理,有助于快速开发,欢迎各位网友补充完善...
  6. Java NIO学习篇之通道FileChannel详解
  7. ApacheCN PythonWeb 译文集 20211028 更新
  8. C++基础::自制异常定位器
  9. 黑金AX7Z100 FPGA开发板移植LWIP库(二)PL端
  10. 美图秀秀各插件适用场景
  11. 工厂模式及在Spring中的应用
  12. 图鸟小程序+前后端开源项目
  13. 理“ Druid 元数据”之乱
  14. SIFT,SURF,ORB,FAST,BRISK 特征提取算法比较
  15. json单引号和双引号转义 完美解决由特殊字符引起的json解析错误(转载)
  16. vb中imp是什么意思_oracle
  17. 页面自动更新(javascript)
  18. 善泳者溺:最好並不是最好
  19. 大数据日知录:架构与算法
  20. 搭建hexo个人博客爬坑之一

热门文章

  1. 本地部署在线客服系统、客服机器人
  2. 订单30分钟未支付自动取消怎么实现?
  3. Leetcode904
  4. 微信支付回调到底回调了什么?
  5. 跳板机配置,镜像创建,网站云平台部署
  6. elasticsearch安装和配置,elasticsearch启动报错:can not run elasticsearch as root
  7. 网站流量从100PV到1亿级PV网站架构演变
  8. OPENMV和STM32的识别追踪小车(详细版)之OPENMV端
  9. zFuse for Mac(视频播放软件)
  10. java timestamp 范围_你可能不会注意的Timestamp