centos6.5下部署sersync+rsync --daemon同步数据
rsync --daemon端配置
[root@rsync-daemon etc]# /etc/init.d/iptables stop
[root@rsync-daemon ~]# dos2unix rsyncd.conf
dos2unix: converting file rsyncd.conf to UNIX format ...
[root@rsync-daemon ~]# cp rsyncd.conf /etc/
[root@rsync-daemon ~]# cd /etc/
[root@rsync-daemon etc]# useradd -M -s /sbin/nologin rsync
[root@rsync-daemon etc]# vi rsyncd.conf
[root@rsync-daemon etc]# cat rsyncd.conf
[root@rsync-daemon data]# cat /etc/rsyncd.conf
##rsyncd.conf start##
uid = rsync
gid = rsync
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
[data]
path = /data/
ignore errors
read only = false
list = false
hosts allow = 10.0.0.0/24
#hosts deny = 0.0.0.0/32
auth users = rsync_backup
secrets file = /etc/rsync.password
#rsync_config_______________end [root@rsync-daemon etc]# mkdir /data
[root@rsync-daemon etc]# chown -R rsync.rsync /data
[root@rsync-daemon etc]# echo "rsync_backup:123456" >>/etc/rsync.password
[root@rsync-daemon etc]# chmod 600 /etc/rsync.password
[root@rsync-daemon etc]# echo "rsync --daemon" >>/etc/rc.local
[root@rsync-daemon data]# rsync --daemon --config=/etc/rsyncd.conf
[root@rsync-daemon etc]# netstat -lntup|grep rsync
tcp 0 0 0.0.0.0:873 0.0.0.0:* LISTEN 2821/rsync
tcp 0 0 :::873 :::* LISTEN 2821/rsync
sersync数据推送端配置
[root@sersync tools]# tar xf sersync2.5.4_64bit_binary_stable_final.tar.gz
[root@sersync tools]# ll
total 716
drwxr-xr-x 2 root root 4096 Oct 26 2011 GNU-Linux-x86
-rw-r--r-- 1 root root 727290 Feb 26 18:34 sersync2.5.4_64bit_binary_stable_final.tar.gz
[root@sersync tools]# cp -a GNU-Linux-x86 /usr/local/sersync
[root@sersync tools]# cd /usr/local/sersync/
[root@sersync sersync]# ll
total 1772
-rwxr-xr-x 1 root root 2214 Oct 26 2011 confxml.xml
-rwxr-xr-x 1 root root 1810128 Oct 26 2011 sersync2
[root@sersync sersync]# echo "PATH=/usr/local/sersync:$PATH" >/etc/profile.d/sersync.sh
[root@sersync sersync]# source /etc/profile.d/sersync.sh
[root@sersync sersync]# echo "123456" >/etc/rsync.password
[root@sersync sersync]# chmod 600 /etc/rsync.password
[root@sersync sersync]# rsync -avzP /data/ rsync_backup@10.0.0.4::data --password-file=/etc/rsync.password #<===首先测试rsync同步是否成功
[root@sersync sersync]# vi confxml.xml
[root@sersync sersync]# cat confxml.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"/> #<===系统是否是xfs
<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> #<===这里配置rsync --daemon端的ip地址,及模块的名称(带!是注释掉了的)
<localpath watch="/data">
<remote ip="10.0.0.4" name="data"/>
</localpath>
<rsync>
<commonParams params="-artuz"/> #<===调用的rsync的参数
<auth start="true" users="rsync_backup" passwordfile="/etc/rsync.password"/> #<===启用rsync及用户及指定密码文件
<userDefinedPort start="false" port="874"/><!-- port=874 -->
<timeout start="true" time="100"/><!-- timeout=100 --> #<===设置超时时间
<ssh start="false"/>
</rsync>
<failLog path="/usr/local/sersync/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> [root@sersync sersync]# sersync2 -r -d -o /usr/local/sersync/confxml.xml #<===启动sersync
[root@sersync sersync]# echo "sersync2 -r -d -o /usr/local/sersync/confxml.xml" >>/etc/rc.local #<===加入开机自启动
以上是所有配置,经测试,同步成功,速度极快.......
小结:sersync优点(sersync可以过滤重复事件减轻负担、自带crontab功能、多线程调用rsync、失败重传。)
sersync是使用c++编写,而且对linux系统文件系统产生的临时文件和重复的文件操作进行过滤,所以在结合rsync同步的时候,节省了运行时耗和网络资源。因此更快。
sersync配置很简单,其中bin目录下已经有静态编译好的2进制文件,配合bin目录下的xml配置文件直接使用即可。
sersync使用多线程进行同步,尤其在同步较大文件时,能够保证多个服务器实时保持同步状态。
sersync有出错处理机制,通过失败队列对出错的文件重新同步,如果仍旧失败,则按设定时长对同步失败的文件重新同步。
sersync自带crontab功能,只需在xml配置文件中开启,即可按要求隔一段时间整体同步一次,无需再额外配置crontab功能。
sersync可以二次开发。
附:sersync配置文件confxml.xml 详解
<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
<host hostip="localhost" port="8008"></host>
<debug start="false"/> # 是否开启调试模式(下面所有出现false和true的地方都分别表示关闭和开启的开关)
<fileSystem xfs="false"/> # 监控的是否是xfs文件系统,如果是xfs文件系统,就开启为true
<filter start="false"> # 是否启用监控的筛选功能,筛选的文件将不被监控
<exclude expression="(.*)\.svn"></exclude>
<exclude expression="(.*)\.gz"></exclude>
<exclude expression="^info/*"></exclude>
<exclude expression="^static/*"></exclude>
</filter>
<inotify> # 监控的事件,默认监控的是delete/close_write/moved_from/moved_to/create folder(上面实验是全部打开)
<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> # sersync调用rsync socket网络套接字服务端的相关配置
<localpath watch="/www"> # 本地(sersync)需要同步的目录或文件,同inotify+rsync一样,建议同步目录
<remote ip="172.16.10.5" name="/tmp/www"/> # 这里是rsync daemon端的服务器IP地址及模块名(模块名可以对应多个),rsync服务器端要以daemon模式先运行好rsync服务
<!--remote ip="IPADDR" name="module"--> # 除非下面开启了ssh start,此时name为远程shell方式运行时的目标目录
</localpath>
<rsync> # 指定rsync参数及选项
<commonParams params="-az"/> #默认参数是-zrtuz ,生产环境使用-az即可
<auth start="false" users="root" passwordfile="/etc/rsync.pas"/>
<userDefinedPort start="false" port="874"/><!-- port=874 -->
<timeout start="false" time="100"/><!-- timeout=100 -->
<ssh start="false"/> # 是否使用远程shell模式而非rsync daemon运行rsync命令
</rsync>
<failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once--> # 将传输失败的文件写入此sh文件中,出现错误时重传
<crontab start="false" schedule="600"><!--600mins--> # 是否开启crontab功能
<crontabfilter start="false"> # crontab定时传输的筛选功能
<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>
对于sersync多实例,也即监控多个目录时,只需分别配置不同配置文件(拷贝原来的修改),然后使用sersync2指定对应配置文件运行即可。
sersync2命令相关参数(sersync2命令总是会先设置inotify相关的系统内核参数)
[root@xuexi sersync]# sersync2 -h
set the system param
execute:echo 50000000 > /proc/sys/fs/inotify/max_user_watches
execute:echo 327679 > /proc/sys/fs/inotify/max_queued_events
parse the command param
_____________________________________________________________
参数-d :启用守护进程模式,让sersync2运行在后台
参数-r :在监控前,将监控目录与远程主机用rsync命令推送一遍,
:即首先让远端目录和本地一致,以后再同步则通过监控实现增量同步
参数-n :指定开启守护线程的数量,默认为10个
参数-o :指定配置文件,默认使用confxml.xml文件
参数-m :单独启用其他模块,使用 -m refreshCDN 开启刷新CDN模块
参数-m :单独启用其他模块,使用 -m socket 开启socket模块
参数-m :单独启用其他模块,使用 -m http 开启http模块
不加-m参数,则默认执行同步程序
更多知识及原理深入了解,查看好友博客 http://www.cnblogs.com/f-ck-need-u/p/7220193.html
centos6.5下部署sersync+rsync --daemon同步数据的更多相关文章
- RedHat Linux下利用sersync进行实时同步数据
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://linux5588.blog.51cto.com/65280/772054 拓扑图 ...
- CentOS6.8下部署Zabbix3.0
Centos6.8下部署安装zabbix3.0: 环境要求 PHP >= 5.4 (CentOS6默认为5.3.3,需要更新) curl >= 7.20 (如需支持SMTP认证,需更新) ...
- 架设rsync服务器同步数据
什么是rsync rsync 是一个快速增量文件传输工具,它可以用于在同一主机备份内部的备分,我们还可以把它作为不同主机网络备份工具之用.本文主要讲述的是如何自架rsync服 务器,以实现文件传输.备 ...
- inotify+rsync sersync+rsync实时同步服务
中小型网站搭建-数据实时的复制-inotify/sersync inotify是一种强大的,细粒度的.异步的文件系统事件监控机制(软件),linux内核从2.6.13起,加入inotify支持,通过i ...
- Linux下如何使用Rsync备份服务器重要数据
Rsync介绍: Rsync英文全称Remote synchronization,从软件的名称就可以看出来,Rsync具有可使本地和远程两台主机之间的数据快速复制同步镜像,远程备份的功能,这个功能类似 ...
- Rsync备份同步数据工具
Rsync is a fast and extraordinarily versatile file copying tool. Rsync是一款开源的,快速的,多功能的,可实现全量和增量的本地 ...
- centos下部署NTP时间服务器同步环境记录
1)服务端部署 安装所需软件包 [root@test ~]# yum -y install ntp ntpdate 服务端自己先手工同步一次时间. [root@test ~]# ntpdate ntp ...
- 腾讯云centos6.5下部署django环境
基于腾讯云CentOS6.5的环境 首先说下需要用到的软件 1.gcc环境 腾讯云默认是没有gcc编译器的,需要手动安装一下:yum install gcc 2.python环境 因为我用的cento ...
- CentOS6.5下部署SVN
查看系统版本,安装SVN软件及创建目录 [root@A-linux ~]# uname -r 2.6.32-431.el6.x86_64 [root@A-linux ~]# cat /etc/redh ...
随机推荐
- cogs 173. 词链 字典树模板
173. 词链 ★★☆ 输入文件:link.in 输出文件:link.out 简单对比时间限制:1 s 内存限制:128 MB [问题描述]给定一个仅包含小写字母的英文单词表,其中每个 ...
- 开源导入导出库Magicodes.IE 导出教程
要点 导出特性 如何导出Excel表头 如何导出数据.如何进行数据的切割.如何使用筛选器 导出特性 ExporterAttribute Name: 名称(当前Sheet 名称) HeaderFontS ...
- 学习 lind 语 里的一些组件使用。
step one autofac : link:http://files.cnblogs.com/files/ganmk--jy/AutofacTest.rar step two 还有很多
- Android教程2020 - RecyclerView响应点击
本文介绍RecyclerView设置点击的方法.这里给出比较常见的使用方式. Android教程2020 - 系列总览 本文链接 前面我们已经知道如何用RecyclerView显示一列数据. 用户点击 ...
- Centos 7 部署lnmp集群架构
前言介绍 lnmp的全程是 linux + nginx + mysql + php; lnmp就是上述系统及应用程序的简写组合: lnmp其实已经代表了一个用户正常对一个页面请求的流程,nginx接收 ...
- 【Java并发基础】利用面向对象的思想写好并发程序
前言 下面简单总结学习Java并发的笔记,关于如何利用面向对象思想写好并发程序的建议.面向对象的思想和并发编程属于两个领域,但是在Java中这两个领域却可以融合到一起.在Java语言中,面向对象编程的 ...
- 七、django学习之聚合函数
七.django学习之聚合函数 如何使用 from django.db.models import Avg,Max,Min,Sum models.Book.objects.all().aggregat ...
- 【2020-02-11】1346. Check If N and Its Double Exist
更多LeetCode解题详解 Easy Given an array arr of integers, check if there exists two integers N and M such ...
- 透彻分析和解决一切javaWeb项目乱码问题
前言 乱码是我们在程序开发中经常碰到且让人头疼的一件事,尤其是我们在做javaweb开发,如果我们没有清楚乱码产生的原理,碰到乱码问题了就容易摸不着头脑,无从下手. 乱码主要出现在两部分,如下: 第一 ...
- Junit单元测试案例(测试语言Java)
# 二.单元测试案例##### 1. 首先我们先创建一个Operation类,在类中我们写几个方法,分别为加.减.乘.除.这些方法都不加边界值与判断.如下图所示:![在这里插入图片描述](https: ...