Rsync+Sersync文件实时同步

rsync介绍:

rsync是linux系统下的数据镜像备份工具。使用快速增量备份工具Remote Sync可以远程同步,支持本地复制,或者与其他SSH、rsync主机同步。

基本特性
⚫ 可以镜像保存整个目录树和文件系统
⚫ 可以很容易做到保持原来文件的权限、时间、软硬链接等
⚫ 无须特殊权限即可安装
⚫ 优化的流程,文件传输效率高
⚫ 可以使用 rsh、ssh 方式来传输文件,当然也可以通过直接的 socket 连接
⚫ 支持匿名传输,以方便进行网站镜象在 windows 平台下也有相应的版本,如 cwrsync 和DeltaCopy 等。

Sersync介绍和对比 :

1、Sersync 使用 c++ 编写,对 linux 系统文件产生的临时文件和重复的文件操作会进行过滤,在本文后面会提到该点。使用sersyc和rsync结合做同步的时候,会大大减少运行时所消耗的本地以及网络资源,因此在速度方面有显著提升。

2、相比 Inotify-tools 和 Openduckbill,Sersync 配置起来更为简单方便。在谷歌 S
ersync 项目下载的安装包的 bin 目录下,放置了已经编译好的二进制文件,搭配 bin 目录下的xml文件可以直接部署使用。

3、Sersync 采用多线程(默认10)进行同步(即可以并发同步多个不同文件),尤其是针对较大文件同步的时候,它能够保证多个服务器实时保持同步状态。

4、Sersync 自带了出错处理机制。它可以通过失败队列自动对之前出错的文件进行重新同步操作。如果届时依旧失败,它会每 10 个小时对同步失败的文件再进行重新同步操作,直到文件同步为止。

5、Sersync 自带有 crontab 功能,因此不需要借助系统的 crontab ,只需在 xml 配置文件中开启该功能,即可按预先的配置,每隔一段时间自动做一次整体同步操作。

6、Sersync 还自带了 socket 与 refreshCDN 的协议扩展,可以满足有特殊需求的公司二次开发。

Sersync和inotify进行对比

inotify优点:
监控文件系统事件变化,通过同步工具实现实时数据同步
iontify缺点:
1.并发如果大于200个文件(10-100K),同步会有延迟
2.监控到事件后,调用rsync同步是单线程的(加&并发),sersync多进程同步

sersync的优点:
(1)配置文件
(2) 真正的守护进程socket
(3)可以对失败的文件定时重传
(4)第三方的http接口
(5) 默认是多线程的同步

环境介绍:

机器 Centos7.x

主机名ip软件包
backup192.168.200.10Rsync
master192.168.200.20Sersync

Rsync配置

Centos 7 自带rsync

[root@backup ~]# rpm -qa rsync
rsync-3.1.2-6.el7_6.1.x86_64

# 配置rsync配置文件 按照需求根据下面修改
[root@backup ~]# cat /etc/rsyncd.conf 
 #用户远端的命令使用rsync访问共享目录
uid = rsync
 #安全组
gid = rsync
#安全相关
use chroot = no
#最大连接
max connections = 200
#超时时间
timeout = 300
#pid存放位置
pid file = /var/run/rsyncd.pid
#锁文件
lock file = /var/run/rsync.lock
#日志文件
log file = /var/log/rsyncd.log
#忽略错误
ignore errors
#可写
read only = false
#不能列表
list = false
#允许主机网段
hosts allow = 192.168.200.0/24
#虚拟用户
auth users = rsync_backup 
#虚拟用户和密码
secrets file = /etc/rsync.password
fake super = yes
#共享模块名
[www]
#模块注释
comment = "Here's the explanation"
#共享位置
path = /data/www/
[bbs]								
comment = "Here's the explanation"	
path = /data/bbs/

[root@backup ~]# mkdir /data/{www,bbs} -p 
[root@backup ~]# ll /data/
总用量 0
drwxr-xr-x. 2 root root 6 12月 18 15:27 bbs
drwxr-xr-x. 2 root root 6 12月 18 15:27 www

