rsync daemon模式介绍

15 篇文章 0 订阅

Rsync介绍

rsync通常用于存储服务器节点内部,存储服务器节点之间文件、文件夹的拷贝和遍历等操作,使用方式大致分为两种:

1. rsync基本使用

2. rsync daemon模式使用

这里着重介绍rsync daemon模式,第一种模式网上有好多示例比较简单,rsync daemon模式如果是存储节点之间做数据传输,无需每次输入密码

Rsync daemon模式

rsync daemon模式分为客户端跟服务端,如果客户端想要使用rsync,服务端必须启动rsync

  • rsync daemon 服务端配置文件 /etc/rsyncd.conf
uid = root
gid = root
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
ignore errors
read only = false
list = false
auth users = rsync
secrets file = /etc/rsync.password
[backup]
comment = "backup dir by oldboy"
path = /root/target_backup

 

  • rsync 保存auth users用户列表的用户名和密码文件 /etc/rsync.password

  • 启动rsync daemon

1. Ubuntu 【rsync daemon】

2. Centos  【/usr/lib/systemd/system/rsyncd.service】

[Unit]
Description=fast remote file copy program daemon
ConditionPathExists=/etc/rsyncd.conf
 
[Service]
EnvironmentFile=/etc/sysconfig/rsyncd
ExecStart=/usr/bin/rsync --daemon --no-detach "$OPTIONS"
 
[Install]
WantedBy=multi-user.target
port=888    # 指定rsync端口。默认873
uid = rsync # rsync服务的运行用户,默认是nobody,文件传输成功后属主将是这个uid
gid = rsync # rsync服务的运行组,默认是nobody,文件传输成功后属组将是这个gid
use chroot = no # rsync daemon在传输前是否切换到指定的path目录下,并将其监禁在内
max connections = 200 # 指定最大连接数量,0表示没有限制
timeout = 300         # 确保rsync服务器不会永远等待一个崩溃的客户端,0表示永远等待
motd file = /var/rsyncd/rsync.motd   # 客户端连接过来显示的消息
pid file = /var/run/rsyncd.pid       # 指定rsync daemon的pid文件
lock file = /var/run/rsync.lock      # 指定锁文件
log file = /var/log/rsyncd.log       # 指定rsync的日志文件,而不把日志发送给syslog
dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2  # 指定哪些文件不用进行压缩传输
 
###########下面指定模块,并设定模块配置参数,可以创建多个模块###########
[bigtera1]        # 模块ID
path = /vol/bigtera2 # 指定该模块的路径,该参数必须指定。启动rsync服务前该目录必须存在。rsync请求访问模块本质就是访问该路径。
ignore errors      # 忽略某些IO错误信息
read only = false  # 指定该模块是否可读写,即能否上传文件,false表示可读写,true表示可读不可写。所有模块默认不可上传
write only = false # 指定该模式是否支持下载,设置为true表示客户端不能下载。所有模块默认可下载
list = false       # 客户端请求显示模块列表时,该模块是否显示出来,设置为false则该模块为隐藏模块。默认true
hosts allow = 10.0.0.0/24 # 指定允许连接到该模块的机器,多个ip用空格隔开或者设置区间
hosts deny = 0.0.0.0/32   # 指定不允许连接到该模块的机器
auth users = rsync_backup # 指定连接到该模块的用户列表,只有列表里的用户才能连接到模块,用户名和对应密码保存在secrts file中,
                          # 这里使用的不是系统用户,而是虚拟用户。不设置时,默认所有用户都能连接,但使用的是匿名连接
secrets file = /etc/rsyncd.passwd # 保存auth users用户列表的用户名和密码,每行包含一个username:passwd。由于"strict modes"
                                  # 默认为true,所以此文件要求非rsync daemon用户不可读写。只有启用了auth users该选项才有效。
[bigtera2]    # 以下定义的是第二个模块
path=/vol/storcls-s3
read only = false
ignore errors
comment = anyone can access
  •  rsync 客户端配置文件 /etc/rsync.password

  • rsync客户端测试
rsync --list-only rsync@172.17.37.141::backup --password-file=/etc/rsync.password


# auto user: rsync
# rsync server: 172.17.37.141
# 模块:backup
# 客户端访问rsync server密钥

rsync -azru  rsync@172.17.37.141::backup ./current/ --password-file=/etc/rsync.password


# 源端 :是从rsync server配置文件里读取
# 目标端 -- ./current/: 是当前目录下的current

thanks ~

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qin147896325

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值