install_mfs.sh
#/bin/bash
useradd mfs -s /sbin/nologin
yum -y install fuse fuse-devel pkgconfig zlib-devel gcc-c++ vim net-tools wget
#wget http://ppa.moosefs.com/src/moosefs-2.0.81-1.tar.gz
tar -xf moosefs-2.0.81-1.tar.gz
cd moosefs-2.0.81
./configure --prefix=/usr/local/mfs --with-default-user=mfs --with-default-group=mfs
make && make install
chown -R mfs:mfs /usr/local/mfs
ln -s /usr/local/mfs/sbin/mfs* /usr/bin/
ln -s /usr/local/mfs/bin/mfs* /usr/bin/
# 安装检测
if [[ `/usr/local/mfs/bin/mfsmount mountpoint --version 2>/dev/null|wc -l` -eq 1 ]];then
hostname|xargs echo 安装成功 $IP
else
hostname|xargs echo 安装出错 $IP
fi
vim install.sh
[root@V217_jswx_buyer-shop ~]# cd script/
[root@V217_jswx_buyer-shop script]# ls
install_mfs.sh install.sh ip.list moosefs-2.0.81 moosefs-2.0.81-1.tar.gz mountmfs.sh
[root@V217_jswx_buyer-shop script]# cat ip.list
1.105 1.107 1.109 1.111 1.113 1.115 1.117 1.119 1.121 1.123 1.125 1.127 1.129
[root@V217_jswx_buyer-shop script]#
pre_deploy.sh
#!/bin/bash
TIME=`/bin/date +%Y%m%d-%s`
FILE_NAME=admin.war
[ ! -d /usr/pre_deploy ] && /bin/mkdir /usr/pre_deploy
[ ! -d /usr/web_bk ] && /bin/mkdir /usr/web_bk
if [ -f /usr/pre_deploy/$FILE_NAME ];then
mv /usr/local/tomcat/webapps/www /usr/web_bk/$TIME && mkdir -p /usr/local/tomcat/webapps/www && cd /usr/local/tomcat/webapps/www && mv /usr/pre_deploy/$FILE_NAME . && unzip -o $FILE_NAME && rm -rf $FILE_NAME && rsync -avrl /web/conf/application.properties /usr/local/tomcat/webapps/www/WEB-INF/classes/ && rsync -avrl /web/conf/taglibs.jsp /usr/local/tomcat/webapps/www/common/ && sh /root/scripts/tomcat_reboot.sh
vim root/scripts/tomcat_reboot.sh
#!/bin/bash
# tomcat reboot
PORT=8080
/etc/init.d/nginx stop
if [ $? -eq 0 ];then
if [ `netstat -tnulp |grep :$PORT |awk -F: '{print $4}'` -eq "$PORT" ];then
kill -9 `netstat -tnulp |grep :$PORT |awk '{print $NF}' |awk -F/ '{print $1}'`
fi
fi
rm -rf /usr/local/tomcat/work/*
rm -rf /usr/local/tomcat/temp/*
chown -R www:www /usr/local/tomcat
su - www -c "/usr/local/tomcat/bin/startup.sh"
sleep 10
/etc/init.d/nginx start
vim rsync_all_admin.sh
#!/bin/bash
#admin
TIME=`/bin/date +%Y%m%d-%s`
for name in 10.0.0.54 10.0.0.65; do
ssh root@"$name" "[ ! -d /usr/web_bk ] && /bin/mkdir /usr/web_bk"
ssh root@"$name" "cp -a /usr/local/tomcat/webapps/www /usr/web_bk/$TIME"
if [ $? -eq 0 ];then
/usr/bin/rsync -avrl --delete -e ssh --exclude=/WEB-INF/classes/application.properties --exclude=/WEB-INF/classes/applicationContext-quartz.xml /usr/local/tomcat/webapps/www/ root@"$name":/usr/local/tomcat/webapps/www/ && ssh root@"$name" "/bin/bash /root/scripts/tomcat_reboot.sh"
sleep 30
fi
done
vim rsync_single_admin.sh
#!/bin/bash
#admin
TIME=`/bin/date +%Y%m%d-%s`
if [ "$1" = "" ] ;then
echo "please input sync file"
else
for name in 10.0.0.54 10.0.0.65; do
ssh root@"$name" "[ ! -d /usr/web_bk ] && /bin/mkdir /usr/web_bk"
ssh root@"$name" "cp -a /usr/local/tomcat/webapps/www /usr/web_bk/$TIME"
/usr/bin/rsync -avR -L --progress --delete -e ssh --exclude=/usr/local/tomcat/webapps/www/WEB-INF/classes/application.properties /usr/local/tomcat/webapps/www/$1 root@"$name":/
if [ "`echo $1 |awk -F. '{print $NF}'`" != "jsp" ];then
ssh root@"$name" "/bin/bash /root/scripts/tomcat_reboot.sh"
sleep 20
fi
done
fi
vim tomcat_war.sh
#!/bin/bash
TIME=`/bin/date +%Y%m%d-%s`
FILE_NAME=admin.war
for name in 10.0.0.54 10.0.0.65; do
ssh root@"$name" "[ ! -d /usr/web_deploy ] && /bin/mkdir /usr/web_deploy"
[ ! -d /usr/web_deploy ] && /bin/mkdir /usr/web_deploy
rsync -avrl --progress --delete /usr/web_deploy/$FILE_NAME root@$name:/usr/web_deploy/
if [ "`md5sum /usr/web_deploy/$FILE_NAME |awk '{print $1}'`" = "`ssh root@$name md5sum /usr/web_deploy/$FILE_NAME |awk '{print $1}'`" ];then
ssh root@"$name" "mv /usr/local/tomcat/webapps/www /usr/web_bk/$TIME && mkdir -p /usr/local/tomcat/webapps/www && mv /usr/web_deploy/$FILE_NAME /usr/local/tomcat/webapps/www/ && cd /usr/local/tomcat/webapps/www/ && unzip -o $FILE_NAME && rm -rf $FILE_NAME && sh /root/scripts/tomcat_reboot.sh && rm -rf /usr/web_deploy/$FILE_NAME"
sleep 20
fi
done
vim v_rollback.sh
#!/bin/bash
#admin
if [ "$1" = "" ] ;then
echo "please input sync file"
else
for name in 10.0.0.54 10.0.0.65; do
ssh root@"$name" "[ -d /usr/web_bk/$1 ] && rsync -avrl --progress --delete -e ssh /usr/web_bk/$1/ /usr/local/tomcat/webapps/www/" && sleep 20 && ssh root@"$name" "/bin/bash /root/scripts/tomcat_reboot.sh"
done
fi
vim test_rsync_all_admin.sh
#!/bin/bash
#admin
TIME=`/bin/date +%Y%m%d-%s`
for name in 10.0.0.54 10.0.0.65; do
ssh root@"$name" "[ ! -d /usr/web_bk ] && /bin/mkdir /usr/web_bk"
ssh root@"$name" "cp -a /usr/local/tomcat/webapps/www /usr/web_bk/$TIME"
if [ $? -eq 0 ];then
/usr/bin/rsync -avrl --progress --delete -e ssh --exclude=/WEB-INF/classes/application.properties --exclude=/WEB-INF/classes/applicationContext-quartz.xml --dry-run /usr/local/tomcat/webapps/www/ root@"$name":/usr/local/tomcat/webapps/www/
fi
done
镜像从哪里来:
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://04be47cfm.daocloud.io
for IP in `cat ip.list`;
do
scp -r /root/script/ root@10.0.$IP:/root/ 2>/dev/null
#ssh root@10.0.${IP} "cd /root/script/&&/bin/bash /root/script/install_mfs.sh"
ssh root@10.0.${IP} "umount /usr/local/img.happytoo.cn/"
ssh root@10.0.${IP} "umount /usr/local/img.happytoo.cn/"
ssh root@10.0.${IP} "umount /usr/local/img.happytoo.cn/"
ssh root@10.0.${IP} "cd /root/script/&&/bin/bash /root/script/mountmfs.sh"
done
# 计划任务调整
sed '/10.0.1.85/d' /var/spool/cron/root -i
sed '/10.0.1.85/d' /var/spool/cron/www -i
if [[ $(df -a|grep "10.0.1.50:9421"|wc -l) -ne 1 ]];then /usr/local/mfs/bin/mfsmount /usr/local/img.happytoo.cn/ -H 10.0.1.50 -o nonempty;fi
## 开机任务整理
sed '/10.0.1.85/d' /etc/fstab -i
sed -e '/mount/d' -e '/umask/d' /etc/rc.d/rc.local -i
cat <<EOF >>/etc/rc.d/rc.local
/usr/local/mfs/bin/mfsmount /usr/local/img.happytoo.cn -H 10.0.1.50 -o nonempty
/usr/sbin/ntpdate 10.0.0.94
EOF
## 挂载变更
umount /usr/local/img.happytoo.cn
/usr/local/mfs/bin/mfsmount /usr/local/img.happytoo.cn -H 10.0.1.50 -o nonempty
http://user.qzone.qq.com/3313268531/blog/1502648154?&_wv=7