服务器群秒级别文件同步(ssh+SHELL)
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)的更多相关文章
- 负载均衡配置下的不同服务器【Linux】文件同步问题
负载均衡配置下的不同服务器[Linux]文件同步问题2017年04月13日 22:04:28 守望dfdfdf 阅读数:2468 标签: linux负载均衡服务器 更多个人分类: 工作 问题编辑版权声 ...
- linux多服务器之间的目录文件同步
一.rsync是什么 在开始正式学习rsync之前,我们先来回答这个问题:rsync是什么. rsync(remote synchronize)是Liunx/Unix下的一个远程数据同步工具.它可通过 ...
- 文件同步服务器,iis 集群 ,代码同步(一)
文件同步服务器 BitTorrent Sync 有点像TeamViewer远程协助 软件,私钥连接. 使用版本就30 天,最近测试了,功能不够理想.有点遗憾,我觉得我可以写一个! 确实很好用.
- rsync+sersync+inotify实现服务器间文件同步之一
rsync+sersync+inotify实现服务器间文件同步之一:rsync安装配置 2013年12月14日 ⁄ Linux管理, 服务器集群技术 ⁄ 共 4925字 ⁄ rsync+sersync ...
- 使用inotify+rsync实现服务器间文件同步
1. rsync 1.1 什么是rsync rsync是一个远程数据同步工具,可通过LAN/WAN快速同步多台主机间的文件.它使用所谓的“Rsync演算法”来使本地和远程两个主机之间的文件达到 ...
- BAT实现服务器文件同步
服务器文件同步有很多工具,例如 GoodSync.rsync.BitTorrent Sync等……其实WINDOWS下自带了一个文件同步利器:ROBOCOPY.它是一个命令行的目录复制命令,自从Win ...
- BitTorrent Sync - 神奇的文件同步软件,无需服务器让多台电脑互相同步!
176,487 微博 腾讯 空间 微信 141 49 如今人们对文件备份和同步的需求已经越来越强烈了.像 Dropbox 一样的云存储网盘有很多,但它们都有一个局限性,就是所有的文件都得经过它们的服务 ...
- linux服务器之间的文件同步;rsync+inotifywait;同步多个目录
1.双向同步:unison+inotify 2.单向同步:rsync+inotify python版的pyinotify 本文介绍第二种方法: 1.Inotify 是一个 Linux特性,它监控文件系 ...
- Rsync+inotify实现文件实时同步#附shell脚本
强烈推荐先仔细看此文 https://segmentfault.com/a/1190000002427568 实验环境 centos 7.3 vm2:192.168.221.128 同步服务器 vm1 ...
随机推荐
- scanf_s,scanf安全版本
%s,%c必须加sizeof(it)
- 安装Python模块:pygame
Pygame项目托管在代码分享网站Bitbucket中.要在Windows系统中安装Pygame,请访问https://bitbucket.org/pygame/pygame/downloads/ , ...
- flume配置文件
读文件log传入kafka中 agent.sources = s1 agent.channels = c1 agent.sinks = k1 agent.sources.s1.type=exec ag ...
- [OpenCV] IplImage and Operation
IplImage 一.资源 In this chapter, APIs will make U crazy. Good luck! Next, Review Linear Algebra. Ref: ...
- iOS - 解决Unable to add a source with url `https://github.com/CocoaPods/Specs.git` named
1 本来cocopods没有问题,最近创建项目,利用cocopods导入第三方库的时候,出现如下错误: [!] Unable to add a source with url `https://gi ...
- Redis 未授权访问漏洞(附Python脚本)
0x01 环境搭建 #下载并安装 cd /tmp wget http://download.redis.io/releases/redis-2.8.17.tar.gz tar xzf redis-.t ...
- RGB24转YUV420
BOOL RGB2YUV(LPBYTE RgbBuf, UINT nWidth, UINT nHeight, LPBYTE yuvBuf, unsigned long *len) { if (RgbB ...
- sharepoint权限操作(记录以备忘)
using Microsoft.SharePoint; using System; using System.Collections.Generic; using System.Linq; using ...
- repr方法字符串输出实例对象的值
#coding=utf-8 #repr方法字符串输出实例对象的值 class CountFromBy(object): def __init__(self, val=0, incr=1): self. ...
- 深入浅出MFC——消息映射与命令传递(六)
1. 消息分类: 2. 万流归宗——Command Target(CCmdTarget): 3. "消息映射"是MFC内建的一个信息分派机制.通过三个宏(DECLARE_MESSA ...