Jenkins “高可用方案探索”之实时同步
2019-12-31 本文已影响0人
博翼腾飞
实现方式
1.inotify+rsync 实时同步文件 (直接同步,后台运行,会降低jenkins应用性能)
2.keepalive vip 监测状态自动重启从master
同步方案
#!/bin/bash
host=192.168.101.1
src=/data/jenkins/home/
#src=/data/jenkins_test/home/
#des=/data/jenkins_test/home/
inotify=/usr/local/include
#${inotify}/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e close_write,modify,delete,create,attrib,move $src | while read files
${inotify}/bin/inotifywait -mrq --exclude '(^.*/~.*|^.*\.swp$|.*~|.swx|4913|tmp$|caches)' --timefmt '%d/%m/%y %H:%M' --format '%T %w%f %e' -e close_write,modify,delete,create,attrib,move $src | while read date time file event
do
# echo "date:$date"
# echo "time:$time"
# echo "file:$file"
# echo "event:$event"
# echo "---------------------------------------------------------------------------------------------------------"
case $event in
MODIFY|CREATE|MOVE|MODIFY,ISDIR|MOVED_FROM|MOVED_FROM,ISDIR|CLOSE_WRITE,CLOSE|ATTRIB)
#echo $event'-'$file
#echo "rsync -avuzP --progress $file $host:$file"
rsync -a $file $host:$file
if [ $? -ne 0 ]
then
dir=`dirname $file`
echo $file
rsync -a $dir/ $host:$dir/
fi
;;
CREATE,ISDIR)
rsync -a $file/ $host:$file/
;;
DELETE|DELETE,ISDIR)
echo $event'-'$file >>delete.txt
;;
esac
#rsync -avuzP --delete --progress $var $host:$var
#echo "${files} was rsynced" >> /tmp/jenkins_rsync.log 2>&1
done
修改版:
#!/bin/bash
host=192.168.101.1
src=/data/jenkins/home/
#src=/data/jenkins_test/home/
#des=/data/jenkins_test/home/
inotify=/usr/local/include
#${inotify}/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e close_write,modify,delete,create,attrib,move $src | while read files
rsync -au $src $host:/data/jenkins/home/
${inotify}/bin/inotifywait -mrq --exclude '(^.*/~.*|^.*\.swp$|.*~|.swx|4913|tmp$|caches)' --timefmt '%d/%m/%y %H:%M' --format '%T %w%f %e' -e close_write,modify,delete,create,attrib,move $src | while read date time file event
do
# echo "date:$date"
# echo "time:$time"
# echo "file:$file"
# echo "event:$event"
# echo "---------------------------------------------------------------------------------------------------------"
case $event in
CLOSE_WRITE,CLOSE)
#MODIFY|CREATE|MOVE|MODIFY,ISDIR|MOVED_FROM|MOVED_FROM,ISDIR|CLOSE_WRITE,CLOSE|ATTRIB)
#echo $event'-'$file
#echo "rsync -avuzP --progress $file $host:$file"
rsync -a $file $host:$file
;;
MOVED_TO)
echo $file | grep 'apiTokenStats.xml' > /dev/null
if [ $? -eq 0 ]
then
rsync -a $file $host:$file &
else
dir=`dirname $file`
echo $dir | grep builds > /dev/null
if [ $? -eq 0 ]
then
dir=`echo $dir |awk -F 'builds' '{print $1}'`
else
echo "file:$file"
echo "event:$event"
rsync -a $dir/ $host:$dir/
fi
fi
;;
CREATE,ISDIR|MOVED_FROM,ISDIR)
rsync -a $file/ $host:$file/
;;
DELETE|DELETE,ISDIR)
echo $event'-'$file >>delete.txt
;;
esac
#rsync -avuzP --delete --progress $var $host:$var
#echo "${files} was rsynced" >> /tmp/jenkins_rsync.log 2>&1
done