#创建rsync用户
[root@backup ~]# useradd rsync -s /sbin/nologin
#编写虚拟用户和密码 把他输出到一个文件里面
[root@backup ~]# echo "rsync_backup:pwd123" > /etc/rsync.password
#给予权限
[root@backup ~]# chmod 600 /etc/rsync.password
#后台启动rsync
[root@backup ~]# rsync --daemon
#查看是否启动 
[root@backup ~]# netstat -anpt | grep rsync
tcp        0      0 0.0.0.0:873             0.0.0.0:*               LISTEN      29893/rsync         
tcp6       0      0 :::873                  :::*                    LISTEN      29893/rsync   

配置Sersync服务 master端

[root@master ~]# rpm -qa | grep rsync
rsync-3.1.2-6.el7_6.1.x86_64
[root@master ~]# echo "pwd123" > /etc/rsync.password
[root@master ~]# cat /etc/rsync.password
pwd123
[root@master ~]# chmod 600 /etc/rsync.password
[root@master ~]# mkdir /backup
[root@master ~]# cd /backup/
[root@localhost backup]# mkdir {1..10}.txt
[root@master backup]# ll
总用量 0
-rw-r--r--. 1 root root 0 12月 18 15:46 10.txt
-rw-r--r--. 1 root root 0 12月 18 15:46 1.txt
-rw-r--r--. 1 root root 0 12月 18 15:46 2.txt
-rw-r--r--. 1 root root 0 12月 18 15:46 3.txt
-rw-r--r--. 1 root root 0 12月 18 15:46 4.txt
-rw-r--r--. 1 root root 0 12月 18 15:46 5.txt
-rw-r--r--. 1 root root 0 12月 18 15:46 6.txt
-rw-r--r--. 1 root root 0 12月 18 15:46 7.txt
-rw-r--r--. 1 root root 0 12月 18 15:46 8.txt
-rw-r--r--. 1 root root 0 12月 18 15:46 9.txt
[root@master backup]# rsync -avz /backup/* rsync_backup@192.168.200.10::www --password-file=/etc/rsync.password
sending incremental file list
1.txt
10.txt
2.txt
3.txt
4.txt
5.txt
6.txt
7.txt
8.txt
9.txt

sent 557 bytes  received 214 bytes  1,542.00 bytes/sec
total size is 0  speedup is 0.00

[root@backup www]# pwd 
/data/www
[root@backup www]# ll
总用量 0
-rw-r--r--. 1 rsync rsync 0 12月 18 15:46 10.txt
-rw-r--r--. 1 rsync rsync 0 12月 18 15:46 1.txt
-rw-r--r--. 1 rsync rsync 0 12月 18 15:46 2.txt
-rw-r--r--. 1 rsync rsync 0 12月 18 15:46 3.txt
-rw-r--r--. 1 rsync rsync 0 12月 18 15:46 4.txt
-rw-r--r--. 1 rsync rsync 0 12月 18 15:46 5.txt
-rw-r--r--. 1 rsync rsync 0 12月 18 15:46 6.txt
-rw-r--r--. 1 rsync rsync 0 12月 18 15:46 7.txt
-rw-r--r--. 1 rsync rsync 0 12月 18 15:46 8.txt
-rw-r--r--. 1 rsync rsync 0 12月 18 15:46 9.txt


在master安装Sersync

