3、rsync+sersync更快更节约资源实现web数据同步
4、unison+inotify实现web数据双向同步

一:为什么要实现同步备份

服务器上有些重要文件或数据时,可以把他们多备份一份到其他服务器上,这样就不怕数据或文件丢失了。

二:环境的搭建

服务器A:192.168.1.10 源服务器

服务器B: 192.168.1.20 目的服务器

我们要实现的就是把A服务器上的文件同步到B服务器上,从而实现备份。我们主要是在B服务器上安装配置rsync,在A服务器上安装配置sersync,通过sersync把文件推送到B服务器上

三:开始搭建

从B服务器开始:

1.关闭selinux,在/etc/sysconfig/selinux 这个文件,设置SELINUX=disable

2.防火墙开通873端口   -A INPUT -m state --state NEW -m tcp -p tcp --dport 873 -j ACCEPT
     3.开始安装rsync

yum install rsync -y

4.配置rsync,rsync的配置文件是/etc/rsyncd.conf,配置如下:

图下方需要注意的地方:secrets file这个是配置同步的密码文件的。[rsynctest]这个是配置同步模块的名称,path是配置同步的目录,hosts allow是允许同步的主机,hosts deny:拒绝同步的主机

5.创建同步的用户与密码的文件,即上图中的secrets file这个配置选项中的文件。/etc/rsync.passwd,同进要设置这个文件的权限为600

echo "user:password" >> /etc/rsync.passwd

chmod 600 /etc/rsync.passwd

6.创建同步的目录:即上图中path配置选项中的目录。

mkdir /home/rsynctest

7.启动rsync

rsync  --daemon --config=/etc/rsyncd.conf

接着重启一下xinetd

/etc/init.d/xinetd restart

8.配置开机启动 echo "rsync --daemon --config=/etc/rsyncd.conf" >> /etc/rc.d/rc.local

到这样B服务器基本就配置完成了。

接着配置A服务器:

1.先到sersync官网下载sersync:http://sersync.sourceforge.net/

wget http://sersync.googlecode.com/files/sersync2.1_64bit_binary.tar.gz

2.安装sersync

# mkdir /usr/local/sersync

# mkdir /usr/local/sersync/conf

# mkdir /usr/local/sersync/bin

# mkdir /usr/local/sersync/log

# tar zxvf sersync2.5_32bit_binary_stable_final.tar.gz

# cd GNU-Linux-x86/

# cp confxml.xml /usr/local/sersync/conf

# cp sersync2 /usr/local/sersync/bin

3.创建密码文件,同B服务器一样,不过这个文件只要保存一个密码就行了,不用用户名,权限也是600

echo "password" >> /etc/rsync.passwd

chmod 600 /etc/rsync.passwd

4.配置sersync,配置文件就是上第二步复制的confxml.xml这个文中,路径在/usr/local/sersync/conf中

---------------------------------------------------------------------------------------------------------------------------

<?xml version="1.0" encoding="ISO-8859-1"?>

<head version="2.5">

# 设置本地IP和端口

<host hostip="localhost" port="8008"></host>

# 开启DUBUG模式

<debug start="false"/>

# 开启xfs文件系统

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

<closeWrite start="true"/>

<moveFrom start="true"/>

<moveTo start="true"/>

<attrib start="true"/>

<modify start="true"/>

</inotify>

<sersync>

# 本地同步的目录路径

<localpath watch="/data">

# 远程IP和rsync模块名

<remote ip="192.168.1.20" name="data"/>

<!--<remote ip="192.168.8.39" name="tongbu"/>-->

<!--<remote ip="192.168.8.40" name="tongbu"/>-->

</localpath>

<rsync>

# rsync指令参数

<commonParams params="-auvzP"/>

# rsync同步认证

<auth start="true" users="user" passwordfile="/etc/rsync.passwd"/>

# 设置rsync远程服务端口,远程非默认端口则需打开自定义

<userDefinedPort start="false" port="874"/><!-- port=874 -->

# 设置超时时间

<timeout start="true" time="100"/><!-- timeout=100 -->

# 设置rsync+ssh加密传输模式,默认关闭,开启需设置SSH加密证书

<ssh start="false"/>

</rsync>

# sersync传输失败日志脚本路径,每隔60会重新执行该脚本,执行完毕会自动清空。

<failLog path="/usr/local/sersync/log/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->

# 设置rsync+crontab定时传输,默认关闭

<crontab start="false" schedule="600"><!--600mins-->

<crontabfilter start="false">

<exclude expression="*.php"></exclude>

<exclude expression="info/*"></exclude>

</crontabfilter>

</crontab>

# 设置sersync传输后调用name指定的插件脚本,默认关闭

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

------------------------------------------------------------------------------------------------------------------

5.创建同步目录:mkdir /home/rsynctest

6.设置环境变量:

# echo "export PATH=$PATH:/usr/local/sersync/bin/" >> /etc/profile

# source /etc/profile

7.启动sersync

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

注:重启操作如下:

# killall sersync2 && sersync2 -r -d -o /usr/local/sersync/conf/confxml.xml

8.设置开机启动

# echo "sersync2 -r -d -o /usr/local/sersync/conf/confxml.xml" >> /etc/rc.local

