Sersync+Rsync互相实时同步

作者: ropon 分类: 分布式集群 发布时间: 2018-04-13 16:26

1、关闭selinux
2、防火墙(iptables、Firewalld)放行873端口(默认)
3、安装Rsync服务
yum install rsync -y
useradd -r -s /sbin/nologin rsync -M
cat > /etc/rsyncd.conf <<EOF
uid = rsync
gid = rsync
use chroot = no
port = 873
address = 192.168.230.10
max connections = 2000
timeout = 200
log file = /var/run/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log format = %t %a %m %f %b

[rsync]
path = /home/wwwroot/test/
commemt = rsync
list = yes
read only = no
#write only = no
auth users = homeuser
secrets file = /etc/rsyncd.secret
ignore errors = yes
hosts allow = 192.168.250.101
hosts deny =
EOF
read only 指定是否允许客户上传文件。若为 true 则不允许上传;若为 false 并且服务器目录也具有读写权限则允许上传。 true
write only 指定是否允许客户下载文件。若为 true 则不允许下载;若为 false 并且服务器目录也具有读权限则允许下载。 false

read only 默认值true 不允许上传,只能读;false 可写(可上传),是否可读取决于write only
write only 默认值false 可读而且可下载;true 不允许下载,是否可写取决于read only

cat > /etc/rsyncd.secret <<EOF
homeuser:test123
EOF
chmod 600 /etc/rsyncd.secret

cat > /etc/rsyncd.pass <<EOF
test123
EOF
chmod 600 /etc/rsyncd.pass

mkdir -p /home/wwwroot/test
chown rsync.rsync -R /home/wwwroot/test
systemctl enable rsyncd
systemctl start rsyncd

4、安装Sersync服务
wget http://luopengtest.gotoip2.com/rsync/sersync.zip
unzip sersync.zip -C /usr/local/
tar xf sersync.zip -C /usr/local/
cat //usr/local/sersync/config.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=”(.*)\.svn”></exclude>
<exclude expression=”(.*)\.gz”></exclude>
<exclude expression=”^info/*”></exclude>
<exclude expression=”^static/*”></exclude>
</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=”/home/wwwroot/test”>
<remote ip=”192.168.250.101″ name=”rsync”/>
<!–<remote ip=”192.168.8.39″ name=”tongbu”/>–>
<!–<remote ip=”192.168.8.40″ name=”tongbu”/>–>
</localpath>
<rsync>
<commonParams params=”-artuz”/>
<auth start=”true” users=”homeuser” passwordfile=”/etc/rsyncd.pass”/>
<userDefinedPort start=”false” port=”873″/><!– port=874 –>
<timeout start=”false” time=”100″/><!– timeout=100 –>
<ssh start=”false”/>
</rsync>
<failLog path=”/tmp/rsync_fail_log.sh” timeToExecute=”60″/><!–default every 60mins execute once–>
<crontab start=”false” schedule=”600″><!–600mins–>
<crontabfilter start=”false”>
<exclude expression=”*.php”></exclude>
<exclude expression=”info/*”></exclude>
</crontabfilter>
</crontab>
<plugin start=”false” name=”command”/>
</sersync>

<plugin name=”command”>
<param prefix=”/bin/sh” suffix=”” ignoreError=”true”/> <!–prefix /opt/tongbu/mmm.sh suffix–>
<filter start=”false”>
<include expression=”(.*)\.php”/>
<include expression=”(.*)\.sh”/>
</filter>
</plugin>

<plugin name=”socket”>
<localpath watch=”/home/wwwroot/test/”>
<deshost ip=”192.168.250.101″ port=”8009″/>
</localpath>
</plugin>
<plugin name=”refreshCDN”>
<localpath watch=”/data0/htdocs/cms.xoyo.com/site/”>
<cdninfo domainname=”ccms.chinacache.com” port=”80″ username=”xxxx” passwd=”xxxx”/>
<sendurl base=”http://pic.xoyo.com/cms”/>
<regexurl regex=”false” match=”cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images”/>
</localpath>
</plugin>
</head>

cat /etc/rc.local
/usr/local/sersync/sersync2 -d -r -o /usr/local/sersync/confxml.xml

B服务器同理
注意开机启动项
cd /home/wwwroot/test && rsync -artuz -R –delete homeuser@192.168.230.10::rsync ./ –password-file=/etc/rsyncd.pass
/usr/local/sersync/sersync2 -d -r -o /usr/local/sersync/confxml.xml

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!

发表评论

电子邮件地址不会被公开。 必填项已用*标注