rsync配置文件详解

配置文件内容说明

man rsyncd.conf

全局参数

rsyncd.conf参数 参数说明
uid=rsync 运行rsync守护进程的用户。
gid=rsync 运行rsync用户组(用户所在的组)
use chroot=no 如果为true,daemon会在客户端传输文件前“chroot to the path”。这是一种安全配置,因为我们大多数都在内网,所以不配也没关系
max connections=200 设置最大连接数,默认0,意思无限制,负值为关闭这个模块
strict modes=yes 是否检查口令文件的权限
port=873 默认端口873
timeout=400 默认为0,表示no timeout,建议300-600(5-10分钟)
pid file rsync daemon启动后将其进程pid写入此文件。如果这个文件存在,rsync不会覆盖该文件,而是会终止
lock file 指定lock文件用来支持“max connections”参数,使得总连接数不会超过限制
log file 不设或者设置错误,rsync会使用rsyslog输出相关日志信息
motd file “motd file”参数用来指定一个消息文件,当客户连接服务器时该文件的内容显示给客户,默认没有motd文件

模块参数

rsyncd.conf参数 参数说明
ignore errors 忽略无关的I/O错误
read only=false 指定客户端是否可以上传文件,默认对所有模块为true
list=false 是否允许客户端可以查看可用模块列表,默认为可以
hosts allow 指定可以联系的客户端主机名或和ip地址或地址段,默认情况没有此参数,即都可以连接
hosts deny 指定不可以联系的客户端主机名或ip地址或地址段,默认情况没有此参数,即都可以连接
auth users 指定以空格或逗号分隔的用户可以使用哪些模块,用户不需要在本地系统中存在。默认为所有用户无密码访问
secrets file 指定用户名和密码存放的文件,格式;用户名;密码,密码不超过8位
[backup] 这里就是模块名称,需用中括号扩起来,起名称没有特殊要求,但最好是有意义的名称,便于以后维护
comment 模块注释信息
path 这个模块中,daemon使用的文件系统或目录,目录的权限要注意和配置文件中的权限一致,否则会遇到读写的问题

定义变量信息实现免密钥交互

添加环境变量

export RSYNC_PASSWORD=vicodona123

测试

[root@mico ~]# export RSYNC_PASSWORD=vicodona123
[root@mico ~]# rsync -azvP /root/practices/tmp/1.txt rsync_backup@47.107.108.121::backup
sending incremental file list sent 48 bytes received 20 bytes 136.00 bytes/sec
total size is 0 speedup is 0.00

守护进程多模块功能配置

第一步:编写配置信息创建多模块

[root@vicodona ~]# vim /etc/rsyncd.conf
......
[micodata]
comment = "micodata dir by vicodona"
path = /backup/micodata [micobackup]
comment = "micobackup dir by vicodona"
path = /backup/micobackup

第二步:创建多模块指定的目录

[root@vicodona xinetd.d]# mkdir /backup/mico{data,backup} -p
[root@vicodona xinetd.d]# chown rsync.rsync /backup/mico{data,backup}

第三步:利用rsync客户端进行测试

[root@mico ~]# rsync -azv /root/practices/tmp/ rsync_backup@47.107.108.121::backup --password-file=/etc/rsync.passwd
sending incremental file list
./
1.txt sent 107 bytes received 46 bytes 306.00 bytes/sec
total size is 0 speedup is 0.00

说明

rsyncd.conf配置文件中,添加多模块信息,可以不用重启rsync服务,即时生效~

全局变量参数针对所有模块生效;局部变量参数只针对指定模块生效

read only参数默认配置为ture,即为只读模式

全局变量发生变化,不用重启rsync服务;局部变量发生变化,需要重启rsync服务

【说明】无论是全局变量发生变化,还是局部变量发生变化,都建议重启rsync服务使配置生效

守护进程的排除功能实践

排除的方式

  • --exclude=要配置的目录或文件名称
  • --exclude-from=要排除多个目录或文件汇总文件名称

    +在配置文件中进行修改,指定要排除的信息

--exclude 排除测试

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

