I. Introduction to Rsync Service

1. Install the software

` [root@splitdns ~]# rpm -q rsync

The rsync software package is not installed

[root@splitdns ~]# yum install -y rsync

[root@splitdns ~]# rpm -q rsync

Rsync 3.1.2-10. El7 x86_64

`

Usage scenarios of rsync in the production environment:

1) For data remote backup (7 days a complete, a daily increase)

2) Batch update (synchronization) of node data in Web cluster

3) For local YUM server and Internet mirror software synchronization

In a remote synchronization task, the client responsible for initiating the Rsync synchronization operation is called the originator, and the server responsible for responding to the Rsync synchronization operation from the client is called the backup source (synchronization source). The synchronization source is responsible for providing the original location of the document, and the originator should have read or write permission to this location.

Rsync runs as a daemon when it is the synchronization source, providing a backup source for other clients. To configure the rsync source, create the /etc/rsyncd.conf configuration file, back up the account information, and run the rsync program as a –daemon.

Rsync has two source modes:

SSH, a backup source
Rsync backup source

1. Create the /etc/rsyncd.conf configuration file

[root@master ~]# yum install -y rsync 

[root@master ~]# vim /etc/rsyncd.conf

Copy the code

Meanings of configuration items:

For security reasons, you are advised to allow read-only downlink synchronization for rsync backup sources. In addition, synchronization can be performed

Use anonymous way, as long as the Auth Users and secrets file configuration records can be removed.

2. Create data files for backup accounts, which are separated by colons (:), and store passwords in plain text. Adjust permissions to avoid leakage

Server: Set the password file permission to 600

[root@rsync-master]#vim /etc/rsync_user.db

backuper:pwd123

[root@rsync-master ~]#chmod 600 /etc/rsyncd_user.db

Client: Set the password file permission to 600

[root@rsync-client ~]# ll /etc/rsyncd.pass

-rw——-. 1 root root 5 6月 30 19:59 /etc/rsyncd.pass

3. Run rsync –daemon in a separate way. Kill $(cat /var/run/rsyncd.pid)

[root@rsync ~]#rsync --daemon --config=/etc/rsyncd.conf

4. Close the service

[root@rsync ~]#kill -9 $(cat /var/run/rsyncd.pid)

Use the rsync backup tool

Setfacl sets file ownership

[root@splitdns ~]# getfacl tmp.txt

#file: tmp.txt

#owner: root

#group: root

user::rw-

group::r–

other::r–

Getfacl gets the file ownership

Rsync Backup operation case

Rsync backup script

In the actual production environment, backup work is usually repeated as planned

1. Non-interactive authentication for RSYN backup sources

2. Specify the file to store the password by specifying the –password-file option

Configure rsync+inotify real-time synchronization

1. Adjust parameters

[root@www inotify]# vim max_queued_events #

[root@www inotify]# max_user_instances #

[root@www inotify]# vim max_user_watches #

If the number of files to be monitored is large or changes frequently, you are advised to set the parameter to the maximum value

[root@rsync-client ~]# vim /etc/sysctl.conf

2. Install inotify-tools

Inotify-tools mainly provides inotify-wait,inotify-watch and other tools to monitor and summarize changes.

The official site inotify-tools.sourceforge.net

The source code to install

[root@rsync-client ~]# tar -xf inotify-tools-3.14.tar.gz -C /usr/src/

[root @ rsync – client ~] # CD/usr/SRC/way – tools – 3.14 /

[root@rsync-client inotify-tools-3.14]# nohup./configure –prefix=/usr/local/inotify &&

make && make install &

Creating a Soft connection

[root@rsync-client ~]# ln -s /usr/local/inotify/bin/* /usr/sbin/

For example, to monitor /var/www/html, run the inotifywait command and modify the contents in the /var/www/html directory on the other terminal

Write trigger scripts

Sersync and Rsync synchronize data files in real time

Synchronization principle

Configure the Sersync service on the client

Sersync is a multi-server automatic file synchronization program based on inotify+ Rsync

Using inotify of the Linux 2.6 kernel to monitor Linux file system events, sersync will automatically capture the event through the kernel if any file changes in the monitored directory and synchronize the file to multiple remote servers using Rsync. Sersync only synchronizes a single file or directory that has been added, deleted, or changed. Unlike Rsync, which requires comparison of tens of millions of files in the entire directory on both servers, sersync supports multi-threaded synchronization, making it very efficient.

Sersync is no longer updated, thanks to Sersync author Zhou Yang

Address: Google project code.google.com/archive/p/s…

64 download address: storage.googleapis.com/google-code…

32-bit download address: storage.googleapis.com/google-code…

Couldn’t get on the Google can wget directly my local package, here provide only 64 – bit version: down.whsir.com/downloads/s…

1, the solution package

[root@rsync-client ~]# tar xf sersync2.5.4_64bit_binary_stable_final.tar.gz -C /usr/local/

2. Modify the configuration file

Modify lines 24, 25 and 31

3. Take a test

[root@rsync-client ~]# sersync2 -r -d -o /usr/local/sersync/confxml.xml

Sersync2 option description

The -r recursively

-o Specifies a file

[root@rsync-client html]# touch {1.. 5}.txt

[root@rsync-sever html]# ls -l {1.. 5}.txt

-rw——-. 1 nobody nobody 0 June 30 21:181.txt

-rw——-. 1 nobody nobody 0 6月 30 21:18 2.txt

-rw——-. 1 nobody nobody 0 June 30 21:183.txt

-rw——-. 1 nobody nobody 0 June 30 21:184.txt

-rw——-. 1 nobody nobody 0 June 30 21:185.txt

[root@rsync-client html]# mkdir test

[root@rsync-client html]# cd test/

[root@rsync-client test]# touch {1.. 5}.txt

[root@rsync-sever html]# ls -ld test/

DRWX ——. 2 nobody nobody 71 June 30 21:21 test/

[root@rsync-sever html]# ls -l test/{1.. 5}.txt

-rw——-. 1 nobody nobody 0 June 30 21:21 test/1.txt

-rw——-. 1 nobody nobody 0 June 30 21:21 test/2.txt

-rw——-. 1 nobody nobody 0 June 30 21:21 test/3.txt

-rw——-. 1 nobody nobody 0 June 30 21:21 test/4.txt

-rw——-. 1 nobody nobody 0 June 30 21:21 test/5.txt

Notice The password file permission is set to 600