服务端部署
1.安装rsync
##查看一下有没有,如果没有安装
[root@ c7-41 ~]# rpm -qa rsync
rsync-3.1.2-6.el7_6.1.x86_64
[root@ c7-41 ~]# yum -y install rsync
2、手动配置rsync配置文件
[root@ c7-41 ~]# vim /etc/rsyncd.conf
vim /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 #日志文件,显示出错信息
##模块配置
[backup] #模块名称
path = /data #模块对应的位置(路径)
ignore errors #忽略错误程序
read only = false #是否只读
list = false #是否可以列表
hosts allow = 10.0.0.0/24 #准许访问rsync服务器的客户范围
#hosts deny = 0.0.0.0/32 #禁止访问rsync服务器的客户范围
auth users = rsync_backup #不存在的用户;只用于认证
secrets file = /etc/rsync.password #设置进行连接认证的密匙文件
3、创建rsync备份目录/授权rsync用户管理备份目录;修改备份目录权限
[root@ c7-41 ~]# mkdir -p /data
[root@ c7-41 ~]# useradd rsync -s /sbin/nologin -M
#添加用户rsync,-s:指定用户 /sbin/nologin:虚拟用户,-M:只被程序使用
[root@ c7-41 ~]# chown -R rsync.rsync /data/
4、创建认证用户密码文件;修改文件权限
[root@ c7-41 ~]# echo "rsync_backup:123456" >/etc/rsync.password
[root@ c7-41 ~]# chmod 600 /etc/rsync.password
5、重启rsync守护进程服务
[root@ c7-41 ~]# systemctl restart rsyncd.service
[root@ c7-41 ~]# systemctl status rsyncd.service
● rsyncd.service - fast remote file copy program daemon
Loaded: loaded (/usr/lib/systemd/system/rsyncd.service; disabled; vendor preset: disabled)
Active: active (running) since Tue 2020-04-21 14:35:12 CST; 9s ago
Main PID: 3089 (rsync)
CGroup: /system.slice/rsyncd.service
└─3089 /usr/bin/rsync --daemon --no-detach
Apr 21 14:35:12 c7-41 systemd[1]: Stopped fast remote file ...
Apr 21 14:35:12 c7-41 systemd[1]: Started fast remote file ...
Hint: Some lines were ellipsized, use -l to show in full.
[root@ c7-41 ~]#
客户端部署
7、创建密码文件,客户端密码文件中,只需要密码即可。同时,密码文件的权限是600
[root@ c7-42 ~]# echo "123456">/etc/rsync.password
[root@ c7-42 ~]# chmod 600 /etc/rsync.password
客户端测试推送文件
#创建一个文件,输入东西
[root@ c7-42 ~]# echo 1708a > 1.txt
[root@ c7-42 ~]# rsync -avz 1.txt rsync_backup@10.0.0.41::backup --password-file=/etc/rsync.password
sending incremental file list
1.txt
sent 98 bytes received 43 bytes 94.00 bytes/sec
total size is 6 speedup is 0.04
注意:rsync默认使用873端口,防火墙开启时,需放行端口
客户端拉取文件
[root@ c7-42 ~]# rsync -avz rsync_backup@10.0.0.41::backup --password-file=/etc/rsync.password /tmp
receiving incremental file list
./
1.txt
sent 50 bytes received 144 bytes 129.33 bytes/sec
total size is 6 speedup is 0.03
可以看一下同步过去没有
[root@ c7-41 ~]# cd /data/
[root@ c7-41 data]# ls
1.txt
[root@ c7-41 data]#
推送和拉取,都是针对客户端