在同步服务器上开启sersync,将监控路径中的文件同步到目标服务器,因此需要在同步服务器配置sersync,在同步目标服务器配置rsync.
一、同步目标服务器配置rsync
rpm -qa |grep rsync
rsync-2.6.8-3.1
rpm -e rsync-2.6.8-3.1
#unistall系统自带安装的rsync,安装3.0版的rsync
wget -c http://rsync.samba.org/ftp/rsync/rsync-3.0.8.tar.gz
tar xf rsync-3.0.8.tar.gz
./configure --prefix=/usr && make && make install
vi /etc/rsyncd.conf
#添加下面的代码到rsyncd.conf中
uid = nobody
gid = nobody
use chroot = no
strict modes = yes
max connections = 200
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
[test]
path = /home/
comment = test
read only = no
write only = no
ignore errors = yes
list = yes
uid = root
gid = root
启动rsync服务:
rsync --daemon
二、配置sersync2 sersync2是金山逍遥网技术支持部平台组周洋童鞋,开发的一款基于 inotify + rsync 的大量文件的多服务器自动同步程序,目前已开源,开源协议为 New BSD License,项目的下载地址:
http://code.google.com/p/sersync/
这个配置超简单的,下载文件,解压即可.
wget -c http://sersync.googlecode.com/files/sersync2.5_64bit_binary_stable_final.tar.gz
tar xf sersync2.5_64bit_binary_stable_final.tar.gz
cd GNU-Linux-x86
mkdir /etc/sersync2
cp confxml.xml /etc/sersync2
cp sersync2 /usr/bin
配置sersync2:
port=874
timeout=100
default every 60mins execute once
600mins
表明要将同步服务器上本地的/data/bb 路径下的文件,同步到远程服务器 192.168.1.4 与 192.168.1.6上的test 模块下. 接下来,运行sersync2:
sersync2 -r -o /etc/sersync2/confxml.xml
#-r 在开启实时监控之前对同步服务器目录与远程目标机目录进行一次整体同步
运行完了输出:
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: /etc/sersync2/confxml.xml
daemon thread num: 10
parse xml config file
host ip : localhost host port: 8008
daemon start,sersync run behind the console
config xml parse success
please set /etc/rsyncd.conf max connections=0 Manually
sersync working thread 112 = 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 /data/bb && rsync -artuz -R --delete ./ 192.168.1.4::test >/dev/null 2>&1
run the sersync:
watch path is: /data/bb
sersync2的参数
sersync2 -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命令推送一遍
#参数-n: 指定开启守护线程的数量,默认为10个
#参数-o:指定配置文件,默认使用confxml.xml文件
#参数-m:单独启用其他模块,使用 -m refreshCDN 开启刷新CDN模块
#参数-m:单独启用其他模块,使用 -m socket 开启socket模块
#参数-m:单独启用其他模块,使用 -m http 开启http模块
#不加-m参数,则默认执行同步程序
索性一次性运行:
sersync2 -r -d -o /etc/sersync2/confxml.xml