sersync + rsync 服务器同步

现在常用的同步软件

单向同步:

rsync一般是server到client

sersync一般是client到server,sersync可以做到实时的监控

sersync+rsync 一般是多台服务器之间的

双向同步:

unison

sersync 监控系统文件变化 然后 rsync 实时同步

如果系统文件没有变化,不会同步

执行同步进程的时候,应该先执行客户端的rsync 再执行 sersync ,而且配置文件中需同步的目录,客户端必须有。



例如A 服务器向B 服务器同步数据

A/B都需要安装rsync,而且B需要开rsync守护进程

1. 在A上安装sersync软件

/usr/local/sersync

下面有个配置文件

confxml.xml


2. B服务器配置rsync

首先得安装rsync

yum -y install rsync

vi /etc/rsyncd.conf

uid=root
gid=root
max connections=36000
use chroot=no
log file=/var/log/rsyncd.log
pid file=/var/run/rsyncd.pid
lock file=/var/run/rsyncd.lock

[website]
path=/www/htdocs
comment = website files
ignore errors = yes
read only = no
hosts allow = 192.168.1.4/24
hosts deny = *

开启rsync守护进程

/usr/bin/rsync --daemon

开启防火墙端口

vi /etc/sysconfig/iptables

#添加

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp -s 192.168.1.4 --dport 873 -j ACCEPT

# 注意,如果报连接失败,不能同步,建议 /etc/init.d/iptables stop

开启rsync服务

/usr/bin/rsync --daemon

3. 配置A 服务器上的confxml.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
<host hostip="localhost" port="8008"></host>
<debug start="false"/>
<fileSystem xfs="false"/>

<filter start="false">

<exclude expression="^public/img/*"></exclude>
<exclude expression="^public/upload/*"></exclude>
<exclude expression="^public/www/*"></exclude> // 上面三行分别是过滤掉那几个目录,不同步这几个目录,需要把filter的start设置为true

</filter>
<inotify>
<delete start="true"/>
<createFolder start="true"/>
<createFile start="false"/>
<closeWrite start="true"/>
<moveFrom start="true"/>
<moveTo start="true"/>
<attrib start="false"/>
<modify start="false"/>
</inotify>


<sersync>
<localpath watch="/www/htdocs/">
<remote ip="192.168.0.58" name="website"/><!---跟上面红色标记相同-->
</localpath>
<rsync>
<commonParams params="-artuz"/>
<auth start="false" users="root" passwordfile="/etc/rsync.pas"/>
<userDefinedPort start="false" port="874"/><!-- port=874 -->
<timeout start="false" time="100"/><!-- timeout=100 -->
<ssh start="false"/>
</rsync>
<failLog path="/tmp/website_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->
<crontab start="true" schedule="600"><!--600mins-->
<crontabfilter start="false"> // 设置过滤后,相应的这里也需要设置为true
<exclude expression="public/img/*"></exclude>
<exclude expression="public/upload/*"></exclude>
<exclude expression="public/www/*"></exclude>
</crontabfilter>
</crontab>
<plugin start="false" name="command"/>
</sersync>
</head>

开启A 服务器上sersync 守护进程

/usr/local/sersync/sersync2 -n 4 -o /usr/local/sersync/confxml.xml -r -d

# /usr/local/sersync/GNU-Linux-x86/sersync2 -n 4 -o /usr/local/sersync/GNU-Linux-x86/website.xml -r -d

# 设置了过滤文件后,执行的守护进程不能加参数 -r

4. A/B 服务器需要解析

192.168.1.4 A
192.168.1.5 B


注意:

有的sftp上传工具,如果上传大的文件,可能会导致只同步一部分的问题,可以考虑更换sftp上传工具解决哦




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值