Linux文件实时同步,可实现一对多
说明:该功能服务端安装sersync2,客户端安装rsync,原理就是服务端主动推送设定目录下的所有更新的文件到各个客户端rsync接收。
rsync大家都知道,是Linux自带的数据同步工具,而sersync2是google大神的开源项目http://code.google.com/p/sersync/
下面给出具体的实现步骤,实现的详细原理大家可以去上面的开源网址,上面说的很详细
- 客户端配置,首先系统安装rsync工具,
[root@yo57 ~]# vi /etc/rsyncd.conf uid=www
gid=www
max connections=36000
use chroot=no
log file=/var/log/rsyncd.log
pid file=/var/run/rsyncd.pid
lock file=/var/run/rsyncd.lock [yowebtongbu]
path=/Data/code/adserver
comment = yo web files
ignore errors = yes
read only = no
hosts allow = 192.168.0.0/24
hosts deny = *
[root@yo57 ~]# /usr/bin/rsync --daemon --config=/etc/rsyncd.conf
[root@yo57 ~]# ps -ef|grep rsyn
root 1070 29923 0 17:04 pts/4 00:00:00 grep rsyn
root 32069 1 0 16:54 ? 00:00:00 /usr/bin/rsync --daemon --config=/etc/rsyncd.conf - 写入开机启动项
[root@yo57 ~]# vi /etc/rc.local #!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff. touch /var/lock/subsys/local ulimit -SHn 51200
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
/usr/local/nginx/sbin/nginx
/etc/init.d/php_fpm start
/usr/bin/rsync --daemon --config=/etc/rsyncd.conf - 服务器端
[root@10
local
]
# tar -zxvf sersync2.5.4_64bit_binary_stable_final.tar.gz[root@10
local
]
# cd sersync2.5.4_64[root@10 sersync2.5.4_64]
# lsconfxml.xml sersync2[root@10 sersync2.5.4_64]
# vi confxml.xml修改这一段即可
<localpath
watch
=
"/Data/code/adserver"
>
<remote ip=
"192.168.0.27"
name=
"yowebtongbu"
/>
<!--<remote ip=
"192.168.8.39"
name=
"tongbu"
/>-->
<!--<remote ip=
"192.168.8.40"
name=
"tongbu"
/>-->
<
/localpath
>进行一次完整同步
[root@10 sersync2.5.4_64]# ./sersync2 -r写入脚本并放入开机启动项
[root@10 sersync2.5.4_64]
# cat /usr/local/sbin/sersync.sh#!/bin/bashPATH=
/bin
:
/sbin
:
/usr/bin
:
/usr/sbin
:
/usr/local/bin
:
/usr/local/sbin
:~
/binexport
PATHSDATH=
"/usr/local/sersync2.5.4_64"SSTART=
"./sersync2 -r -d"SPID=`
ps
-ef|
grep
'sersync2'
|
grep
-
v
'grep'
|
awk
'{print $2}'
`function_start(){
echo
-en
"\033[32;49;1mStarting sersync2......\n"
echo
-en
"\033[39;49;0m"
if
[ -t ${SPID} ];
then
cd
${SDATH}
${SSTART} >
/dev/null
2>&1
printf
"Serync2 is the successful start!\n"
else
printf
"Sersync2 is runing!\n"
exit
1
fi}function_stop(){
echo
-en
"\033[32;49;1mStoping sersync2......\n"
echo
-en
"\033[39;49;0m"
if
[ -t ${SPID} ];
then
printf
"Sersync2 program is not runing!\n"
else
kill
${SPID}
printf
"Sersync2 program is stoped\n"
fi}function_restart(){
echo
-en
"\033[32;49;1mRestart sersync2......\n"
echo
-en
"\033[39;49;0m"
if
[ -t ${SPID} ];
then
cd
${SDATH}
${SSTART} >
/dev/null
2>&1
else
kill
${SPID}
sleep
1
cd
${SDATH}
${SSTART} >
/dev/null
2>&1
fi
printf
"Sersync2 is the successful restart!\n"}function_kill(){
killall sersync2}function_status(){
if
!
ps
-ef|
grep
'sersync2'
|
grep
-
v
'grep'
>
/dev/null
2>&1
then
printf
"Sersync2 is down!!!\n"
else
printf
"Sersync2 is running now!\n"
fi}if
[
"$1"
=
"start"
];
then
function_startelif
[
"$1"
=
"stop"
];
then
function_stopelif
[
"$1"
=
"restart"
];
then
function_restartelif
[
"$1"
=
"kill"
];
then
function_killelif
[
"$1"
=
"status"
];
then
function_statuselse
echo
-en
"\033[32;49;1m Usage: sersync2 {start|stop|restart|kill|status}\n"
echo
-en
"\033[39;49;0m"fi
[root@10 sersync2.5.4_64]
# vi /etc/rc.local#!/bin/sh## This script will be executed *after* all the other init scripts.# You can put your own initialization stuff in here if you don't# want to do the full Sys V style init stuff.touch
/var/lock/subsys/local#/etc/init.d/lemp start/usr/local/nginx/sbin/nginx/etc/init
.d
/php_fpm
start/usr/local/zabbix/sbin/zabbix_agentd/usr/local/sbin/sersync
.sh start
整个实现就这么简单,以后主服务器上面/Data/code/adserver目录下有新建、删除、修改文件或文件夹(包括下层递归)的的数据会自动推送到下面的各个服务端对应目录下,如果临时不需要该功能,kill掉服务端即可,操作完以后在手动开启服务端(此时客户端不用动)
Linux文件实时同步,可实现一对多的更多相关文章
- linux文件实时同步
参考博客:https://www.cnblogs.com/MacoLee/p/5633650.html 一.文件同步很简单 服务端:被动的接收传输过来的数据 客户端:主动提供数据给服务端 安装思路:服 ...
- linux下两台服务器文件实时同步方案设计和实现
inux下两台服务器文件实时同步方案设计和实现 假设有如下需求: 假设两个服务器: 192.168.0.1 源服务器 有目录 /opt/test/ 192.168.0.2 目标服务器 有目录 /o ...
- Linux服务器间文件实时同步的实现
使用场景 现有服务器A和服务器B,如果服务器A的指定目录(例如 /home/paul/rsync/ )中的内容发生变更(增删改和属性变更),实时将这些变更同步到服务器B的目标目录中(例如 /home/ ...
- (转)Linux下通过rsync与inotify(异步文件系统事件监控机制)实现文件实时同步
Linux下通过rsync与inotify(异步文件系统事件监控机制)实现文件实时同步原文:http://www.summerspacestation.com/linux%E4%B8%8B%E9%80 ...
- rsync+inotify 实现服务器之间目录文件实时同步(转)
软件简介: 1.rsync 与传统的 cp. tar 备份方式相比,rsync 具有安全性高.备份迅速.支持增量备份等优点,通过 rsync 可 以解决对实时性要求不高的数据备份需求,例如定期的备份文 ...
- rsync+inotify-tools文件实时同步
rsync+inotify-tools文件实时同步案例 全量备份 Linux下Rsync+sersync实现数据实时同步完成. 增量备份 纯粹的使用rsync做单向同步时,rsync的守护进程是运行在 ...
- inotify用法简介及结合rsync实现主机间的文件实时同步
一.inotify简介 inotify是Linux内核2.6.13 (June 18, 2005)版本新增的一个子系统(API),它提供了一种监控文件系统(基于inode的)事件的机制,可以监控文件系 ...
- eclipse 远程文件实时同步,eclipse远程部署插件
[转自] http://zhwj184.iteye.com/blog/1842730 eclipse 远程文件实时同步,eclipse远程部署插件 github地址:https://github.co ...
- Centos 6.5 rsync+inotify 两台服务器文件实时同步
rsync和inotify是什么我这里就不在介绍了,有专门的文章介绍这两个工具. 1.两台服务器IP地址分别为: 源服务器:192.168.1.2 目标服务器:192.168.1.3 @todo:从源 ...
随机推荐
- 《Android源码设计模式》--策略模式
No1: 定义:策略模式定义了一系列的算法,并将每一个算法封装起来,而且使它们还可以相互替换.策略模式让算法独立于使用它的客户而独立变化. No2: 使用场景: 1)针对同一类型问题的多种处理方式,仅 ...
- [HDU - 5408] CRB and Farm
题意: 给出一个由n个点组成的凸包,以及凸包内的k个点,问是否能够在凸包上选择最多2k个点构造一个新的 凸包,使得新的凸包覆盖原来的k个点. 要求2k个点覆盖原本的k个点,只要对原k个点构造凸包,然后 ...
- 【记录】【持续更新】mybatis使用记录
1.> < 等符号在mybatis中的sql语句需要转义 > : > < : < 2.mybatis动态选择 <choose> <when te ...
- firewalld启动问题
问题 在查看或启动firewalld服务时,提示"Warning: firewalld.service changed on disk. Run 'systemctl daemon-relo ...
- Java 中的异常
前段时间集合的整理真的是给我搞得心力交瘁啊,现在可以整理一些稍微简单一点的,搭配学习 ~ 突然想到一个问题,这些东西我之前就整理过,现在再次整理有什么区别嘛?我就自问自答一下,可能我再次整理会看到不一 ...
- ubuntu下安装和破解navicat的方法
ubuntu下安装和破解navicat的方法 之前我也在苦苦搜寻ubuntu完美破解navicat的方法,但是大家都说是删除掉~/.Navicat,就可以续用,的确是这样,但是很麻烦. 于是我找到了一 ...
- 《Multi-Agent Actor-Critic for Mixed Cooperative-Competitive Environments》论文解读
MADDPG原文链接 OpenAI bog DDPG链接 目录 一.摘要 二.效果展示 三.方法细节 问题分析 具体方法 伪代码 网络结构 四.实验结果 五.总结 附录 Proposition 1 一 ...
- JAVAEE——淘淘商城第一天:电商行业的背景和技术特点,商城的介绍、技术的选型、系统架构和工程搭建
1. 学习计划 1.电商行业的背景. 2.电商行业的技术特点 3.商城的介绍 a) 常用的名词介绍 b) 系统功能介绍 4.淘淘商城的系统架构 a) 传统架构 b) 分布式架构 c) 基于服务的架构 ...
- Little Elephant and Array 线段树
题目:http://codeforces.com/problemset/problem/220/B 题意 给定一组数据,多次询问区间内某数字出现次数与该数字数值相同的数的个数 思路 一看到区间查询,就 ...
- C#中的特性 (Attribute) 入门 (一)
C#中的特性 (Attribute) 入门 (一) 饮水思源 http://www.cnblogs.com/Wind-Eagle/archive/2008/12/10/1351746.html htt ...