• 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
    
    • 1

    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
            }
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    创建虚拟用户密码文件
    [root@nfs ~]# touch /etc/rsyncA.password
    [root@nfs ~]# echo "1" > /etc/rsyncA.password
    chmod 600 /etc/rsync.password
    
    • 1
    • 2
    • 3
    设置服务开机自启
    [root@nfs ~]# systemctl restart lsyncd
    [root@nfs ~]# systemctl enable lsyncd
    
    
    • 1
    • 2
    • 3

    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
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    创建密码文件
    [root@rsync ~]# touch /etc/rsyncB.password
    [root@rsync ~]# echo "rsync_backup:1" >/etc/rsyncB.password
    [root@rsync ~]# chmod 600 /etc/rsyncB.password
    
    • 1
    • 2
    • 3
    加入开机自启
    [root@rsync ~]# systemctl restart rsyncd
    [root@rsync ~]# systemctl enable  rsyncd
    
    
    • 1
    • 2
    • 3

    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
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18

    创建密码文件

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

    加入开机自启

    [root@rsync ~]# systemctl restart rsyncd
    [root@rsync ~]# systemctl enable  rsyncd
    
    
    • 1
    • 2
    • 3

    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
            }
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    创建虚拟用户密码文件
    [root@nfs ~]# touch /etc/rsyncB.password
    [root@nfs ~]# echo "1" > /etc/rsyncB.password
    chmod 600 /etc/rsyncB.password
    
    • 1
    • 2
    • 3
    设置服务开机自启
    [root@nfs ~]# systemctl restart lsyncd
    [root@nfs ~]# systemctl enable lsyncd
    
    • 1
    • 2
  • 相关阅读:
    每日一题:合并两个有序数组
    k8s审计
    【ArcGIS Pro二次开发】(65):进出平衡SHP转TXT、TXT转SHP
    掌握Katalon Studio 导入 swagger 接口文档,接口测试效率提升100%
    Vuex——笔试题、Vuex简介、引入方式、State、Getter、Mutation、Action、Module
    优雅解决spring事务中异步发送MQ,Redis,RPC
    力扣面试题17.05.字母与数字
    浅挖一下String类,解决String常见的面试题
    微服务架构之:Redis的分布式锁---搭建生产可用的Redis分布式锁
    记参加 2022 Google开发者大会
  • 原文地址:https://blog.csdn.net/KaiKaiWaWa/article/details/126389099