Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Server \ Amazon EC2 server using Rsync + Inotify real-time synchronization     - Tsung first test installation (Linux)

- Oracle View index and use indexes Precautions (Database)

- CentOS7 install JAVA notes (Linux)

- RedHat Linux 6.4 installation RTL8188CUS wireless network card driver (Linux)

- Several SQL Server data migration / Export Import Practice (Database)

- MBR partitions under Linux (Linux)

- Java Concurrency -volatile keywords (Programming)

- Python 3.5 will support Async / Await Asynchronous Programming (Programming)

- MySQL Basic tutorial: About varchar (N) (Database)

- Linux find command to find files (Linux)

- Sublime Text 3 best features, plug-ins and settings (Linux)

- RedHat 6 xrdp use remote login interface (Linux)

- Difference in MySQL VARCHAR and CHAR data format (Database)

- Laravel cache paged results (Server)

- RHEL6.4 one key installation Redmine (Linux)

- MySQL full-index scan bug (Database)

- OpenCV 3.0 + Python 2.7 installation and testing under Ubuntu 14.04 (Linux)

- Android Scroller call mechanism and the relationship of computeScroll (Programming)

- JavaScript basic tools list (Programming)

- Oracle rebuild index script (Database)

 
         
  Amazon EC2 server using Rsync + Inotify real-time synchronization
     
  Add Date : 2018-11-21      
         
         
         
  Background:

Amazon needs to synchronize data between two servers, just pass on one machine, you can automatically sync to the other machine.

Install Rsync:

CentOS 6.7 with automatic on Rsync, does not require installation.

##Case Analysis
It is assumed that there are two servers: A and B. Where A is the primary web server (155.28.81.0), B is the server from the server (155.28.82.0). We want A server / home / test / backed up to the server B / home / test / directory.

A server configuration ##
#### A compilation server installation
Compile rsync installation is very simple, just the following simple steps:

[Root @ www ~] # cd / usr / local / src /
[Root @ www src] # wget http://rsync.samba.org/ftp/rsync/src/rsync-3.0.9.tar.gz
[Root @ www src] # tar zxvf rsync-3.0.9.tar.gz
[Root @ www src] # cd rsync-3.0.9
[Root @ www rsync-3.0.9] # ./configure --prefix = / usr / local / rsync /
[Root @ www rsync-3.0.9] # make
[Root @ www rsync-3.0.9] # make install But note that rsync must be installed on servers A and B, based on server mode (passive) run rsync server on which the A, B and places the customer end mode (active) run rsync. Thus runs on web server A rsync daemon running on the client B timed program to back up the contents of the web server A to be backed up.

#### To create a user and password authentication file

[Root @ www rsync-3.0.9] # echo "backup: bk_passwd"> /usr/local/rsync/rsyncd.passwd Remember password file server end establishment, including user name and password, and the client side password file created only password, no user name.

#### Is set to read-only permissions

[Root @ www rsync-3.0.9] # cd / usr / local / rsync
[Root @ www rsync] # chmod 600 rsyncd.passwd might otherwise error:
@ERROR: Auth failed on module ***
rsync error: error starting client-server protocol (code 5) at main.c (1503)

#### Establishing rsync profile

[Root @ www rsync] # vi /usr/local/rsync/rsyncd.conf
uid = root
gid = root
use chroot = no
max connections = 4
strict modes = yes
hosts allow = 121.42.46.213 # spaces can allow multiple
port = 873
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log

[Test]
path = / home / test
ignore errors
read only = true
list = false
auth users = backup
secrets file = /usr/local/rsync/rsyncd.passwd#### way to start rsync daemon server

[Root @ www rsync] # rsync --daemon --config = / usr / local / rsync / rsyncd.confrsync default service port 873, the port server receiving client or anonymous authentication mode backup request.

#### If you want service is set from the start, you can add rc.local

Edit /etc/rc.d/rc.local, add at the end:

/ Usr / local / rsync / bin / rsync --daemon --config = / etc / rsyncd.conf

## Client Configuration B

Compile and install Ibid., Generic error occurs in the server B

#### Establishing access server A password authentication file

[Root @ www rsync] # echo "bk_passwd"> /usr/local/rsync/rsync.passwd#### set permissions to read-only

[Root @ www rsync] # chmod 0600 rsync.passwd #### after rsync installed, run the following command to synchronize backup

[Root @ www rsync] # rsync -vzrtopg --delete --progress --password-file = / usr / local / rsync / rsync.passwd backup@115.28.81.0 :: test / home / test wherein address backup@115.28. 81.0 :: test, backup server a user, 115.28.81.0 server a IP address or domain name, test server a configuration module.

