一度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
#################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
###檢測端口
lsof -i:873
#########################################################################
用戶端(192.168.3.22,192.168.3.23):
yum -y install rsync
vi/etc/rsync.pas
123456
chmod600 /etc/rsync.pas
用戶端測試同步:
/test/svndata/
rsync -vzrtopg--progress [email protected]::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/[email protected]::svnbackup /test/svndata/--password-file=/etc/rsyncd.pas
--------------------------------------------------------------
線上測試(p端)
rsync -vzrtopg--progress --exclude-from /mnt/rsync/excludes [email protected]::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 [email protected]::svnbackup/mnt/yii/630manage/ --password-file=/etc/rsyncd.pas
vim/mnt/rsync/yii_excludes
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"/>-->
</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-->
<includeexpression="(.*)\.php"/>
<includeexpression="(.*)\.sh"/>
</plugin>
<pluginname="socket">
<localpathwatch="/opt/tongbu">
<deshostip="192.168.138.20"port="8009"/>
<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/p_w_picpaths"/>
</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 #設定開機自動運作腳本
# 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
#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檔案夾