您的位置:首页 > 其它

部署sersync实时同步服务器

2018-02-23 14:10 351 查看

部署sersync实时同步服务器

一、部署rsync

服务端的部署

#安装rsync
yum install rsync -y

#编辑配置文件,我这里使用的是root用户
vim /etc/rsyncd.conf
#rsync_config
#created by HQ at 2017
##rsyncd.conf start##

uid = root #rsync用户
gid = root
use chroot = no
max connections = 200
timeout = 300
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.1.0/24 #允许网段
hosts deny = 0.0.0.0/32
auth users = rsync_backup #认证用户
secrets file = /etc/rsync.password
[back]  #这里关系到sersync配置
comment = "nfs_backup"
path = /back

#创建密码验证文件
touch /etc/rsync.password
echo "认证用户:密码" >> /etc/rsync.password
chmod 600 /etc/rsync.password

#启动rsync
rsync --daemon


客户端部署

#安装rsync
yum install rsync -y

#创建密码验证文件
touch /etc/rsync.password
echo "密码"
chmod 600 /etc/rsync.password


二、安全策略

为了使服务器更加安全,这里采用了ipset做安全策略,简单方便,客户端和服务端都安装

#安装
yum install ipset

#使用 ipset 创建列表,我这里起名为server
ipset create server hash:ip

#添加 ip
ipset add server <ip1>
ipset add server <ip2>

#导出 ipset,以后如果再添加ip直接去/etc/sysconfig/ipset修改,修改后执行service ipset reload
ipset save > /etc/sysconfig/ipset

#iptable添加ipset策略
-A INPUT -m set --match-set server src -j ACCEPT


三、安装seresync软件

#直接下载二进制包
wget https://sersync.googlecode.com/files/sersync2.5.4_64bit_binary_stable_final.tar.gz 
#解压后放到usr/local/sersync/下,然后修改配置文件
vim /usr/local/sersync/config/
<?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="false"/>
<createFolder start="true"/>
<createFile start="true"/>
<closeWrite start="true"/>
<moveFrom start="true"/>
<moveTo start="true"/>
<attrib start="false"/>
<modify start="false"/>
</inotify>

<sersync>
<localpath watch="/www/linlaoban/pigcms/upload">   #监控目录
<remote ip="192.168.1.216" name="back"/>
<!--<remote ip="192.168.8.39" name="tongbu"/>-->
<!--<remote ip="192.168.8.40" name="tongbu"/>-->
</localpath>
<rsync> #rsync相关
<commonParams params="-azP"/>
<auth start="true" users="rsync_backup" passwordfile="/etc/rsync.password"/>
<userDefinedPort start="false" port="874"/><!-- 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="/opt/tongbu">
<deshost ip="192.168.138.20" 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>


四、测试

#先测试一下rsync是否可用
rsync -avz /etc/hosts rsync_backup@192.168.1.216::back --password-file=/etc/rsync.password
#没问题后启动sersync
/usr/local/sersync/bin/sersync2 -dro /usr/local/sersync/conf/confxml.xml
参数-d:启用守护进程模式
参数-r:在监控前,将监控目录与远程主机用rsync命令推送一遍
参数-o:指定配置文件,默认使用confxml.xml文件
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  sersync 实时同步