TOC
主机名 | 内网IP | 公网IP |
---|---|---|
rsync | 192.168.0.164 | √ √ |
nfs | 192.168.0.161 | √ √ |
bak | 192.168.0.162 | |
mysql | 192.168.0.163 | |
lib01 | 192.168.0.155 | |
lib02 | 192.168.0.156 | |
mm01 jumpserver | 192.168.0.158 | 47.92.175.186 |
web01 | 192.168.0.157 | |
web02 | 192.168.0.159 | |
web03 | 192.168.0.160 |
rsync可以实现远程数据快速复制,备份,这个服务类似于scp命令,但它的功能远远超出scp的范畴
rsync可以实现增量备份,全量备份功能.这取决于她的 quick check (快速检查)算法
rpm -qa rsync
[root@rsync ~]# rpm -qa rsync rsync-3.1.2-6.el7_6.1.x86_64
如果没有安装可以使用 yum install rsync -y
vim /etc/rsyncd.conf
解释:
uid = rsync # rsync用户
gid = rsync # rsync组
use chroot = no # 安全配置
max connections = 200 # 最大连接数
timeout = 300 # 连接超时时间 (单位: s)
pid file = /var/run/rsyncd.pid # pid文件
lock file = /var/run/rsync.lock # 锁文件
log file = /var/log/rsyncd.log # 日志文件
#hosts deny = 0.0.0.0/32 # 拒绝的IP段
auth users = chenleilei # 允许连接rsync服务的账号(非系统账号)
secrets file = /etc/rsync.password # 密码验证文件
backup # 模块名 可以随意修改
comment = "backup dir by oldboy" # 连接的 欢迎语 没什么用
path = /backup # 备份的目录
ignore errors # 忽略个别传输失败的文件,不影响传输任务
hosts allow = 192.168.0.0/24 # 允许的IP段
list = false # true:禁止写入 flase=允许写入
read only = false # true:禁止写入 flase=允许写入
fake super = yes # !!!重要!!! 在cento7 中需要加上此行,centos6可以忽略
配置:
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
#hosts deny = 0.0.0.0/32
auth users = chenleilei
secrets file = /etc/rsync.password
backup
comment = "backup dir by oldboy"
path = /backup
ignore errors
hosts allow = 192.168.0.0/24
list = false
read only = false
fake super = yes
mkdir -p /backup
chown -R rsync.rsync /backup
echo "chenleilei:123" >/etc/rsync.password
chmod 600 /etc/rsync.password
root@rsync ~chmod 600 /etc/rsync.password
root@rsync ~# ls -la /etc/rsync.password
-rw------- 1 root root 15 Aug 14 04:13 /etc/rsync.password
root@rsync ~# cat /etc/rsync.password
chenleilei:123
useradd rsync -s /sbin/nologin -M
root@rsync ~# id rsync
uid=1000(rsync) gid=1000(rsync) groups=1000(rsync)
root@rsync ~# rsync --daemon
检查端口:
root@rsync ~# netstat -lntup |grep rsync
tcp 0 0 0.0.0.0:873 0.0.0.0:* LISTEN 16526/rsync
tcp6 0 0 :::873 :::* LISTEN 16526/rsync
1. 确认软件是否安装
[root@mm01 ~]# rpm -qa rsync
rsync-3.1.2-6.el7_6.1.x86_64
2. 已安装配置
[root@mm01 ~]# echo "123" >client.pass
[root@mm01 ~]# chmod 600 client.pass
2.1 未安装配置
[root@mm01 ~]# yum install -y rsync
[root@mm01 ~]# echo "123" >client.pass
[root@mm01 ~]# chmod 600 client.pass
rsync -avz /etc/rsyncd.conf chenleilei@192.168.0.164::backup
rsync -avz /etc/hosts chenleilei@192.168.0.164::backup --password-file=/root/client.pass
注意: 密钥所有者权限可以是 root.root 但文件权限必须是 600,这也是客户端部署时为什么要
chmod 600 client.pass 的原因!
将本地数据无差异同步到远程客户端,如果远程客户端同步的文件夹有文件也会一并被清除
此命令需要谨慎使用.一旦出错,无法恢复
语法:
rsync -avz --delete /etc/rsyncd.conf chenleilei@192.168.0.164::backup
在推送时,排除指定文件的推送
[root@mm01 ceshi]# rsync -avz chenleilei@192.168.0.164::backup/888/ /var/log/ --exclude=2.txt --password-file=/root/client.pass
receiving incremental file list
./
1.txt
3.txt
2.txt被排除
@ERROR: Unknown module 'backup'
rsync error: error starting client-server protocol (code 5) at main.c(1648) sender=3.1.2
网络原因无法传输,可能是当前主机IP不在允许的范围
解决: 检查服务器端 /etc/rsyncd.conf 中的 "hosts allow = " 配置
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1178) sender=3.1.2
配置参数问题: fake super = yes
在centos6 中 这行配置不加 也可以成功,但是在centos 7中如果没有此行配置,则会报以上错误
解决: 在配置文件中添加 fake super = yes
failed to create pid file /var/run/rsyncd.pid: File exists
服务已启动,再次启动会报这个错
可以通过 netstat -lntup 来查看服务端口 873 是否存在
rsync: failed to connect to 192.168.0.164 (192.168.0.164): Connection refused (111)
rsync error: error in socket IO (code 10) at clientserver.c(125) sender=3.1.2
这可能是服务没有启动导致的原因,需要检查远程rsync服务是否存在.
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1178) sender=3.1.2
这个报错,除了上面说的 fake super =yes 没有配置 还有可能是 权限不对
需要检查备份文件夹的权限是不是 rsync 所有者和所有主
[root@rsync /]# ll /backup
total 4
drwxr-xr-x 10 root root 4096 Aug 14 17:27 log #如果是root 可能就会出现问题,请改为rsync权限
解决办法:
chown -R rsync.rsync /backup
rsync 防火墙问题:
1565784168698.png
1565784239376.png
1565784286483.png
1565784330026.png
1565784375374.png
rsync -avz chenleilei@192.168.0.164::backup /var/log/ --password-file=/root/client.pass
rsync -avz chenleilei@192.168.0.164::backup /var/log/ --password-file=/root/client.pass
rsync -avz chenleilei@192.168.0.164::backup /var/log/ --password-file=/root/client.pass
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有