Centos系统使用rsyn实现双主机目录实时同步

Centos系统使用rsyn实现双主机附件目录实时同步

A主机:192.168.2.18,B主机:192.168.2.20;目录:/data/{dira,dirb}
数据同步os用户名:hhdb,A、B hhdb用户需要配置免密

1.安装rsyn\lsyncd

yum -y install rsync lsyncd

2.A服务器配置

2.1 /etc/lsyncd.conf

配置文件
vi /etc/lsyncd.conf

----
-- User configuration file for lsyncd.
--
-- Simple example for default rsync, but executing moves through on the target.
--
-- For more examples, see /usr/share/doc/lsyncd*/examples/
--
-- sync{default.rsyncssh, source="/var/www/html", host="localhost", targetdir="/tmp/htmlcopy/"}
settings {
    logfile      ="/var/log/lsyncdA.log",
    statusFile   ="/usr/local/lsyncdA.status",
    inotifyMode  = "CloseWrite",
    maxProcesses = 8,
    -- nodaemon =true,
    }

sync {
    default.rsync,
    source    = "/data/dira",
    target    = "rsync_backup@192.168.2.20::backup",
    rsync     = {
        binary    = "/usr/bin/rsync",
        password_file = "/etc/rsyncA.password",
        archive   = true,
        compress  = true,
        verbose   = true
        }
    }
创建虚拟用户密码文件
[root@nfs ~]# touch /etc/rsyncA.password
[root@nfs ~]# echo "1" > /etc/rsyncA.password
chmod 600 /etc/rsync.password
设置服务开机自启
[root@nfs ~]# systemctl restart lsyncd
[root@nfs ~]# systemctl enable lsyncd

2.2配置 /etc/rsyncd.conf

uid = hhdb
gid = hhdb
port = 873
fake super = yes
use chroot = no
max connections = 200
timeout = 300
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
read only = false
list = false
auth users = rsync_backup
secrets file = /etc/rsyncB.password
[backup]
comment = "backup"
path = /data/dirb

创建密码文件
[root@rsync ~]# touch /etc/rsyncB.password
[root@rsync ~]# echo "rsync_backup:1" >/etc/rsyncB.password
[root@rsync ~]# chmod 600 /etc/rsyncB.password
加入开机自启
[root@rsync ~]# systemctl restart rsyncd
[root@rsync ~]# systemctl enable  rsyncd

3.B服务器配置

3.1配置 /etc/rsyncd.conf

uid = hhdb
gid = hhdb
port = 873
fake super = yes
use chroot = no
max connections = 200
timeout = 300
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
read only = false
list = false
auth users = rsync_backup
secrets file = /etc/rsyncA.password
[backup]
comment = "backup"
path = /data/dira

创建密码文件

[root@rsync ~]# touch /etc/rsyncA.password
[root@rsync ~]# echo "rsync_backup:1" >/etc/rsyncA.password
chmod 600 /etc/rsyncA.password

加入开机自启

[root@rsync ~]# systemctl restart rsyncd
[root@rsync ~]# systemctl enable  rsyncd

3.2配置/etc/lsyncd.conf

配置文件
vi /etc/lsyncd.conf

----
-- User configuration file for lsyncd.
--
-- Simple example for default rsync, but executing moves through on the target.
--
-- For more examples, see /usr/share/doc/lsyncd*/examples/
--
-- sync{default.rsyncssh, source="/var/www/html", host="localhost", targetdir="/tmp/htmlcopy/"}
settings {
    logfile      ="/var/log/lsyncdB.log",
    statusFile   ="/usr/local/lsyncdB.status",
    inotifyMode  = "CloseWrite",
    maxProcesses = 1,
    -- nodaemon =true,
    }

sync {
    default.rsync,
    source    = "/data/dirb",
    target    = "rsync_backup@192.168.2.18::backup",
    rsync     = {
        binary    = "/usr/bin/rsync",
        password_file = "/etc/rsyncB.password",
        archive   = true,
        compress  = true,
        verbose   = true
        }
    }
创建虚拟用户密码文件
[root@nfs ~]# touch /etc/rsyncB.password
[root@nfs ~]# echo "1" > /etc/rsyncB.password
chmod 600 /etc/rsyncB.password
设置服务开机自启
[root@nfs ~]# systemctl restart lsyncd
[root@nfs ~]# systemctl enable lsyncd
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值