Server cluster Second Level file synchronization (Ssh+shell)

Source: Internet
Author: User

1. Introduction

\

2. The Business Server remotely updates the script to browse the server files

#!/bin/bashoperate=$1IP=$2Conf_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[$?-ne0];then #生成cksum值失败 Echo"10005"fi}if[[! $ip =~ ^[0-9]{1,3}\. [0-9]{1,3}\. [0-9]{1,3}\. [0-9]{1,3}$]];then #IP不合法 Echo"10003"; Exit1; Fiif[["${operate}"=="Add"]];then IPs= ' ssh ${file_ser}"cat $conf _file|grep ${ip}/32|wc-l"`  if[${ips}-eq0];then ssh ${file_ser}"Echo"${ip}/ +">> $conf _file"    if[$?-eq0];then cksum #添加IP成功 Echo"10000"Exit0; Else#添加IP失败 Echo"10001"Exit1; FiElse#添加IP成功 (IP already exists) echo"10000"; Exit0; Fielif [["${operate}"=="del"]];then ssh ${file_ser}"sed-i '/${ip}\/32/d ' $conf _file"  if[$?-eq0];then cksum #删除IP成功 Echo"10000"Exit0; Else#删除IP失败 Echo"10002"Exit1; FiElse#参数1 ($1) Not legal echo"10004"Exit1; Fi

3. Browse Server uses HTTP to provide configuration files and Cksum values for browsing and downloading

4.VPS host cluster verifies the Cksum value of the profile every 30 to keep the profile up-to-date

 && sh/tmp/sync_customip.sh && sh/tmp/sync_customip.sh
#!/bin/Bashconf_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_cksumif[["$remote _cksum"!="$local _cksum"]];then sync_file get_cksumif[["$remote _cksum"!="$local _cksum"]];then Cat/tmp/.tmp_ip.txt >${local_conf_file} Echo"${time} sync fail.">>$logElseEcho"${time} sync success .">>$log fiElseEcho"${time} There is no need to sync .">>$logfilog _count= ' Cat $log |WC-l 'if[$log _COUNT-GT -];then sed-I.'1,1000d'$logfi

Server cluster Second Level file synchronization (Ssh+shell)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.