。。。。。。。。。。。。。。。。。。。。。。
分类: LINUX
2007-04-18 13:56:23
■ 简单部署脚本:
#!/bin/sh
echo "
#Include conf/extra/daily.conf
#Include conf/extra/emegency.conf" >> /usr/local/apache2/conf/httpd.conf
mkdir /usr/local/apache2/htdocs/daily
mkdir /usr/local/apache2/htdocs/emegency
touch /usr/local/apache2/conf/extra/daily.conf
touch /usr/local/apache2/conf/extra/emegency.conf
echo "
RewriteLog /usr/local/apache2/logs/rewrite.log
RewriteLoglevel 5
RewriteEngine on
RewriteRule ^/(.*)$ /usr/local/apache2/htdocs/daily/index.html" > /usr/local/apache2/conf/extra/daily.conf
echo "
RewriteLog /usr/local/apache2/logs/rewrite.log
RewriteLoglevel 3
RewriteEngine on
RewriteRule ^/(.*)$ /usr/local/apache2/htdocs/emegency/index.html" > /usr/local/apache2/conf/extra/emegency.conf
touch /usr/local/apache2/htdocs/daily/index.html
touch /usr/local/apache2/htdocs/emegency/index.html
/usr/local/apache2/bin/apachectl configtest
echo "daily page." > /usr/local/apache2/htdocs/daily/index.html
echo "emegency page." > /usr/local/apache2/htdocs/emegency/index.html
■ 切换脚本
#!/bin/sh
#This is used to Switch apache page for (daily/emergency/default)
Apache_dir="/usr/local/apacheweb";
BIN_dir="/usr/local/apacheweb/bin";
CONF_dir="/usr/local/apacheweb/conf";
#Date_time=`date +'%Y%m%d%H%M%S'`;
cp $CONF_dir/httpd.conf $CONF_dir/extra/httpd.conf.bak
#Timer()
#{
#s=0;
#while [ "$s" -lt 60 ]
#do
# s=`expr $s + 1`;
# sleep 1;
# echo "remaining... $s seconds";
#done
#}
emegency_conf=`grep "Include conf/extra/emegency.conf" $CONF_dir/httpd.conf`;
daily_conf=`grep "Include conf/extra/daily.conf" $CONF_dir/httpd.conf`;
while [ -z "$emegency_conf" ] || [ -z "$daily_conf" ]
do
if [ -z "$emegency_conf" ]
then
echo "emegency_conf is not in $CONF_dir/httpd.conf";
echo "Are you sure ADD following into $CONF_dir/httpd.conf(y/n)";
echo "#Include conf/extra/emegency.conf";
Timer;
read yn;
if [ $yn = 'y' ]
then
echo "#Include conf/extra/emegency.conf" >> $CONF_dir/httpd.conf;
fi
if [ $yn = 'n' ]
then
exit 0;
fi
fi
if [ -z "$daily_conf" ]
then
echo "daily_conf is not in $CONF_dir/httpd.conf";
echo "Are you sure ADD following into $CONF_dir/httpd.conf(y/n)";
echo "#Include conf/extra/daily.conf";
Timer;
read yn;
if [ $yn = 'y' ]
then
echo "#Include conf/extra/daily.conf" >> $CONF_dir/httpd.conf;
fi
if [ $yn = 'n' ]
then
exit 0;
fi
fi
emegency_conf=`grep "Include conf/extra/emegency.conf" $CONF_dir/httpd.conf`;
daily_conf=`grep "Include conf/extra/daily.conf" $CONF_dir/httpd.conf`;
done
Apache_conf_check()
{
/usr/local/apacheweb/bin/apachectl configtest >/dev/null 2>&1;
sytax_apache=$?;
if [ "$sytax_apache" == "0" ]
then
return 0;
else
return 1;
fi
}
Switch_e()
{
Apache_conf_check;
if [ "$?" == "0" ]
then
echo "$CONF_dir/httpd.conf's sytax is OK!"
echo "Now,Apache will switch emegency page...";
sed -i 's/^#.*Include conf\/extra\/emegency.conf$/Include conf\/extra\/emegency.conf/' $CONF_dir/httpd.conf;
sed -i 's/^Include conf\/extra\/daily.conf$/#Include conf\/extra\/daily.conf/' $CONF_dir/httpd.conf;
Apache_conf_check;
if [ "$?" == "0" ]
then
$BIN_dir/apachectl restart;
sleep 2;echo "Switch sucessful!!";
else
echo "Apache' sytax is BAD.";
fi
else
echo "$CONF_dir/httpd.conf's sytax is BAD,check it.
COMMAND: /usr/local/apacheweb/bin/apachectl configtest";
mv $CONF_dir/extra/httpd.conf.bak $CONF_dir/httpd.conf;
echo "Error:Not Switch";
fi
}
Switch_d()
{
Apache_conf_check;
if [ "$?" == "0" ]
then
echo "$CONF_dir/httpd.conf's sytax is OK!"
echo "Now,Apache will switch daily page...";
sed -i 's/^Include conf\/extra\/emegency.conf$/#Include conf\/extra\/emegency.conf/' $CONF_dir/httpd.conf;
sed -i 's/^#.*Include conf\/extra\/daily.conf$/Include conf\/extra\/daily.conf/' $CONF_dir/httpd.conf;
Apache_conf_check;
if [ "$?" == "0" ]
then
$BIN_dir/apachectl restart;
sleep 2;echo "Switch sucessful!!";
else
echo "Apache' sytax is BAD.";
fi
else
echo "$CONF_dir/httpd.conf's sytax is BAD,check it.
COMMAND: /usr/local/apacheweb/bin/apachectl configtest";
mv $CONF_dir/extra/httpd.conf.bak $CONF_dir/httpd.conf;
echo "Error:Not Switch";
fi
}
Switch_default()
{
Apache_conf_check;
if [ "$?" == "0" ]
then
echo "$CONF_dir/httpd.conf's sytax is OK!"
echo "Now,Apache will switch default page...";
sed -i 's/^Include conf\/extra\/emegency.conf$/#Include conf\/extra\/emegency.conf/' $CONF_dir/httpd.conf;
sed -i 's/^Include conf\/extra\/daily\.conf$/#Include conf\/extra\/daily.conf/' $CONF_dir/httpd.conf;
Apache_conf_check;
if [ "$?" == "0" ]
then
$BIN_dir/apachectl restart;
sleep 2;echo "Switch sucessful!!";
else
echo "Apache' sytax is BAD.";
fi
else
echo "$CONF_dir/httpd.conf's sytax is BAD,check it.
COMMAND: /usr/local/apacheweb/bin/apachectl configtest";
mv $CONF_dir/extra/httpd.conf.bak $CONF_dir/httpd.conf;
echo "Error:Not Switch";
fi
}
case "$1" in
e|emergency)
Switch_e
;;
d|daily)
Switch_d;
;;
default)
Switch_default;
;;
*)
echo
echo "Usge: Switch_apache.sh [e | d |default]";
echo
echo "----------------------switch----------------------";
echo "1) ./Switch_apache.sh e/emergency (e:emergency page)";
echo "2) ./Switch_apache.sh d/daily (d:daily page)";
echo "3) ./Switch_apache.sh default (default:default page)";
echo "--------------------------------------------------";
exit 1;
esac
■ 在主控机上部署下面的脚本(这台机器到其他机器无密码登陆):
[root@fx-scr12 bin]# vi /export/home/dljroot/jhfsys/bin/Switch.sh
#!/bin/sh
IP_list="
Front_ip="
Mobile_ip="
if [ "$1" != "" ]
then
Stop_ip=$1;
else
# echo "Usge: ./Switch.sh {[all |
front | mobile |
echo "./Switch.sh
echo "Example:"
echo "1)Switch default page!!"
echo " "
echo "./Switch.sh all default"
echo "./Switch.sh front default"
echo "./Switch.sh mobile default"
echo "./Switch.sh
echo " "
echo "2)Switch daily page!!"
echo " "
echo "./Switch.sh all d"
echo "./Switch.sh front d"
echo "./Switch.sh mobile d"
echo "./Switch.sh
echo " "
echo "3)switch emegency page!!"
echo " "
echo "./Switch.sh all e"
echo "./Switch.sh front e"
echo "./Switch.sh mobile e"
echo "./Switch.sh
exit 1;
fi
if [ "$2" != "" ]
then
Stop_type=$2;
else
echo "Please use a Switch page:emegency?daily?OR default page.";
echo "Example:";
echo "1)./Switch
echo "2)./Switch.sh all e/emergency (e:emergency page)";
echo "3)./Switch.sh mobile d/daily (d:daily page)";
echo "4)./Switch.sh front default (default:default page)";
exit 1;
fi
case "$Stop_ip" in
all)
for ip in $IP_list
do
echo "$ip is Switching... to $Stop_type";
ssh dljroot@$ip -- "sh /export/home/dljroot/jhfsys/bin/Switch_apache.sh $Stop_type";
if [ "$?" = "0" ]
then
echo "$ip========================================>OK";
else
echo "$ip========================================>FALSE";
fi
done
;;
front)
for ip in $Front_ip
do
echo "$ip is Switching... to $Stop_type";
ssh dljroot@$ip -- "sh /export/home/dljroot/jhfsys/bin/Switch_apache.sh $Stop_type";
if [ "$?" = "0" ]
then
echo "$ip========================================>OK";
else
echo "$ip========================================>FALSE";
fi
done
;;
mobile)
for ip in $Mobile_ip
do
echo "$ip is Switching... to $Stop_type";
ssh dljroot@$ip -- "sh /export/home/dljroot/jhfsys/bin/Switch_apache.sh $Stop_type";
if [ "$?" = "0" ]
then
echo "$ip========================================>OK";
else
echo "$ip========================================>FALSE";
fi
done
;;
for ip in $Stop_ip
do
echo "$ip is Switching... to $Stop_type";
ssh dljroot@$ip -- "sh /export/home/dljroot/jhfsys/bin/Switch_apache.sh $Stop_type";
if [ "$?" = "0" ]
then
echo "$ip========================================>OK";
else
echo "$ip========================================>FALSE";
fi
done
;;
*)
echo "Please use a Switch page:emegency?daily?OR default page.";
echo "Example:";
echo "1)./Switch
echo "2)./Switch.sh all e/emergency (e:emergency page)";
echo "3)./Switch.sh mobile d/daily (d:daily page)";
echo "4)./Switch.sh front default (default:default page)";
exit 0;
;;
esac