目錄
成果物:計劃表、製作數據方案、制定介面測試方案(後續流程會隨時更新調整)、服務關係調用圖
成果物:資源申請單、指令碼開發進度表、數據準備的檔案及備份指令碼
成果物:階段性報告、會議邀請(報告解讀、壓測過程中遇到的問題或存在風險)
效能測試流程主要分幾個階段,任務受領階段、測試規劃階段、測試準備階段、測試執行與調優階段、測試收尾階段
參加需求評審,任務期間將各版本的評審文件落地歸檔,沒文件也需發郵件將郵件歸檔
計劃表2.1
制定數據方案—— 數據關聯的依賴調研(詳細圖)2.2
制定數據方案—— 數據關聯的依賴調研(精簡圖)2.3
制定介面測試方案——業務呼叫關係調研2.4
服務關係調用圖——遇到複雜的業務呼叫時,需要梳理此圖2.5
規劃階段需要像研發、運維等幹係人員發送【所制定測試方案計劃】郵件
郵件內容包含以上所列的成果物:計劃表、數據方案、介面方案、服務呼叫關係圖
環境搭建與調整——像運維同步研發所確認的資源申請單,申請資源,資源申請後測試人員需覈對資源設定是否正確,並部署壓測目錄、shell指令碼、nmon檔案、ssh互信
此處shell指令碼主要包含(automon.sh、automonbatch.sh後面會有指令碼解釋)
資源申請——所需服務資源與研發調研3.1
應用部署與連通性檢查——資源設定有效,研發人員部署應用服務並連調環境,測試人員需同步設定資訊如Zookeeper
指令碼開發與增強——開發介面
指令碼開發進度表3.2
批次數據準備——複雜場景需要先預埋數據,shell做好乾系庫的數據庫備份及還原指令碼
1、做數據一般通過儲存過程或者批次跑介面完成
2、做數據庫備份:可以重複利用做的數據或者可以直接還原指定場景所用
備份:mysqldump -h主機名 -P埠 -u使用者名稱 -p密碼 --database 數據庫名 > 檔名.sql
還原:mysql -uroot -psymdata xinda_product < ${backupfile}
基準測試——一般基準併發點在100tps,同時檢視服務日誌及資源有沒有異樣情況
單交易負載測試與調優:
混合負載測試與調優:多場景交叉混合執行(一般用LR工具更方便於設計並執行復雜場景)
成果物:場景執行統計單、問題記錄單
場景統計單4.1
問題記錄單4.2
階段性報告主要包含
1、約束:人員/時間上的受限、與線上資源/設定等資訊不同步的情況說明、某些場景無法復現(如線上數據無法模擬)
2、監控日誌:壓測過程中存放的日誌路徑及錯誤資訊手機的資訊,方便開發自行獲取
3、業務指標:是上面場景統計單的彙總 如圖4.1
4、問題清單:如果是階段性報告需要實時更新表單 見圖4.2
5、系統資源監控:如遇到高位執行的服務,執行的場景關聯服務資源過高的各指標展示(如cpu、io讀寫、磁碟讀寫等)
6、抗風險預估:一般結合約束關聯性闡述
會議邀請
將以上五大點的成果物落地歸檔jira
#定義nmon主目錄
monbase=/server/nmondir
#監控間隔時間
interval=$1
#監控總次數
sum=$2
#定義監控啓動時間
monstart_time=`date +%Y%m%d%H%M%S`
#遠端伺服器ip定義
rip=10.1.15.242
#本地伺服器ip獲取
if [[ `LC_ALL=C ifconfig | grep 'Bcast' |cut -d: -f2 | awk '{ print $1}' |cut -d'.' -f1,2,3` = "10.100.24" ]] || [[ `LC_ALL=C ifconfig | grep 'Bcast' |cut -d: -f2 | awk '{ print $1}' |cut -d'.' -f1,2,3` = "10.103.51" ]];then
lip=`LC_ALL=C ifconfig | grep 'Bcast' |cut -d: -f2 | awk '{ print $1}'`
else
#10.100.24.85~88伺服器操作系統爲centos7.0,獲取lip方法如下
lip=`LC_ALL=C ifconfig |grep -A 1 'eth0:' |awk 'NR==2{print}' | awk '{ print $2}'`
fi
#服務名稱變數定義
servicename=`hostname | cut -d '.' -f 1`
#定義監控檔案的遠端儲存伺服器
rip=10.1.15.242
#移動歷史監控檔案至nmonhis目錄
echo "移動歷史監控檔案至nmonhis目錄"
mv /server/tomcat/logs/catalina.out.* ${monbase}/nmonhis;
cd ${monbase}
#mv *.nmon *.conf *.log ${monbase}/nmonhis;ls -lrt ${monbase}/nmonhis;ls -lrt
mv *.nmon *.conf *.log ${monbase}/nmonhis;
#可選監控專案通過替換"[ $? -eq 0 ]"爲"[ $? -ne 0 ]"可遮蔽該監控專案
#開啓dubbo日誌監控(可選監控專案)
##定義dubbo日誌
dubbolog=/home/tomcat/dubbo-governance.log
ps -ef |grep dubbo |grep -v grep
if [ $? -eq 0 ] && [ -f "${dubbolog}" ];
then
echo "${lip}開啓dubbo日誌監控:${lip}.dubbo.${monstart_time}.log"
tail -f ${dubbolog} > ${monbase}/${lip}.dubbo.${monstart_time}.log &
sleep 2
ps -ef |grep tail
else
sleep 1
fi
#開啓nginx日誌監控
##定義nginx日誌
nginxlog=/home/devloper/work/nginx/logs/error.log
ps -ef |grep nginx |grep -v grep
if [ $? -eq 0 ] && [ -f "${nginxlog}" ];
then
echo "${lip}開啓nginx日誌監控:${lip}.nginxerror.${monstart_time}.log"
tail -f ${nginxlog} > ${monbase}/${lip}.nginxerror.${monstart_time}.log &
fi
#開啓haproxy日誌監控(可選監控專案)
##定義haproxy日誌
halog=/var/log/haproxy.log
ps -ef |grep haproxy |grep -v grep
if [ $? -eq 0 ] && [ -f "${halog}" ];
then
echo "${lip}開啓haproxy日誌監控:${lip}.haproxy.${monstart_time}.log"
tail -f ${halog} > ${monbase}/${lip}.haproxy.${monstart_time}.log &
sleep 2
ps -ef |grep tail
else
sleep 1
fi
#開啓tomcat日誌監控
##定義tomcat日誌
tomcatlog=/server/tomcat/logs/catalina.out
ps -ef|grep tomcat |grep -v grep
if [ $? -eq 0 ] && [ -f "${tomcatlog}" ];
then
echo "${lip}開啓tomcat日誌監控:${lip}.tomcat.${monstart_time}.log"
tail -f ${tomcatlog} > ${monbase}/${lip}.tomcat.${monstart_time}.log &
sleep 2
ps -ef |grep tail
else
sleep 1
fi
#開啓trident日誌監控
##定義sidekiq日誌
#sidekiqlog=/home/devloper/work/trident/log/sidekiq.log
sidekiqlog=/data/log/rails/sidekiq.log
ps -ef |grep sidekiq |grep -v grep
if [ $? -eq 0 ] && [ -f "${sidekiqlog}" ];
then
echo "${lip}開啓日誌監控:${lip}.sidekiq.${monstart_time}.log"
tail -f ${sidekiqlog} > ${monbase}/${lip}.sidekiq.${monstart_time}.log &
sleep 2
ps -ef |grep tail
else sleep 1
fi
#開啓redis日誌監控(可選監控專案)
##定義redis日誌
redislog=/server/redis/logs/redis.log
ps -fe|grep redis |grep -v grep
if [ $? -eq 0 ] && [ -f "${redislog}" ]
then
echo "${lip}開啓redis日誌監控:${lip}.redis.${monstart_time}.log"
tail -f ${redislog} >${monbase}/${lip}.redis.${monstart_time}.log &
sleep 2
ps -ef |grep tail
else sleep 1
fi
#開啓rabbitmq日誌監控(可選監控專案)
##定義rabbitmq日誌
mqlog=/var/tmp/rabbitmq-tracing/RabbitMQ_Tracing.log
ps -fe|grep rabbitmq |grep -v grep
if [ $? -eq 0 ] && [ -f "${mqlog}" ];
then
echo "${lip}開啓rabbitmq日誌監控:${lip}.rabbitmq.${monstart_time}.log"
tail -f ${mqlog} > ${lip}.rabbitmq.${monstart_time}.log &
sleep 2
ps -ef |grep tail
else
sleep 1
fi
#開啓mongo日誌監控(可選監控專案)
##定義mongo日誌
mongolog=/server/mongodb/logs/mongodb.log
ps -fe|grep mongod |grep -v grep
if [ $? -eq 0 ] && [ -f "${mongolog}" ]
then
echo "${lip}開啓mongo日誌監控:${lip}.mongo.${monstart_time}.log"
tail -f ${mongolog} > ${monbase}/${lip}.mongo.${monstart_time}.log &
sleep 2
ps -ef |grep tail
else
sleep 1
fi
##定義mysql日誌
mysqlerr=/server/mysql/log/mysql.err.log
mysqlslow=/server/mysql/log/mysql.slow.log
mysqlerr_Trident=/server/mysql_data/mysql.err.log
mysqlslow_Trident=/server/mysql_data/mysql.slow.log
ps -fe|grep mysqld |grep -v grep
if [ $? -eq 0 ] && [ -f "${mysqlslow}" ]
then
echo "${lip}開啓mysql日誌監控:${lip}.mysql.${monstart_time}.log"
tail -f ${mysqlslow} > ${monbase}/${lip}.mysqlslow.${monstart_time}.log &
sleep 2
ps -ef |grep tail
else sleep 1
fi
ps -fe|grep mysqld |grep -v grep
if [ $? -eq 0 ] && [ -f "${mysqlslow_Trident}" ]
then
echo "${lip}開啓mysql日誌監控:${lip}.mysql.${monstart_time}.log"
tail -f ${mysqlslow_Trident} > ${monbase}/${lip}.mysqlslow.${monstart_time}.log &
sleep 2
ps -ef |grep tail
else sleep 1
fi
ps -fe|grep mysqld |grep -v grep
if [ $? -eq 0 ] && [ -f "${mysqlerr}" ]
then
echo "${lip}開啓mysql日誌監控:${lip}.mysql.${monstart_time}.log"
tail -f ${mysqlerr} > ${monbase}/${lip}.mysqlerr.${monstart_time}.log &
sleep 2
ps -ef |grep tail
else sleep 1
fi
ps -fe|grep mysqld |grep -v grep
if [ $? -eq 0 ] && [ -f "${mysqlerr_Trident}" ]
then
echo "${lip}開啓mysql日誌監控:${lip}.mysql.${monstart_time}.log"
tail -f ${mysqlerr_Trident} > ${monbase}/${lip}.mysqlerr.${monstart_time}.log &
sleep 2
ps -ef |grep tail
else sleep 1
fi
#開啓vmstat監控
#echo "${lip}開啓vmstat監控,監控啓動時間:${monstart_time},監控間隔:${interval}秒,監控次數:${sum}次"
#df -hl >${lip}.vmstat.${monstart_time}.conf;sleep 1;vmstat ${interval} ${sum} >>${lip}.vmstat.${monstart_time}.conf &
#sleep 1
#開啓iostat監控
#echo "${lip}開啓iostat監控,監控啓動時間:${monstart_time},監控間隔:${interval}秒,監控次數:${sum}次"
#iostat -x -k -d ${interval} ${sum} >>${lip}.iosat.${monstart_time}.conf &
#sleep 1
#開啓vnstat監控
#echo "${lip}開啓vnstat監控,監控啓動時間:${monstart_time},監控間隔:${interval}秒,監控次數:${sum}次"
#vnstat -l -i eth0 >>${lip}.vnsat.${monstart_time}.conf &
#sleep 2
#開啓dstat監控
echo "${lip}開啓dstat監控,監控啓動時間:${monstart_time},監控間隔:${interval}秒,監控次數:${sum}次"
dstat -tlcmsgnrp ${interval} ${sum} >>${lip}.dstat.${monstart_time}.dstat &
#開啓nmon監控
echo "${lip}開啓nmon監控,監控啓動時間:${monstart_time},監控間隔:${interval}秒,監控次數:${sum}次"
${monbase}/nmon -F ${lip}.nmon.${monstart_time}.nmon -t -s $interval -c $sum &
sleep 2
ps -ef |grep nmon
sleep 1
let endtime=$interval*$sum+5
echo "${lip}監控進程已啓動,監控場景將在${endtime}秒後結束,請耐心等待!"
sleep ${endtime}
#開始收集tomcat錯誤日誌資訊
if [ -f "${monbase}/${lip}.tomcat.${monstart_time}.log" ]; then
grep -A 30 'Exception\|ERROR\|Fail\|失敗' ${monbase}/${lip}.tomcat.${monstart_time}.log > ${lip}.tomcat.${monstart_time}.error.log
fi
filename=${lip}.tomcat.${monstart_time}.error.log
filesize=`ls -l $filename | awk '{ print $5 }'`
minsize=0
if [ $filesize -eq $minsize ] ;then
rm -rf ${lip}.tomcat.${monstart_time}.error.log
fi
sleep 5
echo "${lip}監控已結束,刪除後臺未結束的監控進程"
ps -ef | grep tail | grep -v grep | awk '{print $2}' | xargs kill -9 &
ps -ef |grep "/server/nmondir/nmon" | grep -v grep | awk '{print $2}' | xargs kill -9 &
#ps -ef | grep vmstat | grep -v grep | awk '{print $2}' | xargs kill -9 &
#ps -ef | grep iostat | grep -v grep | awk '{print $2}' | xargs kill -9 &
#ps -ef | grep vnstat | grep -v grep | awk '{print $2}' | xargs kill -9 &
ps -ef | grep dstat | grep -v grep | awk '{print $2}' | xargs kill -9 &
sleep 3
echo "${lip}監控任務至此結束"
#開始傳遞監控檔案到集中控制檯
#scp ${monbase}/*.log *.conf *.nmon ${rip}:${monbase} &
#scp $lip.tomcat.${monstart_time}.log ${rip}:${monbase} &
#echo "$lip傳遞監控檔案到集中控制檯結束"
sleep 5
exit 0
命令演示:automon.sh 30 100 (30: #監控間隔時間 100:#監控總次數)
其實就是執行nmon的命令在指令碼裡有做了一次封裝
指令碼解讀:
1、開啓各服務及中介軟體的日誌監控,如(tomcat、dubbo、mq、nginx、redis、mongo、mysqlslow、mysqlerr)
2、啓動nmon
3、監控sleep到時間了,執行錯誤過濾日誌
4、殺tail進程
#定義監控環境,監控頻率,監控總次數
#定義要監控的環境
echo -e "請輸入監控頻率(數值,>=2秒),監控總次數(數值),監控環境(t/api),變數間用空格分開\n監控範例:2 5 api"
read interval sum envname
if [ ${interval} -lt 2 ];then
echo "輸入的監控頻率爲${interval}<2秒,不合規"
exit 0
fi
#監控主目錄
monbase=/server/nmondir
#tomcat主目錄
tomcatbase=/server/tomcat/logs
#ip名稱變數定義
ip=`LC_ALL=C ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' |cut -d: -f2 | awk '{ print $1}'`
#移動歷史監控檔案至nmonhis目錄
echo "移動歷史監控檔案至nmonhis目錄"
cd ${monbase}
mv *.nmon *.conf *.log ${monbase}/nmonhis;ls -lrt ${monbase}/nmonhis;ls -lrt
if [ "${envname}" = "api" ]; then switch="api"
elif [ "${envname}" = "t" ]; then switch="t"
else switch="*"
fi
case $switch in
api)
echo "連線遠端${envname}環境被監控伺服器並開啓監控指令碼"
Host_List=" 10.100.24.10
10.100.24.11
10.100.24.12
10.100.24.13
10.100.24.133
10.100.24.14
10.100.24.15
10.100.24.16
10.100.24.17
10.100.24.18
10.100.24.19
10.100.24.73
10.100.24.74
10.100.24.75
10.100.24.76
10.100.24.77
10.100.24.78
10.100.24.79
10.100.24.8
10.100.24.80
10.100.24.81
10.100.24.82
10.100.24.83
10.100.24.84
10.100.24.85
10.100.24.86
10.100.24.87
10.100.24.88
10.100.24.89
10.100.24.9
10.103.51.63
10.103.51.71"
for Host in $Host_List
do
ssh root@$Host ${monbase}/servermon.sh ${interval} ${sum}&
ssh root@$Host ${monbase}/automon.sh ${interval} ${sum}&
done
;;
t)
echo "連線遠端${envname}環境被監控伺服器並開啓監控指令碼"
Host_List=" 10.103.51.101
10.103.51.102
10.103.51.137
10.103.51.138
10.103.51.139
10.103.51.156
10.103.51.164
10.103.51.174
10.103.51.217
10.103.51.221
10.103.51.222
10.103.51.225
10.103.51.229
10.103.51.230
10.103.51.231
10.103.51.232
10.103.51.233
10.103.51.234
10.103.51.235
10.103.51.237
10.103.51.26
10.103.51.43
10.103.51.52
10.103.51.54
10.103.51.55
10.103.51.56
10.103.51.57
10.103.51.58
10.103.51.59
10.103.51.60
10.103.51.61
10.103.51.62
10.103.51.63
10.103.51.64
10.103.51.65
10.103.51.66
10.103.51.67
10.103.51.68
10.103.51.69
10.103.51.70
10.103.51.71
10.103.51.72
10.103.51.73
10.103.51.74
10.103.51.75
10.103.51.76
10.103.51.77
10.103.51.79
10.103.51.80
10.103.51.88
10.103.51.89
10.103.51.90
10.103.51.91
10.103.51.92
10.103.51.93
10.103.51.94
10.103.51.95
10.103.51.96
10.103.51.97
10.103.51.98"
for Host in $Host_List
do
ssh $Host ${monbase}/servermon.sh ${interval} ${sum}&
ssh $Host ${monbase}/automon.sh ${interval} ${sum}&
done
;;
*)
echo "no switch can be matched!"
;;
esac
#done #多個傳參的結束標識
#wait
echo "批次監控已結束"
exit 0
命令演示:automon.sh 30 100 test (30: #監控間隔時間 100:#監控總次數 test:切換環境)
指令碼解讀:將不同環境的執行服務列表遍歷並遠端執行automon.sh命令
#監控主目錄
monbase=/server/nmondir
#定義監控啓動時間
monstart_time=`date +%Y%m%d%H%M%S`
#ip名稱變數定義
ip=`LC_ALL=C ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' |cut -d: -f2 | awk '{ print $1}'`
#定義遠端被監控伺服器列表
#Hostlist=="192.168.206.88"
#定義遠端存放檔案的目錄
dst=/server/nmondir
#echo -e "請輸入批次操作的檔案或模糊檔案變數,多個變數用空格分開\n檔案範例:nmon automon.sh servermon.sh\n>模糊檔案範例:*.log *.nmon"
#read scpfiename
#動態傳入多個被拷貝的檔名
count=1
while [ "$#" -ge "1" ];do
scpfilename=$1
echo "檔案序號$count的檔名爲:$1"
let count=count+1
shift
if [ "${scpfilename}" = "nmon" ] || [ "${scpfilename}" = "automon.sh" ] || [ "${scpfilename}" = "servermon.sh" ] || [ "${scpfilename}" = "rm.sh" ] ; then switch="1"
elif [ "${scpfilename}" = "*.log" ] || [ "${scpfilename}" = "*.nmon" ] || [ "${scpfilename}" = "*.conf" ] || [ "${scpfilename}" = "*.timelog" ] || [ "${scpfilename}" = "*servercollect*.log" ] || [ "${scpfilename}" = "*servermon*.log" ] || [ "${scpfilename}" = "*.dstat" ] || [ "${scpfilename}" = "*.servercollect" ] ; then switch="2"
else switch="*"
fi
case $switch in
1)
echo "批次拷貝本地${scpfilename}到遠端被監控伺服器"
Host_List=" 10.103.51.101
10.103.51.102
10.103.51.137
10.103.51.138
10.103.51.139
10.103.51.156
10.103.51.164
10.103.51.174
10.103.51.217
10.103.51.221
10.103.51.222
10.103.51.225
10.103.51.229
10.103.51.230
10.103.51.231
10.103.51.232
10.103.51.233
10.103.51.234
10.103.51.235
10.103.51.237
10.103.51.26
10.103.51.43
10.103.51.52
10.103.51.54
10.103.51.55
10.103.51.56
10.103.51.57
10.103.51.58
10.103.51.59
10.103.51.60
10.103.51.61
10.103.51.62
10.103.51.63
10.103.51.64
10.103.51.65
10.103.51.66
10.103.51.67
10.103.51.68
10.103.51.69
10.103.51.70
10.103.51.71
10.103.51.72
10.103.51.73
10.103.51.74
10.103.51.75
10.103.51.76
10.103.51.77
10.103.51.79
10.103.51.80
10.103.51.88
10.103.51.89
10.103.51.90
10.103.51.91
10.103.51.92
10.103.51.93
10.103.51.94
10.103.51.95
10.103.51.96
10.103.51.97
10.103.51.98"
for Host in $Host_List
do
scp -o GSSAPIAuthentication=no ${monbase}/${scpfilename} $Host:${dst}
done
echo "批次拷貝本地${scpfilename}到遠端被監控伺服器"
Host_List=" 10.100.24.10
10.100.24.11
10.100.24.12
10.100.24.13
10.100.24.133
10.100.24.14
10.100.24.15
10.100.24.16
10.100.24.17
10.100.24.18
10.100.24.19
10.100.24.73
10.100.24.74
10.100.24.75
10.100.24.76
10.100.24.77
10.100.24.78
10.100.24.79
10.100.24.8
10.100.24.80
10.100.24.81
10.100.24.82
10.100.24.83
10.100.24.84
10.100.24.85
10.100.24.86
10.100.24.87
10.100.24.88
10.100.24.89
10.100.24.9
10.103.51.63
10.103.51.71"
for Host in $Host_List
do
scp -o GSSAPIAuthentication=no ${monbase}/${scpfilename} $Host:${dst}
done
;;
2)
#定義要監控的環境
echo "輸入要操作的環境英文簡稱:t(功能測試環境),api(api測試環境)"
read envname
if [ "${envname}" = "api" ]; then
echo "批次拷貝本地${envname}環境${scpfilename}到遠端被監控伺服器"
Host_List=" 10.100.24.10
10.100.24.11
10.100.24.12
10.100.24.13
10.100.24.133
10.100.24.14
10.100.24.15
10.100.24.16
10.100.24.17
10.100.24.18
10.100.24.19
10.100.24.73
10.100.24.74
10.100.24.75
10.100.24.76
10.100.24.77
10.100.24.78
10.100.24.79
10.100.24.8
10.100.24.80
10.100.24.81
10.100.24.82
10.100.24.83
10.100.24.84
10.100.24.85
10.100.24.86
10.100.24.87
10.100.24.88
10.100.24.89
10.100.24.9
10.103.51.63
10.103.51.71"
for Host in $Host_List
do
scp -o GSSAPIAuthentication=no $Host:${monbase}/${scpfilename} ${monbase}
done
elif [ "${envname}" = "t" ];then
echo "批次拷貝本地${envname}環境${scpfilename}到遠端被監控伺服器"
Host_List=" 10.103.51.101
10.103.51.102
10.103.51.137
10.103.51.138
10.103.51.139
10.103.51.156
10.103.51.164
10.103.51.174
10.103.51.217
10.103.51.221
10.103.51.222
10.103.51.225
10.103.51.229
10.103.51.230
10.103.51.231
10.103.51.232
10.103.51.233
10.103.51.234
10.103.51.235
10.103.51.237
10.103.51.26
10.103.51.43
10.103.51.52
10.103.51.54
10.103.51.55
10.103.51.56
10.103.51.57
10.103.51.58
10.103.51.59
10.103.51.60
10.103.51.61
10.103.51.62
10.103.51.63
10.103.51.64
10.103.51.65
10.103.51.66
10.103.51.67
10.103.51.68
10.103.51.69
10.103.51.70
10.103.51.71
10.103.51.72
10.103.51.73
10.103.51.74
10.103.51.75
10.103.51.76
10.103.51.77
10.103.51.79
10.103.51.80
10.103.51.88
10.103.51.89
10.103.51.90
10.103.51.91
10.103.51.92
10.103.51.93
10.103.51.94
10.103.51.95
10.103.51.96
10.103.51.97
10.103.51.98"
for Host in $Host_List
do
scp -o GSSAPIAuthentication=no $Host:${monbase}/${scpfilename} ${monbase}
done
else "other situation"
fi
;;
*)
echo "no switch can be matched!"
;;
esac
done #多個傳參的結束標識
echo "批次拷貝已結束"
if [ $switch = "2" ];then
./getservercollect.sh ${envname}
fi
exit 0
指令碼解讀:將監控伺服器下部署的監控資訊,批次拷貝到遠端機(批次到一個機器上,方便彙總監控資料)
#定義數據庫連線參數
dbhost=10.100.24.15
dbuser=root
dbpwd=C8dM1B9wd1iQC7Y
dbname="ApolloConfigDB ApolloPortalDB bangbang_manage ersdata juanpi_manage mysql scdata test wowo_manage xiaocheng_manage xiaodai xiaodai_black xiaodai_manage xiaodai_market_manage xiaodai_portal xiaodai_r360 xiaodai_third xiaoxiaodai xxl-job xxl-job-182 yinbin-xiaodai-backup0622 yinbintest"
#定義開始時間戳
startime=`date +%Y%m%d%H%M%S`
#定義還原檔案存放路徑
filepath=/server/nmondir
echo -n "請指定還原所需sql檔案('backupfile'):"
read backupfile
echo "所選還原檔案爲:$backupfile"
if [ `echo $backupfile | grep -e fullbackup` ];then switch=1
elif [ `echo $backupfile | grep -e partialbackup` ];then switch=2
else echo "所選還原檔案不合規,請確認還原檔案後再來執行該程式";exit 0
fi
case $switch in
1)
echo "開始從${backupfile}進行全量數據還原,請耐心等待\"還原已結束\"的提示字樣出現"
sleep 2;
#echo "全量還原開始執行的臨時測試資訊"
#mysql -u${dbuser} -p${dbpwd} ${dbname} <${backupfile}
mysql -u${dbuser} -p${dbpwd} <${backupfile}
;;
2)
currentbaklist="
ast_current_account
ast_interest_invest_reocrd
ast_manually_lending
ast_maturity_platform_user_redeem
ast_out_config
ast_to_match
ast_to_match_detail
ast_user_account
ast_user_amount_match_queue
ast_user_in_out_matching
ast_user_out_apply
ast_user_out_interest
ast_user_out_matched_detail
ast_warehousing
curent_product_money_record
current_ast_maturity_platform_user_redeem
current_ast_user_out_apply
current_product
current_product_calendar
current_product_contract
current_product_desc
current_product_history_rate
current_product_pay_record
current_product_rate_info
current_product_statistics
current_user_account
current_user_income_invest_record
current_user_interest_record
current_user_invest_record
current_user_pay_record
current_user_redeem_record
money_record
user_account
loan
loan_asset
loan_base
loan_phase
bank_card"
cat /dev/null>${filepath}/table.CREATE.list
cat /dev/null>${filepath}/table.CREATE.txt
filterlist="CREATE"
for filter in $filterlist;
do
grep $filter ${filepath}/${backupfile}>${filepath}/table.${filter}.list
while read line;
do
echo $line|awk '{print $3}' >>${filepath}/table.${filter}.txt
done<${filepath}/table.${filter}.list
done
echo "列出將被還原的數據列表內容:"
cat ${filepath}/table.${filter}.txt
#echo "列出將被還原的數據列表:${currentbaklist}"
sleep 2;
echo -n "('judge'),確認還原輸入1,我要放棄還原輸入2:"
read judge
echo "您的輸入爲:$judge"
if [ $judge != "1" ];
then echo "您選擇放棄還原,請確認還原後重新執行該程式 ";exit 0
fi
echo "開始從${backupfile}進行指定表的數據還原,請耐心等待\"還原已結束\"的提示字樣出現"
sleep 2;
#echo "部分還原開始執行的臨時測試資訊"
mysql -uroot -psymdata xinda_product < ${backupfile}
;;
*)
echo "不符合規則,請閱讀規則後再執行該程式";exit 0
;;
esac
#定義結束時間戳
endtime=`date +%Y%m%d%H%M%S`
echo "還原已結束,還原開始時間:${startime},還原結束時間:${endtime}";sleep 2;ls -lrt;exit 0
指令碼解讀:用於還原數據場景或重複執行準備的數據所使用
#監控主目錄
monbase=/server/nmondir
#tomcat主目錄
tomcatbase=/server/tomcat/logs
#tomcat啓停服務目錄
tomcatrestart=/server/tomcat/bin
#ip名稱變數定義
lip=`LC_ALL=C ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' |cut -d: -f2 | awk '{ print $1}'`
#定義替換檔案位置
filedir1=/server/tomcat/webapps/ROOT/WEB-INF/classes/spring/
#定義替換檔案
file1=springmvc.xml
#執行檔案替換
echo "${lip} mv ${file1} ${file1}.bak"
cd ${filedir1}/;ls -lrt;sleep 1;mv ${file1} ${file1}.bak;ls -lrt;sleep 1;
echo "${lip} cp ${monbase}/${file1} ${filedir1}"
cp ${monbase}/${file1} ${filedir1};ls -lrt;sleep 1;
chmod 664 ${filedir1}/${file1}
echo "重新啓動tomcat服務"
ps -fe|grep tomcat |grep -v grep
if [ $? -eq 0 ]
then
echo "${lip} tomcat process is still running,need to restart"
cd /etc/init.d;./tomcat restart;
sleep 2;echo "${lip} output the tomcat running status"
#tail -f /server/tomcat/logs/catalina.out |grep "Server startup in"
else
echo "tomcat are not running,need to start"
cd /etc/init.d;./tomcat start;
sleep 1;echo "${lip} output the tomcat running status";
#tail -f /server/tomcat/logs/catalina.out |grep "Server startup in"
fi
exit 0
#ps -fe|grep tomcat |grep -v grep
#if [ $? -eq 0 ]
# then
# echo "${lip} tomcat process is still running,need to kill"
# ps -ef | grep tomcat | grep -v grep | awk '{print $2}' | xargs kill -9;sleep 3
# echo "${lip} output tomcat process after killing "
# ps -ef | grep tomcat;sleep 2
# echo "${lip} stop process end"
# sh ${tomcatrestart}/startup.sh
# echo "${lip} output tomcat process after killing and running startup.sh"
# sleep 1;echo "ps -ef |grep tomcat"
# ps -ef |grep tomcat
# sleep 2;echo "${lip} output the tomcat running status"
#else
# echo "tomcat are not running,need to start"
# sh ${tomcatrestart}/startup.sh;
# echo "${lip} output tomcat process after running startup.sh";
# sleep 2;echo "ps -ef |grep tomcat";
# ps -ef |grep tomcat;
# sleep 1;echo "${lip} output the tomcat running status";
#fi
#exit 0
指令碼解讀:執行壓測前自動替換java程式碼或者組態檔,如替換萬能驗證碼程式碼或者xml等組態檔
好處:開發可以配合壓測修改指定的程式碼,並且不會出現將配合改的程式碼誤發到線上的風險