Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Server \ rsync + inotify to achieve real-time synchronization     - Oracle index visible and hidden (visible / invisible) (Database)

- Ubuntu 12.04 commonly use shortcuts finishing Share (Linux)

- Use Linux firewall camouflage defense hacked (Linux)

- Installation and deployment of MariaDB under CentOS (Database)

- Remove old kernel on Ubuntu (Linux)

- Why JavaScript basic types can invoke methods (Programming)

- Install Debian Linux with R on the Android system (Linux)

- Shutdown - an advanced shutdown artifact (Linux)

- Experience RHEL7 new features (Linux)

- Installation through the network Debian 7 (Wheezy) (Linux)

- CentOS 6/7 Series Docker Installation (Linux)

- Source code to compile and install MySQL 5.7.9 (Database)

- Oracle Database asynchronous IO cause slow query response (Database)

- Spark local development environment to build (Server)

- To upgrade combat MongoDB database replication sets and split versions (Database)

- 10 Codes of good practice PHP (Programming)

- RHEL 7.1 compile and install Ganglia 3.7.1 (Server)

- Ubuntu 14.04.1 LTS compile and install the new kernel (Linux)

- Linux Security Setup Guide (Linux)

- Tomcat itself through simple movement separation (Server)

 
         
  rsync + inotify to achieve real-time synchronization
     
  Add Date : 2018-11-21      
         
         
         
  Rsync + inotify to achieve real-time synchronization

1, install rsync


You can install rsync service via yum source
[Root @ dg test] # yum install rsync


You can also install the source package
 wget http://rsync.samba.org/ftp/rsync/src/rsync-3.0.9.tar.gz
[Root @ dg test] #tar zxvf rsync-3.0.9.tar.gz
[Root @ dg test] #cd rsync-3.0.9
[Root @ dg test] #. / Configure --prefix = / usr / local / rsync
[Root @ dg test] # make
[Root @ dg test] #make install


make -j 4 # make compile the source code is compiled into a binary executable file -j 4 compiled using four processes simultaneously, taking the number of cpu, do not exceed the number of cpu

For example: at the source has a directory under / tmp / test there next file syncs sink 10.10.6.82:/data, but this method only manual synchronization, can not achieve real-time synchronization
[Root @ dg test] # rsync -azP --delete / tmp / test root@10.10.6.82: / data

Note: rsync is based on the ssh protocol, we need to know the server root and password
-a, archive (Archive) archiving mode represents recursively transfer files, and to maintain stable properties, is equivalent to adding a parameter -riptgoD
-z --compress represents compression
-P Shows the transmission speed
--delete delete those target end position and have no original location of the file


Add ssh key service, the next you can not enter a password
[Root @ dg bin] # ssh-keygen
Generating public / private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
1e: 5f: 6e: fe: 15: a6: c1: 12: d7: 1d: 4c: 79: c5: 9f: a3: 9d root @ dg

A copy of the trust relationship to the target end

[Root @ dg .ssh] # ssh-copy-id root@10.10.6.82

 


See key target segment has elapsed
[Root @ rac2 .ssh] # ls
authorized_keys known_hosts

Without entering a password 10.10.6.82, this way no password synchronization
[Root @ dg .ssh] # ssh root@10.10.6.82
Last login: Wed Jan 20 10:42:22 2016 from 10.10.8.54
[Root @ rac2 ~] #


2 Installing inotify


[Root @ dg test] #tar zxvf inotify-tools-3.14.tar.gz
[Root @ dg test] # cd inotify-tools-3.14
[Root @ dg test] # ./configure --prefix = / usr / local / inotify
[Root @ dg test] # make
[Root @ dg test] # make install

inotifywait -mrq -e create, move, delete, modify / tmp / test
-e change attribute is used to specify which events you want to monitor these events include create, create, move move, delete delete, modify content attrib
-m indicates continuous monitoring
-r recursive monitoring indicates
-q represents a simplified output


Also open a window:
root @ dg test] # cp / etc / group / tmp / test
[Root @ dg ~] # inotifywait -mrq -e create, move, delete, modify / tmp / test
/ Tmp / test / CREATE group
/ Tmp / test / MODIFY group

From this it can be seen inotifywait can capture files created message


3 Create rsync replication script


This function is mainly to the server side of the / tmp directory in the content, if you modify (either to add, modify, delete files) can be monitored via inotify, and through rsync real-time synchronization to the client in the / tmp, the following is by shell script to achieve.


[Root @ dg test] # cat rsync.sh
#! / Bin / bash
host = 10.10.6.82
src = / data
des = / data2
user = root
/ Usr / local / inotify / bin / inotifywait -mrq --timefmt '% d /% m /% y% H:% M' --format '% T% w% f% e' -e modify, delete, create , attrib $ src | while read files
do
/ Usr / bin / rsync -vzrtopg --delete $ src $ user @ $ host: $ des
echo "$ {files} was rsynced" >> / rsync.log 2> & 1
done

Wherein the host is a client's ip, src is a server-side real-time monitoring to the directory, des is certified module name, needs to be consistent with the client, user is creating a password file authentication user.
This script named rsync.sh, put monitoring directory, for example, I would put / tmp below, and give 764 permissions, suggest that it rsync log into other directories (non-backup directory).
[Root @ dg test] # chmod 764 rsync.sh


Then run this script
[Root @ dg test] # sh /tmp/rsync.sh &


We can also put rsync.sh script to the boot entry in
echo "/tmp/rsync.sh" >> /etc/rc.local
     
         
         
         
  More:      
 
- How to compile and install wxWidgets in Ubuntu / Debian / Linux Mint (Linux)
- Golang environment configuration recommendations (Linux)
- To install Ganglia (Linux)
- ASP.NET 5 (vNext) Linux deployment (Server)
- MySQL DATE_FORMAT () function (Database)
- Oracle TAF Analysis (Database)
- The most common and most effective security settings under linux (Linux)
- Fatal: unable to connect to github.com problem solving (Linux)
- HTTPS and SSH and use the difference between the way: Git User's Manual (Linux)
- Linux Nginx FastDFS integration module is installed Nginx and FastDFS (Server)
- Ora-00600 [fast hot Atkins soft _ that _ Oh, of course not _less_ profile] (Database)
- Enterprise Hadoop cluster architecture - Hadoop installation (Server)
- VirtualBox snapshots (Linux)
- Archlinux installation tutorial (Linux)
- Build Docker based MongoDB replication cluster environment (Database)
- Row-level security and application-level solutions for the new features of PostgreSQL9.5 (Database)
- Three easy open source firewall on the Linux platform (Linux)
- CentOS 6.5 installation Python3.0 (Linux)
- OpenSSL: implementation creates a private CA, certificate signing request Explanation (Server)
- Oracle archive log deletion (Database)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.