返回总目录页

rsync备份服务器部署详情

 

# 概念介绍

备份服务器是架构中最重要的服务器

rsync软件介绍:

Rsync是一款开源的、快速的、多功能的、可实现全量及增量的本地或远程数据同步备份的优秀工具
全量:将全部数据,进行传输覆盖
增量:只传输差异部分的数据

实现增量复制的原理:

Rsync通过其独特的“quick check”算法,实现增量传输数据

官方增量传输算法说明:
Rsync finds files that need to be transferred using a “quick check” algorithm (by default) that looks
for files that have changed in size or in last-modified time. Any changes in the other preserved
attributes (as requested by options) are made on the destination file directly when the quick check
indicates that the file’s data does not need to be updated.
在同步备份数据时,默认情况下,Rsync通过其独特的“quick check”算法,它仅同步大小或者最后修改时间发生变化的文件或目录,当然也可根据权限,属主等属性的变化同步,
但需要指定相应的参数,甚至可以实现只同步一个文件里有变化的内容部分,所以,可以实现快速的同步备份数据。

rsync软件功能:

01. 类似于cp命令---(本地备份传输数据)
02. 类似于scp命令---(远程备份传输数据)
03. 类似于rm命令--- (实现无差异同步备份)
04. 类似于ls命令 --- (本地文件信息查看)

rsync命令属于1 v 4的命令

## rsync == cp命令

[root@backup ~]# # rsync == cp
[root@backup ~]#
[root@backup ~]# cp -a /etc/hosts /tmp/
[root@backup ~]# ls /tmp/hosts
/tmp/hosts
[root@backup ~]# rm -f /tmp/hosts
[root@backup ~]# ls /tmp/hosts
ls: cannot access /tmp/hosts: No such file or directory
[root@backup ~]# rsync /etc/hosts /tmp/
[root@backup ~]# ls /tmp/hosts
/tmp/hosts

## rsync == scp命令

[root@backup ~]# ## rsync == scp
[root@backup ~]# scp -rp /etc/hosts 10.0.0.31:/tmp/
The authenticity of host '10.0.0.31 (10.0.0.31)' can't be established.
RSA key fingerprint is 4d:00:46:ff:a3:4d:1d:2e:5b:f0:72:28:ec:54:29:86.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.0.31' (RSA) to the list of known hosts.
root@10.0.0.31's password:
hosts 100% 371 0.4KB/s 00:00
[root@backup ~]# rsync -rp /etc/hosts 10.0.0.31:/tmp/
root@10.0.0.31's password:

## rsync == rm命令

[root@backup tmp]# ## rsync == rm
[root@backup tmp]# mkdir /mcw01
[root@backup tmp]# cp -a /tmp/* /mcw01/
[root@backup tmp]# ll /mcw01/
total 16
-rw-r--r-- 1 root root 371 Oct 11 15:12 hosts
-rw-r--r-- 1 root root 4165 Oct 10 12:24 optimize-init_sys.sh
-rw-r--r-- 1 root root 2184 Aug 5 2015 sysctl.conf
[root@backup tmp]# rm -rf /mcw01/*
[root@backup tmp]# ll /mcw01/
total 0
[root@backup tmp]# mkdir /null
[root@backup tmp]# cp -a /tmp/* /mcw01/
[root@backup tmp]# rsync --delete /null/ /mcw01/
rsync: --delete does not work without -r or -d.
rsync error: syntax or usage error (code 1) at main.c(1422) [client=3.0.6]
[root@backup tmp]#
[root@backup tmp]# rsync -r --delete /null/ /mcw01/
[root@backup tmp]# ll /mcw01/
total 0

## rsync == ls -l命令

[root@backup tmp]# # rsync == ls
[root@backup tmp]# ls -l /etc/hosts
-rw-r--r--. 2 root root 371 Oct 10 15:45 /etc/hosts
[root@backup tmp]# rsync /etc/hosts
-rw-r--r-- 371 2017/10/10 15:45:09 hosts

