Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Rsync practice of remote synchronization tools (background service mode)

2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Introduction (extracted from Baidu encyclopedia):

Rsync is a data mirror backup tool under linux system.

Use the fast incremental backup tool Remote Sync to synchronize remotely

Local replication is supported or synchronized with other SSH or rsync hosts.

2. Configure rsync source

Configuring the rsync source server is roughly divided into three steps:

(1) create a rsync configuration file

(2) create synchronous account data file

(3) start the rsync service

-

(1) create a rsync configuration file (the experimental virtual machine is CentOS7)

In previous versions of CentOS7, the rsyncd.conf configuration file needs to be created by yourself (installation: yum install-y rsync)

Rsync has been preinstalled after CentOS7, and simple template reference information is available in rsyncd.conf, as shown below:

Edit the file, configure the module information, and add the following configuration:

Address = 192.168.100.101port = 873uid = rootgid = rootuse chroot = yesmax connections = 10transfer logging = yeslog format = t% a% m% f% bsyslog facility = local3timeout = 300pid file=/var/run/rsy nc.pid lock file=/var/run/rsync.locklog file=/var/ log/ rsync.log[ path] path = / home/anker/rsync-testlist = falseread only = yes hosts allow = 192.168.100.100comment = rsync testauth users = ankersecrets file=/ etc/rsyncd.passwordexclude = bin/ lib/ conf/

(2) add synchronization account and password

Echo anker:123456 > rsyncd.password (password is the password of the user)

The user name and password are separated by: and the file is given 600 permissions.

Chmod 600 rsyncd.password

(3) start the rsync service

Rsync-daemon

III. Remote synchronization

Execute the command rsync-av anker@192.168.100.101::Anker on the synchronization server.

(you need to enter the password of the anker user of the 101server if you do not do it, and you need to log in when you cooperate with the crond to plan the task.)

Common options for rsync

-an archiving mode, which means that files are transferred recursively and all attributes are maintained, which is equivalent to the-rlptgoD,-an option can be followed by a-- no-OPTION this means to turn off one of the-rlptgoD.

For example,-a--no-l equals-rptgoD

-r deal with subdirectories in recursive mode, mainly for directories. If you transfer a single file, you don't need to add-r, but the transfer directory must add-r option.

-v print some information, such as speed, quantity, etc.

-l keep soft links

-L treats soft links like regular files. If there is a soft link file in SRC, if this option is added, the target file pointed to by the soft link will be copied to DST.

-p keep file permissions

-O keep file owner information

-g keep file group information

-D keep device file information

-t keep file time information

-- delete deletes files in DST that are not available in SRC

-- exclude=PATTERN specifies to exclude files that do not need to be transferred, with the equal sign followed by the file name, which can be a wildcard pattern (* .txt)

-- progress can see the process status of synchronization during synchronization, such as counting the number of files to be synchronized, the file transfer speed of synchronization, and so on.

-u adding this option will exclude files in DST that are newer than SRC and will not be overwritten

Common options:-a-v-- delete-- exclude

Transmission speed limit (to prevent rsync from consuming bandwidth):

Rsync-arvuztopg-- port=873-- bwlimit=10240-- password-file=/home/anker/rsync/rsync.passwd anker@192.168.100.101::m2 / home/anker/.m2/repository/

Delete files (you need to create an empty directory first, as follows: anker is empty directory test is the target directory, clear test directory):

Rsync-delete-before-d anker/ test/ # is faster than rm when deleting directories containing a large number of files

Common errors and Solutions in rsync

