参考1:http://www.jb51.net/LINUXjishu/142722.html

参考2:http://sookk8.blog.51cto.com/455855/328076

主服务器IP 192.168.109.128

从服务器IP 192.168.109.132

1.查看 rsync xinetd是否安装

  rpm -q rsync

2.关闭 iptables 和 SELinux

从服务器IP 192.168.109.132 上的配置开始

1.yum install rsync xinetd #安装  如果已经安装可略过

2.vi /etc/xinetd.d/rsync #编辑配置文件

  disable = no #修改为no

3./etc/init.d/xinetd start #启动

4.创建rsyncd.conf配置文件

  vi /etc/rsyncd.conf #创建配置文件,添加以下代码

  

log file = /var/log/rsyncd.log #日志文件位置,启动rsync后自动产生这个文件,无需提前创建
pidfile = /var/run/rsyncd.pid #pid文件的存放位置
lock file = /var/run/rsync.lock #支持max connections参数的锁文件
secrets file = /etc/rsync.pass #用户认证配置文件,里面保存用户名称和密码,后面会创建这个文件
motd file = /etc/rsyncd.Motd #rsync启动时欢迎信息页面文件位置(文件内容自定义)
[test_rsync] #自定义名称
path = /test/ #rsync服务端数据目录路径
comment = test_rsync #模块名称与[home_www.jb51.net]自定义名称相同
uid = root #设置rsync运行权限为root
gid = root #设置rsync运行权限为root
port=873 #默认端口
use chroot = no #默认为true,修改为no,增加对目录文件软连接的备份
read only = no #设置rsync服务端文件为读写权限
list = no #不显示rsync服务端资源列表
max connections = 200 #最大连接数
timeout = 600 #设置超时时间
auth users = root #执行数据同步的用户名,可以设置多个,用英文状态下逗号隔开
hosts allow = 192.168.109.128 #允许进行数据同步的客户端IP地址,可以设置多个,用英文状态下逗号隔开
hosts deny = 192.168.21.254 #禁止数据同步的客户端IP地址,可以设置多个,用英文状态下逗号隔开

5、创建用户认证文件

  vi /etc/rsync.pass #配置文件,添加以下内容  

root:123456 #格式,用户名:密码,可以设置多个,每行一个用户名:密码

6、设置文件权限

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

7、让配置生效
   service xinetd restart

8.检查rsync
#netstat -a | grep rsync
   tcp        0      0 0.0.0.0:873                 0.0.0.0:*                   LISTEN

9.设置开机启动项

  #vi /etc/rc.d/rc.local  加入
    /usr/bin/rsync --daemon     //不知道干嘛用的

    service xinetd start

第二部分:在主服务器192.168.109.128上操作

1.查看和安装 

whereis rsync #查看系统是否已安装rsync,出现下面的提示,说明已经安装
rsync: /usr/bin/rsync /usr/share/man/man1/rsync.1.gz
yum install xinetd #只安装xinetd即可,CentOS中是以xinetd来管理rsync服务的
yum install rsync xinetd #如果默认没有rsync,运行此命令进行安装rsync和xinetd
vi /etc/xinetd.d/rsync #编辑配置文件,设置开机启动rsync
disable = no #修改为no
/etc/init.d/xinetd start #启动(CentOS中是以xinetd来管理rsync服务的)

2、创建认证密码文件

  vi /etc/rsync.pass  #编辑文件,添加以下内容

123456 #密码

3.修改权限

 chmod 600 /etc/passwd.txt  #设置文件权限,只设置文件所有者具有读取、写入权限即可

4.测试是否成功  

rsync -arHz --port=873 --progress --delete /test/ root@192.168.109.132::text_rsync --password-file=/etc/rsync.pass

选项解释:

  -a  保持文件属性

  -r 子目录递归处理

  -H  保持硬链接关系

  -z  传输时压缩处理

  --progress 显示传输过程

  --delete  删除目标备份没有的文件

  -e ssh   使用ssh加密隧道传输

  --password-file  使用本地密码和目标密码匹配  跳过手动输入密码的过程

 二.sersync的安装

查看linux机器是32位还是64位的方法

