Centos6.3下rsync+sersync安装配置笔记

简介:

 最近单位活比较多,所以就很少更新,晚上上网碰巧看到一篇关于sersync的介绍,个人感觉较rsync+inotify配置更加规范,刚好最近手痒,就总结了下,分享给大家。

     目前业内比较靠谱的同步解决方案有:

     rsync+inotify-tools,Openduckbill+inotify-tools和rsync+sersync

     前两者由于是基于脚本语言编写,所以规范程度,执行效率相对rsync+sersync就稍微弱一些。

     sersync是使用c++编写,基于boost1.43.0,inotify api,rsync command开发,主要用于服务器同步,web镜像等功能。其对linux系统文件系统产生的临时文件和重复的文件操作能够进行过滤,所以在结合rsync同步的时候,节省了运行时耗和网络资源。因此更快,更适合线上使用。


    本篇博文就是为了实现将sersync推送端/data下的数据实时同步到rsync接收端/data目录下,实现rsync服务器为sersync的镜像服务器

注:使用rsync+crontab做定时同步时,主服务器端开启rsync守护进程,而镜像服务器是运行rsync客户端,平时一般会利用crontab定时获取rsync服务器上的数据。

但使用rsync+sersync做实时同步时,用于推送文件的服务器运行sersync服务,用于接收文件的服务器则运行rsync守护进程,简单来说就是sersync会利用rsync命令将文件推送到rsync服务器,实际线上使用一般会把sersync作为主服务器,rsync作为镜像服务器,实现数据同步备份,web镜像等功能


解决方案:


操作系统:    centos6.3 x86

rsync:       centos自带yum源

sersync:     sersync2.5_32bit


111603705.jpg


sersync 推送端  192.168.100.74

rsync   接收端  192.168.100.29


环境搭建:(接收端,推送端)


一.首先关闭selinux与iptables

# vi /etc/sysconfig/selinux

---------

SELINUX=disabled

---------

# setenforce 0

# service iptables stop


在使用sersync之前,我们必须安装配置好rsync服务器


rsync (接收端)


一.安装rsync(centos6.3默认已安装)

# yum install rsync -y

# yum install xinetd -y


二.启动rsync依赖服务

# /etc/init.d/xinetd start

# chkconfig xinetd on


三.配置:

# vi /etc/rsyncd.conf

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

uid = root

gid = root

use chroot = no

max connections = 10

strict modes = yes

port = 873

address = 192.168.100.29


[data] # rsync模块名,后面配置sersync会用到

path = /data  # 该同步目录只要uid所指定的用户有写权限即可

comment = mirror for test

ignore errors

read only = no

list = no

auth users = user

secrets file = /etc/rsync.pas # 密码认证文件,必须为600权限,否则rsync传输会报错

hosts allow = *

# hosts deny = 0.0.0.0/0

pid file = /var/run/rsyncd.pid

lock file = /var/run/rsync.lock

log file = /var/log/rsyncd.log

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


四.创建同步目录

# mkdir /data


五.配置认证文件

# echo "user:123456" > /etc/rsync.pas

# chmod 600 /etc/rsync.pas

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


六.重启xinetd使其配置生效:

# /etc/init.d/xinetd restart


七.设置开机启动:

# echo "rsync --daemon --config=/etc/rsyncd.conf" >> /etc/rc.local


sersync (推送端)


一.下载sersync源码包

# wget http://sersync.googlecode.com/files/sersync2.5_32bit_binary_stable_final.tar.gz

注:若在64位平台安装则可下载64位sersync源码包,本例用32位

# wget http://sersync.googlecode.com/files/sersync2.5_64bit_binary_stable_final.tar.gz


二.创建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


三.配置sersync


1.首先创建连接rsyncd的密码文件

# echo "123456" >/etc/rsync.pas

# chmod 600 /etc/rsync.pas


2.配置confxml.xml

# cd /usr/local/sersync/conf

# vi confxml.xml

按照注释进行修改

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

<?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.100.29" 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.pas"/>

   # 设置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>

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


3.创建推送端sersync同步目录

# mkdir /data


4.设置环境变量:

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

# source /etc/profile


5.启动sersync

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

注:重启操作如下:

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


6.设置开机启动

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


验证:


(推送端)

# cd /data

# touch 1 2 3 4 5

# echo "test sersync" > 1


(接收端)

# cd /data

# ls

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

1  2  3  4  5

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

# cat 1

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

test sersync

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

