Install and configure rsync files in centos

Source: Internet
Author: User
Tags ssh centos rsync

The rsync directory is mainly used for file synchronization. Now, record the configuration used.

2 Test machines
Rsync server IP: 192.168.171.22
Client IP: 192.168.171.134

Rsync server operations
Check whether rsync is installed

Rpm-qa | grep rsync
Install rsync and manage rsync through xinetd

Yum-y install rsync xinetd
Check startup. The default port is 873.

Netstat-an | grep 873
Rsync starts with xinetd.

Vi/etc/xinetd. d/rsync
Change disable = yes to disable = no

Create the file required by rsync

Mkdir/etc/rsyncd
Touch/etc/rsyncd. conf # Main configuration file
Touch/etc/rsyncd. secrets # verify the user and password storage location
Touch/etc/rsyncd. motd # server description
Ln/etc/rsyncd. conf/etc/rsyncd. conf # Create a link
For password security, we set the permission to 600.

Chown root: root/etc/rsyncd. secrets
Chmod 600/etc/rsyncd. secrets
Modify the main configuration file

Vi/etc/rsyncd. conf
Add the following content

# Run the command with the root permission when the server transfers files
Uid = root
Gid = root
# Specify the service port. The default value is 873.
Port = 873
Use chroot = no
# Read-only: prevents the client from uploading files to the server
Read only = yes
# Limit access to private LANs
# Restrict the network segments that can access the service
Hosts allow = 192.168.0.0/255.255.0.0
Hosts deny = *
# Maximum number of connections
Max connections = 5
# Tell the process to write to this file
Pid file =/var/run/rsyncd. pid

Secrets file =/etc/rsyncd. secrets
# Lock file =/var/run/rsync. lock
# Server information definition points to this file, which can be written to server information. Welcome text
Motd file =/etc/rsyncd. motd

# This will give you a separate log file
Log file =/var/log/rsync. log

# This will log every file transferred-up to 85,000 + per user, per sync
Transfer logging = yes
# Log file format
Log format = % t % a % m % f % B
Syslog facility = local3
Timeout = 300 # timeout

# MODULE OPTIONS
[Testhome]
# Synchronized Directory
Path =/home/test/
List = yes
# Ignore IO errors
Ignore errors
# Verify the user. My user is cs.
Auth users = cs
Comment = test home
# Non-synchronous directories
Exclude =. git/
Modify the rsyncd. secrets and rsyncd. motd files

Vi/etc/rsyncd. secrets
Add content

Cs: 123456
Cs users are not system users.

Vi/etc/rsyncd. motd
Add content

++
Welcome
++
Firewall settings (rsync default port 837)

Vi/etc/sysconfig/iptables
Add

-A input-p tcp-m state -- state NEW-m tcp -- dport 873-j ACCEPT
Restart service

Service xinetd restart
Client Operations
Install rsync

Yum-y install rsync
Test

Cs@192.168.171.22: testhome/home/test
The above Command means to use the cs user to log on to the server and save the data in the directory specified by testhome to my local/home/test

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.