多台服务器免密登陆设置

在开始之前需要对服务器进行基本的配置

一. Linux配置

  1. 关闭防火墙和selinux
    #关闭防火墙
    service iptables stop
    chkconfig iptables off
    
    #关闭selinux
    vim /etc/selinux/config
    #设置为disabled
    SELINUX=disabled    
    
  2. 百度云分配的名字太麻烦了,为方便操作修改主机名,但是遇到了一些问题,详细请点击 Linux修改hostname的几种方式:
    #百度云   修改后,重启(reboot -h)永久生效
    vi /etc/sysconfig/network
    #第2台  将hostname改为node01
    HOSTNAME=node01
    #第2台  将hostname改为node01
    HOSTNAME=node03
     
    #腾讯云   可能我装的不是原版的,出来的居然是这个鬼东西
    # Created by cloud-init on instance boot automatically, do not edit.
    #在下面添加一行
    NETWORKING=yes
    HOSTNAME=node02
    然后使用: vi /etc/hostname
    node02
    #reboot -h 重启后生效了
    
    
    2.域名映射并测试
    /etc/hosts 文件用于在通过主机名进行访问时做 ip 地址解析之用。
    所以,你想访问一个什么样的主机名,就需要把这个主机名和它对应的 ip 地址. 配置在/etc/hosts 文件中.
    #三台服务器进行域名映射操作
    vim /etc/hosts
    127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
    ::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
    #172.16.0.4 instance-mv524v7d instance-mv524v7d.novalocal
    
    #添加以下配置,前面为你服务器的ip
    192.168.221.100 node01
    192.168.221.110 node02
    192.168.221.120 node03
    
    # 测试腾讯云与百度云 互ping:
    root@node02 etc# ping node01
    PING node01 (106.13.你的ip.你的ip) 56(84) bytes of data.
    64 bytes from node01 (106.13.你的ip.你的ip): icmp_seq=1 ttl=48 time=60.1 ms
    64 bytes from node01 (106.13.你的ip.你的ip): icmp_seq=2 ttl=48 time=59.6 ms
    64 bytes from node01 (106.13.你的ip.你的ip): icmp_seq=3 ttl=48 time=59.7 ms
    
    [root@node01 ~]# ping node02
    PING node02 (132.232.你的ip.你的ip) 56(84) bytes of data.
    64 bytes from node02 (132.232.你的ip.你的ip): icmp_seq=1 ttl=49 time=60.1 ms
    64 bytes from node02 (132.232.你的ip.你的ip): icmp_seq=2 ttl=49 time=59.6 ms
    64 bytes from node02 (132.232.你的ip.你的ip): icmp_seq=3 ttl=49 time=59.6 ms
    
    [root@node03 ~]# ping node01
    PING node01 (106.13.你的ip.你的ip) 56(84) bytes of data.
    64 bytes from node01 (106.13.你的ip.你的ip): icmp_seq=1 ttl=59 time=1.29 ms
    64 bytes from node01 (106.13.你的ip.你的ip): icmp_seq=2 ttl=59 time=0.526 ms
    64 bytes from node01 (106.13.你的ip.你的ip): icmp_seq=3 ttl=59 time=0.570 ms
    
    重启服务器

二、3台服务器免密码登录

1. 三台机器生成公钥与私钥:
[root@node03 ~]# 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:
35:8f:46:e1:19:d1:91:20:44:01:cb:6c:58:bd:4f:85 root@node03
The key's randomart image is:
+--[ RSA 2048]----+
|      o==.==.o   |
|     = ..oE++    |
|    . =  .*.     |
|     .  .o.+     |
|        Soo .    |
|         ..      |
|                 |
|                 |
|                 |
+-----------------+
2. 拷贝公钥到同一台机器
[root@node03 ~]# ssh-copy-id node01
The authenticity of host 'node01 (106.13.55.197)' can't be established.
RSA key fingerprint is 7c:70:21:11:f4:64:f4:2a:db:db:f9:42:65:63:9b:c6.
Are you sure you want to continue connecting (yes/no)? yes  #输入yes
Warning: Permanently added 'node01,106.13.55.197' (RSA) to the list of known hosts.
root@node01's password:   #输入第一台服务器的密码
Now try logging into the machine, with "ssh 'node01'", and check in:

 .ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

3. 复制第一台机器的认证到其他机器
#根据提示,输入yes,和服务器的登陆密码
scp /root/.ssh/authorized_keys node02:/root/.ssh/
scp /root/.ssh/authorized_keys node03:/root/.ssh/
4. 通过网络时钟同步;
#设置定时任务
[root@node01 ~]#  crontab -e
#添加阿里云时钟同步定时任务
*/1 * * * * /usr/sbin/ntpdate ntp4.aliyun.com;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值