Rsync的特性总结(7个特性信息说明):

01. 支持拷贝普通文件与特殊文件如链接文件,设备等。
02. 可以有排除指定文件或目录同步的功能,相当于打包命令tar的排除功能。
#tar zcvf backup_1.tar.gz /opt/data -exclude=mcw
说明:在打包/opt/data时就排除了mcw命名的目录和文件。
03. 可以做到保持原文件或目录的权限、时间、软硬链接、属主、组等所有属性均不改变-p。
04. 可实现增量同步,既只同步发生变化的数据,因此数据传输效率很高(tar -N)。
# 将备份/home 目录自 2008-01-29 以来修改过的文件
# tar -N 2008-01-29 -zcvf /backups/inc-backup_$(date +%F).tar.gz /home
# 将备份 /home 目录昨天以来修改过的文件
# tar -N $(date -d yesterday "+%F") -zcvf /backups/inc-backup_$(date +%F).tar.gz /home
# 添加文件到已经打包的文件
# tar -rf all.tar *.gif
说明:这条命令是将所有.gif的文件增加到all.tar的包里面去。-r是表示增加文件的意思。
05. 可以使用rcp,rsh,ssh等方式来配合进行隧道加密传输文件(rsync本身不对数据加密)
06. 可以通过socket(进程方式)传输文件和数据(服务端和客户端)*****。重点掌握
07. 支持匿名的或认证(无需系统用户)的进程模式传输,可实现方便安全的进行数据备份及镜像。

Rsync的企业工作场景说明

01. 两台服务器之间数据同步(定时任务cron+rsync)
同步网站内部人员数据信息(定时任务最小周期为1分钟)

02. 两台服务器之间数据同步(实时任务inotify/sersync/lrsyncd+rsync)
同步网站用户人员数据信息


# 操作部分

rsync软件工作方式
SYNOPSIS
Local: rsync [OPTION...] SRC... [DEST]
本地数据同步方式

Access via remote shell:
Pull: rsync [OPTION...] [USER@]HOST:SRC... [DEST]
Push: rsync [OPTION...] SRC... [USER@]HOST:DEST
远程数据同步方式:

Access via rsync daemon:
Pull: rsync [OPTION...] [USER@]HOST::SRC... [DEST]
rsync [OPTION...] rsync://[USER@]HOST[:PORT]/SRC... [DEST]
Push: rsync [OPTION...] SRC... [USER@]HOST::DEST
rsync [OPTION...] SRC... rsync://[USER@]HOST[:PORT]/DEST
守护进程方式数据同步:

# 本地数据同步方式(类似于cp)
Local: rsync [OPTION...] SRC... [DEST]
rsync -- 数据同步命令
[OPTION...] -- rsync命令参数信息
SRC -- 要同不得数据信息(文件或目录)
[DEST] -- 将数据传输到什么位置

实例演示命令:
rsync /etc/hosts /tmp/


# 远程数据同步方式(类似scp)---又称为隧道传输
Access via remote shell:
Pull: rsync [OPTION...] [USER@]HOST:SRC... [DEST]
Push: rsync [OPTION...] SRC... [USER@]HOST:DEST

说明:需要进行交互传输数据。如果想实现免交互传输数据,需要借助ssh+key方式实现

pull:
[USER@] : 以什么用户身份传输数据信息
HOST: 远程主机信息(IP地址信息 主机名称信息)
SRC: 远端要恏过来的数据信息
[dest] 恏到本地什么位置

push:
SRC: 本地要怼过去的数据信息
DEST 怼到远端什么位置

实践操作:pull

rsync 10.0.0.31:/tmp/mcw.txt /tmp/

实践操作:push

[root@backup tmp]# rsync -r /tmp 10.0.0.31:/tmp/
root@10.0.0.31's password:
[root@backup tmp]# rsync -r /tmp/ 10.0.0.31:/tmp/
root@10.0.0.31's password:
说明:/tmp -- 表示将tmp目录下面数据内容及目录本身都进行传输
/tmp/ -- 表示只传输tmp目录下面的内容信息

