centos7使用rsync实现两台服务器定时同步某一个文件夹

首先去阿里下一个epel源到服务器上

然后yum -y install rsync下载rsync命令的包

设置两台机器互信

#第一台机器

[root@localhost ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:opyF5g1e1nGWVJ6V455lktwOh4yH20mRgECATkXKj8w root@localhost.localdomain
The key's randomart image is:
+---[RSA 2048]----+
|     ++oo..oo..o |
|   .o.   ..o o=  |
|   oo   . + o* * |
|   o.+ . +  o @ =|
|    E * S    * X |
|   = O .    . = .|
|    * .          |
|                 |
|                 |
+----[SHA256]-----+
[root@localhost ~]# ssh-copy-id 192.168.100.16
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.100.16's password: 
Permission denied, please try again.
root@192.168.100.16's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '192.168.100.16'"
and check to make sure that only the key(s) you wanted were added.

#第二台机器

[root@localhost ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:Wm2n/SWOarfAbv1domU4tCIh6wzRZAMkb2qp0I+Ok9g root@localhost.localdomain
The key's randomart image is:
+---[RSA 2048]----+
|  ..o            |
|   o .           |
|    o +          |
| . + + . .       |
|. = . o S o o    |
|.o o . = + = o   |
|oo. o o . =.= = o|
|+oE  +   ooooO =.|
|...   o  ooo+o+ .|
+----[SHA256]-----+
[root@localhost ~]# ssh-copy-id 192.168.100.15
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.100.15 (192.168.100.15)' can't be established.
ECDSA key fingerprint is SHA256:pSoL7o2TrxRyjd9BkNRsaiefxob8GiBTVkoUgHfVXuk.
ECDSA key fingerprint is MD5:4d:86:96:a1:e7:5f:a8:72:21:8a:0c:ae:48:54:c0:69.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.100.15's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '192.168.100.15'"
and check to make sure that only the key(s) you wanted were added.

将ip为192.168.100.16机器上的/etc/目录中的内容拉到本机的/tmp/目录中

rsync -az root@192.168.100.16:/etc/  /tmp/

或者在ip为192.168.100.16执行,将本机的推到192.168.100.16的/tmp/目录下

rsync -az /etc/   root@192.168.100.15:/tmp/

更多参数请使用rsync --help查看

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值