sersync+rsync

sersync
是金山的周洋开发的一款基于 inotify + rsync 的大量文件的多服务器自动同步程序
监控文件系统事件,文件实时同步

sersync功能:
1 支持配置文件管理
2 真正的守护进程socket
3 可以对失败文件定时重传
4 默认多线程rsync

主机规划:
backup端:192.168.56.9
client端(源数据端):192.168.56.8

client安装sersync推送数据到backup端
[root@tom01 tools]# tar xf sersync2.5.4_64bit_binary_stable_final.tar.gz -C /usr/local/
[root@tom01 tools]# cd /usr/local/
[root@tom01 local]# mv GNU-Linux-x86 sersync
[root@tom01 local]# cd sersync/
[root@tom01 sersync]# mkdir conf bin logs
[root@tom01 sersync]# mv confxml.xml conf/
[root@tom01 sersync]# mv sersync2 bin/sersync
[root@tom01 sersync]# cd conf/
[root@tom01 conf]# ls
confxml.xml
[root@tom01 conf]# cp confxml.xml confxml.xml.bak

修改sersync配置文件
[root@tom01 conf]# vim confxml.xml

 24         <localpath watch="/backup">                                               #本地目录
 25             <remote ip="192.168.56.9" name="backup_server"/>     #远程rsync地址与模块名
 26             <!--<remote ip="192.168.8.39" name="tongbu"/>-->
 27             <!--<remote ip="192.168.8.40" name="tongbu"/>-->
 28         </localpath>
 29         <rsync>
 30             <commonParams params="-az"/>
 31             <auth start="true" users="test" passwordfile="/etc/rsync.password"/> #开启账号认证 账号与本地密码文件路径
 32             <userDefinedPort start="false" port="874"/><!-- port=874 -->
 33             <timeout start="false" time="100"/><!-- timeout=100 -->
 34             <ssh start="false"/>
 35         </rsync>
 36  <failLog path="/usr/local/sersync/logs/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once--> #同步错误信息保存路径,默认60分钟执行一次,在此同步出错的文件

配置sersync环境变量
[root@tom01 conf]# echo ‘export PATH=$PATH:/usr/local/sersync/bin’>>/etc/profile
[root@tom01 conf]# source /etc/profile

开启sersync守护进程同步数据
[root@tom01 backup]# sersync -r -d -o /usr/local/sersync/conf/confxml.xml

-r 初始化同步 伤处目标目录下文件 第一次同步时使用,增量备份千万不要加 不然就是完全备份
-d 后台运行 守护进程
-o 指定配置文件

配置sersync多实例
如果在confxml.xml配置多个实例,测试是不会生效的,这里的解决方案是为多个实例创建不同的配置文件结合-o参数,别的方法不太清楚。
例:
修改backup服务端rsync配置文件
[root@tom01 backup]# vim /etc/rsyncd.conf

uid = rsync
gid = rsync
use chroot = no
max connections = 1000
strict modes = yes
timeout = 600
port = 873
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
ignore errors
hosts allow = 192.168.56.0/24
read only = no
dont compress = *.gz *.bz2 *.zip *.tgz
auth users = gao
secrets file = /etc/rsync.password

[backup_etc]
path = /backup/etc

[backup_script]
path = /backup/scrip

[backup_html]
path = /backup/html

修改client端sersync文件
[root@tom01 backup]# cd /usr/local/sersync/conf/
[root@tom01 conf]# cp confxml.xml etc.xml
[root@tom01 conf]# cp confxml.xml scrip.xml
[root@tom01 conf]# cp confxml.xml html.xml
修改为下面内容

 24         <localpath watch="/etc">                                              
 25             <remote ip="192.168.56.9" name="backup_etc"/>     
 26             <!--<remote ip="192.168.8.39" name="tongbu"/>-->
 27             <!--<remote ip="192.168.8.40" name="tongbu"/>-->
 28         </localpath>
 36  <failLog path="/usr/local/sersync/logs/etc_rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->
 
  24         <localpath watch="/scrip">                                             
 25             <remote ip="192.168.56.9" name="backup_scrip"/>    
 26             <!--<remote ip="192.168.8.39" name="tongbu"/>-->
 27             <!--<remote ip="192.168.8.40" name="tongbu"/>-->
 28         </localpath>
 36  <failLog path="/usr/local/sersync/logs/scrip_rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->

 24         <localpath watch="/var/www/html">                                             
 25             <remote ip="192.168.56.9" name="backup_html"/>   
 26             <!--<remote ip="192.168.8.39" name="tongbu"/>-->
 27             <!--<remote ip="192.168.8.40" name="tongbu"/>-->
 28         </localpath>
 36  <failLog path="/usr/local/sersync/logs/http_rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->

测试
sersync -r -d -o /usr/local/sersync/conf/etc.xml
sersync -r -d -o /usr/local/sersync/conf/scrip.xml
sersync -r -d -o /usr/local/sersync/conf/html.xml

测试成功后设置开机启动
vim /etc/rc.local (开机自启不要加-r选项)
sersync -d -o /usr/local/sersync/conf/etc.xml
sersync -d -o /usr/local/sersync/conf/scrip.xml
sersync -d -o /usr/local/sersync/conf/html.xml

猜你喜欢

转载自blog.csdn.net/bjgaocp/article/details/88556128