新网创想网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

Centos+Serync+inotify实时同步数据文件(二)-创新互联

这2天一直忙其它的事,忘记把剩余的同步过程分享到博客中,望谅解!上周把rsync已经配置完成,可以手动的同步,下面我们将使用Serync进行实时的同步,其实就手动同步而言也可以配置crontab定时备份,因人而异方法很多,选一种适合你自己的。

站在用户的角度思考问题,与客户深入沟通,找到长海网站设计与长海网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:网站建设、网站制作、企业官网、英文网站、手机端网站、网站推广、域名申请、网页空间、企业邮箱。业务覆盖长海地区。

三、Serync Configuration

首先下载软件

[root@nagios01 /]#cd /home/qiuyuetao/
[root@nagios01 qiuyuetao]# wget 
http://sersync.googlecode.com/files/sersync2.5.4_64bit_binary_stable_final.tar.gz

【http://code.google.com/p/sersync/】下载网站

1,安装sersync

[root@nagios01 qiuyuetao]# tar -zxvf sersync2.5.4_64bit_binary_stable_final.tar.gz -C /usr/local/(-C 解压到指定路径)
[root@nagios01 qiuyuetao]# mv /usr/local/GNU-Linux-x86 sersync
[root@nagios01 local]# tree sersync/
sersync/
├── confxml.xml
└── sersync2

2,规范 sersync 目录结构(自行抉择是否规范)

 mkdir conf bin logs (配置文件放到conf、二进制命令Bin下、脚本logs下)
[root@nagios01 local]# cd sersync/
[root@nagios01 sersync]# mkdir conf bin logs
[root@nagios01 sersync]# mv confxml.xml conf/
[root@nagios01 sersync]# mv sersync2 bin/sersync
[root@nagios01 sersync]# tree 
.
├── bin
│   └── sersync
├── conf
│   └── confxml.xml
└── logs
3 directories, 2 files

3,编辑配置文件

备份 cp confxml.xml confxml.xmlq.$(date +%F)

4,更改及优化sersync 配置

(1)定义本地的同步目录
     24         要同步的目录
     25             
     26             
                                   同步到哪台机器       同步到那个模块目录
     27             
     28         
修改后内容为:
 
 
                  
             

   
                  
             

修改前
        
     40             
     41             
                         使用认证     
     42             
     43             
     44             
     45         
修改后内容为:拼接同步命令
        
                 
                  
                 
                 
                 
             
修改36-37行 失败后会写入log
  
修改后内容
  

4,开启sersync守护进程同步数据(全局变量)

 echo 'export PATH=$PATH:/usr/local/sersync/bin'>>/etc/profile
 tail -1 /etc/profile  (查看是否添加)
 source /etc/profile   (使/etc/Porofile 立即生效)
 which sersync         (查看sersync命令路径能否找到)

5,《启动同步命令》

sersync -r(先做一次同步) -d(后台启动) -o(指定文件) /usr/local/sersync/conf/confxml.xml

sersync -r -d -o /usr/local/sersync/conf/confxml.xml
[root@Server conf]# sersync -r -d -o /usr/local/sersync/conf/confxml.xml
(启动过程)
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
option: -r      rsync all the local files to the remote servers before the sersync work
option: -d      run as a daemon
option: -o      config xml name:  /usr/local/sersync/conf/confxml.xml
daemon thread num: 10 默认启动10个线程
parse xml config file
host ip : localhost     host port: 8008
daemon start,sersync run behind the console 
use rsync password-file : 密码文件
user is rsync_backup   用户
passwordfile is         /etc/rsync.password
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: 32大线程数 = 12(Thread pool nums) + 20(Sub threads)
please according your cpu ,use -n param to adjust the cpu rate
------------------------------------------
rsync the directory recursivly to the remote servers once
working please wait...
execute command: cd /usr/local/nagios/etc/cfgs && rsync -artuz -R --delete ./  --timeout=100 
rsync_backup@192.168.1.206::cfgs --password-file=/etc/rsync.password >/dev/null 2>&1 
[root@nagios01 conf]# run the sersync: 
watch path is: /usr/local/nagios/etc/cfgs
成功

6,#####测试结果:发现一个问题,仅能同步一个模块目录 cfgs模块 / objects 没有同步

[root@nagios01 conf]# touch /usr/local/nagios/etc/cfgs/1.txt /usr/local/nag
ios/etc/objects/1.txt
[root@nagios01 conf]# 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个文件

 cp confxml.xml confxml.xml_new
 cp confxml.xml cfgs_confxml.xml
 cp confxml.xml objects_confxml.xml

规范目录看着舒服多了

[root@nagios01 conf]# ll
total 12
-rwxr-xr-x. 1 root root 2328 Feb 23 00:49 cfgs_confxml.xml
-rwxr-xr-x. 1 root root 2339 Feb 23 00:50 objects_confxml.xml
drwxr-xr-x. 2 root root 4096 Feb 23 00:51 tmp

8,配置文件内容删除多余节点目录 修改日志报错名称 如下是比对结果

[root@nagios01 conf]# diff cfgs_confxml.xml objects_confxml.xml 
23,24c23,24
<  
<                   
---
>    
>                   
34c34
< 
---
> 

9,更新sersync运行状态

[root@nagios01 conf]# ps -ef|grep sersync
root      6134     1  0 Feb22 ?        00:00:00 sersync -r -d -o /usr/local/sersync/conf/confxml.xml
root      7178  2428  0 00:55 pts/0    00:00:00 grep sersync
[root@nagios01 conf]# pkill sersync
[root@nagios01 conf]# ps -ef|grep sersync
root      7187  2428  0 00:56 pts/0    00:00:00 grep sersync

10,同时启动2个配置文件,各自指定各自的配置文件(配置要求高些,进程数随之调整)

sersync -r -d -o /usr/local/sersync/conf/cfgs_confxml.xml
sersync -r -d -o /usr/local/sersync/conf/objects_confxml.xml
[root@nagios01 conf]# ps -ef |grep sersync
root      7290     1  0 01:01 ?        00:00:00 sersync -r -d -o /usr/local/sersync/conf/cfgs_confxml.xml
root      7308     1  0 01:01 ?        00:00:00 sersync -r -d -o /usr/local/sersync/conf/objects_confxml.xml
root      7327  2428  0 01:01 pts/0    00:00:00 grep sersync

11,在做一下测试

[root@nagios01 conf]# touch /usr/local/nagios/etc/cfgs/2.txt /usr/local/nagios/etc/objects/2.txt
[root@nagios01 conf]# 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

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


网页标题:Centos+Serync+inotify实时同步数据文件(二)-创新互联
网页URL:http://www.wjwzjz.com/article/dpppgc.html
在线咨询
服务热线
服务热线:028-86922220
TOP