rsync+sersync大数据T级以上进行同步方法

操作系统:rhel 5.7

rsync地址: http://rsync.samba.org/download.html

serync下载地址:https://sersync.googlecode.com/files/sersync2.5.4_64bit_binary_stable_final.tar.gz

这次的实验主要有两台机器,172.16.54.114和172.16.54.115,我们把115做为源服务器,114做为目标服务器

主要是把115上/home/md中的所有数据实时同步到114上的/home/md中

1,先关闭防火墙

vi /etc/selinux/config #编辑防火墙配置文件

#SELINUX=enforcing #注释掉

#SELINUXTYPE=targeted #注释掉

SELINUX=disabled #增加

:wq! #保存,退出

setenforce 0 #立即生效

 

2,查看端口是否被占用(直接在命令行输入)及安装

netstat –apn | grep 873

 

安装rsync,在两台服务器上都要进行这个步骤

首先将下载的包解压

tar -xzvf  rsync-3.1.0.tar.gz

解压后进入目录

./configure --prefix=/usr/local/rsync

 

#说明安装在/usr/local/rsync目录中

在这一步之前要安装相对就的gcc和gcc-c++

make

make install

安装完毕

 

chkconfig rsync on #随系统启动

这个只在114上做

创建rsync配置文件rsync.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启动时欢迎信息页面文件位置(文件内容自定义)

[md] #自定义名称

path = /home/md/ #rsync服务端数据目录路径

comment = md #模块名称

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 = md #执行数据同步的用户名,可以设置多个,用英文状态下逗号隔开

hosts allow = 172.16.54.114  #允许进行数据同步的客户端IP地址,可以设置多个,用英文状态下逗号隔开

#hosts deny = 218.234.1.254 #禁止数据同步的客户端IP地址,可以设置多个,用英文状态下逗号隔开(这个比较随便,也可以没有)

:wq!  #保存,退出

 

创建用户认证文件

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

md:123456 #格式为 用户:密码,如果是多个,可以一行一个

:wq!  #保存,退出

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

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

 

在此,我们普及一个问题,我们先进入/etc/xinetd.d文件中,可以看到rsync这个文件,说明rsync是由xinetd管理,可以通过xinetd来启动rsync

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

service xinetd stop   #停止

service xinetd restart #重新启动

------------------------只在114上进行的到此为止--------------------

 

以下只到115上进行

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

123456 #密码

:wq! #保存退出

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

4,安装sersync

上传sersync2.5.4_64bit_binary_stable_final.tar.gz到/usr/local目录下

cd /usr/local

tar –xzvf  sersync2.5.4_64bit_binary_stable_final.tar.gz

这个解压后会得到一个GUN-linux x86的文件夹

mv G GUN-linux x86/*   /usr/local/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="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>

<localpath watch="/home/md/">

<remote ip="172.16.54.114" name="buspos "/>

</localpath>

<rsync>

<commonParams params="-artuz"/>

<auth start="true" users="buspos" passwordfile="/etc/rsyncd.scrt"/>

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

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

#标红的可按自己的配置改,名字和IP比较随便,是我的配置,红色#的还得根据自己rsync配置进行修改

 

 

5、设置sersync监控开机自动执行

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

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

:wq!  #保存退出

 

写完后,首先对数据进行一次整体同步

cd /usr/local/sersync

./sersync2 –r  #以下是输入之后看到的

set the system param

execute锛歟cho 50000000 > /proc/sys/fs/inotify/max_user_watches

execute锛歟cho 327679 > /proc/sys/fs/inotify/max_queued_events

parse the command param

option: -r      rsync all the local files to the remote servers before the sersync work

daemon thread num: 10

parse xml config file

host ip : localhost     host port: 8008

Start the crontab       Every 600 minutes rsync all the files to the remote servers entirely

use rsync password-file :

user is buspos

passwordfile is         /etc/rsyncd.scrt

config xml parse success

please set /etc/rsyncd.conf max connections=0 Manually

sersync working thread 12  = 1(primary thread) + 1(fail retry thread) + 10(daemon sub threads)

Max threads numbers is: 22 = 12(Thread pool nums) + 10(Sub threads)

please according your cpu 锛寀se -n param to adjust the cpu rate

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

rsync the directory recursivly to the remote servers once

working please wait...

execute command: cd /home/md && rsync -artuz -R --delete ./ buspos@172.16.54.114::buspos --password-file=/etc/rsyncd.scrt >/dev/null 2>&1

run the sersync:

watch path is: /home/md

--------------------------------到此为止-----------------------------

 

我们来写个简单的脚本吧

vi  /home/sh/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    #保存脚本

 

vi /etc/crontab #编辑,在最后添加下面一行

*/5 * * * * root /home/sh/sersync.sh > /dev/null 2>&1  #每隔5分钟执行一次脚本

service crond reload  #重新加载服务

至此就不再管了,加入工作例程了!

 

 

 

转载于:https://my.oschina.net/u/1013648/blog/207600

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值