Linux Server rsync sync settings detailed guide

Source: Internet
Author: User
Tags auth chmod socket ssh file permissions iptables port number rsync

I. Introduction (do not want to see directly can skip)
Migrate Emos servers, the new server has been completed after the test, and then very important work is to complete the old mail system in the mail data migration, the choice of copy of the way naturally, but will inevitably lose some of the mail (in this period received mail), so take into account rsync.

Rsync is a remote data synchronization tool that allows fast synchronization of files between multiple hosts through Lan/wan.  Rsync is a tool used to replace RCP, which is currently maintained by Rsync.samba.org. Rsync uses the so-called "rsync algorithm" to synchronize files between local and remote two hosts, which transfer only a different portion of two files, rather than sending it all at a time, so it's very fast. The machine running Rsync server is also called Backup server, a rsync server can back up multiple client data at the same time, or multiple rsync servers to back up one client's data.

Rsync can be paired with rsh or SSH or even using daemon mode. Rsync Server opens a 873 service channel (port) and waits for an rsync connection. When you connect, Rsync server checks to see if passwords match, and if you check by password, you can start file transfers. When the first connection completes, the entire file is transmitted once, and the next time it transmits only two different parts of the file.

Rsync supports most Unix-like systems, both Linux, Solaris, and BSD are well tested. In addition, it also has a corresponding version under the Windows platform, the more well-known are cwrsync and Sync2nas.

The basic features of Rsync are as follows:
1. Can be mirrored to save the entire directory tree and file system;

2. It is easy to maintain the original file permissions, time, soft and hard links;

3. Installation without special permission;

4. Optimized flow, high efficiency of file transfer;

5. You can use RCP, ssh and other means to transfer files, of course, can also be connected through the direct socket;

6. Support for anonymous transmission.

Core Algorithm Introduction:
Suppose that a similar file a and B are synchronized between two computers named Alpha and beta, where Alpha has access to file a, and beta has access to file B. and assume that the network bandwidth between the host Alpha and beta is very small. Then the rsync algorithm will be done with the following five steps:

1.β splits file B into a set of data blocks that do not overlap with a fixed size of S bytes. The last piece may be smaller than S.

2.β performs two checks on each segmented block: One is a 32-bit scrolling weak checksum and the other is a 128-bit MD4 strong checksum.

3.β These checksum results to alpha.

4.α searches for a block of data with all the size S of file A (the offset can be optional, not necessarily a multiple of s) to find a block of data that has the same weak checksum and strong parity code as a piece of file B. This work can be done quickly with the help of scrolling checksums.

5.α sends a sequence of instructions to Beta to generate a backup of file A on beta. Each instruction here is either proof that file B has a block of data without retransmission, or a block of data that must not match any of the data blocks of file B.

Command:

The command format for rsync can be in the following six ways:

rsync [OPTION] ... SRC DEST

rsync [OPTION] ... SRC [User@]host:dest

rsync [OPTION] ... [user@] HOST:SRC DEST

rsync [OPTION] ... [user@] HOST::SRC DEST

rsync [OPTION] ... SRC [user@]host::D EST

rsync [OPTION] ... rsync://[user@]host[:P ort]/src [DEST]

For each of the above six command formats, Rsync has six different working modes:

1 Copy Local files. This mode of operation is initiated when both SRC and DES path information do not contain a single colon ":" delimiter.

2 Use a remote shell program (such as rsh, SSH) to copy the contents of the local machine to the remote machine. This mode is started when the DST path address contains a single colon ":" Separator.

3 Use a remote shell program (such as rsh, SSH) to copy the contents of the remote machine to the local machine. This mode is started when the SRC address path contains a single colon ":" Separator.

4 Copy files from remote rsync server to local machine. This mode is started when the SRC path information contains the "::" delimiter.

5 copy files from local machine to remote rsync server. This mode is started when the DST path information contains the "::" separator.

6 The list of files for the remote machine. This is similar to rsync transmission, but simply omitting the local machine information in the command.

First, configure Rsync Server synchronization data (RPM package installation rsync and configuration)
[Root@mail home]# rpm-qa |grep rsync #检查系统是否安装了rsync软件包

rsync-2.6.8-3.1

[Root@mail centos]# RPM-IVH rsync-2.6.8-3.1.i386.rpm #如果没有安装则手动安装

[Root@test rsync-3.0.4]# Vim/etc/xinetd.d/rsync

1 Configuring Rsync Server

Vi/etc/xinetd.d/rsync

Change Disable=yes to No

Service rsync

{

Disable = no

Socket_type = Stream

wait = no

user = root

Server =/usr/bin/rsync

Server_args =--daemon

Log_on_failure + + USERID

}

2 Configure Rsync to start automatically

[Root@test etc]# chkconfig rsync on

[Root@test etc]# chkconfig rsync--list

Rsync on

