OSX本地Hadoop无法ssh localhost的问题解决

问题描述

生成rsa公私秘钥、拷贝、修改权限

1
2
3
$ ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
$ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
$ chmod 0600 ~/.ssh/authorized_keys

测试ssh localhost

1
2
$ ssh localhost
ssh: connect to host localhost port 22: Connection refused

打开共享-远程连接

image
image

debug模式测试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$ ssh -v localhost
OpenSSH_7.9p1, OpenSSL 1.0.2q 20 Nov 2018
debug1: Reading configuration data /usr/local/etc/ssh/ssh_config
debug1: Connecting to localhost [::1] port 22.
debug1: Connection established.
debug1: identity file /Users/shaozhipeng/.ssh/id_rsa type 0
debug1: identity file /Users/shaozhipeng/.ssh/id_rsa-cert type -1
debug1: identity file /Users/shaozhipeng/.ssh/id_dsa type -1
debug1: identity file /Users/shaozhipeng/.ssh/id_dsa-cert type -1
debug1: identity file /Users/shaozhipeng/.ssh/id_ecdsa type -1
debug1: identity file /Users/shaozhipeng/.ssh/id_ecdsa-cert type -1
debug1: identity file /Users/shaozhipeng/.ssh/id_ed25519 type -1
debug1: identity file /Users/shaozhipeng/.ssh/id_ed25519-cert type -1
debug1: identity file /Users/shaozhipeng/.ssh/id_xmss type -1
debug1: identity file /Users/shaozhipeng/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.9
ssh_exchange_identification: read: Connection reset by peer

仍然报错

1
2
$ ssh localhost
ssh_exchange_identification: read: Connection reset by peer

解决办法

进入/etc/ssh,将目录下的所有文件移动到其他地方备份
当然这时启动ssh会报错

1
2
3
4
5
6
$ /usr/sbin/sshd
Could not load host key: /etc/ssh/ssh_host_rsa_key
Could not load host key: /etc/ssh/ssh_host_dsa_key
Could not load host key: /etc/ssh/ssh_host_ecdsa_key
Could not load host key: /etc/ssh/ssh_host_ed25519_key
sshd: no hostkeys available -- exiting.

重新生成原始文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
$ sudo ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
Generating public/private dsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /etc/ssh/ssh_host_dsa_key.
Your public key has been saved in /etc/ssh/ssh_host_dsa_key.pub.
The key fingerprint is:
SHA256:yUZVG4NeJyJZAgV2D5aYmamor6oEAbaPnPPlc3VwnpY root@root.local
The key's randomart image is:
+---[DSA 1024]----+
|.. +X*+oo+ |
|o . .*o+=o o+. |
|.. . . .+.+.o |
|..= . o .= o |
|.* . . S. E |
|o o o .. o |
| o . o . |
|. . o |
|*. |
+----[SHA256]-----+

$ sudo ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /etc/ssh/ssh_host_rsa_key.
Your public key has been saved in /etc/ssh/ssh_host_rsa_key.pub.
The key fingerprint is:
SHA256:dHgeOp6HwwZznNgALLK19FV80/dPVkxeqt7B1ZYSY2U root@root.local
The key's randomart image is:
+---[RSA 2048]----+
| .. o. . +.Eo|
|. + ... ..o o =o*|
| = + .. o.+. o.o*|
|. . . * * . o.o+|
| + S . . oo.|
| * + . . ..|
| B . . . |
| . o |
| |
+----[SHA256]-----+

$ sudo ssh-keygen -t dsa -f /etc/ssh/ssh_host_ed25519_key
Generating public/private dsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /etc/ssh/ssh_host_ed25519_key.
Your public key has been saved in /etc/ssh/ssh_host_ed25519_key.pub.
The key fingerprint is:
SHA256:2y5jXPOmrdcRew8bpeE2JSvu6xAYH67kuHPWWSsOY0o root@root.local
The key's randomart image is:
+---[DSA 1024]----+
| |
| |
| . . |
| = . + o|
| S + . X |
| + +o.o @ .|
| E.Boo* = B.|
| ..+B++o* o .|
| o= +=O=. |
+----[SHA256]-----+

$ sudo ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key
Generating public/private ecdsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /etc/ssh/ssh_host_ecdsa_key.
Your public key has been saved in /etc/ssh/ssh_host_ecdsa_key.pub.
The key fingerprint is:
SHA256:rKErgmPjdoAvtWQ9fSQAksvFO9EkkU1a+ATW5NsK4U4 root@root.local
The key's randomart image is:
+---[ECDSA 256]---+
|..o*%= |
|...**= |
|...o=o |
|...o..+.. |
|. E.o.+S |
|..* +.oo. |
|.=.o.o.. |
|=++. . |
|+=o.. |
+----[SHA256]-----+

启动sshd服务

1
$ sudo /usr/sbin/sshd

测试ssh localhost

1
2
3
4
5
6
7
8
9
10
$ ssh localhost
The authenticity of host 'localhost (::1)' can't be established.
ECDSA key fingerprint is SHA256:rKErgmPjdoAvtWQ9fSQAksvFO9EkkU1a+ATW5NsK4U4.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
Last login: Thu Dec 13 13:32:15 2018

$ exit
logout
Connection to localhost closed.

正常启动hadoop3.1.1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$ hadoop namenode -format

$ start-dfs.sh
Starting namenodes on [localhost]
Starting datanodes
Starting secondary namenodes [account.jetbrains.com]
account.jetbrains.com: Warning: Permanently added 'account.jetbrains.com,0.0.0.0' (ECDSA) to the list of known hosts.
2018-12-13 13:55:44,502 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable

$ start-yarn.sh
Starting resourcemanager
Starting nodemanagers

$ jps
45633 DataNode
46002 ResourceManager
46099 NodeManager
46164 Jps
45768 SecondaryNameNode
633
45533 NameNode

http://localhost:9870可以查看hadoop状态等信息
yarn管理的application http://localhost:8088

邵志鹏 wechat
扫一扫上面的二维码关注我的公众号
0%