Centos rsync file synchronization configuration steps

Source: Internet
Author: User
Tags custom name rsync

Rsync is a data image backup tool in unix-like systems. It can be seen from the software name-remote sync

Its features are as follows:
Images can be used to save the entire directory tree and file system.
It is easy to maintain the permissions, time, and soft links of the original file.
Installation without special permissions.
Fast: During the first synchronization, rsync copies all the content, but transfers only modified files in the next synchronization. Rsync can compress and decompress data during data transmission, so it can use less bandwidth.
Security: You can use scp, ssh, and other methods to transmit files. Of course, you can also use a direct socket connection.
Supports anonymous transmission for website images.

I. Server Configuration:
# Yum-y install xinetd

# Vi/etc/xinetd. d/rsync
Run the following code:

Copy codeThe Code is as follows: service rsync
{
Disable = yes
Socket_type = stream
Wait = no
User = root
Server =/usr/bin/rsync
Server_args =-daemon
Log_on_failure + = USERID
}

InDisable = yesChangeDisable = no

Then start xinetd
#/Etc/init. d/xinetd start or service xinetd restart
Note: If the server is installed with a firewall, remember to open the port. The default port is 873.

# Telnet 127.0.0.1 873
Trying 127.0.0.1...
Telnet: connect to address 127.0.0.1: Connection refused
# Iptables-a input-s 192.168.0.0/255.255.255.0-p tcp-m tcp -- dport 873-j ACCEPT
# Iptables-a input-p tcp-m tcp -- dport 873-j DROP

# Vi/etc/rsyncd. conf (if this file does not exist, create it yourself)

# Global Settings
Uid = root # How do I run rsync?
Gid = root
Use chroot = no # Do not use chroot
Max connections = 20 # maximum number of connections
Secrets file =/etc/rsyncd. secrets # password file location, authentication file Settings, set user name and password
Log file =/var/log/rsyncd. log # specify the rsync log file instead of sending the log to syslog.
Pid file =/var/run/rsyncd. pid # specify the pid file of rsync
Lock file =/var/run/rsync. lock # specifies the lock file that supports the max connections parameter. The default value is/var/run/rsyncd. lock.
Comment = hello world
# Motd file =/etc/rsyncd. motd # Welcome information file name and storage location (this file does not exist, you can add it on your own)

[Backup] # The Authentication Module name must be specified on the client.
Path =/titan24/www/repos # image directory
Auth users = rsync # authorize an account. The authenticated user name. If this line is not used, it indicates that it is anonymous. Multiple users are separated by commas (,).
Read only = no # yes the read-only value indicates NO, which indicates the readable and writable mode.
Hosts allow = 192.168.3.128 # IP address of the server to be accessed
Hosts deny = * # blacklist
List = true # Allow column files
# Ignore errors # ignore unrelated IO errors
# Exclude = cache/111/cache/222/# ignored directory

# Vi/etc/rsyncd. secrets (set the user name and password for access (authentication)

Rsync: 111111 # Username: Password secret

Give the file the correct permissions
# Chown root: root/etc/rsyncd. secrets
# Chmod 600/etc/rsyncd. secrets# (It must be 600)

2. client-side Synchronization

By default, the client seems to have installed rsync. If not, install the following:
# Yum-y install rsync

Perform asynchronous synchronization:

/Usr/bin/rsync-avz -- progressRsync@192.168.3.191: backup/Www

# Crontab-e # (files can be synchronized every three minutes at a scheduled time)

*/3 * *** Rsync-avz -- progress Rsync@192.168.3.191: backup /Www

The following command is complete:

# Vi/etc/rsyncd. pas
Add Password
Rsyncofpass
Note that the password file on the client only requires a password instead of a user name!

Change file permissions:
# Chmod 0600/etc/rsyncd. pas

# Rsync-vzrtopgu -- progress -- delete -- password-file =/etc/rsyncd. pasRsync_user@192.168.0.2: rsync_module_name1/www/

In this 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 the detailed progress,
-Delete: if the server deletes the file, the client also deletes the file to ensure true consistency.
The following rsync_user@192.168.0.2: rsync_module_name1, after rsync_module_name1 is the module name, that is, in/etc/rsyncd. the custom name in conf. rsync_user is the user name that can be synchronized specified in the specified module.
The last/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 =/password/path/file 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.

#/Usr/local/rsync/bin/rsync-vzrtopg-progress-deleteRsync_user@192.168.0.2: rsync_module_name1/Tmp/
Password:
Or you can create a password file.
Because the system crontab is required for execution, the password file is read here,
At this time, it is successful.

Synchronization command description:

1. Display directory content

Command
--
A) rsync
B) rsync-r
C) rsync jack@192.168.0.1 ::
D) rsync ssh_user@192.168.0.1:

Command description
---
A) display directory content (level 1)
B) recursively display directory content
C) display the remote host directory content
* Note 1: Port mode, based on rsync User Authentication
* Note 2: The directory on rsync server must have the xx7 permission.

D) view the remote host directory
* Note 1: In remote shell mode, authentication based on the identity of local users connected through ssh
* Note 2: Only one colon (:) is used here, and the user name is the ssh user of the remote host, and the password is also the password of the ssh user.
* Note 3: Use "to list information about the folder itself. To list folder content, use "/".

Parameter description
---
-R performs recursive operations on directories.

2. synchronization between local directories

Command
--
A) rsync-av-progress/*** note (/)***
B) rsync-av-progress
C) rsync-avu-progress-delete/
D) rsync-av-progress-temp-dir =/tmp/

Command description
---
A) synchronize all files under the src-dir directory to the dst-dir directory.
B) synchronize all files under the src-dir directory to the dst-dir/src-dir directory.
C) Update the src-dir directory content to the dst-dir directory for differential updates. If there is an increase/update, add or replace it. If there is a decrease, delete it.
D) More-temp-dir =/tmp than a), that is, specify/tmp as a temporary swap zone, so as to avoid file synchronization errors caused by insufficient space in the target directory.

Parameter description
---
-A is equivalent to the-rlptgoD set.
-U is equivalent to-update. It is not updated when the target file is newer than the source file.
-V: Display synchronized files
-Progress displays the percentage progress and transmission rate during file synchronization.
-Delete: delete files in the target directory that are more than the source directory.

3 synchronization between remote hosts
Command
--
A) rsync-avz-progress jack@192.168.0.1 ::/
B) rsync-avz-progress jack@192.168.0.1:/-password-file =/home/jack/rsync. jack
C) rsync-avuz-progress-delete jack@192.168.0.1:/-password-file =/home/jack/rsync. jack
D) rsync-avz-progress jack@192.168.0.1 ::/

Command description
---
A) synchronize the contents of the local directory to the directory of the remote host 192.168.0.1. jack is the rsync database user (see 3./etc/rsync. secrets)
B) synchronize non-interactive login files by automatically reading user passwords
C) more than B)-u and-delete
D) synchronize the remote host content to the local directory

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.