(excerpt from https://www.jb51.net/article/31920.htm)

Question 1:

@ ERROR: chroot failed

Rsync error: error starting client-server protocol (code 5) at main.c (1522) [receiver=3.0.3]

Reason:

The server-side directory does not exist or does not have permissions. Creating a directory and correcting permissions can solve the problem.

Question 2:

@ ERROR: auth failed on module tee

Rsync error: error starting client-server protocol (code 5) at main.c (1522) [receiver=3.0.3]

Reason:

On the server side, the module (tee) needs to verify the username and password, but the client does not provide the correct username and password, and the authentication fails.

Provide the correct username and password to resolve this problem.

Question 3:

@ ERROR: Unknown module 'tee_nonexists'

Rsync error: error starting client-server protocol (code 5) at main.c (1522) [receiver=3.0.3]

Reason:

The specified module does not exist on the server. Provide the correct module name or modify it to the module you want on the server side to solve the problem.

Question 1:

Encountered a problem on client:

Rsync-auzv-progress-password-file=/etc/rsync.pas root@192.168.133.128::backup / home/

Rsync: could not open password file "/ etc/rsync.pas": No such file or directory (2)

Password:

@ ERROR: auth failed on module backup

Rsync error: error starting client-server protocol (code 5) at main.c (1506) [Receiver=3.0.7]

Encountered this problem: the client did not set the / etc/rsync.pas file, but added this parameter when using the rsync command--

Password-file=/etc/rsync.pas

Question 2:

Rsync-auzv-progress-password-file=/etc/rsync.pas root@192.168.133.128::backup / home/

@ ERROR: auth failed on module backup

Rsync error: error starting client-server protocol (code 5) at main.c (1506) [Receiver=3.0.7]

Encountered this problem: the client has set / etc/rsync.pas this file, which also sets the password 111111, which is the same as the server, but

If there is an error in setting the server segment, the server side should set / etc/rsync.pas, which contains root:111111, where the login name is indispensable.

Question 3:

Rsync-auzv-progress-password-file=/etc/rsync.pas root@192.168.133.128::backup / home/

@ ERROR: chdir failed

Rsync error: error starting client-server protocol (code 5) at main.c (1506) [Receiver=3.0.7]

This problem is encountered because the / home/backup on the server side, in which the backup directory is not set, prompts: chdir failed

Question 4:

Rsync: write failed on "/ home/backup2010/wensong": No space left on device (28)

Rsync error: error in file IO (code 11) at receiver.c [receiver=3.0.7]

Rsync: connection unexpectedly closed (2721 bytes received so far) [generator]

Rsync error: error in rsync protocol data stream (code 12) at io.c [generator=3.0.7]

There is not enough disk space to operate.

You can view free space and used space through df / home/backup2010

Question 5: network collection problem

1. Permission issues

A prompt similar to the following: rsync: opendir "/ kexue" (in dtsChannel) failed: Permission denied (13) pay attention to check whether the synchronized directory permission is 755

2 、 time out

Rsync: failed to connect to 203.100.192.66: Connection timed out

Rsync error: error in socket IO (code 10) at clientserver.c [receiver=3.0.5]

Check the server's port netstat-tunlp for remote telnet testing.

You may be unable to communicate because the firewall on the client or server is turned on. You can set the rule to release rsync (port 873) or turn off the firewall directly.

There is another way that you may be prompted to have no permissions during synchronization (add the synchronization directory with all the permissions of SvcwRsync, and an easier way is to set SvcwRsync as an administrator)

3. The service is not started

Rsync: failed to connect to 10.10.10.170: Connection refused

Rsync error: error in socket IO (code 10) at clientserver.c [receiver=3.0.5]

Startup service: rsync-- daemon-- config=/etc/rsyncd.conf

4. Disk space is full

Rsync: recv_generator: mkdir "/ teacherclubBackup/rsync." Failed: No space left on device (28)

* Skipping any contents from this failed directory * *

5. Ctrl+C or a large number of files

Rsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at rsync.c [receiver=3.0.5]

Rsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at rsync.c [generator=3.0.5]

Description: this problem is mostly caused by the server service is not started normally, go to the server to check whether the service is started, and then check whether the / var/run/rsync.pid file exists, the most straightforward way is to kill the service that has been started, and then start the service again or let the script join the system startup service level and then shutdown-r now server

6. Start xnetid

Rsync: read error: Connection reset by peer

Rsync error: error in rsync protocol data stream (code 12) at io.c [receiver=3.0.5]

View rsync Log

Rsync: unable to open configuration file "/ etc/rsyncd.conf": No such file or directory

The location of the configuration file looked up by xnetid is / etc by default, and soft links are created according to the specific situation. For example:

Ln-s / etc/rsyncd/rsyncd.conf / etc/rsyncd.conf

Or change the default profile path specified in the / etc/xinetd.d/rsync configuration file.

Rsync configure:

Configuration 1:

Ignore errors

Note: it is best to add this option, otherwise you don't know if there are many errors in crontab, because you can't watch log every hour every day. Without this, the probability of error is relatively high, because disk IO is a bottleneck for any larger project and system.

Rsync error:

Error one:

@ ERROR: auth failed on module xxxxx

Rsync: connection unexpectedly closed (90 bytes read so far)

Rsync error: error in rsync protocol data stream (code 12) at io.c

Note: this is because the password is set incorrectly and you cannot log in successfully. Check rsync.pwd to see if the customer service matches. This can also happen if the rsync service is not started on the server side.

Error 2:

Password file must not be other-accessible

Continuing without password file

Password:

Note: this is because the permission of rsyncd.pwd rsyncd.sec is wrong and should be set to 600. For example, chmod 600rsyncd.pwd

Error 3:

@ ERROR: chroot failed

Rsync: connection unexpectedly closed (75 bytes read so far)

Rsync error: error in rsync protocol data stream (code 12) at io.c

Note: this is because the path path you set in rsync.conf does not exist. You need to create a new directory to enable synchronization.

Error 4:

Rsync: failed to connect to 218.107.243.2: No route to host

Rsync error: error in socket IO (code 10) at clientserver.c [receiver=2.6.9]

Explanation: firewall problems lead to, it is best to completely shut down the firewall, the wrong basic law is like this, whether it is S or C, as well as ignore errors option issues will also lead to

Error five:

@ ERROR: access denied to www from unknown (192.168.1.123)

Rsync: connection unexpectedly closed (0 bytes received so far) [receiver]

Rsync error: error in rsync protocol data stream (code 12) at io.c

Description: this problem is obvious, it is the configuration option host allow, beginners like to allow a segment to make a configuration, and then the module is the same, resulting in

Error 6:

Rsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at rsync.c [generator=2.6.9]

Rsync error: received SIGUSR1 (code 19) at main.c (1182) [receiver=2.6.9]

Description: this problem is mostly caused by the server service is not started normally, go to the server to check whether the service is started, and then check whether the / var/run/rsync.pid file exists, the most straightforward way is to kill the service that has been started, and then start the service again or let the script join the system startup service level and then shutdown-r now server

Error 7:

Rsync: read error: Connection reset by peer

Rsync error: error in rsync protocol data stream (code 12) at io.c [sender=2.6.9]

Description: no data exists in the original data directory

A supplement to rsync errors and solutions

Because we often use rsync to synchronize server files, but there are a lot of problems in the configuration process, the following errors are basically analyzed by the errors returned by the client.

In addition, in the process of finding errors, I also learned a way to view errors-check the system log, every step of our operation will be explained in the log, sometimes the error report can not be understood, the log is written clearly.

Command: cat / var/log/messages

Question 1:

@ ERROR: auth failed on module bachup

Rsync error: error starting client-server protocol (code 5) at main.c (1522) [receiver=3.0.3]

Reason: the server-side module (backup) needs to verify the username and password, but the client does not provide the correct username and password, and the authentication fails. Provide the correct username and password to resolve this problem.

This is a stupid question, if it is possible that you have written a password file in the module as clearly as I do, but it doesn't work. At this time, I urge you to check whether the module is the same as the following picture. For example, there is an extra s somewhere.

Question 2: 110error-time out

Rsync: failed to connect to 203.100.192.66: Connection timed out

Rsync error: error in socket IO (code 10) at clientserver.c [receiver=3.0.5]

Reason:

Check the server's port netstat-tunlp for remote telnet testing. You may be unable to communicate because the firewall on the client or server is turned on. You can set the rule to release rsync (port 873) or turn off the firewall directly.

Here the blogger has restarted the server and then reported 1100.Just start the rsync service directly.

Command: service rsyncd start

Question 3: 113 error-Firewall

Rsync: failed to connect to 218.107.243.2: No route to host rsync error: error in socket IO (code 10) at clientserver.c [receiver=2.6.9]

Reason:

Firewall problems lead to, this is very simple, just turn off the firewall. But the blogger is still stuck here for hours because there are two kinds of linux firewalls:

-iptable and-firewall

To recognize this problem, you can first check the type of firewall of the system and the status of the firewall.

Service iptable status

Firewall-cmd-state

Determine the type of firewall and then press the corresponding method to turn off the firewall.

Question 4: 1516 error

@ ERROR: auth failed on module backup

Rsync error: error starting client-server protocol (code 5) at main.c (1516) [Receiver=3.0.9]

Solution: the error of this problem varies greatly. You can check the system log to see the error, and then search for a solution.

Note: in general, this situation is based on connectivity. Go to the server to check the system log, you can check the relevant errors.

Command: cat / var/log/massages

Cat / var/log/rsyncd.log

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 301

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report