Experimental environment
(1) rsync server: 10.0.10.158
(2) rsync client: 10.0.10.173
Rsync Server-side configuration
1. Installing xinetd and rsync
Yum Install Yuminstall rsync
2. Creating configuration directories and files
mkdir /etc/rsync
This directory contains 3 files:
- rsyncd.conf # rsync Master configuration file
- Rsyncd.secrets # Password file
- RSYNCD.MOTD # Service Information definition file
Edit these files individually:
2.1 Editing the master configuration file
# vim/etc/rsync/rsyncd.conf pid file =/var/run/rsyncd.pid #pid文件的存放位置 port = 873 &N Bsp #通信的端口 address = 10.0.10.158 #监听的地址/Server UID = Root #运行rsync守护进程的用户 gid = root &NB Sp #运行rsync守护进程的用户组 Use chroot = yes &N Bsp #是否使用chroot Read Only = no #是 No read only hosts allow=10.0.0.0/255.255.0.0 #设置允许访问的主机 (can be a range or an IP address) hosts deny= * &N Bsp #设置拒绝访问的主机 (this * indicates rejection except allow) max connections = * &NBSP ; #最大连接数 MOTD file =/etc/rsync/rsyncd.motd #指定信息显示文件 log file =/var/log/rsync.log #指定日志文件 Log format = %t %a%m%f%b%l #设置日志文件格式 syslog facility = local3 #设置日志级别 timeout = #设置连接超时时间 (unit: s) [Webroot] &N Bsp #目录的标识/authentication Module name path =/var/www/html #要同步的目录名 list=yes #是否允许列出文件 Ignore errors #忽略一般的IO错误 auth users = admin #认证的用户名 Secrets file =/etc/rsync/rsyncd.secrets #密码文件 comment = web root directory &NBSP ; #说明信息 exclude = secret/#需要排除的目录 (excluded from syncing it)
2.2 Editing a password configuration file
# vim/etc/rsync/rsyncd.secrets admin:123123 #格式是 "User name: Password"
2.3 Editing service information definition file
# VIM/ETC/RSYNC/RSYNCD.MOTD Welcome Access
3. Modify the permissions of the password configuration file
chmod Rsyncd.secrets
4. Start the Rsync service
#/usr/bin/rsync--daemon--config=/etc/rsyncd/rsyncd.conf# vim/etc/xinetd.d/rsync service rsync {disable= noflags= ipv6socket_type = streamwait = Nouser = rootserver =/usr/bin/rsyncserver_args =-- Daemon--config=/etc/rsync/rsyncd.conflog_on_failure + = USERID }# service xinetd restart
Rsync Client Configuration
1. Create a directory, edit a password file
# mkdir/etc/rsync# Vim/etc/rsync/password 123123 #格式是 "Password" # chmod 600/etc/rsync/password #修改密码文件的权限
Parameters of the Rsync synchronization command
-V indicates verbose detailed display
-Z means compression
-R means recursive recursion
-T means keeping the original file creation time
-O means to keep the original file owner
-p means to keep the parameters of the original file
-G means to keep the original file's owning group
-A archive mode
-P represents the option function in place of both-partial and-progress
-e SSH establishes an encrypted connection
--partial prevents rsync from deleting the copied portion when the transmission is interrupted (if the transfer is interrupted while the file is being copied, the default action of rsync is to remove the copied part of the file from the target machine)
--progress means to show detailed progress
--delete means that if the server side deletes the file, then the client will also delete the file accordingly, maintaining a true consistency
--exclude does not contain the specified directory
--size-only This parameter is used in two folders is only a few new files in the source folder, there is no duplicate and modified files, because the content can be modified to the same size, and is skipped. This parameter can greatly improve the efficiency of synchronization because it does not need to check whether the contents of a file of the same name are the same
--password-file to specify a password file that contains the password for the specified authenticated user on the server side
Validation
1. Synchronizing the server's files to a local
# ll/var/www/html/#看服务器上的/var/www/html, what's the total dosage 8-rw-r--r--. 1 root root 0 December 1 01:05 index.html-rw-r--r--. 1 root root 0 December 1 01:05 page.html
# RSYNC-VZRTOPG--progress--delete [email protected]::webroot/var/www/html/--password-file=/etc/rsync/password #在客户 The welcome access receiving incremental file list./index.html 0 100% 0.00kb/s 0:00:00, which performs a synchronous operation to obtain the server's Xfer#1, TO-CHECK=1/3) page.html 0 100% 0.00kb/s 0:00:00 (xfer#2, TO-CHECK=0/3) sent, bytes received 227 bytes 664.00 bytes/sectotal size is 0 speedup is 0.00
# ll/var/www/html/#在服务器端我们试着添加一下新的目录和文件 (including directory secret with a different set of steps) Total usage 8drwxr-xr-x. 2 root root 4096 December 1 01:41 haha-rw-r--r--. 1 root root 0 December 1 01:05 index.html-rw-r--r--. 1 root root
0 December 1 01:40 page_2.html-rw-r--r--. 1 root root 0 December 1 01:05 page.htmldrwxr-xr-x. 2 root root 4096 December C16/>1 01:40 Secret
# RSYNC-VZRTOPG--progress--delete [email protected]::webroot/var/www/html/--password-file=/etc/rsync/password # Perform the synchronization command on the client to obtain updates for the server welcome access receiving incremental file list./page_2.html 0 100% 0.00kb/s 0:00:00 ( Xfer#1, TO-CHECK=0/4) sent bytes received 207 bytes 191.33 bytes/sectotal size is 0 speedup is 0.00# rsync- VZRTOPG--progress--delete [email protected]::webroot/var/www/html/--password-file=/etc/rsync/password Welcome Access receiving incremental file List./haha/sent bytes received 203 bytes 536.00 bytes/sectotal size is 0 Speedup is 0.00# ll/var/www/html/ ---------> #确实没有同步secret这个目录总用量 4drwxr-xr-x. 2 root root 4096 December 1 hah A-rw-r--r--. 1 root root 0 December 1 index.html-rw-r--r--. 1 root root 0 December 1 page_2.html-rw-r--r--. 1 root Root 0 December 1 page.html
2. Synchronizing local files to the server
# Touch new.html #在本地新增一个文件 # RSYNC-VZRTOPG--progress--partial--password-file=/etc/rsync/password/var/www/html/[em AIL protected]::webroot #在本地执行同步命令 to synchronize the local update to the server welcome access sending incremental file list./new.html 0 100% 0.00kb/s 0:00:00 (xfer#1, TO-CHECK=3/6) sent 165 bytes received to bytes 392.00 bytes/sectotal size is 0 Speedup is 0.00
# ls/var/www/html #在服务器上看到了这个new. Htmlhaha index.html new.html page_2.html page.html Secret
Error
@ERROR: Auth failed on module Webroot
Rsync Error:error starting Client-server Protocol (code 5) at MAIN.C (1503) [receiver=3.0.6]
Check the permissions of the server that password file, whether it is 600
[Rsync]--rsync file synchronization and backup