1、Hadoop集群各节点配置
192.168.232.142 master
192.168.232.144 node2
192.168.232.146 secondarynamenode
192.168.232.148 node1
2、在master节点生成登陆密钥
#添加hadoop用户
[root@master1 opt]# groupadd hadoop
[root@master1 opt]# useradd hadoop -g hadoop
#切换Hadoop 用户下
su hadoop
cd /home/hadoop/
#生成公钥和私钥
ssh-keygen -q -t rsa -N "" -f /home/hadoop/.ssh/id_rsa
或
ssh-keygen -t rsa
cd /home/hadoop/.ssh
cat id_rsa.pub > authorized_keys
chmod go-wx authorized_keys
chmod 700 /home/hadoop/.ssh/
注意:通常配置完后无法登陆的原因是因为.ssh文件夹和里边相关文件权限不正确的原因。
要注意权限问题。
3、将master的authorized_keys 复制到 node1:/home/hadoop/.ssh/authorized_keys
[hadoop@master ~]$hostname
Master
[hadoop@master ~]$ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:0E:6F:B6
inet addr:192.168.232.142 Bcast:192.168.232.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe0e:6fb6/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1025 errors:0 dropped:0 overruns:0 frame:0
TX packets:699 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:165818 (161.9 KiB) TX bytes:99175 (96.8 KiB)
[hadoop@master ~]$ scp /home/hadoop/.ssh/authorized_keyshadoop@192.168.232.142:/home/hadoop/.ssh/(用户名@IP:存储地址)
authorized_keys 100% 395 0.4KB/s 00:00
注意:
在配置时,出现如下错误:
[hadoop@master ~]$ scp /home/hadoop/.ssh/authorized_keys hadoop@192.168.57.135:/home/hadoop/.ssh
ssh: connect to host 192.168.57.135 port 22: Connection refused
lost connection
原因:sshd服务没有启动,先启动sshd服务后就没问题了。
1)、查看服务是否启用
ps -ef | grep ssh
2)、如果没有启用,则要安装
yum install openssh-server
3)、安装完之后开启
/etc/init.d/sshd start
4)、安装完之后开启
[root@master Desktop]# /etc/init.d/sshd start
Generating SSH1 RSA host key: [ OK ]
Generating SSH2 RSA host key: [ OK ]
Generating SSH2 DSA host key: [ OK ]
Starting sshd: [ OK ]
[root@master Desktop]#
如果/etc/init.d/sshd start出现:
Generating SSH1 RSA host key: [FAILED]
解决办法:
$ yum search openssh
$ sudo yum install openssh
如果已经安装openssh,启动sshd
$ sudo /etc/init.d/sshd start
sshd re-exec requires execution with an absolute path
[honki@localhost ~]$ sudo service sshd start
Generating SSH1 RSA host key: [ OK ]
Generating SSH2 RSA host key: [ OK ]
Generating SSH2 DSA host key: [ OK ]
Starting sshd: [ OK ]
4、修改authorized_keys权限
chmod go-wx .ssh/authorized_keys
5、切换到hadoop用户登录
Ssh node1