注:这里提一个细节,如果接收端服务器本地创建或修改/data同步目录下的文件,当服务端进行目录同步时则不会对接收端服务器本地创建或修改的文件产生影响。


-------------大功告成----------------





     本文转自 showerlee 51CTO博客,原文链接:http://blog.51cto.com/showerlee/1248429,如需转载请自行联系原作者



相关文章
|
19天前
|
网络安全 开发工具
Centos6.5安装配置autofs服务
配置IP地址和挂载yum源后,安装autofs:`yum -y install autofs`。编辑配置文件 `/etc/auto.misc` 和 `/etc/auto.master`,示例中展示了将yum源路径添加到auto.master。关闭防火墙并重启autofs服务以应用更改。
19 2
|
26天前
|
Java Linux
为centos7配置jdk
为centos7配置jdk
28 3
|
19天前
|
Linux 网络安全 开发工具
Centos6.5安装并配置Telnet服务
该内容是一个关于如何安装配置Telnet服务的教程。首先,通过yum安装vim、xinetd、telnet和telnet-server。接着,修改/etc/xinetd.d/telnet配置文件,将disable改为no,并设置访问限制(如限定特定网段和时间)。关闭防火墙,重启服务。创建测试用户后,分别使用CentOS和Windows的Telnet客户端进行连接测试,显示成功,实验完成。
25 1
|
6天前
|
Linux
CentOS 7 配置yum阿里源 (三步即可)
CentOS 7 配置yum阿里源 (三步即可)
|
17天前
|
网络协议 Java 应用服务中间件
记录_centos7离线环境和虚拟机共享文件安装jdk和tomcat(配置环境变量)
记录_centos7离线环境和虚拟机共享文件安装jdk和tomcat(配置环境变量)
11 0
|
19天前
|
Linux 网络安全 开发工具
Centos7 sendmail服务安装与配置
该文本描述了在Linux系统中设置邮件服务的步骤。首先,启用httpd的邮件发送功能,然后安装sendmail、sendmail-cf和dovecot。接着配置/sendmail.mc,设定IP和邮件域名。在dovecot配置文件中启用imap、pop3和lmtp协议,取消明文认证限制,设定mail_location,并开启SSL。创建用户mail3和mail4,给予相应权限。停止postfix服务,编辑访问控制、提交配置、本地主机名等文件。最后,重置sendmail、dovecot和saslauthd服务。
44 0
|
19天前
|
运维 网络协议 Linux
【运维系列】Centos7安装并配置PXE服务
PXE是Intel开发的预启动执行环境,允许工作站通过网络从远程服务器启动操作系统。它依赖DHCP分配IP,DNS服务分配主机名,TFTP提供引导程序,HTTP/FTP/NFS提供安装源。要部署PXE服务器,需关闭selinux和防火墙,安装dhcpd、httpd、tftp、xinetd及相关服务,配置引导文件和Centos7安装源。最后,通过syslinux安装引导文件,并创建pxelinux.cfg/default配置文件来定义启动参数。
55 0
|
19天前
|
运维 网络协议 Linux
【运维系列】Centos7安装并配置postfix服务
安装CentOS7的Postfix和Dovecot,配置Postfix的`main.cf`文件,包括修改完全域名、允许所有IP、启用邮箱等。然后,配置Dovecot的多个配置文件以启用auth服务和调整相关设置。重启Postfix和Dovecot,设置开机自启,并关闭防火墙进行测试。最后,创建邮箱账户并在Windows邮箱客户端中添加账户设置。
17 0
|
19天前
|
运维 Linux 网络安全
【运维系列】Centos7安装配置ntp服务
配置yum并安装ntp,编辑ntp配置文件,取消17行注释,适应本机网段,22行设置使用本地时间。关闭防火墙,重启ntp服务。测试时先关闭防火墙,然后使用ntpdate命令成功同步时间。
33 0
|
19天前
|
网络协议 Linux 网络安全
Centos7 配置DNS服务
该教程指导配置DNS服务器:首先通过yum安装bind和cach件,然后修改IP设置。接着,编辑/etc/named.conf,将第13行和21行的参数改为&quot;any&quot;。在/etc/named.rfc1912中更新正向和反向域名。创建正向解析文件/var/named.localhost和反向解析文件/var/named.loopback,按指定格式添加解析记录。最后,重启服务,确保防火墙关闭,通过nslookup检查DNS配置效果。
25 1

热门文章

最新文章