[root@backup tmp]# rsync -vzrtopgP -e 'ssh -p 22' root@172.16.1.31:/tmp/ /tmp/
root@172.16.1.31's password:
receiving incremental file list

sent 12 bytes received 154 bytes 36.89 bytes/sec
total size is 6720 speedup is 40.48
[root@backup tmp]# scp -rp root@172.16.1.31:/tmp/ /tmp/
root@172.16.1.31's password:
sysctl.conf 100% 2184 2.1KB/s 00:00
optimize-init_sys.sh 100% 4165 4.1KB/s 00:00
hosts 100% 371 0.4KB/s 00:00
mcw.txt

[root@backup tmp]# rsync -vzrtopgP -e 'ssh -p 22' /tmp/ root@172.16.1.31:/tmp
root@172.16.1.31's password:
sending incremental file list
./
hosts
371 100% 0.00kB/s 0:00:00 (xfer#1, to-check=4/6)
mcw.txt
0 100% 0.00kB/s 0:00:00 (xfer#2, to-check=3/6)
optimize-init_sys.sh
4165 100% 3.97MB/s 0:00:00 (xfer#3, to-check=2/6)
sysctl.conf
2184 100% 2.08MB/s 0:00:00 (xfer#4, to-check=1/6)
.ICE-unix/

sent 2904 bytes received 95 bytes 856.86 bytes/sec
total size is 6720 speedup is 2.24

# 守护进程方式数据同步:(面交互传输同步传输数据)
Access via rsync daemon:
Pull: rsync [OPTION...] [USER@]HOST::SRC... [DEST]
rsync [OPTION...] rsync://[USER@]HOST[:PORT]/SRC... [DEST]
Push: rsync [OPTION...] SRC... [USER@]HOST::DEST
rsync [OPTION...] SRC... rsync://[USER@]HOST[:PORT]/DEST

备份服务器部署规划:

01. backup服务器作为rsync服务端
02. 以rsync客户端服务器作为参照服务器,将数据推到rsync服务端

配置rsync服务端

# 配置rsync守护进程方式(需要有服务端与客户端)(查配用目权密启)
第一部分:配置rsync服务端(将服务端配置到backup服务器上)

第一步:软件是否存在

[root@backup tmp]# rpm -qa|grep rsync
rsync-3.0.6-12.el6.x86_64

第二步:进行软件服务配置

[root@backup tmp]# ll /etc/rsyncd.conf
ls: cannot access /etc/rsyncd.conf: No such file or directory
vim /etc/rsyncd.conf
#rsync_config
#created by HQ at 2017
##rsyncd.conf start##
uid = rsync
gid = rsync
use chroot = no
max connections = 200
timeout = 300
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
[backup]
comment = "backup dir by mcw"
path = /backup
ignore errors
read only = false
list = false
hosts allow = 172.16.1.0/24
hosts deny = 0.0.0.0/32
auth users = rsync_backup
secrets file = /etc/rsync.password

第三步:创建rsync服务管理用户

useradd -s /sbin/nologin -M rsync

第四步:创建数据备份存储目录

mkdir /backup
chown -R rsync.rsync /backup/

第五步:创建认证用户密码文件

echo "rsync_backup:mcw123" >/etc/rsync.password
chmod 600 /etc/rsync.password

 

注意:服务端的这个文件是用户名加密码,客户端的是密码,之前salt统一添加这个文件的时候,把原来的服务端的也给改掉了。否则会报错如下:

auth failed on module backup from gpu001 (10.11.16.213) for rsync_backup: secret not found

第六步:启动rsync服务

rsync --daemon

[root@backup /]# ps -ef|grep rsync
root 2623 1964 0 17:27 pts/0 00:00:00 vim /etc/rsyncd.conf
root 2652 1 0 17:37 ? 00:00:00 rsync --daemon
root 2654 2574 0 17:37 pts/1 00:00:00 grep --color=auto rsync
[root@backup /]# netstat -lntup|grep rsync
tcp 0 0 0.0.0.0:873 0.0.0.0:* LISTEN 2652/rsync
tcp 0 0 :::873 :::* LISTEN 2652/rsync
至此:服务端配置完成

配置rsync客户端

第二部分:配置rsync客户端(架构中其他服务器称为rsync客户端)

第一步:软件是否存在

[root@backup tmp]# rpm -qa|grep rsync
rsync-3.0.6-12.el6.x86_64

第二步:建立认证文件

echo "mcw123" >/etc/rsync.password
chmod 600 /etc/rsync.password

第三步:测试传输

Push: rsync [OPTION...] SRC... [USER@]HOST::DEST
交互式:rsync -avz /etc/hosts rsync_backup@172.16.1.41::backup
非交互式:rsync -avz /etc/hosts rsync_backup@172.16.1.41::backup --password-file=/etc/rsync.password


# 知识扩展

# 常见问题:

问题01:
[root@nfs01 tmp]# rsync -avz /etc/hosts rsync_backup@172.16.1.41::backup
Password:
sending incremental file list
hosts
rsync: mkstemp ".hosts.U5OCyR" (in backup) failed: Permission denied (13)

sent 200 bytes received 27 bytes 13.76 bytes/sec
total size is 371 speedup is 1.63
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1039) [sender=3.0.6]
说明:备份目录权限设置不正确
解决:chown -R rsync.rsync /backup

 

我遇到的问题:

问题一:
[root@nfs01 ~]# rsync -avz /etc/services rsync_backup@172.16.1.
41::nfsdata01
Password:
@ERROR: auth failed on module nfsdata01
rsync error: error starting client-server protocol (code 5) at main.c(1503) [sender=3.0.6]
*********密码错了会出现这个结果,服务端认证用户密码有问题,客户端密码问题

问题二:
[root@nfs01 ~]# rsync -avz /etc/services rsync_backup@172.16.1.41::nfsdata01
rsync: failed to connect to 172.16.1.41: Connection refused (111)
rsync error: error in socket IO (code 10) at clientserver.c(124) [sender=3.0.6]
服务端守护进程方式启动
http://ju.outofmemory.cn/entry/27665

问题三:
[root@nfs01 ~]# rsync -avz /etc/services rsync_backup@172.16.1.41::nfsbackup --password-file=/etc/rsync.password
@ERROR: Unknown module 'nfsbackup'
rsync error: error starting client-server protocol (code 5) at main.c(1503) [sender=3.0.6]
模块写错了

问题四:
[root@nfs01 ~]# rsync -avz /etc/services rsync_backup@172.16.1.41::nfsbackup01 --password-file=/etc/rsync.password
@ERROR: auth failed on module nfsbackup01
rsync error: error starting client-server protocol (code 5) at main.c(1503) [sender=3.0.6]
没有目录文件或目录错了或目录权限不对都会出现这个错误 密码输错饿了,写错认证用户了
[root@backup ~]# mkdir /nfsbackup
[root@backup ~]# chown -R rsync.rsync /nfsbackup
[root@backup ~]# ll -d /nfsbackup
drwxr-xr-x 2 rsync rsync 4096 Oct 12 16:17 /nfsbackup
客户端密码文件中只能是密码,不能加认证用户信息吧,不然非交互式出错
[root@nfs01 ~]# cat /etc/rsync.password
oldboy123
[root@nfs01 ~]# rsync -avz /etc/services rsync_nfsbackup01@172.16.1.41::nfsbackup01 --password-file=/etc/rsync.password
sending incremental file list

sent 29 bytes received 8 bytes 74.00 bytes/sec
total size is 641020 speedup is 17324.86

问题五:
[root@nfs01 data]# rsync -avz /data/ --exclude=a/3.txt --exclude={b,c} rsync_nfsbackup01@172.16.1.41::nfsdata01 --password-file=/etc/rsync.password
@ERROR: chdir failed
rsync error: error starting client-server protocol (code 5) at main.c(1503) [sender=3.0.6]
模块中的path目录被我删了


扩展:

Rsync 12种故障排查及思路

http://www.echojb.com/access/2017/03/15/350088.html

:set list 找空格

 

设置邮件服务

设置邮件服务

#/etc/mail.rc
cat >>/etc/mail.rc <<eof
set from=135xxxxxxx2@163.com smtp=smtp.163.com smtp-auth-user=135xxxxxxx2 smtp-auth-password=xxxx smtp-auth=login
eof
/etc/init.d/postfix start

 

#/etc/mail.rc
cat >>/etc/mail.rc <<eof
set from=13582215632@163.com smtp=smtp.163.com smtp-auth-user=13582215632 smtp-auth-password=xiaoma123456 smtp-auth=login eof
/etc/init.d/postfix start

邮件服务遇到的问题

问题一:
[root@web02 scripts]# echo "ssdddd"|mail -s "ss" 2xxxx6@qq.com
[root@web02 scripts]# smtp-server: 554 DT:SPM 163 smtp10,DsCowABHWuinJ+dZttgZAA--.12805S2 1508xxxx91,please see http://mail.163.com/help/help_spam_16.htm?ip=123.xx.xxx.104&hostid=smtp10&time=1508xx1191
"/root/dead.letter" 0/0
. . . message not sent.
^C
 •554 DT:SPM 发送的邮件内容包含了未被许可的信息,或被系统识别为垃圾邮件。请检查是否有用户发送病毒或者垃圾邮件;
http://help.163.com/09/1224/17/5RAJ4LMH00753VB8.html
瞎写得还不行

02. 守护进程的排除功能实践

a --exclude=要配置的目录或文件名称
b --exclude-from=要排除多个目录或文件汇总文件名称
c 在配置文件中进行修改,指定要排除的信息

# 利用exclude方式进行排除: 环测

第一步:创建模拟测试环境

[root@nfs01 data]# mkdir {a..d} -p
[root@nfs01 data]# ll
total 16
drwxr-xr-x 2 root root 4096 Oct 12 10:28 a
drwxr-xr-x 2 root root 4096 Oct 12 10:28 b
drwxr-xr-x 2 root root 4096 Oct 12 10:28 c
drwxr-xr-x 2 root root 4096 Oct 12 10:28 d
[root@nfs01 data]# touch {a..d}/{1..3}.txt
[root@nfs01 data]# tree
.
├── a
│   ├── 1.txt
│   ├── 2.txt
│   └── 3.txt
├── b
│   ├── 1.txt
│   ├── 2.txt
│   └── 3.txt
├── c
│   ├── 1.txt
│   ├── 2.txt
│   └── 3.txt
└── d
├── 1.txt
├── 2.txt
└── 3.txt

4 directories, 12 files

第二步:利用--exlude参数,测试排除功能

需要:不要a目录中3.txt文件,不要b c目录
[root@nfs01 data]# rsync -avz /data/ --exclude=a/3.txt --exclude=b --exclude=c rsync_backup01@172.16.1.41::nfsdata01
sending incremental file list
./
a/
a/1.txt
a/2.txt
d/
d/1.txt
d/2.txt
d/3.txt

sent 300 bytes received 114 bytes 828.00 bytes/sec
total size is 0 speedup is 0.00
精简方式排除
[root@nfs01 data]# rsync -avz /data/ --exclude=a/3.txt --exclude={b,c} rsync_backup01@172.16.1.41::nfsdata01
sending incremental file list
./
a/
a/1.txt
a/2.txt
d/
d/1.txt
d/2.txt
d/3.txt

sent 300 bytes received 114 bytes 828.00 bytes/sec
total size is 0 speedup is 0.00

# 利用exclude-from方式进行排除:

第一步:同上
第二步:利用--exlude-from参数,测试排除功能
编写排除文件信息
[root@nfs01 data]# vim /tmp/exlude.txt
a/3.txt
b
c
进行排除
[root@nfs01 data]# rsync -avz /data/ --exclude-from=/tmp/exlude.txt rsync_backup01@172.16.1.41::nfsdata01
sending incremental file list
./
a/
a/1.txt
a/2.txt
d/
d/1.txt
d/2.txt
d/3.txt
说明:01. 排除文件中,需要利用相对路径指定排除信息(不能利用绝对路径)
02. 相对路径指的是相对同步的目录信息而言,rsync -avz /data/ 后面的data目录进行相对

# 在配置文件中进行修改,指定要排除的信息
第一步:编写修改服务端配置文件
vim /etc/rsyncd.conf
[nfsdata01]
comment = "nfsdata dir by mcw"
path = /nfsdata
read only = false
exclude = a/3.txt b c
第二步:重启rsync服务(因为修改了局部变量)
killall rsync && sleep 1 && rsync --daemon
killall rsync;killall rsync;rsync --daemon
第三步:客户端进行测试
[root@nfs01 data]# rsync -avz /data/ rsync_backup01@172.16.1.41::nfsdata01
sending incremental file list
./
a/
a/1.txt
a/2.txt
skipping daemon-excluded file "a/3.txt"
skipping daemon-excluded directory "b"
*** Skipping any contents from this failed directory ***
skipping daemon-excluded directory "c"
*** Skipping any contents from this failed directory ***
d/
d/1.txt
d/2.txt
d/3.txt

sent 407 bytes received 116 bytes 1046.00 bytes/sec
total size is 0 speedup is 0.00
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1039) [sender=3.0.6]

03. 守护进程来创建备份目录

第一步:通过客户端命令创建服务端备份目录中子目录

[root@nfs01 backup]# rsync -avz /etc/services rsync_backup01@172.16.1.41::data/sa/
sending incremental file list
created directory sa
services

sent 127417 bytes received 27 bytes 254888.00 bytes/sec
total size is 641020 speedup is 5.03
[root@nfs01 backup]# rsync -avz /etc/services rsync_backup01@172.16.1.41::data/dev/
sending incremental file list
created directory dev
services

sent 127417 bytes received 27 bytes 254888.00 bytes/sec
total size is 641020 speedup is 5.03
[root@nfs01 backup]# rsync -avz /etc/services rsync_backup01@172.16.1.41::data/dba/
sending incremental file list
created directory dba
services

sent 127417 bytes received 27 bytes 254888.00 bytes/sec
total size is 641020 speedup is 5.03
说明:a 目标目录名称后要加上 "/", 表示创建目录,否则变为修改传输文件名称了
b 利用客户端创建服务备份子目录时,只能创建一级子目录。

04. 守护进程的访问控制配置

第一步:在服务端配置文件,编写白名单策略或黑名单策略(只能取其一)

vim /etc/rsyncd.conf
hosts allow = 172.16.1.0/24
#hosts deny = 0.0.0.0/32
说明:01. 白名单和黑名单同时存在时,默认控制策略为不匹配的传输数据信息全部放行
02. 白名单单一存在时,默认控制策略为不匹配的传输数据信息全部禁止
03. 黑名单单一存在时,默认控制策略为不匹配的传输数据信息全部放行
全局变量修改控制策略信息,rsync服务必须重启

第二步:客户端进行测试

[root@nfs01 backup]# rsync -avz /etc/services rsync_backup01@10.0.0.41::data
@ERROR: Unknown module 'data'
rsync error: error starting client-server protocol (code 5) at main.c(1503) [sender=3.0.6]
[root@nfs01 backup]# rsync -avz /etc/services rsync_backup01@172.16.1.41::data
sending incremental file list

sent 29 bytes received 8 bytes 74.00 bytes/sec
total size is 641020 speedup is 17324.86

05. 守护进程无差异同步配置

什么是无差异:
推模式:我有什么,你就有什么;我没有,你也不能有
拉模式:你有什么,我就有什么;你没有,我也不能有
总结:服务端客户端数据完全一致(一模一样)

实现无差异同步方法:

第一步:创建实验环境

[root@nfs01 backup]# cd /data/
[root@nfs01 data]# ll
total 16
drwxr-xr-x 2 root root 4096 Oct 12 10:29 a
drwxr-xr-x 2 root root 4096 Oct 12 10:41 b
drwxr-xr-x 2 root root 4096 Oct 12 10:29 c
drwxr-xr-x 2 root root 4096 Oct 12 10:29 d

第二步:进行第一次数据同步

[root@nfs01 data]# rsync -avz --delete /data/ rsync_backup01@172.16.1.41::data
sending incremental file list
./
a/
a/1.txt
a/2.txt
a/3.txt
b/
b/1.txt
b/2.txt
b/3.txt
c/
c/1.txt
c/2.txt
c/3.txt
d/
d/1.txt
d/2.txt
d/3.txt

sent 669 bytes received 255 bytes 1848.00 bytes/sec
total size is 0 speedup is 0.00

第三步:删除指定目录,并添加指定文件,测试无差异功能

[root@nfs01 data]# rsync -avz --delete /data/ rsync_backup01@172.16.1.41::data
sending incremental file list
./
deleting a/3.txt
deleting a/2.txt
deleting a/1.txt
deleting a/
mcw.txt

sent 244 bytes received 33 bytes 554.00 bytes/sec
total size is 0 speedup is 0.00

应用:01. 实现存储数据与备份数据完全一致(慎用)
rsync -avz --delete rsync_backup01@172.16.1.41::data / --可能把根内容清空
02. 快速删除大文件数据
mkdir /null --创建出一个空目录
rsync -avz --delete /null/ /bigdata/ 删除效率高于 rm -rf /bigdata

06. 守护进程的列表功能配置

第一步:在服务端配置文件中开启list列表功能

vim /etc/rsyncd.conf
list = true

第二步:重启rsync服务

第三步:客户端进行查看服务端模块信息

rsync rsync_backup@172.16.1.41::
data "data dir by mcw"
nfsdata01 "nfsdata dir by mcw"
nfsbackup01 "nfsbackup dir by mcw"
说明:为了提升备份服务器安全性,建议关闭list列表功能


问题一:

[root@backup data]# ls /nfsdata/
d e
[root@backup data]# ss -lntup|grep rsync
[root@backup data]# rsync --daemon
[root@backup data]# ss -lntup|grep rsync
tcp LISTEN 0 5 :::873 :::* users:(("rsync",2077,5))
tcp LISTEN 0 5 *:873 *:* users:(("rsync",2077,3))
[root@backup data]# ls /nfsdata/
a b c d
[root@backup data]# tree /nfsdata/
/nfsdata/
├── a
│   ├── 1.txt
│   ├── 2.txt
│   └── 3.txt
├── b
│   ├── 1.txt
│   ├── 2.txt
│   └── 3.txt
├── c
│   ├── 1.txt
│   ├── 2.txt
│   └── 3.txt
└── d


客户端
c/3.txt
d/
rsync: failed to set times on "d" (in nfsdata01): Operation not permitted (1)
d/1.txt
d/2.txt
d/3.txt
rsync: mkstemp "d/.1.txt.UcJj2M" (in nfsdata01) failed: Permission denied (13)
rsync: mkstemp "d/.2.txt.tbjHle" (in nfsdata01) failed: Permission denied (13)
rsync: mkstemp "d/.3.txt.gBu5EF" (in nfsdata01) failed: Permission denied (13)

sent 686 bytes received 255 bytes 1882.00 bytes/sec
total size is 0 speedup is 0.00
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1039) [sender=3.0.6]
[root@nfs01 data]# ls
a b c d

为啥

服务端建空目录
[root@backup nfsdata]# ls
a b c
[root@backup nfsdata]# mkdir d
[root@backup nfsdata]# ls
a b c d
客户端无差异推送失败,没权限
[root@nfs01 data]# rsync -avz --delete /data/ rsync_nfsbackup01@172.16.1.41::nfsdata01 --password-file=/etc/rsync.password
sending incremental file list
./
d/
rsync: failed to set times on "d" (in nfsdata01): Operation not permitted (1)
d/1.txt
d/2.txt
d/3.txt
rsync: mkstemp "d/.1.txt.4qJjBB" (in nfsdata01) failed: Permission denied (13)
rsync: mkstemp "d/.2.txt.0wNCd2" (in nfsdata01) failed: Permission denied (13)
rsync: mkstemp "d/.3.txt.e86WPs" (in nfsdata01) failed: Permission denied (13)

sent 353 bytes received 75 bytes 856.00 bytes/sec
total size is 0 speedup is 0.00
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1039) [sender=3.0.6]