好了,两台机器的配置都已经完成,现在你在A服务器的/home/rsynctest这个目录下创建文件,看看B服务器同样目录下是不是也生成了这个文件,如果是,那就恭喜,你成功了!

如何通过rsync+sersync 实现同步备份的更多相关文章

  1. Rsync + sersync 实时同步备份

    一      Rsync + Sersync  实时同步介绍 1.Rsync 服务搭建介绍 云机上搭建Rsync server,在本地搭建Rsync Clinet. 2. Sersync 服务搭建介绍 ...

  2. rsync+sersync自动同步备份数据

    一.为什么要用Rsync+sersync架构?1.sersync是基于Inotify开发的,类似于Inotify-tools的工具2.sersync可以记录下被监听目录中发生变化的(包括增加.删除.修 ...

  3. Linux下简单粗暴使用rsync实现文件同步备份【转】

    这篇来说说如何安全的备份,还有一点不同的是上一篇是备份服务器拉取数据,这里要讲的是主服务器如何推送数据实现备份. 一.备份服务器配置rsync文件 vim /etc/rsyncd.conf #工作中指 ...

  4. Linux Rsync实现文件同步备份(转载)

    原文地址:Linux Rsync实现文件同步备份作者:夷北 转自:http://www.mike.org.cn/blog/index.php?load=read&id=639###pp=0 [ ...

  5. Rsync+Sersync实时同步数据目录

    第1章 Rsync简介 1.1 Rsync基本概述 rsync是一款开源的备份工具,可以在不同主机之间进行同步,可实现全量备份与增量备份 全量:将全部数据,进行传输覆盖 增量:只传输差异部分的数据 1 ...

  6. Rsync+sersync 数据同步指南

    (1):sersync 可以记录下被监听目录中发生变化的(包括增加.删除.修改)具体某一个文件或 某一个目录的名字: (2):rsync 在同步的时候,只同步发生变化的这个文件或者这个目录(每次发生变 ...

  7. centos7下rsync+crontab定期同步备份

    最近需求想定期备份内部重要的服务器数据到存储里面,顺便做个笔记 以前整过一个win下的cwrsync(客户端)+rsync(服务端:存储)的bat脚本 这次整一个Linux下的脚本sh,执行定期自动备 ...

  8. linux之rsync远程数据同步备份

    rsync服务是一种高效的远程数据备份的工具,该服务的port号为873, 是Liunx下的一种非独立服务.由xinetd超级服务管理,取代监听873port. 长处: 1.rsync能够利用ssh和 ...

  9. rsync & sersync 实时同步

    1.根据之前一篇关于rsync的随笔部署好rsync服务后,可以开始inotify的部署 2.sersync的部署 ①.部署服务(安装和配置过程) #Master 部署Sersync服务 mkdir ...

随机推荐

  1. moment.js常用时间示例,时间管理

    '今天': moment() '昨天': moment().subtract(1, 'days') '过去7天':moment().subtract(7, 'days'),moment() '上月': ...

  2. Goland 提示 :configuration is still incorrect 的解决

    安装好 Goland 后,调试编译的时候提示 goland configuration is still incorrect,百度 和 Google 都没有明确答案 Google 上有一些提示,但是也 ...

  3. Java8 按照类属性去重

    测试po package com.shiwulian.test.po; public class Person {private String id;private String name;priva ...

  4. JS中的DOM— —节点以及操作

    DOM操作在JS中可以说是非常常见了吧,很多网页的小功能的实现,比如一些元素的增删操作等都可以用JS来实现.那么在DOM中我们需要知道些什么才能完成一些功能的实现呢?今天这篇文章就先简单的带大家入一下 ...

  5. SQL SERVER Management Studio

    1.​ 实验目的 ​ 熟悉SQL SERVER Management Studio的部分操作 ​ 数据SQL SERVER简化版和完整版数据库设计 2.​ 实验内容 2.1.​ 熟悉简化版SQL ...

  6. MongoDB Limit与Skip方法

    MongoDB Limit() 方法 如果你需要在MongoDB中读取指定数量的数据记录,可以使用MongoDB的Limit方法,limit()方法接受一个数字参数,该参数指定从MongoDB中读取的 ...

  7. Android Design Support Library使用详解——Snackbar

    Google在2015 I/O大会上,给我们带来了更加详细的Material Design规范,同时也引入了Android Design Support Library,为我们提供了基于Materia ...

  8. Rails在MacOS上搭建Heroku部署环境

    heroku只是用postgresql,而不能兼容sqlite数据库.所以很重要的一步就是在部署实际产品的时候将数据库类型修改为postgresql,否则你将无法push到heroku上去. hero ...

  9. 【Android】给Android Studio设置代理

    先打开我们的Android Studio,点击工具栏的file下的settings,如下图 之后再搜索框上面输入Proxy,然后按第四步提示点击,如下图 之后就进入了设置代理的界面了,如下图 默认情况 ...

  10. WebService案例入门(基础篇)

    [版权申明:本文系作者原创,转载请注明出处] 文章出处:http://blog.csdn.net/sdksdk0/article/details/52106690 作者:朱培 ID:sdksdk0 邮 ...