Rsync service for Push, pull

Source: Internet
Author: User
Tags rsync

1. Introduction

Rsync is a remote data synchronization tool that enables one rsync server to back up multiple client data at the same time, requiring Scp,ssh,daemon support with a default port of 873.

Rsync + Crond can achieve data timing synchronization, Rsync + inotify can achieve real-time data synchronization.

The Rsync service at work is best served by providing the data to be backed up in read-only mode to avoid mis-operation.


2. Introduction to the experimental environment

Two CentOS6.3 x64 test machine, one server, one client. The system has already installed the Rsync software by default.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/8A/01/wKioL1gkBdaDE-dQAAAE5R3eKYo767.png "/>


3.Rsync command format and command parameters

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/8A/05/wKiom1gkBdaBFVmoAAAEEauWqYY331.png "/>

Parameter description:

-a archive mode, which means that files are transferred in an archived manner and that all file attributes are maintained

-V Verbose mode output

-Z Compress the backed-up files as they are transmitted

--delete No difference synchronization


Three modes of operation in 4.Rsync

1) local copy and delete

# rsync avz/etc/hosts/tmp Copies the file hosts to the/tmp directory. Similar to the CP command, but the difference is that rsync can compare two files by itself to achieve incremental backups

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/8A/05/wKiom1gkBdaCu9GFAAAENpjOZwk289.png "/>

# rsync AvZ delete/tmp//opt//tmp/directory is empty, plus--delete parameter, equivalent to RM command

--delete can be understood as: there is a remote local, local does not delete the remote

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/8A/01/wKioL1gkBdfBqcSQAAAEeSjaT88079.png "/>


2)remote shell

rsync remote "push" and "pull"

(push) # rsync avzp e ' ssh p '/tmp/[email protected]:/tmp/aaa

Copy the files from the local/tmp/directory to the/TMP/AAA directory in 192.168.87.138 via port 22

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/8A/01/wKioL1gkBdfgv6I3AAAGCVg3uT4163.png "/>

(pull) # rsync avzp e ' ssh p ' [Email protected]:/tmp//tmp

Copy the 192.168.87.138/tmp/directory file to the local/tmp directory

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/8A/05/wKiom1gkBdfRu9JBAAAF6tIHihM264.png "/>

# rsync-avzp-e ' ssh-p '/tmp/ [email protected]:/tmp

# rsync-avzp-e ' ssh-p ' [email protected]:/tmp/ tmp

Red Slash, there is this is to push the entire contents of the specified folder, no this is to push the whole directory


3)Daemon (Configure Rsync server steps)

First verify that the rsync version and its version number are installed in the system

# rsync--version View current rsync version

# RPM QA Rsync

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/8A/01/wKioL1gkBdfzI5MAAAAfMXva_mk381.png "/>

The configuration file for rsync does not exist by default and needs to be created manually. Path is/etc/rsyncd.conf

Edit the/etc/rsyncd.conf file with the following content. Copy and paste save to exit.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/8A/05/wKiom1gkBdfyZRnNAAAEUhEq4iU490.png "/>

#Rsync Server

#yuci

UID = rsync

GID = rsync

Use chroot = no

Max connections = 2000

Timeout = 600

PID file =/var/run/rsyncd.pid

Lock file =/var/run/rsync.lock

Log file =/var/log/rsyncd.log

Ignore errors

Read Only = False

List = False

Hosts allow = 192.168.0.0/24

Hosts Deny = 0.0.0.0/32

Auth users = Rsync_backup

Secrets file =/etc/rsync.password

###################################

[Backup]

Comment = www by yuci

Path =/backup


Create rsync users and Shared directories/backup (check after creation, develop good habits)

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/8A/01/wKioL1gkBdjzcbjKAAAM4CSuIcI314.png "/>

As on the edited file, secrets file =/etc/rsync.password as the password files, can realize two machine mutual trust. Because it is a password, you need to change permissions.

Rsync_backup is the auth users = rsync_backup "123456" of the configuration file above is the password that needs to be verified when connecting

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/8A/05/wKiom1gkBdjD35w0AAAKUNSr_A8689.png "/>

# rsync--daemon Start rsync service

# netstat Lntup | grep rsync to see if rsync is functioning properly on port 873

# PS EF | grep rsync

# echo "Rsync--daemon" >>/etc/rc.local add to boot

# cat/etc/rc.local

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/8A/01/wKioL1gkBdjzn-nSAAAIrYeLOGo175.png "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/8A/05/wKiom1gkBdjy_DqPAAAHzZg6JvE349.png "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/8A/05/wKiom1gkBdnSIG1-AAASzQvpjwU577.png "/>

So far, the server-side configuration is complete. Next Configure the Client

# echo "123456" >>/etc/rsync.password

Only require a password, because the Rsync_backup user is already in the connection command

# chmod 600/etc/rsync.password

Same as the server's password file, need to modify permissions

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/8A/01/wKioL1gkBdmwQdYDAAAIMT79i0I947.png "/>

The client only needs this simple two-step.


5. Whether the test environment is built successfully

Now to push the files in the client's/tmp/directory to the/backup directory on the server, empty the/backup directory and create a few files in the/tmp/directory

No error push succeeded, the selected backup is to correspond to the module command in/etc/rsyncd.conf

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/8A/01/wKioL1gkBdmBNVCUAAAR1mwLce0510.png "/>

With:: Backup correspondence

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/8A/05/wKiom1gkBdmDlzuxAAAJfLW17Hc554.png "/>

Back to server-side check, test successful

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/8A/05/wKiom1gkBdmwYMjTAAAE0_uB2wo600.png "/>


This article is from the "LULU" blog, make sure to keep this source http://aby028.blog.51cto.com/5371905/1871433

Rsync service for Push, pull

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.