Data Synchronization between servers using rsync in CentOS

Source: Internet
Author: User
Tags tmp file
1. rsync Full name: remotesync remote synchronization purpose: servers often need to keep some files or directories consistent. for example, some large software download websites usually use multiple servers to provide the download service. When files on one server are updated, other servers also need to be updated. during the update process, only new or modified files must be updated. otherwise

1. rsync

Full name: remote sync remote Synchronization

 

Purpose: files or directories must be consistent between servers. for example, for large software download websites, multiple servers are usually used to provide download services. When files on one server are updated, other servers also need to be updated. during the update process, only new or modified files are updated, otherwise, the network bandwidth and time will be wasted. Rsync is an excellent software that effectively keeps files and directories consistent.

Features: During file synchronization, rsync can retain the permissions, timestamps, soft and hard connections, and other additional information of the original file. at the same time, rsync can transmit files through ssh to ensure transmission security.

 

 

 

  # Rsync command working mode: # First: shell mode, also known as local mode # Second: Remote shell mode. in this case, you can use the ssh protocol to host the data transmission process # third: the list mode works in a similar way as ls. it only lists the source content; # rsync-nv # Fourth: server mode. at this time, rsync can work as a daemon, it can receive data transmission requests from customer service. during use, you can use the rsync command on the client to send the file to the daemon or the server to obtain the file.

 

 

  # Rsync command option #-n: when you are not sure whether the command can be executed as required, you must test it in advance; #-n can complete this function; #-v: -- verbose, detailed output mode #-q: -- quiet, silent mode #-c: -- checksum, enable the verification function and force file transfer verification #-r: -- recursive, recursive replication; #-a: -- archives, archive, retain the original attributes of the file #-p: -- perms keep the file permission #-t: -- times keep the file timestamp #-l: -- links retains the symbolic link of the file #-g: -- group retains the file group #-o: -- owner retains the file owner #-D: -- devices keep the device file # (-a is equivalent to the sum of other attributes, that is,-p-t-l-g-o-d ...) #-e ssh: indicates the use of ssh protocol for bearer #-z: file compression and transmission # -- progress: Display progress bar # -- stats: shows how to perform compression and transmission

 

 

  # Note: # When The rsync command is in use, if there is a diagonal line at the end of the source parameter, the content of the specified directory will be copied, instead of # The Directory itself; no diagonal lines, the directory itself will be copied; the slash at the end of the target parameter does not work; # for example: # rsync-r/data/backup/synchronize the entire data directory to/backup # rsync-r/data/backup/synchronize all content in the data directory to/backup

 

 

2. rsync for inter-server synchronization

The plan is as follows:

2.1 configure the rsync service on the MySQL server

 

  # Rsync script:/etc/xinetd. d/rsync # rsync configuration file:/etc/rsyncd. conf # rsync help command: man rsyncd. conf

 

(1) edit the rsync configuration file

  # Vim/etc/rsyncd. conf

 

  # Global Settings, description: uid = nobody user gid = nobody user who runs rsync process use chroot = no whether the user is banned in the home directory max connections = 5 maximum number of connections during data synchronization strict modes = false strict mode: we recommend that you set this parameter to false. otherwise, pid file =/var/run/rsyncd is prone to errors during user verification. pid process file Directory log file =/var/log/rsyncd. log File Directory [mydata] shared directory name path =/tmp file storage location to be backed up ignore errors = yes during data synchronization ignore I/O error read only = no read-only, if read-only data cannot be uploaded write only = no write only, if you only write data, you cannot download the data hosts allow = 172.16.0.0/16 allowed hosts or network segment hosts deny = * denied hosts or network segment list = false not listed file uid = root running process User gid = root running process Group auth users = myuser authenticate user secrets file =/etc/rsync. passwd user password file

(2) create a user password file and put the file on the backup server.

  # Vim/etc/rsync. passwd # set the account password # for example, myuser: mypass

 

  # Granting file permissions # chmod 600/etc/rsync. passwd only the administrator is recommended to have the permission # rsync/etc/rsync. passwd root@172.16.251.226: put the/etc-p file on the backup server and keep the same-p

 

(3) test the backup server --> linux server 172.16.251.226

View files in the shared directory of the MySQL server

Synchronize data from mydata on the mysql server to the current server/backup directory

 

  # Rsync-r myuser@172.16.251.241: mysql/backup recursively synchronize to local/backup directory # ll/backup View/backup directory file

Backup Server periodic task plan

  # Note: the backup server stores a user password file at the same time to avoid entering the account password during data synchronization; therefore, we can create a periodic task scheduler to automate O & M # rsync-r -- password-file =/etc/rsync. passwd myuser@172.16.251.241: mydata/backup

Method ①

  # Crontab-e #30 2 **** rsync-r -- password-file =/etc/rsynac. passwd myuser@172.16.251.241: mydata/backup

Method 2

  # Vim rsync. sh script # script content #! /Bin/bash echo "start" rsync-r -- password-file =/etc/rsync. passwd myuser@172.16.251.241: mydata/backup &>/dev/null echo "finished" # crontab-e create periodic task statement #30 2 ***. rsync. bash performs a data synchronization at A.M. by executing a script.

 

(4) data synchronization on windows server 17.0254.84

 

Download green edition cwRsync https://www.itefix.no/i2/content/cwrsync-free-edition

1 # After downloading the file, create the rsync. passwd file in the folder with the password mypass.

  # Create a batch file a. bat # file content rsync-r myuser@172.16.251.241: mydata/cygdrive/f/test -- password-file = rsync. passwd

 

  # Manual synchronization # cwRsync is stored in the local path C: \ Users \ jun \ Desktop \ 3.1.0 # run-> cmd # cd C: \ Users \ jun \ Desktop \ 3.1.0 # rsync-r myuser@172.16.251.241: mydata/cygdrive/f/test -- password-file = rsync. passwd: Synchronize data to the local F: // test folder.

  # If you want to make a periodic plan # find the task scheduler and run the automatically synchronized script on a scheduled basis.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.