Rsync installation
The latest version of the current rsync is 3.0.9.
wget http://rsync.samba.org/ftp/rsync/rsync-3.0.9.tar.gz Tar-xvzf rsync-3.0.9.tar.gz; CD rsync-3.0.9;./configure; Make Make install
Rsync Server-side configuration
1.
VI/ETC/RSYNCD.CONF (manual generation required)
Rsyncd.conf's parameter is written on the top of the global parameter and is written in the module is the module parameter
#运行RSYNC守护进程的用户 uid = root #运行RSYNC守护进程的组 gid = root #不使用chroot use chroot = no #最大连接数是4 max connections = 4 #pid文件存放位置 pi d file =/var/run/rsyncd.pid #锁文件存放位置 lock file =/var/run/rsync.lock #日志文件存放位置 log file =/var/log/rsyncd.log [logs] #要同步 Directory path =/usr/local/lnmp# Ignore irrelevant io error ignore errors #只读, cannot upload read only = true# prohibit viewing file list = false# IP #hosts that allow access to services allow = 192.168.1.200 #禁止访问服务的ip #hosts deny = 0.0.0.0/32 #认证的用户名, the system must exist for the user, but the password needs to be in the secrets file configuration, not the system password. Auth users = root #认证用户密码文件, configure Auth users password Secrets file =/etc/backserver.pas
2.
The rsync password file is a colon-delimited plaintext.
Each user line, preceded by a user name, followed by a password, and the user needs to be a user of the operating system.
The owner of the file must be root and the permission is 600.
Vi/etc/backserver.pas, add
root:123456
Execute after saving and exiting
Chown Root:root/etc/backserver.pas chmod 600/etc/backserver.pas
3.
Start the Rsync service
/usr/local/bin/rsync--daemon
4.
Check if the process exists,
Ps-aux |grep rsyncroot 4406 0.0 0.0 4228 588? Ss May14 0:00/usr/local/bin/rsync--daemon netstat-an |grep 873 TCP 0 0 0.0.0.0:873 0.0. 0.0:* LISTEN
The above results indicate that the rsync server side has been started.
5.
Open firewall
Iptables-i input-p TCP--dport 873-j ACCEPT
Iptables-l
The results are as follows
Chain INPUT (Policy ACCEPT)
Target Prot opt source destination
ACCEPT TCP--anywhere anywhere TCP Dpt:rsync
6.
End Process: value of kill-9 pid
KILL-15 Process Name
7.
rsync boot
echo "/usr/bin/rsync--daemon" >>/etc/rc.local
(Start the Rsync service automatically)
Attention matters
1 hint that the password file can not be read, you need to manually enter the password, may be the password file permissions are not 600, or the format is wrong, or the wrong path.
2 prompts to create a new directory or file transfer failure, may be synchronized directory does not have permissions, it is best to sync the directory permissions to modify to 744.
3 from the client synchronization files to the server, the best single file directory transmission, or error prone.
Rsync Client Configuration
1.
The client is not configured to use the rsync command directly,
RSYNC-VZRTOPG--progress--delete Root@118.244.216.177::logs/data/lnmp
2.
If you want to rsync no password login, the client as long as the password file can be configured.
Vim/etc/rsyncd.secretes, this file contains only the server-side auth user password and does not need to configure the username
123456
chmod rsyncd.secretes (password file permission is 600, this step must be set)
Note: The password must be consistent with the password in the Rsync server-side password file. And should be the Rsync client password.
RSYNC-VZRTOPG--progress--delete--password-file=/etc/rsyncd.secretes root@118.244.216.177::logs/data/lnmp
Note: The above command means to sync the files under this path (/USR/LOCAL/LNMP) of the server to the client's path (/DATA/LNMP).
To reverse, synchronize the client's files to the server, as follows:
RSYNC-VZRTOPG--progress--delete--password-file=/etc/rsyncd.secretes/data/lnmp root@118.244.216.177::logs
3.
Rsync timed Tasks
Perform an rsync backup at four in the morning.
Crontab-e
* * * * * RSYNC-VZRTOPG--progress--delete--password-file=/etc/rsyncd.secretes root@118.244.216.177::logs/data/lnmp
4.
Rsync Sync Parameters Description
-VZRTOPG in the V is Verbose,z is compressed, R is RECURSIVE,TOPG is to maintain the original properties of the file, such as the owner, time parameters.
--progress means showing detailed progress.
--delete means that if this file is deleted by the server side, the client also deletes the file accordingly
Root in Root@xxx.xxx.xxx.xxx is the username in the specified password file, xxx is the IP address
Logs refers to the module name defined in rsyncd.conf
/DATA/LNMP refers to the local backup directory
5.
Rsync Common parameters:
#rsync [option] Source path target path
Where [option] is:
A: Use archive mode, equal to-rlptgod, that is, maintain the original file permissions
Z: Compress data on transfer
V: Display to the screen
E: Use a remote shell program (you can use rsh or SSH)
–delete: Exact save copy, source host deleted files, target host will also be deleted synchronously
–include=pattern: Do not exclude files or directories that match pattern
–exclude=pattern: Exclude all pattern-compliant files or directories
–password-file: Specifies the user authentication password for the rsync server
--------------------------------------------------------
Rsync Common Error Troubleshooting
1.
rsync:failed to connect to 118.244.216.177:no route to host (113)
Rsync error:error in Socket IO (code ten) at CLIENTSERVER.C (124) [receiver=3.0.6]
Reason: The firewall is blocking the port
Solve: Open 873 paragraph test
Iptables-i input-p TCP--dport 873-j ACCEPT
Iptables-l
If the above instructions are not available, you can simply stop the firewall
/etc/init.d/iptables stop
2.
@ERROR: Auth failed on module backup
Rsync Error:error starting Client-server Protocol (code 5) at MAIN.C (1506) [receiver=3.0.7]
That's probably the cipher. File not set permissions OH: chmod 600/home/admin/security/rsync.pass
It should be almost there.
3. @ERROR: Auth failed on module xxxxx
Rsync:connection unexpectedly closed (bytes read so far)
Rsync Error:error in Rsync protocol The data Stream (code) at IO.C (150)
This is because the password is set incorrectly, can not login successfully, please check the password in the RSYNCD.SCRT, the two end is consistent?
4.password file must not is other-accessible
Continuing without password file
Password:
This means that the Rsyncd.scrt file permissions attribute is incorrect and should be set to 600.
5. @ERROR: Chroot failed
Rsync:connection unexpectedly closed (bytes read so far)
Rsync Error:error in Rsync protocol The data Stream (code) at IO.C (150)
This is usually not the result of the directory that is set up in your path path in your rsyncd.conf. Please start with mkdir to back up your catalog
6. @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 The data Stream (code) at IO.C (359)
The last reason was finally found. Because there are two network segments that need to synchronize the contents of the folder, there is no additional IP segment after the hosts allow
Hosts allow = 192.168.1.0/24
To
Hosts allow = 192.168.1.0/24 192.168.2.0/24
Restart the Rsync service to solve the problem
7. @ERROR: Auth failed on module backup
Rsync Error:error starting Client-server Protocol (code 5) at MAIN.C (1506) [receiver=3.0.7]
The client side did not set/etc/rsync.pas this file, and when using the rsync command, this parameter was added--PASSWORD-FILE=/ETC/RSYNC.SCRT
8.rsync:recv_generator:mkdir "/teacherclubbackup/rsync ..." failed:no spaces left on device (28)
Skipping any contents from this failed directory * * *
Disk space is full.
9.rsync:opendir "/kexue" (in Dtschannel) Failed:permission denied (13)
The permission settings for the Sync directory are not correct, change to 755
10.rsync:read error:connection Reset by Peer (104)
Rsync Error:error in Rsync protocol The data Stream (code) at IO.C (759) [receiver=3.0.5]
XINETD Daemon Not started
[ROOT@CC02/]# Service xinetd start
11.rsync:unable to open configuration file "/etc/rsyncd.conf": No such file or directory
Xnetid Lookup profile Location defaults to/etc, rsyncd.conf file not found under/etc
12.rsync:failed to connect to 203.100.192.66:connection timed out (110)
Rsync error:error in Socket IO (code ten) at CLIENTSERVER.C (124) [receiver=3.0.5]
Connect server timeout, check server port NETSTAT–TUNLP, remote Telnet test
13. What ports do I need to open on a fireproof wall to accommodate rsync?
Depending on the situation. Rsync can transfer files directly through a TCP connection on port 873, or through 22-port SSH for file delivery, but you can also change its port via the following command:
Rsync--port 8730 otherhost::
Or
Rsync-e ' Ssh-p 2002 ' Otherhost:
14. How do I replicate directory structures through rsync, ignoring files?
Rsync-av--include ' * * *--exclude ' * ' Source-dir dest-dir
15. Why do I always have the "Read-only file system" error?
See if you forgot to set "Read Only = no".
@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 resolves the problem.
@ERROR: Auth failed on module tee
Rsync Error:error starting Client-server Protocol (code 5) at MAIN.C (1522) [receiver=3.0.3]
Reason:
The server side of this module (TEE) needs to authenticate the username password, but the client does not provide the correct username password, authentication failed. Provide the correct username password to resolve this issue.
@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 the server side to the module you want to solve the problem.
19. Permissions cannot be replicated. Remove the parameters for the sync permission. (This happens more often when Linux is to Windows)