源码地址
作者博客
环境说明:
OS:CetnOS 6.4 32bit
Sersync 服务器IP: 192.168.0.12 (这台可以叫主服务器,我们想同步的资源在这台机器上, 它只需要配置开启Sersync ,并不需要sync 服务)
Rsync 服务器IP: 192.168.0.64 (这台机器可以理解成客户端,需要被同步192.168.0.12上的资源,需要启动rsync 服务)
从这上可以看出, Sersync 是利用rsync 把资源"推"给客户端。
实验过程:
一、咱们还是先从客户端说起吧,192.168.0.64 安装 rsync 服务。
点击(此处)折叠或打开
-
[root@zabbix_server opt]# rpm -qa | grep rsync
- rsync-3.0.6-4.el5_7.1
注意:rsync 推荐大家用3版本的,3版本采用增量备份方式,比2.x快多了。
点击(此处)折叠或打开
-
[root@zabbix_server opt]# cat /etc/rsyncd.conf
-
read only = no
-
list = yes
-
use chroot = no
-
max connections = 15
-
uid = root
-
gid = root
-
log file = /var/log/rsyncd.log
-
pid file = /var/run/rsyncd.pid
-
lock file = /var/run/rsync.lock
-
-
[testpic]
-
path = /opt/pic/
-
comment =
-
list = no
-
auth users = rsync
-
secrets file = /etc/rsyncd.pass
-
ignore errors = yes
-
hosts allow = 192.168.0.12/24
- hosts deny = *
说明:testpic 模块名,需要把资源同步到/opt/pic 目录下。
开启rsync 服务,修改 disable = no
点击(此处)折叠或打开
-
[root@zabbix_server pic]# cat /etc/xinetd.d/rsync
-
# default: off
-
# description: The rsync server is a good addition to an ftp server, as it \
-
# allows crc checksumming etc.
-
service rsync
-
{
-
disable = no
-
socket_type = stream
-
wait = no
-
user = root
-
server = /usr/bin/rsync
-
server_args = --daemon
-
log_on_failure += USERID
- }
点击(此处)折叠或打开
- [root@zabbix_server opt]# /etc/init.d/xinetd restart
注意:/etc/rsyncd.pass 权限是600 ,明文书写。格式为 用户名:密码
[root@zabbix_server opt]# cat /etc/rsyncd.pass
rsync:123456
二、Sersync 服务器192.168.0.12
1.下载Sersync
sersync2.5_32bit_binary_stable_final.tar.gz
注意:下载适合你自己服务器的版本,分为32bit 64bit .
点击(此处)折叠或打开
-
[root@mem1 src]# tar xzvf sersync2.5_32bit_binary_stable_final.tar.gz
-
-
[root@mem1 src]# cd GNU-Linux-x86/
-
[root@mem1 GNU-Linux-x86]# ls
- confxml.xml sersync2
2.修改 sersync的配置文件
[root@mem1 GNU-Linux-x86]# vim confxml.xml
修改如下两个内容
1) 把本地目录/export/website/pic 下内容“推” 给192.168.0.64 的testpic 模块。如果有多个需要同步的机器,请顺序添写ip 和 name。
2) 如果rsync 启用密码,请修改这里
3) 如果想限速请添加 --bwlimit=20000 单位KB
4) sersync 默认是加 --delete 参数的,如果想去掉,真接修改
注意: 密码文件 /etc/rsyncd.pass11 权限是600 格式是 密码
点击(此处)折叠或打开
-
[root@mem1 GNU-Linux-x86]# cat /etc/rsyncd.pass11
- 123456
启动服务
点击(此处)折叠或打开
- [root@mem1 GNU-Linux-x86]# ./sersync2 -r -d
注意:如果启动后 没有进行同步,请查看请查看rsync 的日志
测试:我们去 192.168.0.12 /export/website/pic/ 创建目录或者文件,会自动同步到 192.168.0.64 的 /opt/pic/ 目录下。
FAQ
(1)
2013/07/31 17:04:44 [17606] ERROR: module is read only
2013/07/31 17:04:44 [17606] rsync error: syntax or usage error (code 1) at main.c(866) [receiver=3.0.6]
注意read only = no 才可以向上传 否则会提示module is read only
[root@zabbix_server ~]# cat /etc/rsyncd.conf
read only = no
(2)
@ERROR: Unknown module 'website'
rsync error: error starting client-server protocol (code 5) at main.c(1530) [sender=3.0.6]
日志
2013/08/01 15:05:38 [23302] connect from UNKNOWN (192.168.100.8)
2013/08/01 15:06:58 [23354] 192.168.100.8 is not a known address for "localhost": spoofed address?
rsync 权限问题,在/etc/rsyncd.conf 允许主机
hosts allow = 192.168.100.0/24
hosts deny = *
(3)
@ERROR: auth failed on module website
rsync error: error starting client-server protocol (code 5) at main.c(1530) [sender=3.0.6]
日志
2013/08/01 15:07:23 [23302] auth failed on module website from unknown (192.168.100.8): password mismatch
密码文件有问题,检查 拼写错误 权限错误 格式错误
请看作者的博客,还有其它没用到的功能。