自己测试一:

服务端创建文件d
[root@backup nfsdata]# ls
a b c
[root@backup nfsdata]# touch d
[root@backup nfsdata]# ls
a b c d
[root@backup nfsdata]# ls
a b c d
客户端有目录d,无差异同步推送
[root@nfs01 data]# rsync -avz --delete /data/ rsync_nfsbackup01@172.16.1.41::nfsdata01 --password-file=/etc/rsync.password
sending incremental file list

sent 239 bytes received 12 bytes 167.33 bytes/sec
total size is 0 speedup is 0.00
服务端的被覆盖,只有目录d
[root@backup nfsdata]# ls
a b c d
[root@backup nfsdata]# ll -d d
drwxr-xr-x 2 rsync rsync 4096 Oct 12 16:55 d


# 知识补充

01. 配置文件内容参考资料

man rsyncd.conf

02. 配置文件内容总结:(实践理解)

模块之上内容为全局变量信息
模块之下内容为局部变量信息
说明:无论是全局变量发生变化,还是局部变量发生变化,都建议重启rsync服务使配置生效

03. rsync --daemon启动扩展参数

--daemon #←daemon表示以守护进程的方式启动rsync服务。
--address #←绑定指定IP地址提供服务。
--config=FILE #←更改配置文件路径,而不是默认的/etc/rsyncd.conf
--port=PORT #←更改其它端口提供服务,而不是缺省的873端口

