设为首页 收藏本站
查看: 526|回复: 0

[经验分享] Centos+Serync+inotify实时同步数据文件(二)

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-2-24 08:13:13 | 显示全部楼层 |阅读模式
这2天一直忙其它的事,忘记把剩余的同步过程分享到博客中,望谅解!上周把rsync已经配置完成,可以手动的同步,下面我们将使用Serync进行实时的同步,其实就手动同步而言也可以配置crontab定时备份,因人而异方法很多,选一种适合你自己的。
三、Serync Configuration
首先下载软件
1
2
3
[iyunv@nagios01 /]#cd /home/qiuyuetao/
[iyunv@nagios01 qiuyuetao]# wget
http://sersync.googlecode.com/fi ... stable_final.tar.gz




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

1,安装sersync
1
2
3
4
5
6
[iyunv@nagios01 qiuyuetao]# tar -zxvf sersync2.5.4_64bit_binary_stable_final.tar.gz -C /usr/local/(-C 解压到指定路径)
[iyunv@nagios01 qiuyuetao]# mv /usr/local/GNU-Linux-x86 sersync
[iyunv@nagios01 local]# tree sersync/
sersync/
├── confxml.xml
└── sersync2




2,规范 sersync 目录结构(自行抉择是否规范)
1
2
3
4
5
6
7
8
9
10
11
12
13
mkdir conf bin logs (配置文件放到conf、二进制命令Bin下、脚本logs下)
[iyunv@nagios01 local]# cd sersync/
[iyunv@nagios01 sersync]# mkdir conf bin logs
[iyunv@nagios01 sersync]# mv confxml.xml conf/
[iyunv@nagios01 sersync]# mv sersync2 bin/sersync
[iyunv@nagios01 sersync]# tree
.
├── bin
│   └── sersync
├── conf
│   └── confxml.xml
└── logs
3 directories, 2 files




3,编辑配置文件
1
备份 cp confxml.xml confxml.xmlq.$(date +%F)




4,更改及优化sersync 配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
(1)定义本地的同步目录
     24         <localpath watch="/opt/tongbu">要同步的目录
     25             <remote ip="127.0.0.1" name="tongbu1"/>
     26             <!--<remote ip="192.168.8.39" name="tongbu"/>-->
                                   同步到哪台机器       同步到那个模块目录
     27             <!--<remote ip="192.168.8.40" name="tongbu"/>-->
     28         </localpath>
修改后内容为:
<sersync>
<localpath watch="/usr/local/nagios/etc/cfgs">
                  <remote ip="192.168.1.206" name="cfgs"/>
             </localpath>
<!--###############################################################-->
   <localpath watch="/usr/local/nagios/etc/objects">
                  <remote ip="192.168.1.206" name="objects"/>
             </localpath>
<!--###############################################################-->
修改前
        <rsync>
     40             <commonParams params="-artuz"/>
     41             <auth start="false" users="root" passwordfile="/etc/rsync.pas"/>
                         使用认证     
     42             <userDefinedPort start="false" port="874"/><!-- port=874 -->
     43             <timeout start="false" time="100"/><!-- timeout=100 -->
     44             <ssh start="false"/>
     45         </rsync>
修改后内容为:拼接同步命令
        <rsync>
                 <commonParams params="-artuz"/>
                  <auth start="true" users="rsync_backup" passwordfile="/etc/rsync.password"/>
                 <userDefinedPort start="false" port="874"/><!-- port=874 -->
                 <timeout start="true" time="100"/><!-- timeout=100 -->
                 <ssh start="false"/>
             </rsync>
修改36-37行 失败后会写入log
  <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->
修改后内容
  <failLog path="/usr/local/sersync/logs/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins
execute once-->




4,开启sersync守护进程同步数据(全局变量)
1
2
3
4
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
1
sersync -r -d -o /usr/local/sersync/conf/confxml.xml



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
[iyunv@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
[iyunv@nagios01 conf]# run the sersync:
watch path is: /usr/local/nagios/etc/cfgs
成功



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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[iyunv@nagios01 conf]# touch /usr/local/nagios/etc/cfgs/1.txt /usr/local/nag
ios/etc/objects/1.txt
[iyunv@nagios01 conf]# tree /usr/local/nagios/etc/
/usr/local/nagios/etc/
├── cfgs
│   ├── 1.txt
│   ├── cfgs.log
├── objects
│   ├── 1.txt
│   ├── objects.log

[iyunv@Nagios02 /usr/local/nagios/etc]$tree
├── cfgs
│   ├── 1.txt
│   ├── cfgs.log
├── objects
│   ├── objects.log




7,####如下是采用多实例的方法进行 同时同步2个目录#####
创建2个文件
1
2
3
cp confxml.xml confxml.xml_new
cp confxml.xml cfgs_confxml.xml
cp confxml.xml objects_confxml.xml



规范目录看着舒服多了
1
2
3
4
5
[iyunv@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,配置文件内容删除多余节点目录 修改日志报错名称 如下是比对结果
1
2
3
4
5
6
7
8
9
10
11
12
13
[iyunv@nagios01 conf]# diff cfgs_confxml.xml objects_confxml.xml
23,24c23,24
<  <localpath watch="/usr/local/nagios/etc/cfgs">
<                   <remote ip="192.168.1.206" name="cfgs"/>
---
>    <localpath watch="/usr/local/nagios/etc/objects">
>                   <remote ip="192.168.1.206" name="objects"/>
34c34
< <failLog path="/usr/local/sersync/logs/cfgs_rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins
execute once-->
---
> <failLog path="/usr/local/sersync/logs/objects_rsync_fail_log.sh" timeToExecute="60"/><!--default every
60mins execute once-->



9,更新sersync运行状态

1
2
3
4
5
6
[iyunv@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
[iyunv@nagios01 conf]# pkill sersync
[iyunv@nagios01 conf]# ps -ef|grep sersync
root      7187  2428  0 00:56 pts/0    00:00:00 grep sersync



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

1
2
3
4
5
6
sersync -r -d -o /usr/local/sersync/conf/cfgs_confxml.xml
sersync -r -d -o /usr/local/sersync/conf/objects_confxml.xml
[iyunv@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,在做一下测试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[iyunv@nagios01 conf]# touch /usr/local/nagios/etc/cfgs/2.txt /usr/local/nagios/etc/objects/2.txt
[iyunv@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

[iyunv@Nagios02 /usr/local/nagios/etc]$tree
├── cfgs
│   ├── 1.txt
│   ├── 2.txt
│   ├── cfgs.log
├── objects
│   ├── 1.txt
│   ├── 2.txt
│   ├── objects.log



Sersync 多实例 实时同步配置成功

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-181969-1-1.html 上篇帖子: Centos+Sersync+inotify实时同步数据文件(一) 下篇帖子: 用snmp和mrtg监控linux
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表