rsync+sersync实现双向同步

1.安装配置rsync用于同步

使用root用户安装配置,10.58.2.4、10.158.2.4安装配置方式一样,其中rsync为centos默认安装过了,可以先行检查,如果没有安装则使用如下方式进行安装,已经安装则跳过安装步骤进行配置即可。

1、安装配置rsync用于同步

shell>

yum install -y rsync

2、创建rsyncd.conf配置文件

shell>

vim /etc/rsyncd.conf

输入如下内容:

uid = xxxx #备份以什么身份进行,用户ID

gid = root #备份以什么身份进行,组ID

use chroot = no #禁锢在源目录

max connections = 36000

  #最大连接数,0代表没有限制

strict modes = yes #是否检查口令文件的权限

log file =/var/log/rsyncd.log #日志记录文件

pid file =/var/run/rsyncd.pid #运行进程的PID文件

lock file =/var/run/rsyncd.lock #运行进程的LOCK文件


[tongbu] #指定认证的备份模块名,后续sersync配置中会用到

comment = web files

path =/app/xxxx/tomcat8.0.24/webapps/xxxx-portal/upload #需要备份的目录的路径

ignore errors = yes #忽略一些无关的IO错误

read only = no #设置为no,即可以传至服务器的相应目录

write only = no #设置为no,表示客户端可以下载文件

auth users = xxxx #连接模块的用户名

secrets file =/etc/rsyncd.pwd #连接模块用户名的密码文件存储路径

3、创建用户认证文件

shell>

vim /etc/rsyncd.pwd

输入如下内容:

用户名:密码#注意:该用户名密码为:本机的用户名密码

4、设置文件权限

shell>

      chmod  600 /etc/rsyncd.conf #设置文件所有者读取、写入权限

      chmod  600 /etc/rsyncd.pwd  #设置文件所有者读取、写入权限


2 安装配置sersync用于监控指定目录文件变化并触发同步

使用root用户安装配置sersync用于监控指定目录文件变化并触发同步

1、上传sersync安装包

shell>

      cd /usr/local/src

rz #上传sersync2.5.4_64bit_binary_stable_final.tar.gz

tar -zxvf sersync2.5.4_64bit_binary_stable_final.tar.gz

cd /usr/local

mkdir sersync

mv GNU-Linux-x86 /usr/local/sersync

2、配置sersync的confxml.xml文件

shell>

cd /usr/local/sersync/GNU-Linux-x86

cp confxml.xml confxml.xmlbak

vim confxml.xml #编辑写入如下内容:


<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>

<!--此处的IP为待同步的机器的IP地址及rsyncd.conf中指定认证的备份模块名,例如我们现在配置的机器为10.58.2.4,则此处IP需要配置为10.158.2.4-->

</localpath>

<rsync>

<commonParams

  params="-artuz"/>

<!--此处一定要设定为true才会自动同步,/etc/sersync.secrets为待同步机器密码文件,例如我们现在配置的机器为10.58.2.4,则此处sersync.secrets文件中需要配置10.158.2.4的xxxx用户的密码-->

<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="true" 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">



<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/p_w_picpaths"/>

</localpath>

</plugin>

</head>

3、创建用户认证文件

shell>

vim /etc/sersync.secrets

输入如下内容:

待同步机器xxxx用户对应密码

#例如:我们现在配置的机器为10.58.2.4,

#则此处sersync.secrets文件中需要配置10.158.2.4的xxxx用户的密码

4、设置文件权限

shell>

      chmod  600 /etc/sersync.secrets #设置文件所有者读取、写入权限


3 启动rsync

1、启动rsync

shell>

/usr/bin/rsync --daemon

  --config=/etc/rsyncd.conf

2、检查rsync是否启动

shell>

lsof -i:873

3、加入开机自启动

shell>

echo “/usr/bin/rsync

  --daemon --config=/etc/rsyncd.conf” >> /etc/rc.local


4启动sersync

1、启动sersync

shell>

/usr/local/sersync/GNU-Linux-x86/sersync2

  -d -r -o /usr/local/sersync/GNU-Linux-x86/confxml.xml

2、检查sersync是否启动

shell>

ps -ef|grep sersync

3、加入开机自启动

shell>

vim /etc/rc.d/rc.local #编辑,在最后一行添加

/usr/local/sersync/GNU-Linux-x86/sersync2 -d -r -o

  /usr/local/sersync/GNU-Linux-x86/confxml.xml

#设置开机自动启动脚本

:wq! #保存退出


5测试双向同步是否生效

[if !supportLists]1、  [endif]在10.58.2.4的/app/xxxx/tomcat8.0.24/webapps/xxxx-portal/upload下新建、删除、修改测试文件,然后到10.158.2.4中查看是否已经同步。

在10.158.2.4的/app/xxxx/tomcat8.0.24/webapps/xxxx-portal/upload下新建、删除、修改测试文件,然后到10.58.2.4中查看是否已经同步。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容