1.查看linux机器是32位还是64位的方法:

  file /sbin/init 或者 file /bin/ls
  /sbin/init:
ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked
(uses shared libs), for GNU/Linux 2.6.18, stripped

  如果显示 64-bit 则为64位;

  file /sbin/init
  /sbin/init:
ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux
2.2.5, dynamically linked (uses shared libs), stripped
  如果显示为32 bit 则为32bit;

2.32位系统TAR包 http://pan.baidu.com/s/1ntyn2XF

  64位系统 http://pan.baidu.com/s/1qWNPMpu

3.ls -l /proc/sys/fs/inotify   #列出文件目录,出现下面的内容,说明服务器内核支持inotify

-rw-r--r-- 1 root root 0 Mar 7 02:17 max_queued_events
-rw-r--r-- 1 root root 0 Mar 7 02:17 max_user_instances
-rw-r--r-- 1 root root 0 Mar 7 02:17 max_user_watches

备注:Linux下支持inotify的内核最小为2.6.13,可以输入命令:uname -a查看内核

CentOS 5.X 内核为2.6.18,默认已经支持inotify

4.修改inotify默认参数(inotify默认内核参数值太小)

  查看系统默认参数值:

    sysctl -a | grep max_queued_events

    结果是:fs.inotify.max_queued_events = 16384

    sysctl -a | grep max_user_watches

    结果是:fs.inotify.max_user_watches = 8192

    sysctl -a | grep max_user_instances

    结果是:fs.inotify.max_user_instances = 128

  修改参数:

sysctl -w fs.inotify.max_queued_events="99999999"
sysctl -w fs.inotify.max_user_watches="99999999"
sysctl -w fs.inotify.max_user_instances="65535"

参数说明:

max_queued_events:

inotify队列最大长度,如果值太小,会出现"** Event Queue Overflow **"错误,导致监控文件不准确

max_user_watches:

要同步的文件包含多少目录,可以用:find /home/www.jb51.net -type d | wc -l 统计,必须保证max_user_watches值大于统计结果(这里/home/www.jb51.net为同步文件目录)

max_user_instances:

每个用户创建inotify实例最大值

5.安装sersync

  上传安装包到服务器 解压

    tar -zxvf ......

    mv GNU-Linux-x86 /usr/local/sersync #移动目录到/usr/local/sersync

6.配置sersync

  cd /usr/local/sersync #进入sersync安装目录
  cp confxml.xml confxml.xml-bak #备份原文件

  vi confxml.xml  编辑,修改下面的代码

  

<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
<host hostip="192.168.109.128" 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="/test">
<remote ip="192.168.109.132" name="test_rsync"/>
<!--<remote ip="192.168.8.40" name="tongbu"/>-->
</localpath>
<rsync>
<commonParams params="-artuz"/>
<auth start="true" users="root" passwordfile="/etc/rsync.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="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">
<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="<a href="http://pic.xoyo.com/cms"/">http://pic.xoyo.com/cms"/</a>>
<regexurl regex="false" match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"/>
</localpath>
</plugin>
</head>

7.设置sersync监控开机自动执行

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

    /usr/local/sersync/sersync2 -d -r -o /usr/local/sersync/confxml.xml #设置开机自动运行脚本

8.添加脚本监控sersync是否正常运行

  vi  /root/check_sersync.sh 编辑,添加以下代码

#!/bin/sh
sersync="/usr/local/sersync/sersync2"
confxml="/usr/local/sersync/confxml.xml"
status=$(ps aux |grep 'sersync2'|grep -v 'grep'|wc -l)
if [ $status -eq 0 ];
then
$sersync -d -r -o $confxml &
else
exit 0;
fi

  :wq! #保存退出
  chmod +x /root/check_sersync.sh #添加脚本执行权限

  vi /etc/crontab #编辑,在最后添加下面一行
  */5 * * * * root  /root/check_sersync.sh > /dev/null 2>&1 #每隔5分钟执行一次脚本
  service crond reload #重新加载服务

9.启动服务查看效果

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

  mkdir /test/rsync_success

  去从服务器查看效果