#下载Sersync包
[root@master ~]# wget https://raw.githubusercontent.com/wsgzao/sersync/master/sersync2.5.4_64bit_binary_stable_final.tar.gz
[root@master ~]# tar xf sersync2.5.4_64bit_binary_stable_final.tar.gz -C /usr/local/
[root@master ~]# cd /usr/local/
#解压改名
[root@master local]# mv GNU-Linux-x86/ sersync
[root@master local]# cd sersync/
#创建 存放配置文件和启动和日志目录 
[root@master sersync]# mkdir conf bin logs
[root@master sersync]# mv confxml.xml conf/
[root@master sersync]# mv sersync2 bin/sersync
[root@master sersync]# cd /usr/local/sersync/conf/
[root@master conf]# ls
confxml.xml  
[root@master conf]# cp confxml.xml confxml.xml.bak
#修改配置文件 24行,25行,31行,33行,36行日志位置 
[root@master conf]# cat  confxml.xml 
     1	<?xml version="1.0" encoding="ISO-8859-1"?>
     2	<head version="2.5">
     3	    <host hostip="localhost" port="8008"></host>
     4	    <debug start="false"/>
     5	    <fileSystem xfs="false"/>
     6	    <filter start="false">
     7		<exclude expression="(.*)\.svn"></exclude>
     8		<exclude expression="(.*)\.gz"></exclude>
     9		<exclude expression="^info/*"></exclude>
    10		<exclude expression="^static/*"></exclude>
    11	    </filter>
    12	    <inotify>
    13		<delete start="true"/>
    14		<createFolder start="true"/>
    15		<createFile start="false"/>
    16		<closeWrite start="true"/>
    17		<moveFrom start="true"/>
    18		<moveTo start="true"/>
    19		<attrib start="false"/>
    20		<modify start="false"/>
    21	    </inotify>
    22	
    23	    <sersync>
    24		<localpath watch="/backup/">
    25		    <remote ip="192.168.200.10" name="www"/>
    26		    <!--<remote ip="192.168.8.39" name="tongbu"/>-->
    27		    <!--<remote ip="192.168.8.40" name="tongbu"/>-->
    28		</localpath>
    29		<rsync>
    30		    <commonParams params="-artuz"/>
    31		    <auth start="true" users="rsync_backup" passwordfile="/etc/rsync.password"/>
    32		    <userDefinedPort start="false" port="874"/><!-- port=874 -->
    33		    <timeout start="true" time="100"/><!-- timeout=100 -->
    34		    <ssh start="false"/>
    35		</rsync>
    36		<failLog path="/usr/local/sersync/logs/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->
    37		<crontab start="false" schedule="600"><!--600mins-->
    38		    <crontabfilter start="false">
    39			<exclude expression="*.php"></exclude>
    40			<exclude expression="info/*"></exclude>
    41		    </crontabfilter>
    42		</crontab>
    43		<plugin start="false" name="command"/>
    44	    </sersync>
    45	
    46	    <plugin name="command">
    47		<param prefix="/bin/sh" suffix="" ignoreError="true"/>	<!--prefix /opt/tongbu/mmm.sh suffix-->
    48		<filter start="false">
    49		    <include expression="(.*)\.php"/>
    50		    <include expression="(.*)\.sh"/>
    51		</filter>
    52	    </plugin>
    53	
    54	    <plugin name="socket">
    55		<localpath watch="/opt/tongbu">
    56		    <deshost ip="192.168.138.20" port="8009"/>
    57		</localpath>
    58	    </plugin>
    59	    <plugin name="refreshCDN">
    60		<localpath watch="/data0/htdocs/cms.xoyo.com/site/">
    61		    <cdninfo domainname="ccms.chinacache.com" port="80" username="xxxx" passwd="xxxx"/>
    62		    <sendurl base="http://pic.xoyo.com/cms"/>
    63		    <regexurl regex="false" match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"/>
    64		</localpath>
    65	    </plugin>
    66	</head>




#添加环境变量
[root@master ~]#  echo "export PATH=$PATH:/usr/local/sersync/bin">>/etc/profile

[root@master ~]#  tail -n 1   /etc/profile

export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/sersync/bin

[root@master ~]#  source  /etc/profile 
#启动sersync
[root@master conf]#  sersync  -r   -d  -o  /usr/local/sersync/conf/confxml.xml
set the system param
execute:echo 50000000 > /proc/sys/fs/inotify/max_user_watches
execute:echo 327679 > /proc/sys/fs/inotify/max_queued_events
parse the command param
option: -r 	rsync all the local files to the remote servers before the sersync work
option: -d 	run as a daemon
option: -o 	config xml name:  /usr/local/sersync/conf/confxml.xml
daemon thread num: 10
parse xml config file
host ip : localhost	host port: 8008
daemon start,sersync run behind the console 
use rsync password-file :
user is	rsync_backup
passwordfile is 	/etc/rsync.password
config xml parse success
please set /etc/rsyncd.conf max connections=0 Manually
sersync working thread 12  = 1(primary thread) + 1(fail retry thread) + 10(daemon sub threads) 
Max threads numbers is: 22 = 12(Thread pool nums) + 10(Sub threads)
please according your cpu  use -n param to adjust the cpu rate
------------------------------------------
rsync the directory recursivly to the remote servers once
working please wait...
execute command: cd /backup && rsync -artuz -R --delete ./  --timeout=100 rsync_backup@192.168.200.10::www --password-file=/etc/rsync.password >/dev/null 2>&1 
run the sersync: 
watch path is: /backup

