一度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同步指令碼執行正常