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

服务器群秒级别文件同步(ssh+SHELL)的更多相关文章

  1. 负载均衡配置下的不同服务器【Linux】文件同步问题

    负载均衡配置下的不同服务器[Linux]文件同步问题2017年04月13日 22:04:28 守望dfdfdf 阅读数:2468 标签: linux负载均衡服务器 更多个人分类: 工作 问题编辑版权声 ...

  2. linux多服务器之间的目录文件同步

    一.rsync是什么 在开始正式学习rsync之前,我们先来回答这个问题:rsync是什么. rsync(remote synchronize)是Liunx/Unix下的一个远程数据同步工具.它可通过 ...

  3. 文件同步服务器,iis 集群 ,代码同步(一)

    文件同步服务器 BitTorrent Sync 有点像TeamViewer远程协助 软件,私钥连接. 使用版本就30 天,最近测试了,功能不够理想.有点遗憾,我觉得我可以写一个! 确实很好用.

  4. rsync+sersync+inotify实现服务器间文件同步之一

    rsync+sersync+inotify实现服务器间文件同步之一:rsync安装配置 2013年12月14日 ⁄ Linux管理, 服务器集群技术 ⁄ 共 4925字 ⁄ rsync+sersync ...

  5. 使用inotify+rsync实现服务器间文件同步

      1. rsync 1.1 什么是rsync   rsync是一个远程数据同步工具,可通过LAN/WAN快速同步多台主机间的文件.它使用所谓的“Rsync演算法”来使本地和远程两个主机之间的文件达到 ...

  6. BAT实现服务器文件同步

    服务器文件同步有很多工具,例如 GoodSync.rsync.BitTorrent Sync等……其实WINDOWS下自带了一个文件同步利器:ROBOCOPY.它是一个命令行的目录复制命令,自从Win ...

  7. BitTorrent Sync - 神奇的文件同步软件,无需服务器让多台电脑互相同步!

    176,487 微博 腾讯 空间 微信 141 49 如今人们对文件备份和同步的需求已经越来越强烈了.像 Dropbox 一样的云存储网盘有很多,但它们都有一个局限性,就是所有的文件都得经过它们的服务 ...

  8. linux服务器之间的文件同步;rsync+inotifywait;同步多个目录

    1.双向同步:unison+inotify 2.单向同步:rsync+inotify python版的pyinotify 本文介绍第二种方法: 1.Inotify 是一个 Linux特性,它监控文件系 ...

  9. Rsync+inotify实现文件实时同步#附shell脚本

    强烈推荐先仔细看此文 https://segmentfault.com/a/1190000002427568 实验环境 centos 7.3 vm2:192.168.221.128 同步服务器 vm1 ...

随机推荐

  1. Java面试经典题:线程池专题

    1.什么是线程池 线程池的基本思想是一种对象池,在程序启动时就开辟一块内存空间,里面存放了众多(未死亡)的线程,池中线程执行调度由池管理器来处理.当有线程任务时,从池中取一个,执行完成后线程对象归池, ...

  2. 7 Django系列之关于bootstrap-table插件的简单使用

    preface 我们在前端html页面的时候做表格最常用的就是jinja2渲染,这样的好处是无须引用外部插件,直接使用就行,方便.但是不好的就是前端CSS样式以及其他表格排序筛选功能需要自己写,增加了 ...

  3. 给自己的android扫盲文 - 1

    1. 你得知道,android开发打一开始就是java的事,没其它语言什么事情,就是说google提供的android sdk中的api都是java的api2. 至于强大的跨平台语言,你懂的,非c/c ...

  4. cocos2dx 3.0 scrollview 在android下面背景變綠色了

    在windows上面跑的是OK的,  在android下面跑的時候就變成這樣子了:

  5. Python "HTTP Error 403: Forbidden"

    问题: 执行下面的语句时 def set_IPlsit(): url = 'https://www.whatismyip.com/' response = urllib.request.urlopen ...

  6. GSAP JS基础教程--认识GSAP JS

    第一次写博文呢,这次写博客是因为应一位同学的要求,写一下GSAP JS的一个小教程.为什么说小呢?因为它实际上就是小,只是一个入门级的小教程.如果你想问:“那你为什么不写详细一点呢?”,我想说,说., ...

  7. hudson.AbortException: No files found in path D:\testproject\project2\testoutput\ with configured filemask: output.xml

    错误描述: hudson.AbortException: No files found in path D:\testproject\project2\testoutput\ with configu ...

  8. Druid连接池基本配置及监控配置

    1.配置Druid连接池,监控慢sql <!-- 数据源配置, 使用 Druid 数据库连接池 --> <bean name="dataSource" class ...

  9. MySQL,查看连接数和状态等

    1.MySQL> show status like '%connect%'; Connections,试图连接到(不管是否成功)MySQL服务器的连接数.   Max_used_connecti ...

  10. codeblocks编码设置

    注意编码统一,即文件编码和编译时的编码统一即可. codeblock13.12下: 文件编码: setting -> editor ->general setting -> othe ...