3 Configuration rsyncd.conf

[Root@test etc]# Vim rsyncd.conf

UID = root

GID = root

Use chroot = no

Max connections = 4

Strict modes = yes

Port = 873

PID file =/var/run/rsyncd.pid

Lock file =/var/run/rsync.lock

Log file =/var/log/rsyncd.log

[Backup]

Path =/home/domains/kidslandchina.com

Comment = Maildirectory

Auth users = Mail

UID = root

GID = root

Secrets file =/home/rsync.ps

Read Only = no

List = no

4 Ensure that the Rsync port number is correct in etc/services

[Root@test etc]# Vim/etc/services

rsync 873/tcp # rsync

rsync 873/UDP # rsync

5 Configure the Rsync password (the path is already written in the configuration file above)/home/rsync.ps (name casually, as long as the same as in the top configuration file), format (a line of users)

[Root@test etc]# vi/home/rsync.ps

Mail:abc123

6 Configure rsync Password file permissions

[Root@test home]# chown root.root rsync.ps

[Root@test home]# chmod rsync.ps

7 Boot Configuration

[Root@test home]#/etc/init.d/xinetd Restart

stopping xinetd: [OK]

Starting xinetd: [OK]

8 If xinetd not, need to install

[Root@test home]# yum-y Install xinetd

Start Rsync Server

Two ways to start an rsync server

9, start rsync Server (Independent launch)

[Root@test home]#/usr/bin/rsync--daemon

10, Start rsync server (with XINETD super process startup)

[Root@test home]#/etc/init.d/xinetd Reload

11 Join Rc.local

In various operating systems, RC file storage location is not the same, you can modify the system to start when the rsync--daemon loaded in.

[Root@test home]# vi/etc/rc.local

/usr/local/rsync–daemon #加入一行

12 Check to see if rsync starts

[Root@test home]# lsof-i: 873

COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME

xinetd 4396 root 5u IPv4 633387 TCP *:rsync (LISTEN)

Second, configure rsync client synchronization data (RPM package installation rsync and configuration)

1 configuration three processes will be OK

1.1 Set Password file

1.2 Test rsync Execution Instructions

1.3 Putting rsync instructions into a work schedule (crontab)

[Root@aj1 home]# Vi/etc/xinetd.d/rsync

# Default:off

# description:the Rsync server is a good addition to a FTP server, as it

# allows CRC Checksumming etc.

Service rsync

{

Disable = yes

Socket_type = Stream

wait = no

user = root

Server =/usr/bin/rsync

Server_args =--daemon

Log_on_failure + + USERID

}

1.1 Configuration Password file (note: For security, the setting password file property is: 600. rsync.ps Password must be the same as the password in the Rsync server password setting.

[Root@aj1 home]# VI rsync.ps

Abc123

[Root@mail home]# chown root.root. rsync.ps # Note that permissions must be given

[Root@mail home]# chmod rsync.ps # must modify permissions

1.2 Downloading files from the server

Rsync-avz--password-file=/home/rsync.ps mail@10.100.0.175::backup/home/domains/kidslandchina.com/

[Root@mail rsync-3.0.4]# Rsync-avz--password-file=/home/rsync.ps scihoo@192.168.0.206::backup/home/

Upload it locally to the server.

[Root@mail rsync-3.0.4]# Rsync-avz--password-file=/home/rsync.ps/home scihoo@192.168.0.206::backup

Fault Row Error:
1. Question one: rsync:failed to connect to X.x.x.x:no route to host (113)
The Rsync routing backup task did not execute successfully. As follows:

rsync:failed to connect to X.x.x.x:no route to host (113)

Rsync error:error in Socket IO (code ten) at CLIENTSERVER.C [sender=2.6.8]

Two hosts can ping to each other, the error message said no route to the host!

Failure reason: The other side did not boot, firewall block, through the network firewall blocked, it is possible.

Workaround: Turn off the firewall, or open the TCP UDP 873 port on the firewall to allow rsync to pass.

Implementation plan:

1, the firewall starts and stops

# service Iptables Start/stop

2, allow rsync through the firewall

To clear the rule for the reboot, I add the rule directly to the rule configuration file (/etc/sysconfig/iptables), as follows:

-A input-p tcp-s x.x.x.x--dport 873-j ACCEPT

Note that this rule is to be added before the Reject rule.

After the addition, restart the lower iptables (# service iptables restart).

2. Question two: @ERROR: Auth failed on module backup

@ERROR: Auth failed on module backup

Rsync Error:error starting Client-server Protocol (code 5) at MAIN.C (1522) [receiver=3.0.3]

Reason:

The server side of this module (backup) needs to authenticate the username password, but the client does not provide the correct username password, authentication failed. Provide the correct username password to resolve this issue.

In server-side/etc/rsyncd.conf the user name specified in the backup module, and the password file, check the/home/rsync.ps file password

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.