Rsync installation Configuration

Source: Internet
Author: User

Rsync installation Configuration
Yum-y install rsync
Configure rsync

The rsync service requires three files.

Rsyncd. conf rsync service configuration file

The rsyncd. secrets rsync service user password file must be an existing user on the server

Rsyncd. motd rsync service logon prompt information

To ensure password security, you must change the rsyncd. secrets permission to 600 chmod 0600 rsyncd. secrets.

By default, the mkdir-p/etc/rsyncd files do not exist.

Cd/etc/rsyncd

Touch rsyncd. conf

Touch rsyncd. secrets

Touch rsyncd. motd

Chmod 600/etc/rsyncd. secrets # Set the File Attribute of the rsyncd. secrets password file to root and set the permission to 600. Otherwise, the backup will fail!

Set rsyncd. conf

Vi rsyncd. conf

Pid file =/var/run/rsyncd. pid
Port = 873
Address = 192.168.1.2 # Server IP address
Uid = root
Gid = root
Use chroot = yes
Read only = yes # primary read
Hosts allow = 192.168.1.3 192.168.1.4 # list of accessible hosts
Hosts deny = *
Max connections = 5
# Motd file =/etc/rsyncd. motd
Log format = % t % a % m % f % B
Syslog facility = local3
Timeout = 300

[Video] # the group to be synchronized. The group name is random.
Path =/home/web/video # synchronized directory
List = no # prohibit listing objects
Ignore errors
Auth users = root # executed user
Exclude = folder folder1 # excluded directory
Secrets file =/etc/rsyncd. secrets # password file, which reads the user's password from the file directly, saving the interaction between the input password, and is mostly used to schedule tasks.

Save and exit

Enable rsync server and firewall settings

It is quite simple to start the rsync server. There are several methods as follows:

A. -- daemon parameter mode: enables rsync to run in Server Mode

#/Usr/bin/rsync -- daemon -- config =/etc/rsyncd. conf # -- config is used to specify the location of rsyncd. conf. If it is in/etc, no write

B. xinetd Mode

Add the following content to modify services:
# Nano-w/etc/services
Rsync 873/tcp # rsync
Rsync 873/udp # rsync
This step can generally be left blank.
Set/etc/xinetd. d/rsync. A simple example is as follows:

# Default: off
# Description: The rsync server is a good addition to am ftp server, as it \
# Allows crc checksumming etc.
Service rsync
{
Disable = no
Socket_type = stream
Wait = no
User = root
Server =/usr/bin/rsync
Server_args = -- daemon
Log_on_failure + = USERID
}

Above, We need to enable the rsync daemon. Once an rsync client is connected, xinetd will forward it to rsyncd (port 873 ). Then the service xinetd restart takes effect.
Rsync server and Firewall

Linux Firewall uses iptables, so we should at least let the defined rsync server port pass through on the server side, and the client should also pass through.

# Iptables-a input-p tcp-m state -- state NEW-m tcp -- dport 873-j ACCEPT
# Iptables-L check if port 873 is enabled in the firewall

Use the rsync client to synchronize data

A. Syntax explanation
 
After configuring the rsync server, you can issue the rsync command from the client to implement various synchronization operations. Rsync has many functions. The following describes common options:

The Command Format of rsync can be:

1. rsync [OPTION]... SRC [SRC]... [USER @] HOSTEST
2. rsync [OPTION]... [USER @] HOST: SRC DEST
3. rsync [OPTION]... SRC [SRC]... DEST
4. rsync [OPTION]... [USER @] HOST: SRC [DEST]
5. rsync [OPTION]... SRC [SRC]... [USER @] HOST: EST
6. rsync [OPTION]... rsync: // [USER @] HOST [ORT]/SRC [DEST]

Rsync has six different working modes:

1. Copy the local file. This mode is enabled when the SRC and DES paths do not contain a single colon ":" separator.
2. Use a remote shell program (such as rsh and ssh) to copy the content of the local machine to the remote machine. This mode is enabled when the DST path address contains a single colon ":" separator.
3. Use a remote shell program (such as rsh and ssh) to copy the contents of the remote machine to the local machine. This mode is enabled when the SRC address path contains a single colon ":" separator.
4. Copy files from the remote rsync server to the local machine. This mode is enabled when the SRC path information contains the ":" separator.
5. Copy files from the local machine to the remote rsync server. This mode is enabled when the DST path information contains the ":" separator.
6. List of remote machine files. This is similar to rsync transmission, but you only need to omit the local machine information in the command.


Parameters in rsync
-A operates in archive mode, copies directories, and symbols to connect-rlptgoD
-R is recursion
-L indicates a linked file, which means copying a linked file;-p indicates retaining the original permissions of the file;-t indicates retaining the original time of the file;-g indicates retaining the original user group of the file; -o: the original owner of the file;-D is equivalent to a block device file;
-Z compression during transmission;
-P transmission progress;
-V transmission progress and other information. It has something to do with-P. Try it on your own. You can see the document;
-E ssh parameters establish an encrypted connection.
-U is only updated to prevent new local files from being overwritten. Pay attention to the clock of both machines at the same time.
-- Progress indicates that the detailed progress is displayed.
-- Delete: if the server deletes this file, the client also deletes the file to ensure true consistency.
-- Password-file =/password/path/file to specify the password file, which can be used in the script without the need to enter the verification password interactively, note that only the owner can read the permission attribute of the password file.

B. Some Instances

B1. List the synchronization content provided on the rsync server;

First, let's take a look at the available data sources on the rsync server.
# Rsync -- list-only root@192.168.1.3 ::

B2, rsync client data synchronization;
# Rsync-avzP root@192.168.1.3: video
Note: This command means to log on to the server as the root user and synchronize the video data to the local video directory. Of course, the local directory can be defined by yourself.
If you do not have the video directory in the current operation directory on the client, the system will automatically create one for you. If the video directory exists, pay attention to its write permission.

Set Password File
# Touch/etc/rsyncd/syncd. secrets
# Chmod 600/etc/rsyncd. secrets
# Echo "123456">/etc/rsyncd. secrets note: the rsync server executes the User Password
# Rsync-avzP -- password-file =/etc/rsyncd. secrets root@192.168.1.3: video

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.