Master server: 192.168.5.13 _ ubuntu
Slave server: 192.168.5.11 _ centos
=======================1> install rsync on both hosts ========
Install ubuntu as follows:
Compile and install: download this Free Software
Rsync.samba.org/or samba.anu.edu. au/rsync
Download the latest version from the official website.
Decompress the package to the directory and run #./configure & make install
Normally, the rsync server is easy to set up. After rsync is installed, no configuration file or rsync server startup program is found, because each administrator may have different purposes for rsync, therefore, the general release only completes the installation of software and allows administrators to set up their own rsync servers based on their own purposes and methods.
================================= 2> rsync server configuration ============== ==========
Create an rsyncd directory under the/etc directory, which is used to store the rsyncd. conf, rsyncd. secrets, and rsyncd. motd files;
Rsyncd. conf is the main configuration file of the rsync server;
Rsyncd. secrets is the user password file;
Rsyncd. motd: Configure some service welcome and instructions;
A> Create and modify rsyncd. conf
Rsyncd. conf is the main configuration file of the rsync server. Let's take a simple example. For example, we want to back up the/tmp/directory on the server, in/tmp, I want to set the test directory and test. PHP files excluded;
Zhouda # cd/etc
Zhouda # mkdir rsyncd
Zhouda # cd rsyncd
Zhouda # vi rsyncd. conf
Write (ensure that there is no space in each line of the file ):
Pid =/var/run/=. ====== .... 5. Set the interval. /= .. = * =/etc/rsyncd/=/var/log/transferred-up to, + per user, per = % t % a % m % f % =/www/=/etc/rsyncd/= test/test. php
B> Create and modify the password file rsyncd. secrets
Write:
Exit and save.
Modify the permission of the password file:
C> Create and modify the rsync. motd File
Rsyncd. motd defines the rysnc server information, that is, the user login information. For example, let the user know who provided the server. For example, when logging on to an ftp server, we see the linuxsir.org ftp
....... Of course, this is not necessary for global definition of variables. You can use # To note or delete them. For example:
Write:
=============================== 3> Start the rsync service ============= ==========
============= 4> rsync has been configured on the master server! Next we set the slave server ================
You only need to install rsync on the slave server. If not, you can run yum install rsync:
# Because no password file is specified, You need to manually enter the password set on the master server
Enter the password: roger
Roger is the user name in the specified password file.
: Linuxsirhome indicates the module name set in rsyncd. conf.
/Tmp is the slave server directory (192.168.5.11/tmp)
So far, the rsync synchronization between the two hosts (192.168.5.11/tmp and 192.168.5.14/tmp) has been configured. You only need to execute the above command on the slave server and enter the password to synchronize.
Note: In the following command line, the v in vzrtopg is verbose,
Z is compressed transmission,
R is recursive,
Topg is a parameter that maintains the original attributes of a file, such as the owner and time.
U is only used to synchronize updated files to avoid repeated updates to non-updated files. Note the clock synchronization between the two machines.
-- Progress indicates that the detailed progress is displayed,
-- Delete: if the server deletes the file, the client also deletes the file to ensure true consistency. The following roger@192.168.5.13: linuxsirhome, after linuxsirhome is the module name, that is, in/etc/rsyncd. the name defined in conf. roger is the user name that can be synchronized specified in the specified module. The last/root/www is the name of the local directory that is backed up. You can also use the-e ssh parameter to establish an encrypted connection.
You can use-password-file =/root/rsync. pass to specify the password file, so that you can use it in the script without entering the verification password interactively, note that only the owner can read the permission attribute of the password file.
Zhouda #/usr/bin/rsync-vzrtopg -- progress -- delete -- password-file =/root/rsync. pass roger@192.168.5.13: linuxsirhome/root/www
=========================== 5> set automatic synchronization for the master-slave server =====
The crond service on the slave server is used for automatic synchronization. For more information about crond, see linux scheduled execution system.
We create two rsync. sh files and rsync. pass files under the/root/www directory of 192.168.5.11 from the server.
The rsync. sh file is the script file to be executed by crond.
Rsync. pass is the file that saves the master server password.
A>CreateRsync. shFile
Write:
Exit and save.
B> Create the rsync. pass password file.
Write:
Exit save and modify permissions:
C> Configure the crond Service
Add a row:
*/1 */root/www/rsync. sh // synchronize once every minute
Exit and save.
After the settings are complete, manually execute./rsync. sh to see if it works properly.
The master server/www directory will be updated to the slave server/root/www every other minute.
Specific parameters:
- -V, -- verbose detailed mode output
-Q, -- quiet simplified output mode
-C, -- checksum: enable the verification switch to force file transfer verification
-A, -- archive mode, indicating that the file is transmitted recursively and all file attributes are kept, equal to-rlptgoD.
-R, -- recursive processes subdirectories in recursive Mode
-R, -- relative uses relative path information
-B, -- backup creates a backup, that is, if the object already has the same file name, rename the old file ~ Filename. You can use the -- suffix option to specify different backup file prefixes.
-- Backup-dir: backs up files (for example ~ Filename) is stored in the directory.
-Suffix = SUFFIX defines the backup file prefix.
-U, -- update only performs updates, that is, skipping all files that already exist in DST and whose file time is later than the time to be backed up. (Do not overwrite the updated file)
-L, -- links retains soft links
-L, -- copy-links: process soft links like regular files
-- Copy-unsafe-links: only copies links other than the SRC path directory tree.
-- Safe-links ignores links other than the SRC path directory tree
-H, -- hard-links
-P, -- perms to keep File Permissions
-O, -- owner keeps file owner information
-G, -- group: Keep file group information
-D, -- devices: Keep Device File Information
-T, -- times preserve the file time information
-S, -- sparse performs special processing on sparse files to save DST Space
-N, -- dry-run which files will be transmitted
-W, -- whole-file: Copy files without incremental Detection
-X, -- one-file-system do not span the boundaries of the file system
-B, -- block-size = SIZE indicates the block size used by the algorithm. The default value is 700 bytes.
-E, -- rsh = COMMAND specifies that rsh and ssh are used for data synchronization.
-- Rsync-path = PATH specifies the path of the rsync command on the remote server
-C, -- cvs-exclude automatically ignores files in the same way as CVS to exclude files that do not want to be transmitted
-- Existing only updates the files that already exist in DST, instead of backing up the new files.
-- Delete: delete the files that are not in the SRC file in DST.
-- Delete-excluded: delete Files specified by this option at the receiving end.
-- Delete-after: delete after transmission
-- Ignore-errors is deleted when an IO error occurs in a timely manner.
-- Max-delete = NUM: a maximum of NUM files can be deleted.
-- Partial retains the files that are not completely transferred for any reason, so as to speed up subsequent re-transmission.
-- Force directory deletion, even if not empty
-- Numeric-ids does not match the number user and group ID with the user name and group name.
-- Timeout = time ip timeout, in seconds
-I, -- ignore-times do not skip files with the same time and length
-- Size-only: when determining whether to back up a file, only check the file size, regardless of the file time
-- Modify-window = NUM determines whether the timestamp window of the file is used at the same time. The default value is 0.
-T -- temp-dir = DIR create a temporary file in DIR
-- Compare-dest = DIR: compare the files in DIR to determine whether to back up data.
-P is equivalent to -- partial
-- Progress displays the backup process
-Z, -- compress compresses backup files during transmission
-- Exclude = PATTERN specifies to exclude file modes that do not need to be transmitted
-- Include = PATTERN specifies the file mode to be transmitted without exclusion
-- Exclude-from = FILE: exclude files in the specified mode in the FILE.
-- Include-from = FILE: files with the specified FILE pattern matching are not excluded.
-- Version: prints version information.
-- Address: bind to a specific address
-- Config = FILE: specify other configuration files. The default rsyncd. conf FILE is not used.
-- Port = PORT specify other rsync service ports
-- Blocking-io: block IO for remote shell
-Stats indicates the transmission status of some files.
-- SS actual transmission process during transmission
-- Log-format = formAT specifies the log file format
-- Password-file = FILE get password from FILE
-- Bwlimit = KBPS limits I/O bandwidth, KBytes per second
-H, -- help: displays help information