rsync 实验的更多相关文章

  1. sersync + rsync 实现文件的实时同步

    这里有一点要特别注意了,就是在你完成备份之后,先不要把本地的文件都给删除了,先把服务停了之后再删除文件, 因为你已删除,检查到两边不一致,他又会把备份端给删除了.所以特别得注意了.这里吃过一次亏. 还 ...

  2. rsync与inotify 数据同步

    发布:thebaby   来源:脚本学堂     [大 中 小] 本文介绍下,在linux系统中,使用rsync与inotify实现数据同步的一个实例,有研究文件同步的朋友可以作个参考.本文转自:ht ...

  3. [Linux]Linux下rsync服务器和客户端配置

    一.rsync简介 Rsync(remote sync)是UNIX及类UNIX平台下一款神奇的数据镜像备份软件,它不像FTP或其他文件传输服务那样需要进行全备份,Rsync可以根据数据的变化进行差异( ...

  4. Linux下Rsync+Inotify-tools实现数据实时同步

    Linux下Rsync+Inotify-tools实现数据实时同步 注意:下面的三个案例都是rsync 每次都是全量的同步(这就坑爹了),而且 file列表是循环形式触发rsync ,等于有10个文件 ...

  5. centos7服务搭建常用服务配置之二:Rsync+sersync实现数据实时同步

    目录 1.RSYNC数据备份 1.1 rsync服务简介 1.2 rsync特点和优势 1.3 rysnc运行模式简介 1.4 数据同步方式 2 Rsync实验测试 2.1 实验环境说明 2.2 服务 ...

  6. rsync+nfs+sersync实战案例

    回顾: 1.rsync 统一备份各个服务器的配置文件或重要文件 系统配置文件 日志文件 系统日志文件 messages.secure.cron 服务日志文件 access_log.access.log ...

  7. rsync 服务介绍及相关实验

    一.rsync 简介 rsync 是类 unix 系统下的数据镜像备份工具.一款支持快速完全备份和增量备份的工具,支持本 地复制,远程同步等,类似于 scp 命令:rsync 命令在同步文件之前要先登 ...

  8. Mysql+Mycat+NFS+Rsync+LVS+DNS+IPtables综合实验

    1.环境准备 服务器 IP地址 作用 系统版本 Mysql-master eth0:10.0.0.58 主数据库 Rocky8.6 Mysql-slave1 eth0:10.0.0.68 备数据库 R ...

  9. RSync实现文件备份同步

    [rsync实现网站的备份,文件的同步,不同系统的文件的同步,如果是windows的话,需要windows版本cwrsync] 一.什么是rsync rsync,remote synchronize顾 ...

随机推荐

  1. HDOJ 1319 Prime Cuts<数论>

    学会了不难.通过这道题学习了两点: 1:筛选法求素数. 2:在写比较长的程序的时候,给每个功能部分加上注释,思路会更清晰. 题意: 1.题目中所说的素数并不是真正的素数,包括1: 2.需要读懂题意,对 ...

  2. libevent和libev的区别对比(二)

    之前有一篇文章描述过一些对比: http://www.cnblogs.com/charlesblc/p/6078029.html 这里在代码和应用方面再说一下. 看一下两边的Helloworld基本就 ...

  3. PHP聊天室开源系统workerman-chat

    PHP聊天室开源系统workerman-chat (2015-01-23 09:07:50) 转载▼ http://www.workerman.net/ http://www.workerman.ne ...

  4. 如何判断js是否加载完全

    var script=document.createElement('script'); if(script.onreadystatechange){ script.onreadystatechang ...

  5. WebDriver(Selenium2) 常见异常及处理方法

    http://uniquepig.iteye.com/blog/1568197 Exception NoSuchElementException Solutions    1. Check the l ...

  6. CodeForces 621A Wet Shark and Odd and Even

    水题 #include<cstdio> #include<cstring> #include<cmath> #include<ctime> #inclu ...

  7. Monitorix 监控 安装配置

    Monitorix 监控 安装配置 1. 首先安装RPMforge RPMforge 是由 Dag 及其他包裝者合作維護的.他們為 CentOS 提供超過 5000 個套件,包括 wine.vlc.m ...

  8. (简单) POJ 3259 Wormholes,SPFA判断负环。

    Description While exploring his many farms, Farmer John has discovered a number of amazing wormholes ...

  9. js Date 日期格式化(转)

    var myDate = new Date();myDate.getYear();        //获取当前年份(2位)myDate.getFullYear();    //获取完整的年份(4位,1 ...

  10. POJ 1862 Stripies

    每次合并最大的两个,优先级队列维护一下. 输出的时候%.3lf G++会WA,C++能AC,改成%.3f,都能AC. #include<cstdio> #include<cstrin ...