Rsync file synchronization application: server-side configuration

Source: Internet
Author: User
Tags anonymous definition file system ftp syslog file permissions rsync linux

For the choice of Linux as an application platform for small and medium-sized enterprises or Web sites, often face how to achieve remote Data backup or Web site mirror image of the problem, although there are commercial backup and mirror products to choose from, but these products are often too expensive prices. So how to use free software to efficiently implement remote backup and Web site mirror image is a topic worthy of discussion.

The easiest way to make remote data backups or Web site mirrors over a network is to use wget, but it is inefficient to have all the data transferred over the network at a time without considering which files are updated. Especially when the amount of data that needs to be backed up is large, it often takes hours to transfer data over the network.
So here is an efficient network remote backup and Mirror tool-rsync, which can meet most of the requirements are not particularly stringent backup requirements.

Rsync is a data mirroring Backup tool under Unix-like systems, which can be seen from the name of the software--remote sync

One, the characteristics of rsync

Can be mirrored to save the entire directory tree and file system.
It is easy to maintain the original file permissions, time, soft and hard links and so on.
can be installed without special permissions.
Fast: Rsync replicates all content on the first synchronization, but only the modified files are transferred the next time. Rsync can compress and decompress in the process of transmitting data, so it can use less bandwidth.
Security: You can use the SCP, SSH and other means to transfer files, of course, can also be connected through a direct socket.

Support for anonymous transmission, to facilitate the use of Web site mirror image.

It is important to note that rsync must be installed on both the server test3 and Test4, where rsync is running in server mode on the TEST3 server, and Rsync is run on the test4 on a client-side basis. This runs the rsync daemon on the server test3 and periodically runs the client on Test4 to back up the content that needs to be backed up on the server test3.

The typical Linux system comes with rsync packages, Rhel and CentOS can install the package via RPM or yum, and I'm using CentOS 6.0, which is simple to install:

[Root@test3 ~]# Yum Install rsync

Here I will not install rsync through the Yum, but by compiling and installing the rsync package, in fact, compiling the installation is also very simple, now I compile the installation via the source packet rsync

Second, rsync download compile installation installation

I am here with the latest version, download the website is http://rsync.samba.org, complete download the following http://rsync.samba.org/ftp/rsync/rsync-3.0.9.tar.gz

[Root@test3 ~]# tar xzvf rsync-3.0.9.tar.gz

[Root@test3 ~]# CD rsync-3.0.9

[Root@test3 rsync-3.0.9]#./configure--prefix=/usr/local/rsync

The presence of rsync 3.0.9 configuration successful only means configure through

[Root@test3 rsync-3.0.9]# make

[Root@test3 rsync-3.0.9]# make install

[Root@test3 rsync-3.0.9]# cp/usr/local/rsync/bin/rsync/usr/bin/

Third, rsync server test3

To start the rsync server in a daemon mode on the TEST3

[Root@test3 rsync-3.0.9]# rsync--daemon

This is going to show no configuration file, don't worry about the back slowly introduction

Failed to parse config file:/etc/rsyncd.conf

The Rsync default service port is 873, and the server receives a client's anonymous or authenticated backup request on that port.

If you want to boot up

/usr/local/rsync/bin/rsync--daemon added to the file/etc/rc.d/rc.local.

If you have XINETD installed in your system, then you need to configure it in xinetd

Configure Rsync Servervi/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}

Iv. description of the configuration parameters of Rsync

The rsync server's configuration file is/etc/rsyncd.conf, which controls authentication, access, logging, and so on.

The file is made up of one or more module structures. A module definition begins with the module name in square brackets until the next module definition begins or the file ends, and the module contains a parameter definition formatted with NAME = value. Each module actually corresponds to a directory tree that needs to be backed up, for example, in our instance environment, there are three trees that need to be backed up:/www/,/home/web_user1/and/home/web_user2/, then you need to define three modules in the configuration file. Corresponds to three trees respectively.

Global parameters
All parameters before [Modlue] in a file are global parameters, and of course you can define module parameters in the global Parameters section, when the value of this parameter is the default value for all modules.
MOTD file
The MOTD file parameter is used to specify a message file that, when the client connects to the server, displays the contents of the file to the customer, and there is no MOTD file by default.

Log file
"Log File" specifies the log files for rsync and does not send the log to syslog.

PID File
Specifies the PID file for rsync.

Syslog facility
Specifies the message level for rsync when sending log messages to syslog, common message levels: Uth, Authpriv, cron, Daemon, FTP, Kern, LPR, mail, news, security, Sys-log, user, UUCP , Local0, Local1, Local2, Local3,local4, LOCAL5, Local6 and LOCAL7.

The default value is daemon.

Module parameters

After a global parameter, you need to define one or more modules, and the following parameters can be defined in the module:

Comment

Assign a description to the module, which is displayed to the customer, along with the module name, when the client connects to the module list. The default does not describe the definition.

Path

Specifies the directory tree path for the module to be backed up, which must be specified.

Use Chroot

If "Use Chroot" is specified as true, rsync first chroot to the directory specified by the path parameter before transferring the file. The reason for this is to implement additional security protection, but the disadvantage is that you need to roots permissions, and you cannot back up the directory files that point to external symbolic connections. The chroot value is true by default.

Max connections

Specify the maximum number of concurrent connections to the module to protect the server, and a connection request exceeding the limit will be told to try again later. The default value is 0, which means there is no limit.

Lock file

Specifies the lock file that supports the Max connections parameter, and the default value is/var/run/rsyncd.lock.

Read Only

This option sets whether the customer is allowed to upload files. If true, any upload requests will fail, and if it is false and the server directory read-write permission is allowed, the upload is allowed. The default value is true.

List

This option sets whether the module should be listed when the client requests a list of modules that can be used. If you set this option to False, you can create a hidden module. The default value is true.

Uid

This option specifies the UID that the daemon should have when the module transmits files, with the GID option used to determine which file permissions to access, and the default value is "nobody".

Gid

This option specifies the GID that the daemon should have when the module transmits files. The default value is "nobody".

Exlude

Use to specify multiple pattern lists separated by spaces and add them to the exclude list. This is equivalent to using--exclude in the client command to specify the pattern, although the exclude mode specified in the configuration file is not passed to the client and is applied only to the server. A module can specify only one exlude option, but it is possible to use "-" and "+" in front of the pattern to specify whether it is exclude or include.

However, it is important to note that this option has a certain security problem, the customer is likely to bypass the Exlude list, if you want to ensure that a particular file can not be accessed, it is best to combine the uid/gid option.

Exlude from

Specifies a filename that contains the definition of the Exclude mode from which the server reads the Exlude list definition.

Include

A list of patterns that specify multiple exlude that are separated by spaces and should be used. This equates to specifying patterns using--include in client commands, combining include and exlude to define complex exlude/include rules. A module can only specify an include option, but it is possible to use "-" and "+" in front of the pattern to specify whether it is exclude or include.

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.