机器:192.168.29.182/186
注:因为rsync基于sshd服务器,所以需要两台服务器互相做好免密登陆
方法一:
[root@186 ~]# ssh-copy-id 192.168.29.182 [root@186 ~]# ssh 192.168.29.182 #这时ssh连接不需要密码 Last login: Wed Sep 2 17:37:23 2020 from 192.168.xx方法二: 没有ssh-copy-id时,手动将182的id_rsa.pub内容添加到186的authorized_keys中
[root@182 ~]# vim /root/.ssh/id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAA... [root@186 ~]# vim /root/.ssh/authorized_keys ssh-rsa AAAAB3NzaC1yc2EAA... [root@182~]# ssh 192.168.29.186 #ssh测试 Last login: Wed Sep 2 17:36:32 2020 from 192.168.xx测试
186触发: [root@186 service]# sh rsync.sh & #后台执行脚本 [1] 21253 [root@186 service]# echo "186:hello 182" >> hello.txt [root@186 service]# echo "186:hello 182" >> /opt/service/vsftpd/hello.txt [root@186 service]# sending incremental file list #rsync.sh执行返回 ./ hello.txt hello.txt sent 304 bytes received 39 bytes 686.00 bytes/sec total size is 9,014 speedup is 26.28 sent 301 bytes received 36 bytes 674.00 bytes/sec total size is 9,014 speedup is 26.75 sending incremental file list 182验证: [root@182 ~]# cat /opt/service/vsftpd/hello.txt 186:hello 182 182触发: [root@182 service]# sh rsync.sh & #后台执行脚本 [root@182 service]# echo "182:hello 186" >> /opt/service/vsftpd/hello.txt sending incremental file list hello.txt sent 306 bytes received 42 bytes 232.00 bytes/sec total size is 9,028 speedup is 25.94 186验证: [root@186 ~]# cat /opt/service/vsftpd/hello.txt 186:hello 182 182:hello 186 大功告成!