验证一下

[root@master backup]# mkdir {1..3}.txt
[root@master backup]# ls
1.txt  2.txt  3.txt
#去那个机器查看一下查看一下 
#www对应的是 /data/www目录 
[root@backup ~]# cd /data/www/
[root@backup www]# pwd
/data/www
[root@backup www]# ls
1.txt  2.txt  3.txt

到这里实时同步已经完成

Rsync参数说明

q, --quiet 精简输出模式
-c, --checksum 打开校验开关,强制对文件传输进行校验
-a, --archive 归档模式,表示以递归方式传输文件,并保持所有文件属性,等于-rlptgoD
-r, --recursive 对子目录以递归模式处理
-R, --relative 使用相对路径信息
-b, --backup 创建备份,也就是对于目的已经存在有同样的文件名时,将老的文件重新命名为~filename。可 以使用–suffix选项来指定不同的备份文件前缀。
–backup-dir 将备份文件(如~filename)存放在在目录下。
-suffix=SUFFIX 定义备份文件前缀
-u, --update 仅仅进行更新,也就是跳过所有已经存在于DST,并且文件时间晚于要备份的文件。(不覆盖更新的文件)
-l, --links 保留软链结
-L, --copy-links 想对待常规文件一样处理软链结
–copy-unsafe-links 仅仅拷贝指向SRC路径目录树以外的链结
–safe-links 忽略指向SRC路径目录树以外的链结
-H, --hard-links 保留硬链结
-p, --perms 保持文件权限
-o, --owner 保持文件属主信息
-g, --group 保持文件属组信息
-D, --devices 保持设备文件信息
-t, --times 保持文件时间信息
-W, --whole-file 拷贝文件,不进行增量检测
-x, --one-file-system 不要跨越文件系统边界
-B, --block-size=SIZE 检验算法使用的块尺寸,默认是700字节
-e, --rsh=COMMAND 指定使用rsh、ssh方式进行数据同步
–rsync-path=PATH 指定远程服务器上的rsync命令所在路径信息
-C, --cvs-exclude 使用和CVS一样的方法自动忽略文件,用来排除那些不希望传输的文件
–existing 仅仅更新那些已经存在于DST的文件,而不备份那些新创建的文件
–delete 删除那些DST中SRC没有的文件
–delete-excluded 同样删除接收端那些被该选项指定排除的文件
–delete-after 传输结束以后再删除
–ignore-errors 及时出现IO错误也进行删除
–max-delete=NUM 最多删除NUM个文件
–partial 保留那些因故没有完全传输的文件,以是加快随后的再次传输
–force 强制删除目录,即使不为空
–numeric-ids 不将数字的用户和组ID匹配为用户名和组名
–timeout=TIME IP超时时间,单位为秒
-I, --ignore-times 不跳过那些有同样的时间和长度的文件
–size-only 当决定是否要备份文件时,仅仅察看文件大小而不考虑文件时间
–modify-window=NUM 决定文件是否时间相同时使用的时间戳窗口,默认为0
-T --temp-dir=DIR 在DIR中创建临时文件
–compare-dest=DIR 同样比较DIR中的文件来决定是否需要备份
-P 等同于 --partial
–progress 显示备份过程
-z, --compress 对备份的文件在传输时进行压缩处理
–exclude=PATTERN 指定排除不需要传输的文件模式
–include=PATTERN 指定不排除而需要传输的文件模式
–exclude-from=FILE 排除FILE中指定模式的文件
–include-from=FILE 不排除FILE指定模式匹配的文件
–address 绑定到特定的地址
–config=FILE 指定其他的配置文件,不使用默认的rsyncd.conf文件
–port=PORT 指定其他的rsync服务端口
–blocking-io 对远程shell使用阻塞IO
-stats 给出某些文件的传输状态
–progress 在传输时现实传输过程
–log-format=formAT 指定日志文件格式
–password-file=FILE 从FILE中得到密码
–bwlimit=KBPS 限制I/O带宽,KBytes per second

