- rsync 除了支持本地数据的同步传输,还可以支持网络互传,实现远程同步。
- 4-10.12 内容:
通过虚拟机开启两个 CentOS 系统,模拟网络远程同步。 -
操作步骤:
1、首先通过虚拟机开启两个 CentOS 7 系统。
一台的 IP 是:192.168.0.223。
192.168.0.223
-
另一台 IP 是:192.168.0.224。
192.168.0.224
- 2、分别在两个系统当中建立测试目录。IP:192.168.0.223 的系统家目录下创建一个 backups_223 目录。
[root@localhost ~]# mkdir backups_223
[root@localhost ~]#
[root@localhost ~]# ll
total 0
drwxr-xr-x. 2 root root 32 Jul 13 23:51 a
drwxr-xr-x. 2 root root 19 Jul 13 23:53 b
drwxr-xr-x. 2 root root 6 Sep 7 21:18 backups_223 ## ip 223 创建的目录
drwxr-xr-x. 2 root root 32 Jul 13 23:53 c
- IP:192.168.0.224 的系统家目录下创建 test 目录,test 目录创建 backups_224 和 SRC 源目录。SRC 目录下创建 file1.txt、file2.txt 和 file3.txt,三个文件。
[root@localhost test]# mkdir backups_224
[root@localhost test]#
[root@localhost test]# mkdir SRC
[root@localhost test]#
[root@localhost test]# ll
total 0
drwxr-xr-x. 2 root root 6 Sep 7 21:17 backups_224 ## ip 224 创建的目录
drwxr-xr-x. 2 root root 6 Sep 6 23:15 SRC ## 源目录
[root@localhost test]#
## SRC 源目录下创建 file1.txt、file2.txt 和 file3.txt
[root@localhost test]# touch SRC/file1.txt SRC/file2.txt SRC/file3.txt
[root@localhost test]#
[root@localhost test]# tree ## 目录结构
.
├── backups_224
└── SRC
├── file1.txt
├── file2.txt
└── file3.txt
2 directories, 3 files
[root@localhost test]#
- 3、223 系统 和 224 系统互 ping 查看相互是否能 ping 通。
223 ping 224:ok
[root@localhost ~]# ping -c 5 192.168.0.224
PING 192.168.0.224 (192.168.0.224) 56(84) bytes of data.
64 bytes from 192.168.0.224: icmp_seq=1 ttl=64 time=0.990 ms
64 bytes from 192.168.0.224: icmp_seq=2 ttl=64 time=0.313 ms
64 bytes from 192.168.0.224: icmp_seq=3 ttl=64 time=0.321 ms
64 bytes from 192.168.0.224: icmp_seq=4 ttl=64 time=0.326 ms
64 bytes from 192.168.0.224: icmp_seq=5 ttl=64 time=0.445 ms
--- 192.168.0.224 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4003ms
rtt min/avg/max/mdev = 0.313/0.479/0.990/0.260 ms
[root@localhost ~]#
- 224 ping 223:ok
[root@localhost ~]# ping -c 5 192.168.0.223
PING 192.168.0.223 (192.168.0.223) 56(84) bytes of data.
64 bytes from 192.168.0.223: icmp_seq=1 ttl=64 time=0.285 ms
64 bytes from 192.168.0.223: icmp_seq=2 ttl=64 time=0.347 ms
64 bytes from 192.168.0.223: icmp_seq=3 ttl=64 time=0.382 ms
64 bytes from 192.168.0.223: icmp_seq=4 ttl=64 time=0.440 ms
64 bytes from 192.168.0.223: icmp_seq=5 ttl=64 time=0.327 ms
--- 192.168.0.223 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4001ms
rtt min/avg/max/mdev = 0.285/0.356/0.440/0.053 ms
[root@localhost ~]#
- 4、ip 224 的系统 传输 test/SRC 目录下的文件 到 ip 223 系统的 backups_223 目录。
初次建立通信会有校验码,输入 yes 才可以继续。然后,提示输入对面系统的密码,也就是 223 系统的密码。密码正确后建立通信,传输文件。
## 把当前系统(也就是 ip 224 系统)的 test/SRC/ 目录文件传输到 ip 223 系统的 backups_223 下。
[root@localhost ~]# rsync -av test/SRC/ 192.168.0.223:/root/backups_223
## 初次建立通信会有校验码,输入 yes 才可以继续。
ECDSA key fingerprint is SHA256:Jg8XXWbrg7/RJIm9rApblU34o5yvdAoOQo0R5U7tW3A.
ECDSA key fingerprint is MD5:18:b8:10:06:5e:ed:cb:db:d1:8d:34:8a:e4:9f:de:96.
Are you sure you want to continue connecting (yes/no)? y
Please type 'yes' or 'no': yes
## 输入对面系统的密码,也就是 ip 223 系统的密码。密码正确后建立通信,传输文件。
root@192.168.0.223's password:
sending incremental file list ## 传输列表的文件就是 SRC 目录下的文件
./
file1.txt
file2.txt
file3.txt
sent 222 bytes received 76 bytes 85.14 bytes/sec
total size is 0 speedup is 0.00
[root@localhost ~]#
- 5、到 ip 223 的系统查看 backups_223 目录,ip 224 系统 SRC 目录下的文件已经传输过来了。
[root@localhost ~]# ll backups_223/
total 0
-rw-r--r--. 1 root root 0 Sep 7 21:25 file1.txt
-rw-r--r--. 1 root root 0 Sep 7 21:25 file2.txt
-rw-r--r--. 1 root root 0 Sep 7 21:25 file3.txt
[root@localhost ~]#
- 6、发送文档到 ip 223 系统成功后,现在需要测试从 ip 223 系统拉文件过来 ip 224 系统。从 ip 223 系统的目录结构来看,打算拉家目录下的 a 目录到 ip 224 系统。
## ip 192.168.0.223 的目录结构
[root@localhost ~]# tree
.
├── a ## 需要拉到 ip 224 系统的 a 目录
│ ├── 1.txt
│ └── 2.txt
├── b
│ └── 1.txt
├── backups_223
│ ├── file1.txt
│ ├── file2.txt
│ └── file3.txt
└── c
├── 1.txt
└── 2.txt
4 directories, 8 files
[root@localhost ~]#
- 7、ip 224 系统操作:rsync -av 192.168.0.223:/root/a test/backups_224/。
意思是:把 ip 192.168.0.223 系统的 /root/a 整个 a 目录递归式的拉到本机的 backups_224 目录。(也就是 ip 192.168.0.224 系统)
建立通信时需要输入对方系统的密码,这里是系统 ip 192.168.0.223 系统的密码。密码正确后建立传输。
[root@localhost ~]# rsync -av 192.168.0.223:/root/a test/backups_224/
## 输入对面系统的密码,也就是 ip 223 系统的密码。密码正确后建立通信,传输文件。
root@192.168.0.223's password:
receiving incremental file list ## 传输列表是 ip 223 的 a 目录及文件
a/
a/1.txt
a/2.txt
sent 66 bytes received 174 bytes 53.33 bytes/sec
total size is 0 speedup is 0.00
[root@localhost ~]#
- 8、ip 224 的系统查看 backups_224目录,ip 223 系统 a 目录及文件已经传输过来了。
[root@localhost ~]#
[root@localhost ~]# ll test/backups_224/
total 0
drwxr-xr-x. 2 root root 32 Jul 13 23:51 a
[root@localhost ~]#
[root@localhost ~]# ll test/backups_224/a
total 0
-rw-r--r--. 1 root root 0 Jul 13 22:34 1.txt
-rw-r--r--. 1 root root 0 Jul 13 22:34 2.txt
[root@localhost ~]#
-
综上测试。
-
发送文件到另一个 linux 系统应该是:
源目录 对方ip :对方目标目录
例: rsync -av test/SRC/ 192.168.0.223:/root/backups_223 -
从另一个 linux 系统拉文件到本系统应该是:
对方ip :源目录 本地目标目录
例:rsync -av 192.168.0.223:/root/a test/backups_224/








网友评论