lsync+rsync自动同步数据

环境:主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 解决

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值