10.31 rsync經過ssh同步

Linux文件同步工具-rsync

  • rsync經過ssh方式同步
  • rsync -av test1/ 192.168.133.132:/tmp/test2/
  • rsync -av -e "ssh -p 22" test1/ 192.168.133.132:/tmp/test2/

rsync命令,將文件傳輸到另外一臺虛擬機

  1. 在終端打開兩個不一樣ip的虛擬機,而且兩個虛擬機是能夠互通ping通的
在hf的虛擬機中,ping另外一臺虛擬機
[root@hf-01 ~]# ping 192.168.74.130
PING 192.168.74.130 (192.168.74.130) 56(84) bytes of data.
64 bytes from 192.168.74.130: icmp_seq=1 ttl=64 time=1.42 ms
64 bytes from 192.168.74.130: icmp_seq=2 ttl=64 time=0.873 ms
^C
--- 192.168.74.130 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1004ms
rtt min/avg/max/mdev = 0.873/1.147/1.422/0.276 ms
[root@hf-01 ~]# 


在hf-02的虛擬機上,ping第一臺虛擬機
[root@hf-02 ~]# ping 192.168.74.129
PING 192.168.74.129 (192.168.74.129) 56(84) bytes of data.
64 bytes from 192.168.74.129: icmp_seq=1 ttl=64 time=1.05 ms
64 bytes from 192.168.74.129: icmp_seq=2 ttl=64 time=0.725 ms
^C
--- 192.168.74.129 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1002ms
rtt min/avg/max/mdev = 0.725/0.891/1.058/0.169 ms
[root@hf-02 ~]#
  1. 在hf的終端虛擬機上,將文件傳輸到hf-02的虛擬機上
    • 前提:在兩個虛擬機上都安裝rsync包——>yum install -y rsync
在hf的虛擬上,傳文件到hf-02的虛擬機上
[root@hf-01 ~]# rsync -av /etc/passwd 192.168.74.130:/tmp/hanfeng.txt
root@192.168.74.130's password:          //輸入192.168.74.130虛擬機的密碼,就是hf-02的密碼
sending incremental file list
passwd

sent 1100 bytes  received 31 bytes  323.14 bytes/sec
total size is 1026  speedup is 0.91
[root@hf-01 ~]# 


在hf-02虛擬機上查看
[root@hf-02 ~]# ls /tmp/hanfeng.txt
/tmp/hanfeng.txt
[root@hf-02 ~]# cat !$
cat /tmp/hanfeng.txt
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:999:998:User for polkitd:/:/sbin/nologin
avahi:x:70:70:Avahi mDNS/DNS-SD Stack:/var/run/avahi-daemon:/sbin/nologin
avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
mysql:x:1000:1000::/home/mysql:/bin/bash
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
[root@hf-02 ~]#

rsync命令,將另外一臺虛擬機文件傳輸到本機上

  • 將hf-02機器中的文件傳輸到本機上
[root@hf-01 ~]# rsync -avP 192.168.74.130:/tmp/hanfeng.txt /tmp/12345.txt
root@192.168.74.130's password:        
receiving incremental file list
hanfeng.txt
        1026 100% 1001.95kB/s    0:00:00 (xfer#1, to-check=0/1)

sent 30 bytes  received 1110 bytes  78.62 bytes/sec
total size is 1026  speedup is 0.90
[root@hf-01 ~]#

rsync命令,參數-e 指定端口傳輸文件

  • rsync -avP -e "ssh -p 22" /etc/passwd 192.168.74.130:/tmp/hanfeng.txt //指定對方的22端口,就能夠鏈接對面的22端口
[root@hf-01 ~]# rsync -avP -e "ssh -p 22" /etc/passwd 192.168.74.130:/tmp/hanfeng.txt
root@192.168.74.130's password: 
sending incremental file list

sent 31 bytes  received 12 bytes  7.82 bytes/sec
total size is 1026  speedup is 23.86
[root@hf-01 ~]#

ssh命令

  • ssh -p 22 192.168.74.130 //鏈接ip爲192.168.74.130的虛擬機
    • 輸入exit退出
[root@hf-01 ~]# ssh -p 22 192.168.74.130
root@192.168.74.130's password: 
Last login: Wed Dec  6 05:14:27 2017 from 192.168.74.1
[root@hf-02 ~]# exit
登出
Connection to 192.168.74.130 closed.
[root@hf-01 ~]#
相關文章
相關標籤/搜索