[root@mico data]# mkdir {a..d}
[root@mico data]# touch {a..d}/{1..3}.txt
[root@mico 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

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

需求:不要a目录中的3.txt 也不要b、c目录

[root@mico data]# rsync -avz /root/practices/data/ --exclude=a/3.txt --exclude=b --exclude=c rsync_backup@47.107.108.121::micodata
sending incremental file list
./
a/
a/1.txt
a/2.txt
d/
d/1.txt
d/2.txt
d/3.txt sent 372 bytes received 134 bytes 1,012.00 bytes/sec
total size is 0 speedup is 0.00

精简方式排除

[root@mico data]# rsync -avz /root/practices/data/ --exclude=a/3.txt  --exclude={b,c} rsync_backup@47.107.108.121::micodata
sending incremental file list
./
a/
a/1.txt
a/2.txt
d/
d/1.txt
d/2.txt
d/3.txt sent 372 bytes received 134 bytes 1,012.00 bytes/sec
total size is 0 speedup is 0.00

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

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

[root@mico data]# mkdir {a..d}
[root@mico data]# touch {a..d}/{1..3}.txt

第二步:进行排除

# 将需要排除的文件写入delete.txt文件
[root@mico data]# vim delete.txt
a/1.txt
b/2.txt
c/3.txt
[root@mico data]# rsync -avz /root/practices/data/ --exclude-from=/root/practices/data/delete.txt rsync_backup@47.107.108.121::micodata
sending incremental file list
./
delete.txt
a/
a/2.txt
a/3.txt
b/
b/1.txt
b/3.txt
c/
c/1.txt
c/2.txt
d/
d/1.txt
d/2.txt
d/3.txt sent 716 bytes received 241 bytes 638.00 bytes/sec
total size is 26 speedup is 0.03

说明:

  1. 排除文件中,需要利用相对路径指定排除信息(不能利用绝对路径)
  2. 相对路径指的是相对同步的目录信息而言,是对rsync -avz /data/ 后面的data目录进行相对

在配置文件中修改要排除的文件

第一步:编写修改服务端配置文件

vim /etc/rsyncd.conf
[nfsdata]
comment = "micodata dir by vicodona"
path = /backup/micodata
exclude=a/3.txt b c

第二步:重启rsync服务

[root@vicodona micodata]# systemctl restart rsyncd
[root@vicodona micodata]# rsync --daemon

第三步:进行测试

[root@mico data]# rsync -avz /root/practices/data/  rsync_backup@47.107.108.121::micodata
sending incremental file list
./
delete.txt
ERROR: daemon refused to receive file "a/3.txt"
ERROR: daemon refused to receive directory "b"
*** Skipping any contents from this failed directory ***
ERROR: daemon refused to receive directory "c"
*** Skipping any contents from this failed directory ***
a/
a/1.txt
a/2.txt
d/
d/1.txt
d/2.txt
d/3.txt sent 617 bytes received 435 bytes 701.33 bytes/sec
total size is 26 speedup is 0.02
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1178) [sender=3.1.2]

守护进程来创建备份目录

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

