环境:主192.168.2.191
备192.168.2.193
1,在备服务器上安装rsync和xinetd
yum install rsync xinetd
配置xinetd
vim /etc/xinetd.d/rsync
# default: off
# description: The rsync server is a good addition to am ftp server, as it \
# allows crc checksumming etc.
service rsync
{
disable = no(把yes修改为no)
flags = IPv6
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon
log_on_failure += USERID
}
设置xinetd开机自启
systemctl start xinetd.service
systemctl enable xinetd.service
修改rsync配置文件
vim /etc/rsyncd.conf
[data]
path = /soft(备服务器存放数据目录)
hosts allow = 192.168.2.191
hosts deny = *
list = true
uid = root
gid = root
read only = false
/usr/bin/rsync --daemon启动rsync
可以nmap查看873端口是否开启
2,在主服务器上安装lsync和rsync
yum install lsyncd rsync
修改lsync配置文件
vim /etc/sysconfig/lsyncd
# Keep the space there for systemd. Don't nest variables without
# changing the systemd service file to use: /usr/bin/sh -c 'eval XXXX'
#
LSYNCD_OPTIONS="-pidfile /var/run/lsyncd.pid /etc/lsyncd.conf"(把#去掉)
#LSYNCD_OPTIONS=" "
#LSYNCD_USER=""
vim /etc/lsyncd.conf
settings {
logfile ="/var/log/lsyncd/lsyncd.log",
statusFile ="/var/log/lsyncd/lsyncd.status",
inotifyMode = "CloseWrite",
maxProcesses = 7,
-- nodaemon =true,
}
sync {
default.rsync,
source = "/soft",(主服务器存放数据目录)
target = "192.168.2.193::data",(备服务器IP::(备服务器rsync.conf设定))
-- excludeFrom = "/etc/rsyncd.d/rsync_exclude.lst",
rsync = {
binary = "/usr/bin/rsync",
archive = true,
compress = true,
verbose = true
}
}
/rc.d/init.d/lsyncd start
service lsyncd start
chkconfig lsyncd on
/usr/bin/rsync --daemon
最后在主服务器上/soft目录下创建文件
然后等几秒在备服务器上查看
主机上也需要/etc/rsyncd.conf文件
vim /etc/rsyncd.conf
[data]
path = /soft(主服务器存放数据目录)
hosts allow = 192.168.2.193
hosts deny = *
list = true
uid = root
gid = root
read only = false
可能出现的错误:
1.rsync -avz --delete /soft 192.168.2.191::data
rsync: read error: Connection reset by peer (104)
rsync error: error in rsync protocol data stream (code 12) at io.c(759) [receiver=3.0.6]
问题主服务器没有/etc/rsyncd.conf配置文件
2.ps -ef|grep lsyncd
root 168452 167119 0 10:56 pts/1 00:00:00 grep lsyncd
已经启动了但是没有该进程,查看日志
Wed Jan 31 10:56:25 2018 Error: Terminating since out of inotify watches.
Consider increasing /proc/sys/fs/inotify/max_user_watches
因lsyncd使用了inotify触发机制,但是监控的文件数是有限的(默认是8192)
vim /etc/sysctl.conf
fs.inotify.max_user_watches =1048576
sysctl -p 解决