参考文章:
https://blog.51cto.com/wsxxsl/1767071

Remote Administrator (Radmin) 是应用最为广泛的一款远程控制软件,这是它的最新版本,已经附带了服务端 30 天时间限制的破解,主要的更新内容是: 兼容性: 支持 Windows Vista SP1 (32-bit and 64-bit). 支持 Windows Server 2008 (32-bit and 64-bit). 支持左手鼠标; 支持 27 国语言; 性能: 更快更平滑的控制体验. Radmin 详细介绍 + Radmin(Remote Administrator)是一款屡获殊荣的安全远程控制软件,帮助您在远程电脑上工作,如同您坐在那台电脑前一样。 该软件是理想的远程访问解决方案。 您可以从多个地点访问同一台电脑,并使用高级文件传输、远程关机、Telnet、操作系统集成的NT安全性系统支持,以及其它功能。Radmin在速度、可靠性及安全性 方面的表现超过了所有其它远程控制软件! Radmin是一款屡获殊荣的远程控制软件,它将远程控制、外包服务组件、以及网络监控结合到一个系统里,提供目前为止最快速、强健而安全的工具包。 完全兼容WindowsVista Radmin3.2完全支持WindowsVista32-bit和64-bit,包括用户账户控制(UAC)和快速用户切换。RadminServer3.2支持WindowsVista/XP/2003/2000(32-bit)和WindowsVista/XP/2003(64-bit)操作系统。RadminViewer3.2支持WindowsVista/XP/2003/2000/ME/98/95/NT4.0(32-bit)和WindowsVista/XP/2003(64-bit)操作系统。 最高的工作速度 Radmin是目前为止最快的远程控制软件,在10Mbps局域网的测试中,它比流行的VNC要快上150倍,也超过了PcAnywhere。它针对低带宽连接而优化(如调制解调器)。通过调制解调器连接,屏幕刷新率可以达到每秒钟更新5-10。如果连接到LAN,您可以实时在远程电脑上工作,每秒钟屏幕刷新率超过100。 最高的安全级别 Radmin以加密方式工作,所有的数据、屏幕图像、鼠标移动和键盘信号都使用256-位AES强密钥,每个连接都采用随机生成的密钥。Radmin的用户验证既可以使用Windows活动目录或Kerberos支持的安全性验证,或它自己的个别用户权限和安全登录/密码验证。Radmin安全性使用基于Diffie-Hellman的密钥交换,密钥长度2048-位。另外IP过滤器限制对特点主机和网络的访问。 文本和语音聊天 文本聊天、语音聊天和发送消息模式,都是Radminversion3新开发的功能,它们有助于您与所连接的远程电脑上操作的用户进行交流。 使用简单 Radmin非常易于学习和使用。我们大多数的客户都认为Radmin的主要优点在于简易。所有的报告界面很直观,而程序也非常易于使用。不同于那些臃肿软件(bloatware),Radmin没有无用的“增值”功能使它难以使用,不易学习或拖累它的性能。 安全的“拖放式”文件传输,带有“增量复制”(DeltaCopy)功能 使用Radmin您可以在资源管理器风格的界面中轻松拖放,对远程电脑上的任何文件以加密方式进行传输。Radmin在复制文件的时候有项功能,可以允许仅更新在两台电脑上不同的部分文件。这项功能称为“增量复制”(DeltaCopy)因为只复制文件的差异(“增量”)。它允许在网络故障之后继续复制操作,从故障发生的地方开始复制而非从头开始。此功能在从/往远程电脑上复制任何文件时自动使用。 支持多连接 Radmin支持同时多个连接到同一远程屏幕。这意味着您可以邀请朋友或同事远程观看您的屏幕(很适合开会),或从您自己的电脑屏幕上查看或控制若干远程屏幕(非常适合远程外包服务或教学)。 免费通过E-mail提供技术支持 Famatech通过e-mail对注册客户提供免费的技术支持。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值