一、rsync的参数:
-a == rltopgD
-r 递归复制
-l 复制软连接
-t mtime 文件最后修改时间
-o 保持onwer所有者不变
-g group 所属用户组不变
-p permission 权限
-D 复制特殊设备
-v 显示同步的过程
-z 同步时进行压缩
--delete(极其凶险)
目标必须与源一模一样
从哪里 来 到哪里去 一模一样
二、Access via rsync daemon rsync守护进程模式(服务端客户端)
1、添加虚拟用户
[root@backup ~]# useradd -s /sbin/nologin -M rsync
[root@backup ~]# grep 'rsync' /etc/passwd
rsync:x:1001:1001::/home/rsync:/sbin/nologin
2、创建共享目录 修改所有者
[root@backup ~]# mkdir /data/ -p
[root@backup ~]# chown -R rsync.rsync /data
[root@backup ~]# ll -d /data
drwxr-xr-x 2 rsync rsync 6 May 16 17:09 /data
3、创建密码文件 设置文件权限
[root@backup ~]# echo 'rsync_backup:123456'>/etc/rsync.password
[root@backup ~]# cat /etc/rsync.password
rsync_backup:123456
[root@backup ~]# chmod 600 /etc/rsync.password
[root@backup ~]# ll /etc/rsync.password
-rw------- 1 root root 20 May 20 19:22 /etc/rsync.password
4、配置/etc/rsyncd.conf文件
[root@backup ~]# vim /etc/rsyncd.conf
#Rsync server
##created by oldboy 15:01 2009-6-5
##rsyncd.conf start##
fake super = yes //无需让rsync以root身份运行,允许接收文件的完整属性
uid = rsync //运行进程的用户
gid = rsync //运行进程的用户组
use chroot = no //禁锢推送的数据至某个目录,buyunxu
max connections = 2000 //最大连接数
timeout = 600 //超时时间 秒
pid file = /var/run/rsyncd.pid //pid进程号
lock file = /var/run/rsync.lock //lock 锁文件 两个窗口同时运行yum
log file = /var/log/rsyncd.log //日志文件 拍错必备
ignore errors
read only = false //关闭只读
list = false
#hosts allow = 10.0.0.0/24 //allow 准许 应用 只开启allow(白名单)
#hosts deny = 0.0.0.0/32 //deny 拒绝
auth users = rsync_backup //指定认证用户(不存在)
secrets file = /etc/rsync.password // 密码文件
#####################################
[data] //[data] data模块
comment = www by old0boy 14:18 2012-1-13
path = /data //path 指定共享的目录
5、启动rsync服务端(rsyncd或rsync.service)
[root@backup ~]# systemctl restart rsyncd
[root@backup ~]# ps -ef |grep rsync
root 7541 1 0 19:26 ? 00:00:00 /usr/bin/rsync --daemon --no-detach
root 7546 7454 0 19:27 pts/0 00:00:00 grep --color=auto rsync
[root@backup ~]# ss -lntup |grep rsync
tcp LISTEN 0 5 *:873 *:* users(("rsync",pid=7541,fd=3))
tcp LISTEN 0 5 :::873 :::* users(("rsync",pid=7541,fd=5))
6、检查rsync服务端是否能用
rsync -avz /etc/hosts [email protected]::data
7、排查故障思路
- 看日志
[root@backup ~]# tail -f /var/log/rsyncd.log
- 配置文件
[root@backup ~]cat /etc/rsyncd.conf
8、rsync客户端
- 创建密码文件(只有密码就行)
[root@nfs01 ~]echo 123456 >/etc/rsync,password
[root@nfs01 ~]chmod 600 /etc/rsync.password
[root@nfs01 ~]cat /etc/rsync.password
123456
- 进行客户端推送文件
[root@nfs01 ~]rsync -avz /etc/hosts [email protected]::data --password-file /etc/passwd
9、rsync多模块
- 在配置文件中添加多个目录
#####################################
[data]
comment = www by old0boy 14:18 2012-1-13
path = /data
#####################################
[backup]
comment = www by old0boy 14:18 2012-1-13
path = /backup
三、故障集合
- auth failed on module data
data模块 认证错误(密码)
原因:
1.密码写错
2.密码文件 不存在
3.密码文件 权限不对
[root@backup log]# rsync -avz /etc/hosts [email protected]::data
Password:
@ERROR: auth failed on module data
rsync error: error starting client-server protocol (code 5) at main.c(1648) [sender=3.1.2]
- secrets file
日志中
密码文件问题
查看日志的提示:
019/05/20 16:52:32 [15755] secrets file must be owned by root when running as root (see strict modes)
2019/05/20 16:52:32 [15755] auth failed on module data from backup (172.16.1.41) for rsync_backup: ignoring secrets file
secrets file must be owned by root when running as root (see strict modes)
密码文件 当root运行rsync的时候 ,必须属于 root
[root@backup ~]# ll /etc/rsync.password
-rw------- 1 rsync rsync 20 May 20 16:49 /etc/rsync.password
3.Unknown module 'data'
未知的模块
[root@backup ~]# rsync -avz /etc/hosts [email protected]::data
@ERROR: Unknown module 'data'
rsync error: error starting client-server protocol (code 5) at main.c(1648) [sender=3.1.2]
4.read error: Connection reset by peer
配置文件错误
[root@backup ~]# rsync -avz /etc/hosts [email protected]::data
sending incremental file list
rsync: read error: Connection reset by peer (104)
rsync error: error in socket IO (code 10) at io.c(785) [sender=3.1.2]
- password file must not be other-accessible
rsync -avz /etc/sysconfig/ [email protected]::backup --password-file=/etc/rsync.password
ERROR: password file must not be other-accessible
rsync error: syntax or usage error (code 1) at authenticate.c(196) [sender=3.1.2]
6.Unknown module 'data'
@ERROR: Unknown module 'data'
2019/05/20 17:45:46 [10514] rsync denied on module data from UNKNOWN (10.0.0.31)