Centos+Serync+inotify实时同步数据文件(二)
这2天一直忙其它的事,忘记把剩余的同步过程分享到博客中,望谅解!上周把rsync已经配置完成,可以手动的同步,下面我们将使用Serync进行实时的同步,其实就手动同步而言也可以配置crontab定时备份,因人而异方法很多,选一种适合你自己的。
三、Serync Configuration
首先下载软件
[root@nagios01/]#cd/home/qiuyuetao/[root@nagios01qiuyuetao]#wgethttp://sersync.googlecode.com/files/sersync2.5.4_64bit_binary_stable_final.tar.gz
【http://code.google.com/p/sersync/】下载网站
1,安装sersync
[root@nagios01qiuyuetao]#tar-zxvfsersync2.5.4_64bit_binary_stable_final.tar.gz-C/usr/local/(-C解压到指定路径)[root@nagios01qiuyuetao]#mv/usr/local/GNU-Linux-x86sersync[root@nagios01local]#treesersync/sersync/├──confxml.xml└──sersync2
2,规范 sersync 目录结构(自行抉择是否规范)
mkdirconfbinlogs(配置文件放到conf、二进制命令Bin下、脚本logs下)[root@nagios01local]#cdsersync/[root@nagios01sersync]#mkdirconfbinlogs[root@nagios01sersync]#mvconfxml.xmlconf/[root@nagios01sersync]#mvsersync2bin/sersync[root@nagios01sersync]#tree.├──bin│└──sersync├──conf│└──confxml.xml└──logs3directories,2files
3,编辑配置文件
备份cpconfxml.xmlconfxml.xmlq.$(date+%F)
4,更改及优化sersync 配置
(1)定义本地的同步目录24<localpathwatch="/opt/tongbu">要同步的目录25<remoteip="127.0.0.1"name="tongbu1"/>26<!--<remoteip="192.168.8.39"name="tongbu"/>-->同步到哪台机器同步到那个模块目录27<!--<remoteip="192.168.8.40"name="tongbu"/>-->28</localpath>修改后内容为:<sersync><localpathwatch="/usr/local/nagios/etc/cfgs"><remoteip="192.168.1.206"name="cfgs"/></localpath><!--###############################################################--><localpathwatch="/usr/local/nagios/etc/objects"><remoteip="192.168.1.206"name="objects"/></localpath><!--###############################################################-->修改前<rsync>40<commonParamsparams="-artuz"/>41<authstart="false"users="root"passwordfile="/etc/rsync.pas"/>使用认证42<userDefinedPortstart="false"port="874"/><!--port=874-->43<timeoutstart="false"time="100"/><!--timeout=100-->44<sshstart="false"/>45</rsync>修改后内容为:拼接同步命令<rsync><commonParamsparams="-artuz"/><authstart="true"users="rsync_backup"passwordfile="/etc/rsync.password"/><userDefinedPortstart="false"port="874"/><!--port=874--><timeoutstart="true"time="100"/><!--timeout=100--><sshstart="false"/></rsync>修改36-37行失败后会写入log<failLogpath="/tmp/rsync_fail_log.sh"timeToExecute="60"/><!--defaultevery60minsexecuteonce-->修改后内容<failLogpath="/usr/local/sersync/logs/rsync_fail_log.sh"timeToExecute="60"/><!--defaultevery60minsexecuteonce-->
4,开启sersync守护进程同步数据(全局变量)
echo'exportPATH=$PATH:/usr/local/sersync/bin'>>/etc/profiletail-1/etc/profile(查看是否添加)source/etc/profile(使/etc/Porofile立即生效)whichsersync(查看sersync命令路径能否找到)
5,《启动同步命令》
sersync -r(先做一次同步) -d(后台启动) -o(指定文件) /usr/local/sersync/conf/confxml.xml
sersync-r-d-o/usr/local/sersync/conf/confxml.xml
[root@Serverconf]#sersync-r-d-o/usr/local/sersync/conf/confxml.xml(启动过程)setthesystemparamexecute:echo50000000>/proc/sys/fs/inotify/max_user_watchesexecute:echo327679>/proc/sys/fs/inotify/max_queued_eventsparsethecommandparamoption:-rrsyncallthelocalfilestotheremoteserversbeforethesersyncworkoption:-drunasadaemonoption:-oconfigxmlname:/usr/local/sersync/conf/confxml.xmldaemonthreadnum:10默认启动10个线程parsexmlconfigfilehostip:localhosthostport:8008daemonstart,sersyncrunbehindtheconsoleusersyncpassword-file:密码文件userisrsync_backup用户passwordfileis/etc/rsync.passwordconfigxmlparsesuccesspleaseset/etc/rsyncd.confmaxconnections=0Manuallysersyncworkingthread12工作线程数=1(primarythread)+1(failretrythread)+10(daemonsubthreads)Maxthreadsnumbersis:32最大线程数=12(Threadpoolnums)+20(Subthreads)pleaseaccordingyourcpu,use-nparamtoadjustthecpurate------------------------------------------rsyncthedirectoryrecursivlytotheremoteserversonceworkingpleasewait...executecommand:cd/usr/local/nagios/etc/cfgs&&rsync-artuz-R--delete./--timeout=100rsync_backup@192.168.1.206::cfgs--password-file=/etc/rsync.password>/dev/null2>&1[root@nagios01conf]#runthesersync:watchpathis:/usr/local/nagios/etc/cfgs成功
6,#####测试结果:发现一个问题,仅能同步一个模块目录 cfgs模块 / objects 没有同步
[root@nagios01conf]#touch/usr/local/nagios/etc/cfgs/1.txt/usr/local/nagios/etc/objects/1.txt[root@nagios01conf]#tree/usr/local/nagios/etc//usr/local/nagios/etc/├──cfgs│├──1.txt│├──cfgs.log├──objects│├──1.txt│├──objects.log│[root@Nagios02/usr/local/nagios/etc]$tree├──cfgs│├──1.txt│├──cfgs.log├──objects│├──objects.log
7,####如下是采用多实例的方法进行 同时同步2个目录#####
创建2个文件
cpconfxml.xmlconfxml.xml_newcpconfxml.xmlcfgs_confxml.xmlcpconfxml.xmlobjects_confxml.xml
规范目录看着舒服多了
[root@nagios01conf]#lltotal12-rwxr-xr-x.1rootroot2328Feb2300:49cfgs_confxml.xml-rwxr-xr-x.1rootroot2339Feb2300:50objects_confxml.xmldrwxr-xr-x.2rootroot4096Feb2300:51tmp
8,配置文件内容删除多余节点目录 修改日志报错名称 如下是比对结果
[root@nagios01conf]#diffcfgs_confxml.xmlobjects_confxml.xml23,24c23,24<<localpathwatch="/usr/local/nagios/etc/cfgs"><<remoteip="192.168.1.206"name="cfgs"/>---><localpathwatch="/usr/local/nagios/etc/objects">><remoteip="192.168.1.206"name="objects"/>34c34<<failLogpath="/usr/local/sersync/logs/cfgs_rsync_fail_log.sh"timeToExecute="60"/><!--defaultevery60minsexecuteonce-->---><failLogpath="/usr/local/sersync/logs/objects_rsync_fail_log.sh"timeToExecute="60"/><!--defaultevery60minsexecuteonce-->
9,更新sersync运行状态
[root@nagios01conf]#ps-ef|grepsersyncroot613410Feb22?00:00:00sersync-r-d-o/usr/local/sersync/conf/confxml.xmlroot71782428000:55pts/000:00:00grepsersync[root@nagios01conf]#pkillsersync[root@nagios01conf]#ps-ef|grepsersyncroot71872428000:56pts/000:00:00grepsersync
10,同时启动2个配置文件,各自指定各自的配置文件(配置要求高些,进程数随之调整)
sersync-r-d-o/usr/local/sersync/conf/cfgs_confxml.xmlsersync-r-d-o/usr/local/sersync/conf/objects_confxml.xml[root@nagios01conf]#ps-ef|grepsersyncroot72901001:01?00:00:00sersync-r-d-o/usr/local/sersync/conf/cfgs_confxml.xmlroot73081001:01?00:00:00sersync-r-d-o/usr/local/sersync/conf/objects_confxml.xmlroot73272428001:01pts/000:00:00grepsersync
11,在做一下测试
[root@nagios01conf]#touch/usr/local/nagios/etc/cfgs/2.txt/usr/local/nagios/etc/objects/2.txt[root@nagios01conf]#tree/usr/local/nagios/etc//usr/local/nagios/etc/├──cfgs│├──1.txt│├──2.txt│├──cfgs.log├──objects│├──1.txt│├──2.txt│├──objects.log│[root@Nagios02/usr/local/nagios/etc]$tree├──cfgs│├──1.txt│├──2.txt│├──cfgs.log├──objects│├──1.txt│├──2.txt│├──objects.log
Sersync 多实例 实时同步配置成功,希望大家多多支持。http://qiuyt.blog.51cto.com
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。