记录一下hdfs集群安装的步骤
准备4台虚拟机 node01、node02、node03、node04
角色:
- NN : NameNode (node01)
- SNN:SecondaryNameNode (node02)
- DN :DataNode (node02、node03、node04)
前置环境
基础环境搭建:见文章:Centos6.5虚拟机环境配置
ssh免密设置 : 见文章:Centos6.5的ssh免密设置
去官网下载hadoop-2.6.5.tar.gz,并上传到centos上,如目录:/root/mmm/中
node01上安装hadoop
解压并拷贝hadoop到指定目录
[root@node01 ~]# cd mmm
[root@node01 mmm]# ll
总用量 306352
-rw-r--r--. 1 root root 199635269 5月 30 20:28 hadoop-2.6.5.tar.gz
-rw-r--r--. 1 root root 114063112 5月 30 20:28 jdk-8u291-linux-x64.rpm
[root@node01 mmm]# tar xf hadoop-2.6.5.tar.gz
[root@node01 mmm]# mkdir /opt/bigdata
[root@node01 mmm]# cp -rf hadoop-2.6.5 /opt/bigdata/
配置Hadoop的环境变量
[root@node01 ~]# vi /etc/profile
export JAVA_HOME=/usr/java/default
export HADOOP_HOME=/opt/bigdata/hadoop-2.6.5
export PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
[root@node01 ~]# source /etc/profile
修改配置文件
/opt/bigdata/hadoop-2.6.5/etc/hadoop目录下修改配置文件
- hadoop-env.sh
修改Java环境变量,因为要免密执行脚本,不能使用变量名称,只能使用具体Java环境变量的路径- core-site.xml
设置NameNode在node01节点上- hdfs-site.xml
设置SecondaryNameNode在node02节点上和DataNode
设置副本数
设置NN、SNN、DN存储目录- slaves
设置DataNode的节点为:node02、node03、node04
[root@node01 ~]# cd /opt/bigdata/hadoop-2.6.5/etc/hadoop
[root@node01 hadoop]# vi hadoop-env.sh
export JAVA_HOME=/usr/java/default
##
[root@node01 hadoop]# vi core-site.xml
<configuration>
<!-- 设置hdfs的NameNode节点是node01,默认端口9000 -->
<property>
<name>fs.defaultFS</name>
<value>hdfs://node01:9000</value>
</property>
</configuration>
[root@node01 hadoop]# vi hdfs-site.xml
<configuration>
<!-- 只有3个DN节点,设置副本数位2 -->
<property>
<name>dfs.replication</name>
<value>2</value>
</property>
<!-- 设置NameNode存储路径 -->
<property>
<name>dfs.namenode.name.dir</name>
<value>/var/bigdata/hadoop/full/dfs/name</value>
</property>
<!-- 设置DataNode存储路径 -->
<property>
<name>dfs.datanode.data.dir</name>
<value>/var/bigdata/hadoop/full/dfs/data</value>
</property>
<!-- 设置SecondaryNameNode在node02节点上 -->
<property>
<name>dfs.namenode.secondary.http-address</name>
<value>node02:50090</value>
</property>
<!-- 设置SecondaryNameNode存储路径 -->
<property>
<name>dfs.namenode.checkpoint.dir</name>
<value>/var/bigdata/hadoop/full/dfs/secondary</value>
</property>
</configuration>
[root@baseimage hadoop]# vi slaves
node02
node03
node04
配置node02~04节点
分发/opt/bigdata目录到其它三个节点上
[root@node01 hadoop]# cd /opt
[root@node01 opt]# scp -r ./bigdata/ node02:`pwd`
[root@node01 opt]# scp -r ./bigdata/ node03:`pwd`
[root@node01 opt]# scp -r ./bigdata/ node04:`pwd`
分发profile文件到其它节点上
[root@node01 opt]# cd /etc
[root@node01 etc]# scp ./profile node02:`pwd`
profile 100% 1944 1.9KB/s 00:00
[root@node01 etc]# scp ./profile node03:`pwd`
profile 100% 1944 1.9KB/s 00:00
[root@node01 etc]# scp ./profile node04:`pwd`
profile 100% 1944 1.9KB/s 00:00
[root@node01 etc]#
使profile生效
[root@node02 ~]# source /etc/profile
[root@node03 ~]# source /etc/profile
[root@node04 ~]# source /etc/profile
node01节点格式化
[root@node01 etc]# cd /opt/bigdata/hadoop-2.6.5
[root@node01 hadoop-2.6.5]# hdfs namenode -format
验证生成的目录
node01节点
[root@node01 hadoop-2.6.5]# ll /var/bigdata/hadoop/full/dfs/name/current/
fsimage_0000000000000000000 seen_txid
fsimage_0000000000000000000.md5 VERSION
启动hdfs
[root@node01 hadoop-2.6.5]# start-dfs.sh
22/06/02 18:33:31 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Starting namenodes on [node01]
node01: starting namenode, logging to /opt/bigdata/hadoop-2.6.5/logs/hadoop-root-namenode-node01.out
node04: starting datanode, logging to /opt/bigdata/hadoop-2.6.5/logs/hadoop-root-datanode-node04.out
node02: starting datanode, logging to /opt/bigdata/hadoop-2.6.5/logs/hadoop-root-datanode-node02.out
node03: starting datanode, logging to /opt/bigdata/hadoop-2.6.5/logs/hadoop-root-datanode-node03.out
Starting secondary namenodes [node02]
node02: starting secondarynamenode, logging to /opt/bigdata/hadoop-2.6.5/logs/hadoop-root-secondarynamenode-node02.out
22/06/02 18:33:47 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
验证
node01
[root@node01 hadoop-2.6.5]# jps
122933 NameNode
125016 Jps
[root@node01 hadoop-2.6.5]#
node02
[root@node02 ~]# jps
106641 Jps
104436 DataNode
104582 SecondaryNameNode
[root@node02 ~]#
node03
[root@node03 .ssh]# jps
124539 Jps
122252 DataNode
[root@node03 .ssh]#
node04
[root@node04 .ssh]# jps
124987 Jps
122460 DataNode
[root@node04 .ssh]#
windos验证
访问地址:http://node01的ip:50070