搭建Hadoop完全分布式环境
node01 | node02 | node03 | node04 |
---|---|---|---|
NameNode | SecondaryNameNode | ||
DataNode01 | DataNode02 | DataNode03 |
- 配置node01、node02、node03、node04上的免密钥登录
在node02、node03、node04上生成密钥:
ssh-keygen
保证node01、node02、node03、node04上都有四台主机的公钥:
ssh-copy-id -i ~/.ssh/id_rsa.pub node01
- 安装node02、node03、node04上的Hadoop和JDK
tar -zxvf hadoop-3.1.1.tar.gz -C /opt/hadoop/
rpm -ivh jdk-8u172-linux-x64.rpm
- 配置node02、node03、node04上的环境变量
将node01上的
/etc/profile
拷贝到node02、node03、node04:
scp /etc/profile node02:/etc/ && scp /etc/profile node03:/etc/ && scp /etc/profile node04:/etc/
在node02、node03、node04上运行:
. /etc/profile
- 配置node01、node02、node03、node04上的Hadoop
在node01上修改
/opt/hadoop/hadoop-3.1.1/etc/hadoop/core-site.xml
:
vim /opt/hadoop/hadoop-3.1.1/etc/hadoop/core-site.xml
添加:<configuration> <!-- HDFS的URI,同时也表明NameNode运行在node01上 --> <property> <name>fs.defaultFS</name> <value>hdfs://node01:9000</value> </property> <property> <name>hadoop.tmp.dir</name> <value>/opt/hadoop/data/tmp/full</value> </property> </configuration>
在node01上修改
/opt/hadoop/hadoop-3.1.1/etc/hadoop/hdfs-site.xml
:
vim /opt/hadoop/hadoop-3.1.1/etc/hadoop/hdfs-site.xml
添加:<configuration> <property> <name>dfs.replication</name> <value>2</value> </property> <property> <name>dfs.namenode.secondary.http-address</name> <value>node02:9868</value> </property> </configuration>
在node01上修改
/opt/hadoop/hadoop-3.1.1/etc/hadoop/workers
:
vim /opt/hadoop/hadoop-3.1.1/etc/hadoop/workers
添加:node02 node03 node04
将node01上的
/opt/hadoop/hadoop-3.1.1/etc/hadoop/core-site.xml
、/opt/hadoop/hadoop-3.1.1/etc/hadoop/hdfs-site.xml
、/opt/hadoop/hadoop-3.1.1/etc/hadoop/workers
拷贝到node02、node03、node04:
scp /opt/hadoop/hadoop-3.1.1/etc/hadoop/core-site.xml /opt/hadoop/hadoop-3.1.1/etc/hadoop/hdfs-site.xml /opt/hadoop/hadoop-3.1.1/etc/hadoop/workers node02:/opt/hadoop/hadoop-3.1.1/etc/hadoop/ && scp /opt/hadoop/hadoop-3.1.1/etc/hadoop/core-site.xml /opt/hadoop/hadoop-3.1.1/etc/hadoop/hdfs-site.xml /opt/hadoop/hadoop-3.1.1/etc/hadoop/workers node03:/opt/hadoop/hadoop-3.1.1/etc/hadoop/ && scp /opt/hadoop/hadoop-3.1.1/etc/hadoop/core-site.xml /opt/hadoop/hadoop-3.1.1/etc/hadoop/hdfs-site.xml /opt/hadoop/hadoop-3.1.1/etc/hadoop/workers node04:/opt/hadoop/hadoop-3.1.1/etc/hadoop/
- 格式化Hadoop
在node01上运行:
hdfs namenode -format
- 启动Hadoop
在node01/node02/node03/node04上运行:
start-dfs.sh
- 查看进程
在node01、node02、node03、node04上运行:
jps
- 访问网页
NameNode:http://192.168.163.191:9870
SecondaryNameNode:http://192.168.163.192:9868
DataNode01:http://192.168.163.192:9864
DataNode02:http://192.168.163.193:9864
DataNode03:http://192.168.163.194:9864