利用sersync进行实时同步数据.docx
《利用sersync进行实时同步数据.docx》由会员分享,可在线阅读,更多相关《利用sersync进行实时同步数据.docx(12页珍藏版)》请在冰豆网上搜索。
利用sersync进行实时同步数据
利用sersync进行实时同步数据
在同步服务器上开启sersync,将监控路径中的文件同步到目标服务器,因此需要在同步服务器配置sersync,在同步目标服务器配置rsync。
一、同步目标服务器配置rsync
1.
# rpm -qa |grep rsync
2.
3.
rsync-2.6.8-3.1
4.
5.
#rpm-ersync-2.6.8-3.1
6.
unistall系统自带安装的rsync,安装3.0版的rsync
1.
# wget -c http:
//rsync.samba.org/ftp/rsync/rsync-3.0.8.tar.gz
2.
3.
#tarxfrsync-3.0.8.tar.gz
4.
5.
#./configure--prefix=/usr&&make&&makeinstall
6.
7.
#vi/etc/rsyncd.conf
8.
添加下面的代码到rsyncd.conf中
1.
uid = nobody
2.
3.
gid = nobody
4.
5.
use chroot = no
6.
7.
strict modes = yes
8.
9.
max connections = 200
10.
11.
pid file = /var/run/rsyncd.pid
12.
13.
lock file = /var/run/rsync.lock
14.
15.
log file = /var/log/rsyncd.log
16.
17.
18.
19.
[test]
20.
21.
path = /home/
22.
23.
comment = test
24.
25.
read only = no
26.
27.
write only = no
28.
29.
ignore errors = yes
30.
31.
list = yes
32.
33.
uid = root
34.
35.
gid = root
36.
启动rsync服务
1.
#rsync --daemon
2.
二、配置sersync2
sersync2是金山逍遥网技术支持部平台组周洋童鞋,开发的一款基于inotify+rsync的大量文件的多服务器自动同步程序,目前已开源,开源协议为NewBSDLicense,项目的下载地址:
1.
2.
这个配置超简单的,下载文件,解压即可
1.
# wget -c
2.
3.
# tar xf sersync2.5_64bit_binary_stable_final.tar.gz
4.
5.
# cd GNU-Linux-x86
6.
7.
# mkdir /etc/sersync2
8.
9.
# cp confxml.xml /etc/sersync2
10.
11.
# cp sersync2 /usr/bin
12.
配置sersync2
1.
2.
3.
4.
5.
6.
7.
8.
9.
---->
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
-- port=874 -->
20.
21.
-- timeout=100 -->
22.
23.
24.
25.
26.
27.
--default every 60mins execute once-->
28.
29.
--600mins-->
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
表明要将同步服务器上本地的/data/bb 路径下的文件,同步到远程服务器 192.168.1.4 与 192.168.1.6上的test 模块下。
接下来,运行sersync2
# sersync2 -r -o /etc/sersync2/confxml.xml
-r的意义
1.
-r 在开启实时监控之前对同步服务器目录与远程目标机目录进行一次整体同步
2.
运行完了输出
1.
set the system param
2.
3.
execute:
echo 50000000 > /proc/sys/fs/inotify/max_user_watches
4.
5.
execute:
echo 327679 > /proc/sys/fs/inotify/max_queued_events
6.
7.
parse the command param
8.
9.
option:
-r rsync all the local files to the remote servers before the sersync work
10.
11.
option:
-d run as a daemon
12.
13.
option:
-o config xml name:
/etc/sersync2/confxml.xml
14.
15.
daemon thread num:
10
16.
17.
parse xml config file
18.
19.
host ip :
localhost host port:
8008
20.
21.
daemon start,sersync run behind the console
22.
23.
config xml parse success
24.
25.
please set /etc/rsyncd.conf max connections=0 Manually
26.
27.
sersync working thread 112 = 1(primary thread) + 1(fail retry thread) + 10(daemon sub threads)
28.
29.
Max threads numbers is:
32 = 12(Thread pool nums) + 20(Sub threads)
30.
31.
please according your cpu ,use -n param to adjust the cpu rate
32.
33.
------------------------------------------
34.
35.
rsync the directory recursivly to the remote servers once
36.
37.
working please wait...
38.
39.
execute command:
cd /data/bb && rsync -artuz -R --delete ./ 192.168.1.4:
:
test >/dev/null 2>&1
40.
41.
run the sersync:
42.
43.
watch path is:
/data/bb
44.
sersync2的参数
1.
sersync2 -h
2.
3.
set the system param
4.
5.
execute:
echo 50000000 > /proc/sys/fs/inotify/max_user_watches
6.
7.
execute:
echo 327679 > /proc/sys/fs/inotify/max_queued_events
8.
9.
parse the command param
10.
11.
_______________________________________________________
12.
13.
参数-d:
启用守护进程模式
14.
15.
参数-r:
在监控前,将监控目录与远程主机用rsync命令推送一遍
16.
17.
c参数-n:
指定开启守护线程的数量,默认为10个
18.
19.
参数-o:
指定配置文件,默认使用confxml.xml文件
20.
21.
参数-m:
单独启用其他模块,使用 -m refreshCDN 开启刷新CDN模块
22.
23.
参数-m:
单独启用其他模块,使用 -m socket 开启socket模块
24.
25.
参数-m:
单独启用其他模块,使用 -m http 开启http模块
26.
27.
不加-m参数,则默认执行同步程序
28.
29.
________________________________________________________________
30.
索性一次性运行
1.
# sersync2-r-d-o/etc/sersync2/confxml.xml
2.
其他功能待研究中