zoukankan      html  css  js  c++  java
  • centos7 使用rsync 实现文件同步

    一、服务端(192.168.8.81):

    1. 安装软件:
      yum  -y  install  rsync
    2. 创建需同步的目录:
      mkdir  -p  /home/root/rsync
    3. 编辑配置文件:vim /etc/rsyncd.conf
      motd file = /etc/rsyncd.motd
      transfer logging = yes
      log file = /var/log/rsyncd.log
      port = 873
      address = 192.168.8.81
      uid = root
      gid = root
      use chroot = no
      read only = no
      max connections = 10
      [common]
      comment = rsync lee
      path = /home/lee/rsync/
      ignore errors
      auth users = lee
      secrets file = /etc/rsyncd.secrets
      hosts allow = 192.168.8.0/255.255.255.0
      hosts deny = *
      list = false
    4. 创建用户密码:
      echo  "root:123456"  >  /etc/rsyncd.secrets
      chmod  600  /etc/rsyncd.secrets
    5. 配置防火墙规则:
      iptables  -I  INPUT  -p  tcp  --dport  873  -j  ACCEPT
    6. 启动服务:
        rsync  --daemon
        echo  "rsync  --daemon"  >>  /etc/rc.local

    二、客户端(192.168.8.82):

    1. 安装软件:
      yum  -y  install  rsync
    2. 创建需同步的目录:
      mkdir  -p  /home/root/rsync
    3. 创建密码文件(免输入密码):
      echo  "123456"  >  /root/passwd
      chmod  600  /root/passwd
    4. 拉取(在客户端(192.168.8.82)):
      rsync  -avz  --password-file=/root/passwd  root@192.168.8.81::common  /home/root/rsync/

      centos7安装配置rsync

    5. 推送(在服务端(192.168.8.81)):
      rsync  -avz  --password-file=/root/passwd  /home/root/rsync/  root@192.168.8.81::common

      centos7安装配置rsync

     

    三、实现定时自动同步

        创建一个需要定时执行的脚本文件,如:rsyncd.sh脚本:vi  /etc/rsyncd.sh
                (路径自己设置的),在此脚本中添加如下内容
                 
     
        设置脚本执行的时间:crontab –e,添加如下内容  
                
  • 相关阅读:
    获取安卓控件的大小
    最详细eclipse汉化插件安装教程
    android图片的内存优化
    网站性能并发测试工具
    [php]数据结构&算法(PHP描述) 半折插入排序 straight binary sort
    ubuntu 环境变量
    [php]php设计模式 Interator (迭代器模式)
    nginx 显示文件目录
    [php]php设计模式 (总结)
    [php]数据结构&算法(PHP描述) 冒泡排序 bubble sort
  • 原文地址:https://www.cnblogs.com/pangguoming/p/9855244.html
Copyright © 2011-2022 走看看