sersync服务是利用inotify服务与rsync服务共同来实现的数据实时同步功能。
实现sersync需要先配置rsync可以参考前面的文章(rsync数据同步)
继续使用上篇文章的环境。
server:30.32.4.171 同步文件夹/backup/
client:30.32.4.172 同步文件夹/date/test/
安装sersync服务
谷歌项目地址
1
2
3
4
| [root@172 ~]# tar -xvf sersync2.5.4_64bit_binary_stable_final.tar.gz
GNU-Linux-x86/
GNU-Linux-x86/sersync2 #启动文件
GNU-Linux-x86/confxml.xml #配置文件
|
1
| [root@172 ~]# mv GNU-Linux-x86 /usr/local/sersync #移动项目
|
目录结构如下
1
2
3
4
5
6
7
8
9
| [root@172 sersync]# tree
.
├── bin
│ └── sersync
├── conf
│ ├── confxml.xml
│ └── confxml.xml.back
└── logs
└── rsync_fail_log.sh
|
修改配置文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| [root@172 conf]# vi confxml.xml +24
<localpath watch="/date/test"> #监听的同步目录路径
<remote ip="30.32.4.171" name="backup"/> #服务器地址,与rsync配置的模块名称
<!--<remote ip="192.168.8.39" name="tongbu"/>-->
<!--<remote ip="192.168.8.40" name="tongbu"/>-->
</localpath>
[root@172 conf]# vi confxml.xml +31
<rsync>
<commonParams params="-artuz"/>
<auth start="true" users="rsync_user" passwordfile="/etc/rsyncd.password"/> #开启认证,用户名,认证密码文件
<userDefinedPort start="false" port="874"/><!-- port=874 -->
<timeout start="true" time="100"/><!-- timeout=100 --> #开启超时
<ssh start="false"/>
</rsync>
[root@172 conf]# vi confxml.xml +36
<failLog path="/usr/local/sersync/logs/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->
|
添加环境
1
2
| [root@172 conf]# echo "export PATH=$PATH:/usr/local/sersync/bin">>/etc/profile
[root@172 conf]# source /etc/profile
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| [root@172 ~]# sersync -h
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
_______________________________________________________
参数-d:启用守护进程模式
参数-r:在监控前,将监控目录与远程主机用rsync命令推送一遍
c参数-n: 指定开启守护线程的数量,默认为10个
参数-o:指定配置文件,默认使用confxml.xml文件
参数-m:单独启用其他模块,使用 -m refreshCDN 开启刷新CDN模块
参数-m:单独启用其他模块,使用 -m socket 开启socket模块
参数-m:单独启用其他模块,使用 -m http 开启http模块
不加-m参数,则默认执行同步程序
________________________________________________________________
|
启动测试
1
| [root@172 ~]# sersync -r -d -o /usr/local/sersync/conf/confxml.xml
|
1
2
3
4
5
6
7
8
| [root@172 test]# echo "ttt">test
[root@172 test]# ls
sersync.tt test
服务端
[root@server backup]# ll
总用量 8
-rw------- 1 rsync rsync 13 3月 22 17:57 sersync.tt
-rw------- 1 rsync rsync 4 3月 22 18:20 test
|