Hadoop集群包含1个主节点和3个从节点,需要实现各节点之间的免密码登录,下面介绍具体的实现方法。

一、Hadoop集群环境

二、免密登录原理

每台主机authorized_keys文件里面包含的主机(ssh密钥),该主机都能无密码登录,所以只要每台主机的authorized_keys文件里面都放入其他主机(需要无密码登录的主机)的ssh密钥就行了。

三、实现方法

1. 配置每个节点的hosts文件

#vim /etc/hosts
1 192.168.44.3 hadoop01
192.168.44.4 hadoop02
192.168.44.5 hadoop03
192.168.44.6 hadoop04

2. 每个节点生成ssh密钥

[root@hadoop01 ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
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.
..................... [root@hadoop01 .ssh]# ls
id_rsa id_rsa.pub

执行命令后会在~目录下生成.ssh文件夹,里面包含id_rsa和id_rsa.pub两个文件。

注:使用ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa命令可避免上述交互式操作。

3. 在主节点上将公钥拷到一个特定文件authorized_keys中。

[root@hadoop01 ~]# cd .ssh
[root@hadoop01 .ssh]# ls
id_rsa id_rsa.pub
[root@hadoop01 .ssh]# cp id_rsa.pub authorized_keys
[root@hadoop01 .ssh]# ls
authorized_keys id_rsa id_rsa.pub

4. 将authorized_keys文件拷到下一个节点,并将该节点的ssh密钥id_rsa.pub加入该文件中。

#在hadoop01上使用scp命令实现远程文件拷贝
[root@hadoop01 .ssh]# scp authorized_keys root@hadoop02:/root/.ssh/
The authenticity of host 'hadoop02 (192.168.44.11)' can't be established.
ECDSA key fingerprint is SHA256:MyB1zs0E3J/fm8pC0AN8ycsgEIBNHtUqd9xS0WAyv3s.
ECDSA key fingerprint is MD5:::3a:ba:3e::a7:d7::f6:::::f9:.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'hadoop02,192.168.44.11' (ECDSA) to the list of known hosts.
root@hadoop02's password:
authorized_keys % .2KB/s : #登录hadoop02主机

[root@hadoop02 ~]# cd .ssh/
[root@hadoop02 .ssh]# ls
authorized_keys id_rsa id_rsa.pub
[root@hadoop02 .ssh]# cat id_rsa.pub >> authorized_keys #使用cat追加方式

5. 重复第4步的操作,依次将hadoop03、hadoop04节点的ssh密钥加入到authorized_keys文件中,并将hadoop04节点生成的authorized_keys文件拷贝到其他三个节点(hadoop01、hadoop02、hadoop03)即可。

#登录hadoop03主机,将ssh密钥加入authorized_keys文件中
[root@hadoop03 .ssh]# cat id_rsa.pub >> authorized_keys
[root@hadoop03 .ssh]# scp authorized_keys root@hadoop04:/root/.ssh/ #登录hadoop04主机,将ssh密钥加入authorized_keys文件中
[root@hadoop04 .ssh]# cat id_rsa.pub >> authorized_keys #将最后生成的authorized_keys文件分别拷贝到hadoop01、hadoop02和hadoop03
[root@hadoop04 .ssh]# scp authorized_keys root@hadoop01:/root/.ssh/
[root@hadoop04 .ssh]# scp authorized_keys root@hadoop02:/root/.ssh/
[root@hadoop04 .ssh]# scp authorized_keys root@hadoop03:/root/.ssh/

6. 验证免密登录

使用ssh 用户名@节点名或ssh ip地址命令验证免密码登录。

[root@hadoop01 .ssh]# ssh root@hadoop02
Last login: Tue Feb :: from 192.168.44.1 [root@hadoop02 .ssh]# ssh root@hadoop01
Last login: Tue Feb :: from hadoop04 [root@hadoop03 .ssh]# ssh root@hadoop04
Last login: Tue Feb :: from 192.168.44.1 [root@hadoop04 .ssh]# ssh root@hadoop01
Last login: Tue Feb :: from hadoop02

Hadoop集群配置免密SSH登录方法的更多相关文章

  1. [Kubernetes]集群配置免密登录Permission denied (publickey,password) 解决办法

    在用ansible部署Kubernetes集群是需要配置免密登录,但是遇到Permission denied (publickey,password)的问题 首先推断可能是sshd_config的配置 ...

  2. hadoop集群配置SSH免登陆

    今天给大家总结一下hadoop集群之间免登陆的步骤 node1 ssh node4 1.在node1中生成密钥 [root@node1 ~]# ssh-keygen -t dsa -P '' -f ~ ...

  3. hadoop集群配置和在windows系统上运用java操作hdfs

    安装 配置 概念 hadoop常用shell命令 使用java操作hadoop 本文介绍hadoop集群配置和在windows系统上运用java操作hdfs 安装 http://mirror.bit. ...

  4. Hadoop集群配置(最全面总结)

    Hadoop集群配置(最全面总结) 通常,集群里的一台机器被指定为 NameNode,另一台不同的机器被指定为JobTracker.这些机器是masters.余下的机器即作为DataNode也作为Ta ...

  5. Hadoop集群配置(最全面总结 )(转)

    Hadoop集群配置(最全面总结) huangguisu 通常,集群里的一台机器被指定为 NameNode,另一台不同的机器被指定为JobTracker.这些机器是masters.余下的机器即作为Da ...

  6. 大数据测试之hadoop集群配置和测试

    大数据测试之hadoop集群配置和测试   一.准备(所有节点都需要做):系统:Ubuntu12.04java版本:JDK1.7SSH(ubuntu自带)三台在同一ip段的机器,设置为静态IP机器分配 ...

  7. Hadoop 集群配置记录小结

    Hadoop集群配置往往按照网上教程就可以"配置成功",但是你自己在操作的时候会有很多奇奇怪怪的问题出现, 我在这里整理了一下常见的问题与处理方法: 1.配置/etc/hosts ...

  8. hadoop集群配置方法---mapreduce应用:xml解析+wordcount详解---yarn配置项解析

    注:以下链接均为近期hadoop集群搭建及mapreduce应用开发查找到的资料.使用hadoop2.6.0,其中hadoop集群配置过程下面的文章都有部分参考. hadoop集群配置方法: ---- ...

  9. Hadoop集群搭建过程中ssh免密码登录(二)

    一.为什么设置ssh免密码登录 在集群中,Hadoop控制脚本依赖SSH来执行针对整个集群的操作.例如,某个脚本能够终止并重启集群中的所有守护进程.所以,需要安装SSH,但是,SSH远程登陆的时候,需 ...

随机推荐

  1. 51nod1428 活动安排问题 (贪心加暴力)

    1428 活动安排问题 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题  收藏  关注 有若干个活动,第i个开始时间和结束时间是[Si,fi),同一个教室安排的活动 ...

  2. Agc004_C AND Grid

    传送门 题目大意 给定一个$N\times M\space(N,M\leq 500)$的网格,有一些格子是紫色,保证边界没有颜色. 构造两个$N\times M$的网格$A,B$,在$A$中染红色在$ ...

  3. uva1160 易爆物

    #include<iostream>#include<cstdio>#include<algorithm>#include<cstdlib>using ...

  4. 51nod 1686 第K大区间2

    1685 第K大区间2 定义一个区间的值为其众数出现的次数.现给出n个数,求将所有区间的值排序后,第K大的值为多少. 众数(统计学/数学名词)_百度百科 Input 第一行两个数n和k(1<=n ...

  5. 【LeetCode】019. Remove Nth Node From End of List

    Given a linked list, remove the nth node from the end of list and return its head. For example, Give ...

  6. WSGI服务与django的关系

    WSGI接口 wsgi是将python服务器程序连接到web服务器的通用协议.uwsgi是独立的实现了wsgi协议的服务器.   web服务器 服务端程序 简化版的WSGI架构 服务端程序(类似dja ...

  7. 系列文章--打造自己的MVC框架

    MVC源码学习系列文章目录: MVC系列——MVC源码学习:打造自己的MVC框架(一:核心原理) MVC系列——MVC源码学习:打造自己的MVC框架(二:附源码) MVC系列——MVC源码学习:打造自 ...

  8. 在Eclipse中用JDBC连接Mysql数据库

    一.配置要求 JDK(下载http://www.oracle.com/technetwork/java/javase/downloads/index.html) Mysql(下载http://www. ...

  9. POJ 1503 Integer Inquiry(大数相加)

    一.Description One of the first users of BIT's new supercomputer was Chip Diller. He extended his exp ...

  10. 我推荐的一些C\C++书籍

    原文链接: 我推荐的一些C\C++书籍 人们常常问我有什么C++和编程的书籍推荐,也许是因为我在PowerDNS有一个关于"编写可读性良好的C++代码"的演讲.这篇博文可以作为我对 ...