Rsync+unison双向文件同步

本文介绍如何使用RSYNC配置服务器同步源,并利用inotify工具实现文件系统的实时监控与同步。主要内容包括基于SSH和RSYNCD两种方式配置同步源、设置免密登录流程及inotify结合RSYNC或Unison进行文件变动实时响应的具体步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.配置RSYNC服务器的同步源:

  • 基于SSH同步源  
    • rsync -avz /server/rsyncd/*  chen@172.16.23.204:/client/rsyncd
  • 基于RSYNC同步源
    • /etc/rsyncd.conf
      • address = 172.16.23.203
        port 873
        pid file = /var/run/rsyncd.pid
        lock file = /var/run/rsync.lock
        log file = /var/log/rsyncd.log
        read only = false
        auth users = chen
        secrets file = /etc/rsync_user.db
        [share]
        comment = soft
        path=/server/rsyncd
    • /etc/rsyncd_user.db
      • 文件的权限必须是600
        chen:123456
        上行同步的时候:nobody必须有权限(setfacl -m u:nobody:rwx  /client/rsyncd)
        •  rsyncd -avz chen@172.16.23.203::share  /client/rsyncd/ 
        •    rsyncd -avz  rsyncd://chen@172.16.23.203/share /client/rsyncd
  • 免验证登录
    • 基于ssh秘钥对登录
      • 密钥对ssh-keygen -t rsa
      • 传到对端:ssh-copy-id 172.16.23.204
    • 基于RSYNCD系统变量
      • RSYNC_PASSWORD=123456

2.inotify+rsyncd

  • 服务端建立脚本
    • #!/bin/bash
      a="/usr/local/bin/inotifywait -mrq -e create,delete /server/rsyncd" b="/usr/bin/rsync -avz /server/rsyncd/* 172.16.23.204:/client/rsyncd" $a | while read diretory event file do $b done

      执行 bash a.sh & 放到后台执行

3.inotify+unison

  安装软件:inotify-tools-3.14.tar.gz   ocaml-3.10.0.tar.gz  unison-2.13.16.tar.gz

    • tar zxvf inotify-tools-3.14.tar.gz 
      • ./configure && make && make install
    • tar -zxvf ocaml-3.10.0.tar.gz  
      • ./configure
      • make world opt
      • make install
    • tar zxvf   unison-2.13.16.tar.gz
      • cd unison-2.13
      • make UISTYLE=text THREADS=true STATIC=true
      • cp unison /usr/local/bin
    • 建立脚本
      • #!/bin/bash
        a="/usr/local/bin/inotifywait -mrq -e create,delete /server1"
        b="/usr/bin/unison -batch /server1  ssh://172.16.23.204//server2"
        $a | while read diretory event file
        do
                $b
        done
        

          

转载于:https://www.cnblogs.com/powpoia/p/6789523.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值