Implement bidirectional real-time remote file sync (inotifyrsync and nfs) Configuration

Source: Internet
Author: User
Tags inotify
If files on two machines need to be synchronized in real time in the project, try the following two methods: project requirements: machine A (190) and machine B (217) make sure that the content of A folder is the same as that of the other folder. Both machine A and machine B may receive files separately to synchronize the files to the other folder. Method 1: Use rsync-server and inotify to synchronize files 1. rsync-server configuration (2

If files on two machines need to be synchronized in real time in the project, try the following two methods:
Project requirements: machine A (190) and machine B (217) require that the content of A folder be the same as that of the other party. Both machine A and machine B may receive files separately to synchronize the files to the other party.
Method 1: Use rsyNc-Synchronize files with inotify
1. rSync-Server configurations (217)

# vi /etc/xinetd.d/rsync # default: off#       allows crc checksumming etc.service rsync{        disable = no        socket_type     = stream        wait            = no        user            = root        server          = /usr/bin/rsync        server_args     = --daemon        log_on_failure   = USERID}

2. Specify the file location

# Vi/etc/rsynCd. Conf uId= Rootgid = rootuse chroot = yesmax connections = 4 strict modes = yessyslog facility = local5port = 873 [backup] path =/home/rsync/test/# folder to be synchronized comment = This is a testignore errorsread only = no # Write Permission list = yesauth users = rsyncsecretsFile=/Etc/rsync. pas # verify the file. The file hosts allow = 192.168.1.190 # Client IP

3. Create rsync. pas

# vi /etc/rsync.passync:test

4. Client synchronization script (190)

#vi inotify_rsync.sh#!/bin/bashSRC=/home/rsync/test/DST=rsync@192.168.1.217::backup/usr/bin/inotifywait -mrq -e modify,delete,create,attrib ${SRC} | while read D E Fdo/usr/bin/rsync -ahqzt --progress --delete --password-file=/etc/rsync.pas $SRC $DSTdone

5. Set the script to boot automatically

# cat "/root/inotify_rsync.sh &" >> /etc/rc.local

6. Implementation and problems of Bidirectional synchronization the above operations only implement synchronization from machine A (190) to machine B (217), and change the configuration to machine A (190) two-way synchronization can be achieved by setting up the rsync server, but the deletion operation cannot be performed because they do not have the method to determine which operation is the main cause, resulting in the deletion of new files.

Method 2: Use the NFS Shared Server to synchronize files
1. Configure NFS

# Service portmap start # service nfs start # vi/etc/ExPorts/home/rsync/test * (rw, sync, no_root_squash) # rw: read/write permission; sync: data is synchronized to the memory; no_root_squash: if the user logging on to the NFS host is a ROOT user, the user must have the ROOT permission #ExportFs-rv # reload settings

2. Before loading the NFS shared directory, connect to the two machines through SSH, so that no authentication is required, and then write it into the/etc/fstab file.

mount -t nfs 192.168.1.190:/home/rsync/test /home/rsync/test

Conclusion: method 1 files are stored on two machines at the same time, which is real-time and secure, but only suitable for environments where files are not deleted. method 2 files are only stored on NFS servers, if you use the rsync server to regularly back up data to another location, you can recover the data manually in case of a fault, which is also a good choice.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.