1.介绍
\
2.业务服务器远程更新浏览服务器文件的脚本
#!/bin/bash operate=$
ip=$
conf_file="/var/www/html/test/ip_list"
file_chsum="/var/www/html/test/cksvalue"
file_ser="10.60.10.62" cksum(){
ssh ${file_ser} "cksum ${conf_file}|awk '{print\$1}' > ${file_chsum}"
if [ $? -ne ];then
#生成cksum值失败
echo ""
fi
} if [[ ! $ip =~ ^[-]{,}\.[-]{,}\.[-]{,}\.[-]{,}$ ]];then
#IP不合法
echo "";
exit ;
fi if [[ "${operate}" == "add" ]];then
ips=`ssh ${file_ser} "cat $conf_file|grep ${ip}/32|wc -l"`
if [ ${ips} -eq ];then
ssh ${file_ser} "echo "${ip}/" >> $conf_file"
if [ $? -eq ];then
cksum
#添加IP成功
echo ""
exit ;
else
#添加IP失败
echo ""
exit ;
fi
else
#添加IP成功(IP已存在)
echo "";
exit ;
fi
elif [[ "${operate}" == "del" ]];then
ssh ${file_ser} "sed -i '/${ip}\/32/d' $conf_file"
if [ $? -eq ];then
cksum
#删除IP成功
echo ""
exit ;
else
#删除IP失败
echo ""
exit ;
fi
else
#参数1($)不合法
echo ""
exit ;
fi
3.浏览服务器采用http的方式提供配置文件和cksum值的浏览和下载
4.VPS主机群每隔30校验一次配置文件的cksum值来保持配置文件的最新状态
* * * * * sleep && sh /tmp/sync_customIP.sh
* * * * * sleep && sh /tmp/sync_customIP.sh
#!/bin/bash conf_file_url="http://10.60.10.62:8060/test/ip_list"
cksum_url="http://10.60.10.62:8060/test/cksvalue"
local_conf_file="/tmp/ip_list"
time=`date`
log="/tmp/sync_customIP.log" get_cksum() {
remote_cksum=`curl -s "${cksum_url}"`
local_cksum=`cksum ${local_conf_file}|awk '{print\$1}'`
} sync_file() {
cat ${local_conf_file} > /tmp/.tmp_ip.txt
wget -q ${conf_file_url} -O ${local_conf_file};
} get_cksum if [[ "$remote_cksum" != "$local_cksum" ]];then
sync_file
get_cksum
if [[ "$remote_cksum" != "$local_cksum" ]];then
cat /tmp/.tmp_ip.txt > ${local_conf_file}
echo "${time} sync fail.." >> $log
else
echo "${time} sync success.." >> $log
fi
else
echo "${time} there are no need to sync.. ">> $log
fi log_count=`cat $log |wc -l`
if [ $log_count -gt ];then
sed -i '1,1000d' $log
fi