1.下载rsync
yum -y install rsync
2.vi /etc/rsyncd.conf
uid = rsync
gid = rsync
port = 873
fake super = yes
use chroot = yes
max connections = 200
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
exclude = lost+found/
transfer logging = yes
log file = /var/log/rsyncd.log
log format = %t %a %m %f %b
ignore errors
list = false
hosts allow = 192.168.198.0/24
hosts deny = *[backup]
path = /backup
comment = nebula userdate backup
read only = false
use chroot = no
auth users = hello
secrets file = /etc/rsync.passworduid = root
gid = root
3.创建rsync用户
useradd -s /sbin/nologin -M rsync
4.创建数据备份储存目录,目录修改属主
mkdir /backup/
chown -R root:root /backup
5.创建认证用户密码文件
echo "hello:123" >> /etc/rsync.password
chmod 600 /etc/rsync.password
6.重启rsync服务,关闭selinux
systemctl restart rsync
setenforce 0
7.保证防火墙处于允许状态,检查873端口是否处于开放状态
firewall-cmd --state(running)
firewall-cmd --add-rich-rule='rule family=ipv4 source address=192.168.198 .0/24 port port=873 protocol=tcp accept' --permanent
客户端:
1.在客户端查看软件是否存在,不存在则下载
rpa -qa | grep rsync
2.创建认证文件
echo "123" >> /etc/rsync.password (只需要密码)
chmod 600 /etc/rsync.password
3.实现数据传输
交互式
rsync -avz /etc/passwd hello@192.168.198.128::backup
免交互式
rsync -avzP /etc/hosts hello@192.168.198.128::backup --password-file=/ etc/rsync.password