zoukankan      html  css  js  c++  java
  • CentOS7通过rsync+crontab实现两台服务器文件同步

    centos7系统中已经默认安装rsync

    1:主服务器配置

    (1)修改rsyncd.conf 配置文件

    [root@localhost app]# vi /etc/rsyncd.conf
    motd file = /etc/rsyncd.motd
    log file = /var/log/rsyncd.log
    pid file = /var/run/rsyncd.pid
    lock file = /var/run/rsyncd.lock
    port = 873
    address = 192.168.0.24
    uid = wzh
    gid = wzh
    use chroot = no
    read only = no
    max connections = 10
    timeout = 900
    ignore nonreadable = yes

    [common]
    comment = rsync data
    path = /data/imgs/
    ignore errors
    auth users = wzh
    secrets file = /etc/rsyncd.secrets
    hosts allow = 192.168.0.0/255.255.255.0
    hosts deny = *
    list = false

    (2)创建用户密码

    echo "wzh:wzh" > /etc/rsyncd.secrets
    chmod 600 /etc/rsyncd.secrets

    (3)创建提示信息文件

    echo "rsync data" > /etc/rsyncd.motd

     (4)配置防火墙

    firewall-cmd --zone=public --add-port=873/tcp --permanent
    firewall-cmd --reload

    (5)启动服务

    rsync --daemon
    echo "rsync --daemon" >> /etc/rc.local

     2:备服务器配置

    (1)创建密码文件

    echo "wzh" > /home/wzh/passwd
    chmod 600 /home/wzh/passwd

    (2)拉取

    [wzh@localhost ~]$ rsync -avz --password-file=/home/wzh/passwd wzh@192.168.0.24::common /data/imgs/
    rsync data

    receiving incremental file list
    ./

    sent 58 bytes received 121 bytes 358.00 bytes/sec
    total size is 0 speedup is 0.00

     (3)将命令加入到定时任务中,每1分钟执行同步一次


    $ vi /home/wzh/rsync_data_imgs.sh

    #!/bin/bash
    rsync -avz --password-file=/home/wzh/passwd wzh@192.168.0.24::common /data/imgs/ > /dev/null 2>&1 &

    $ crontab -e
    */1 * * * * /home/wzh/rsync_data_imgs.sh

    $ crontab -l

  • 相关阅读:
    系统吞吐量、TPS(QPS)、用户并发量、性能測试概念和公式
    限流实现与解决方案
    mysql事务,select for update,及数据的一致性处理
    **MySQL锁机制与用法分析**
    死锁的排查
    系统中异常的设计与处理
    Spring如何处理线程并发问题
    ThreadLocal作用、场景、原理
    Database Administration Statements
    mybatis 无法自动补全,没有获得dtd文件
  • 原文地址:https://www.cnblogs.com/yshyee/p/10716521.html
Copyright © 2011-2022 走看看