Real-time synchronization of Linux and Windows system files

  
                  

Real-time synchronization of multiple servers, Linux and Windows system files using software Rsync and Inotify Real-time synchronization of files between two Linux hosts Host A: 192.168.254.201 Host B: 192.168.254.202 Experimental purpose, implemented on host B Make changes, real-time synchronization on host A. 1.1 Configuration on host A 1.1.1 Create a folder to be synchronized Mkdir /opt/rsync 1.1.2 Install Rsync Emerge rsync I use Gentoo, it is installed by default, and the configuration file is in /etc. /rsyncd.conf 1.1.3 Modify the configuration file Nano –w /etc/rsyncd.conf # Globel setting uid = root gid = root use chroot =no max connectiongs = 10 pid file = /var/run/rsyncd.pid lock file = /var/run/rsync.lock log file = /var/log/rsync.og # Folder Setting,Permit add more folder [images] path = /opt/image/read only = no auth users = rsyncuser secrets file = /Etc/rsyncd.secrets 1.1.4 Write verification file Nano –w /etc/rsyncd.secrets rsyncuser:Password01

Chown -R 600 /etc/rsy Ncd.secrets 1.1.5 Startup Service Rsync --daemon --config=/etc/rsyncd.conf Echo –en ‘rsync –daemon –config=/etc/rsyncd.conf’ >> /etc/Rc.local 1.2 Configuration on Host B 1.2.1 Create the same directory Mkdir /opt/rsync 1.2.2 Install rsync and inotify Emerge rsync Emerge inotify-tools 1.2.3 Create Access Password Echo –en ‘Password01’ > /etc/rsyncd.secrets Chmod 600 /etc/rsyncd.secrets 1.2.4 Configuring Synchronization Scripts nano -w /root/InotifyRsync.sh #!/bin/bash host_1=192.168.254.201 src=/opt/image/dst=images User=valeRsync inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' -e

modify,delete$ do rsync - avzP --delete --password-file=/etc/rsyncd.secrets $src $ echo "${file} was rsynced" done exit 0 1.2.5 Test Run echo -ne ‘/root/InotifyRsync.sh & ’ >> /etc/rc.local Sh /root/InotifyRsync.s h Also open a terminal to test under /opt/rsync and check if the A host is synchronized. 1.2.6 Properties supported by inotify

IN_ACCESS, ie the file is accessed

IN_MODIFY, the file is written IN_ATTRIB, the file attributes are modified, such as chmod, chown, touch, etc. IN_CLOSE_WRITE, the writable file is Close IN_CLOSE_NOWRITE, the non-writable file is closed IN_OPEN, the file is opened by IN_MOVED_FROM, the file is removed, such as mv IN_MOVED_TO, the file is moved, such as mv, cp IN_CREATE, create a new file IN_DELETE, the file is deleted, such as rm IN_DELETE_SELF, self-delete , that is, an executable file deletes itself when executing IN_MOVE_SELF, self-moving, that is, an executable file moves itself IN_UNMOUNT during execution, the host file system is umount IN_CLOSE, the file is closed, equivalent to (IN_CLOSE_WRITE

Copyright © Windows knowledge All Rights Reserved