The above command line -vzrtopg where v is verbose, z is compressed, r is recursive, topg original file attributes are maintained in the case of the main parameters, time, - progress means showing details of the progress - -delete means that if the server to delete this file, then the client is also appropriate to delete the file, keep it real consensus. --password-file = / usr / local / rsync / rsync.passwd to specify a password file, so that you can interactively without having to enter a password to use in the script, to note here is this property to the password file permissions set to be readable only by root.

Here the contents of the backup stored in the backup machine / home / test / directory.

#### Install inotify

[Root @ www rsync] # cd / usr / local / src /
[Root @ www src] # wget http://cloud.github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
[Root @ www src] # tar zxvf inotify-tools-3.14.tar.gz
[Root @ www src] # cd inotify-tools-3.14
[Root @ www inotify-tools-3.14] # ./configure --prefix = / usr / local / inotify
[Root @ www inotify-tools-3.14] # make
[Root @ www inotify-tools-3.14] # make install

Rsync synchronization scripts:

#! / Bin / bash
#variables
current_date = $ (date +% Y% m% d_% H% M% S)
source_path = / home / www /
log_file = / usr / local / rsync / rsync_client.log
  
#rsync configuration
rsync_server = 115.28.81.0
rsync_module = www
rsync_user = backup
rsync_pwd = / usr / local / rsync / rsync.passwd
INOTIFY_EXCLUDE = '(.. * / * Log |.. * / * Swp) $'
INOTIFY_EXCLUDE_LIST = '/ usr / local / inotify / inotify_exclude.lst'
RSYNC_EXCLUDE = '/ etc / rsync_exclude.list'
  
#rsync client pwd check
if [! -e $ {rsync_pwd}]; then
    echo -e "rsync client passwod file $ {rsync_pwd} does not exist!"
    exit 0
fi
  
#inotify_function
#This Function is used to monitor folder (/ home / www) files, but exclude subfolders (storage, bootstrape / cache).
inotify_fun () {
    / Usr / local / inotify / bin / inotifywait -mrq --timefmt '% Y /% m /% d-% H:% M:% S' --format '% T% w% f'
          --exclude $ {INOTIFY_EXCLUDE} --fromfile $ {INOTIFY_EXCLUDE_LIST} -e modify, delete, create, move, attrib $ {source_path}
          | While read file
      do
          / Usr / bin / rsync -auvrtzopgP --exclude-from = $ {RSYNC_EXCLUDE} --progress --bwlimit = 500 --password-file = $ {rsync_pwd} $ {source_path} $ {rsync_user} @ $ {rsync_server}: : $ {rsync_module}
      done
}
#inotify log
inotify_fun >> $ {log_file} 2> & 1

Wherein INOTIFY_EXCLUDE_LIST = '/ usr / local / inotify / inotify_exclude.lst' as follows:
[Ec2-user @ ip-172-31-7-248 rsync] $ cat /usr/local/inotify/inotify_exclude.lst
/ Home / www
@ / Home / www / www.xxx.com / storage
@ / Home / www / www.xxx.com / bootstrap / cache
@ / Home / www / xxx.com / storage

RSYNC_EXCLUDE = '/ etc / rsync_exclude.list'

[Ec2-user @ ip-172-31-7-248 rsync] $ cat /etc/rsync_exclude.list
www.xxx.com/storage
www.xxx.com/bootstrap/cache
xxx.com/storage
     
         
         
         
  More:      
 
- Generators and iterators in Python (Programming)
- How to limit network bandwidth usage in Linux (Linux)
- Linux POST fstab configuration file read-only variable can not be modified problem (Linux)
- VNC connection VMware vSphere ESXi 5.5 (Linux)
- Linux system last command usage (Linux)
- MongoDB learning Notes (2) basic connection example of -Nodejs and MongoDB (Database)
- MySQL error: ERROR 1175: You are using safe update mode solution (Database)
- Linux Telnet access Windows 7 configuration procedure (Linux)
- Linux ps command (Linux)
- CentOS 7 server environment to quickly build Linux (Server)
- How to make Linux a non-root user uses less than 1024 ports (Linux)
- Snapshot DataGuard (Database)
- DataGuard Standby backup error RMAN-06820 ORA-17629 to solve (Database)
- Java implementation of stacks and queues (Programming)
- Row-level security and application-level solutions for the new features of PostgreSQL9.5 (Database)
- How to configure SNMPv3 on Ubuntu, CentOS and Cisco systems (Linux)
- Linux iptables port mapping settings (Server)
- Installation of Python2.7.8 and iPython under CentOS6.5 (Linux)
- [SHELL] MySQL primary recovery solution from + Keepalived online (Server)
- Android to determine whether the device to open WIFI, GPRS data connection (Programming)
     
           
     
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.