# 推送/root/practices/data/a/delete.txt 文件到服务器 /backup/sda 目录
[root@mico practices]# rsync -avzP /root/practices/data/delete.txt rsync_backup@47.107.108.121::backup/sda
sending incremental file list
delete.txt
26 100% 0.00kB/s 0:00:00 (xfr#1, to-chk=0/1) sent 116 bytes received 43 bytes 318.00 bytes/sec
total size is 26 speedup is 0.16

查看同步结果

[root@vicodona backup]# ll sda/
total 4
-rw-r--r-- 1 rsync rsync 26 Jul 15 16:06 delete.txt

说明:

a 目标目录名称后要加上 "/", 表示创建目录,否则变为修改传输文件名称了

b 利用客户端创建服务备份子目录时,只能创建一级子目录。

守护进程的访问控制配置

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

[root@vicodona backup]# cat /etc/rsyncd.conf
hosts allow = 47.107.108.0/24
# hosts deny = 0.0.0.0/32

关于访问控制说明:

  1. 白名单和黑名单同时存在时,默认控制策略为不匹配的传输数据信息全部放行
  2. 白名单单一存在时,默认控制策略为不匹配的传输数据信息全部禁止
  3. 黑名单单一存在时,默认控制策略为不匹配的传输数据信息全部放行

守护进程无差异同步配置

什么是无差异

  • 推模式:我有什么,你就有什么;我没有,你也不能有
  • 拉模式:你有什么,我就有什么;你没有,我也不能有

    总结:服务端客户端数据完全一致(一模一样)

实现无差异同步的方法

第一步: 建实验环境

[root@mico practices]# ll  data/
总用量 20
drwxr-xr-x 2 root root 4096 7月 15 15:42 a
drwxr-xr-x 2 root root 4096 7月 15 15:42 b
drwxr-xr-x 2 root root 4096 7月 15 15:42 c
drwxr-xr-x 2 root root 4096 7月 15 15:42 d
-rw-r--r-- 1 root root 26 7月 15 16:06 delete.txt

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

[root@mico practices]# rsync -avz --delete /root/practices/data/ rsync_backup@47.107.108.121::backup/micodata/
sending incremental file list
./
delete.txt
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 879 bytes received 298 bytes 2,354.00 bytes/sec
total size is 26 speedup is 0.02

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

# 删除客户端中的 a/ 目录,再进行无差异传输
[root@mico data]# rm -rf a/
[root@mico data]# rsync -avz --delete /root/practices/data/ rsync_backup@47.107.108.121::backup/micodata/
Password:
sending incremental file list
deleting a/3.txt
deleting a/2.txt
deleting a/1.txt
deleting a/
./ sent 300 bytes received 69 bytes 82.00 bytes/sec
total size is 26 speedup is 0.07

第四步:查看服务端的数据同步情况

[root@mico data]# ll
总用量 16
drwxr-xr-x 2 root root 4096 7月 15 15:42 b
drwxr-xr-x 2 root root 4096 7月 15 15:42 c
drwxr-xr-x 2 root root 4096 7月 15 15:42 d
-rw-r--r-- 1 root root 26 7月 15 16:06 delete.txt

可以看见,a目录下的数据已经同步删除

【注意】无差异同步方法对应用

实现存储数据与备份数据完全一致(慎用)

rsync -avz --delete  /data/ rsync_backup@47.107.108.121::backup /

快速删除大文件数据

 1.mkdir /null      --创建出一个空目录。
2.rsync -avz --delete /null/ /bigdata/
# 删除效率高于 rm -rf /bigdata

守护进程的列表功能配置

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

[root@vicodona ~]# vim /etc/rsyncd.conf
list = true

第二步:客户端查看服务端模块信息

[root@vicodona ~]# systemctl stop rsyncd
[root@vicodona ~]# rsync --daemon

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

[root@mico data]# rsync  rsync_backup@47.107.108.121::
backup "backup dir by vicodona"
micodata "micodata dir by vicodona"
micobackup "micobackup dir by vicodona"

为了提升备份服务器安全性,建议关闭list列表功能

服务端常见问题

问题一

@ERROR: chroot failed
rsync error: error starting client-server protocol (code 5) at main.c(1522) [receiver=3.0.3]

【原因】服务器端的目录不存在或无权限,创建目录并修正权限可解决问题。

问题二

@ERROR: auth failed on module tee
rsync error: error starting client-server protocol (code 5) at main.c(1522) [receiver=3.0.3]

【原因】服务器端该模块(tee)需要验证用户名密码,但客户端没有提供正确的用户名密码,认证失败。

提供正确的用户名密码解决此问题。

问题三

@ERROR: Unknown module ‘tee_nonexists’
rsync error: error starting client-server protocol (code 5) at main.c(1522) [receiver=3.0.3]

【原因】服务器不存在指定模块。提供正确的模块名或在服务器端修改成你要的模块以解决问题。

问题四

password file must not be other-accessible
continuing without password file
Password:

【解决】这是因为rsyncd.pwd rsyncd.secrets的权限不对,应该设置为600。如:chmod 600 rsyncd.pwd

问题五

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

【解决】对方没开机、防火墙阻挡、通过的网络上有防火墙阻挡,都有可能。关闭防火墙,其实就是把tcp udp的873端口打开。

问题六

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

【解决】/etc/rsyncd.conf配置文件内容有错误。请正确核对配置文件。

问题七

rsync: chown "" failed: Invalid argument (22)

【解决】权限无法复制。去掉同步权限的参数即可。(这种情况多见于Linux向Windows的时候)

问题八:

@ERROR: daemon security issue -- contact admin
rsync error: error starting client-server protocol (code 5) at main.c(1530) [sender=3.0.6]

【原因】

同步的目录里面有软连接文件,需要服务器端的/etc/rsyncd.conf打开use chroot = yes。掠过软连接文件。

问题九:

ERROR: module is read only
rsync error: syntax or usage error (code 1) at main.c(747) [receiver=2.6.8]
rsync: connection unexpectedly closed (4 bytes received so far) [sender]
rsync error: error in rsync protocol data stream (code 12) at io.c(600) [sender=3.0.6]

【解决】 提示打开了read only,将配置文件 read only = no

问题十:

cat /var/log/rsyncd.log
2011/12/14 11:58:37 [22377] name lookup failed for XX.XX.XX.XX: Name or service not known
2011/12/14 11:58:37 [22377] connect from UNKNOWN (XX.XX.XX.XX)
2011/12/14 11:58:37 [22377] rsync to html/ from unknown (XX.XX.XX.XX)

【解决】需要在服务端这台机上上的/etc/hosts里面添加客户端机的ip和机器名

问题十一:

[root@Dell-R710 ~]# rsync -artuz -R --delete ./ 192.168.1.233::gex
rsync: failed to connect to 61.145.118.206: Connection refused (111)
rsync error: error in socket IO (code 10) at clientserver.c(124) [sender=3.0.6]

【解决】

一、查看防火墙

二、查看服务端是否开启守护进程

ps ax|grep rsync
rsync --daemon --config=/etc/rsyncd.conf

客户端常见问题

问题一

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]