04. 利用/etc/init.d/启动rsync服务方式

a. 编写rsync启动脚本(有一定的shell能力 if case)
b. 利用xinetd服务,管理启动rsync服务
yum install -y xinetd
rpm -qa |grep xinet
vim /etc/xinetd.d/rsync
disable = no
/etc/init.d/xinetd start
netstat -lntup|grep 873
tcp 0 0 :::873 :::* LISTEN 3289/xinetd

05. 定义变量信息实现免秘钥交互

[root@nfs01 ~]# export RSYNC_PASSWORD=mcw123
[root@nfs01 ~]# rsync -avz /etc/services rsync_backup01@172.16.1.41::backup
sending incremental file list

sent 29 bytes received 8 bytes 74.00 bytes/sec
total size is 641020 speedup is 17324.86


# 常见问题:

问题01:
[root@nfs01 tmp]# rsync -avz /etc/hosts rsync_backup@172.16.1.41::backup
Password:
sending incremental file list
hosts
rsync: mkstemp ".hosts.U5OCyR" (in backup) failed: Permission denied (13)

sent 200 bytes received 27 bytes 13.76 bytes/sec
total size is 371 speedup is 1.63
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1039) [sender=3.0.6]
说明:备份目录权限设置不正确

 

 

01:nfs共享存储服务知识
02:总结rsync服务配置部署重点知识
03:思考全网备份方案需求
04:windows主机如何部署rsync软件,
将windows主机设置为rsync客户端,将数据推送到备份服务器上

 

限速命令

rsync -av --bwlimit=200M 原文件 目标目录

 

posted @ 2021-10-30 00:46  马昌伟  阅读(244)  评论(0编辑  收藏  举报
博主链接地址:https://www.cnblogs.com/machangwei-8/