CentOS
#配置Hadoop
假设配置3台服务器:
192.168.100.1 node1 (master)
192.168.100.2 node2 (slave1)
192.168.100.3 node3 (slave2)
在/etc/hosts中添加机器名配置:(将下面内容添加到/etc/hosts中)
192.168.100.1 node1
192.168.100.2 node2
192.168.100.3 node3
###创建用户
$ useradd hadoop
$ cd /home/hadoop
###配置NameNode(node1)的ssh无需密码登录
#####安装SSH:
sudo apt-get install ssh
或
yum install ssh
#####SSH无密码登录
使用root编辑 /etc/ssh/sshd_config 将下面3个配置前面的注释去掉
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
然后重启ssh服务: service sshd restart
3台机器都需要修改
####创建id_rsa
$ ssh-keygen -t rsa
生成密钥对,会询问密码,直接回车采用默认路径,直到结束
$ cd /home/hadoop/.ssh
$ cp id_rsa.pub authorized_keys
测试
$ ssh localhost
$ ssh node1
第一次ssh会有提示信息:
The authenticity of host ‘node1 (192.168.100.1)’ can’t be established.
RSA key fingerprint is 03:e0:30:cb:6e:13:a8:70:c9:7e:cf:ff:33:2a:67:30.
Are you sure you want to continue connecting (yes/no)?
输入yes
如果不需要密码,则连接成功
在node2和node3上,分别执行:
$ su hadoop
$ cd /home/hadoop
$ ssh-keygen -t rsa
回到node1上:
$ scp authorized_keys node2:/home/hadoop/.ssh/
$ scp authorized_keys node3:/home/hadoop/.ssh/
或:
$ cat id_rsa.pub | ssh hadoop@node2 'cat - >> ~/.ssh/authorized_keys'
$ cat id_rsa.pub | ssh hadoop@node3 'cat - >> ~/.ssh/authorized_keys'
这里需要输入node2和node3密码
测试是否成功:
$ ssh node2
$ ssh node3
######在CentOS中,如果还是需要输入密码,可以执行下面的命令:(否则权限太大,CentOS不让通过?)
chmod 600 .ssh/authorized_keys
chmod 700 .ssh