【说明】遇到这个问题:client端没有设置/etc/rsync.pas这个文件,而在使用rsync命令的时候,加了这个参数--

password-file=/etc/rsync.pas

问题二

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]

【说明】遇到这个问题:client端已经设置/etc/rsync.pas这个文件,里面也设置了密码111111,和服务器一致,但是

服务器段设置有错误,服务器端应该设置/etc/rsync.pas ,里面内容root:111111 ,这里登陆名不可缺少

问题三

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]

【说明】遇到这个问题,是因为服务器端的/home/backup 其中backup这个目录并没有设置,所以提示:chdir failed

问题四:

rsync: write failed on "/home/backup2010/wensong": No space left on device (28)
rsync error: error in file IO (code 11) at receiver.c(302) [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(601) [generator=3.0.7]

【说明】磁盘空间不够,所以无法操作。

可以通过df /home/backup2010 来查看可用空间和已用空间

问题五:网络收集问题

1、权限问题

类似如下的提示:rsync: opendir "/kexue" (in dtsChannel) failed: Permission denied (13)注意查看同步的目录权限是否为755

2、time out

rsync: failed to connect to 203.100.192.66: Connection timed out (110)
rsync error: error in socket IO (code 10) at clientserver.c(124) [receiver=3.0.5]

【说明】检查服务器的端口netstat –tunlp,远程telnet测试。

3、服务未启动

rsync: failed to connect to 10.10.10.170: Connection refused (111)
rsync error: error in socket IO (code 10) at clientserver.c(124) [receiver=3.0.5]

【说明】启动服务:rsync --daemon --config=/etc/rsyncd.conf

4、磁盘空间满

rsync: recv_generator: mkdir "/teacherclubBackup/rsync……" failed: No space left on device (28)
*** Skipping any contents from this failed directory ***

5、Ctrl+C或者大量文件

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

6、xnetid启动

rsync: read error: Connection reset by peer (104)
rsync error: error in rsync protocol data stream (code 12) at io.c(759) [receiver=3.0.5]

查看rsync日志

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

xnetid查找的配置文件位置默认是/etc下,根据具体情况创建软链接。例如:

ln -s /etc/rsyncd/rsyncd.conf /etc/rsyncd.conf

或者更改指定默认的配置文件路径,在/etc/xinetd.d/rsync配置文件中

Rsync学习之旅中的更多相关文章

  1. Rsync学习之旅上

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

  2. ROS2学习之旅(4)——理解ROS2 Graph中的节点

    ROS(2)图(ROS(2) graph)是一个同时处理数据的基于ROS2元素的网络,它包含了所有的可执行文件以及它们之间的连接.图中的基本元素包括:节点(nodes).话题(topics).服务(s ...

  3. WCF学习之旅—第三个示例之四(三十)

           上接WCF学习之旅—第三个示例之一(二十七)               WCF学习之旅—第三个示例之二(二十八)              WCF学习之旅—第三个示例之三(二十九)   ...

  4. Hadoop学习之旅二:HDFS

    本文基于Hadoop1.X 概述 分布式文件系统主要用来解决如下几个问题: 读写大文件 加速运算 对于某些体积巨大的文件,比如其大小超过了计算机文件系统所能存放的最大限制或者是其大小甚至超过了计算机整 ...

  5. WCF学习之旅—第三个示例之二(二十八)

    上接WCF学习之旅—第三个示例之一(二十七) 五.在项目BookMgr.Model创建实体类数据 第一步,安装Entity Framework 1)  使用NuGet下载最新版的Entity Fram ...

  6. WCF学习之旅—第三个示例之三(二十九)

    上接WCF学习之旅—第三个示例之一(二十七) WCF学习之旅—第三个示例之二(二十八) 在上一篇文章中我们创建了实体对象与接口协定,在这一篇文章中我们来学习如何创建WCF的服务端代码.具体步骤见下面. ...

  7. WCF学习之旅—WCF服务部署到IIS7.5(九)

    上接   WCF学习之旅—WCF寄宿前的准备(八) 四.WCF服务部署到IIS7.5 我们把WCF寄宿在IIS之上,在IIS中宿主一个服务的主要优点是在发生客户端请求时宿主进程会被自动启动,并且你可以 ...

  8. WCF学习之旅—WCF服务部署到应用程序(十)

    上接  WCF学习之旅—WCF寄宿前的准备(八) WCF学习之旅—WCF服务部署到IIS7.5(九) 五.控制台应用程序宿主 (1) 在解决方案下新建控制台输出项目 ConsoleHosting.如下 ...

  9. WCF学习之旅—WCF服务的Windows 服务程序寄宿(十一)

    上接    WCF学习之旅—WCF服务部署到IIS7.5(九) WCF学习之旅—WCF服务部署到应用程序(十) 七 WCF服务的Windows 服务程序寄宿 这种方式的服务寄宿,和IIS一样有一个一样 ...

随机推荐

  1. python crawler

    crawl blog website: www.apress.com # -*- coding: utf-8 -*- """ Created on Wed May 10 ...

  2. OpenFOAM——在钝板上分离的层流

    本算例来自<ANSYS Fluid Dynamics Verification Manual>中的VMFL063: Separated Laminar Flow Over a Blunt ...

  3. mysql优化查找执行慢的sql

    想要进行sql优化,肯定得先找出来需要优化的sql语句 一.mysql有一个自带的sql执行慢记录日志文件,所记录的日志取决于参数long_query_time控制,默认情况下long_query_t ...

  4. GlusterFS 安装

    一.简介 GlusterFS 是近年兴起的一个高性能开源分布式文件系统,其目标是全局命名空间.分布式前端的高性能文件系统,目前已被 RedHat 看中,GlusterFS 具有高扩展.高可性.高性能. ...

  5. [技术博客]使用adb命令获取app(游戏)错误和警告日志

    adb命令的使用 直接在命令行中输入: adb logcat *:W 注意:这句命令的意思是显示所有优先级大于等于警告(Warning)的日志,查找崩溃问题一般用: adb logcat *:E 注意 ...

  6. 使用Sabaki和Leela Zero配置AI围棋对弈环境

    求 李昌镐儿童围棋课堂 的pdf. 一.下载Sabaki和Leela Zero最新版本 二.安装Sabaki 三.安装leela zero 四.Sabaki配置leela zero引擎 五.Sabak ...

  7. pandas.DataFrame.sample随机抽样

    https://study.163.com/course/courseMain.htm?courseId=1006383008&share=2&shareId=400000000398 ...

  8. 003 okhttp超时与缓存

    上文的介绍都没添加,如果要添加,则按照下面的方式设置. File sdcache = getExternalCacheDir(); int cacheSize = 10 * 1024 * 1024; ...

  9. wms证书配置操作

      1. 在应用的/home下 把证书cp到/usr/local/apache2/conf 2. 打开文件/usr/local/apache2/conf/extra/httpd-ssl.conf,找到 ...

  10. shell基础知识之数组

    数组允许脚本利用索引将数据集合保存为独立的条目.Bash支持普通数组和关联数组,前者 使用整数作为数组索引,后者使用字符串作为数组索引.当数据以数字顺序组织的时候,应该使 用普通数组,例如一组连续的迭 ...