准备两台centos7
服务机:192.168.43.68
客户机:192.168.43.134
服务端安装rsync
安装
[root@localhost fdfs]# yum -y install rsync
修改配置文件
[root@localhost fdfs]# vim /etc/rsyncd.conf
添加以下行
motd file=/etc/rsyncd.welcome
[test]
path=/world
自定义欢迎信息
[root@localhost fdfs]# vim /etc/rsyncd.welcome
启动服务,关闭防火墙
[root@localhost fdfs]# systemctl start rsyncd.service
[root@localhost fdfs]# systemctl stop firewalld
[root@localhost fdfs]# setenforce 0
创建文件,稍后做测试用
[root@localhost fdfs]# touch /world/{1..10}.txt
客户端配置
安装
[root@localhost ~]# yum -y install rsync
查看同步路径名
[root@localhost databak]# rsync -v 192.168.43.64::
创建同步目录并同步
[root@localhost ~]# mkdir /databak
[root@localhost databak]# rsync -a 192.168.43.64::test /databak/
查看是否成功
[root@localhost databak]# cd /databak/
[root@localhost databak]# ls
10.txt 1.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt 9.txt #成功
启动定时任务
crontab -e
* */5 * * * /usr/bin/rsync -a 192.168.43.64::test /databak/ #每隔五小时同步一次