Rsync+unison雙向文件同步

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

  • 基於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+rsyncdlinux

  • 服務端創建腳本
    • #!/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 & 放到後臺執行bash

3.inotify+unison服務器

  安裝軟件:inotify-tools-3.14.tar.gz   ocaml-3.10.0.tar.gz  unison-2.13.16.tar.gzssh

    • 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
        
相關文章
相關標籤/搜索