一、环境准备
1、安装JDK
(1)卸载自带的jdk
[root@bda1 .ssh]# rpm -qa | grep java 查看已经安装的jdk
libvirt-java-devel-0.4.9-4.el7.noarch
java-1.7.0-openjdk-headless-1.7.0.111-2.6.7.8.el7.x86_64
java-1.8.0-openjdk-1.8.0.102-4.b14.el7.x86_64
java-1.6.0-openjdk-1.6.0.40-1.13.12.9.el7.x86_64
tzdata-java-2016g-2.el7.noarch
libvirt-java-0.4.9-4.el7.noarch
java-1.7.0-openjdk-1.7.0.111-2.6.7.8.el7.x86_64
python-javapackages-3.4.1-11.el7.noarch
java-1.8.0-openjdk-devel-1.8.0.102-4.b14.el7.x86_64
java-1.8.0-openjdk-headless-1.8.0.102-4.b14.el7.x86_64
java-1.6.0-openjdk-devel-1.6.0.40-1.13.12.9.el7.x86_64
javapackages-tools-3.4.1-11.el7.noarch
java-1.7.0-openjdk-devel-1.7.0.111-2.6.7.8.el7.x86_64
javamail-1.4.6-8.el7.noarch
卸载openjdk1.8
rpm -e --nodeps java-1.8.0-openjdk-1.8.0.102-4.b14.el7.x86_64
rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.102-4.b14.el7.x86_64
rpm -e --nodeps java-1.8.0-openjdk-devel-1.8.0.102-4.b14.el7.x86_64
卸载openjdk1.7
rpm -e --nodeps java-1.7.0-openjdk-1.7.0.111-2.6.7.8.el7.x86_64
rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.111-2.6.7.8.el7.x86_64
rpm -e --nodeps java-1.7.0-openjdk-devel-1.7.0.111-2.6.7.8.el7.x86_64
卸载openjdk1.6
rpm -e --nodeps java-1.6.0-openjdk-1.6.0.40-1.13.12.9.el7.x86_64
rpm -e --nodeps java-1.6.0-openjdk-devel-1.6.0.40-1.13.12.9.el7.x86_64
验证如下表示已经卸载完成
[root@bda1 .ssh]# java -version
-bash: /usr/bin/java: 没有那个文件或目录
(2)安装jdk
jdk-8u131-linux-x64.tar.gz
[root@localhost software]# mkdir /usr/java
创建cdh默认的jdk目录,jdk必须放在此目录下,否则可能会出现运行出错
[root@localhost software]# tar -zxf jdk-8u131-linux-x64.tar.gz -C /usr/java/ 解压
[root@bda1 java]# vi /etc/profile 在文件末尾新增如下配置
export JAVA_HOME=/usr/java/jdk1.8.0_131
export CLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib
export PATH=$PATH:$JAVA_HOME/bin
[root@localhost java]# source /etc/profile 是配置生效
验证:查看java版本
[root@localhost java]# java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
2、创建hadoop用户
[root@localhost ~]#useradd hadoop 添加hadoop用户,默认会创建hadoop用户组
[root@localhost ~]#id hadoop 查看hadoop用户信息
uid=515(hadoop) gid=515(hadoop) groups=515(hadoop)
[root@localhost ~]#vi /etc/sudoers 在/etc/sudoers 文件中增加以下配置,使得hadoop用户获得root免密码权限
hadoop ALL=(root) NOPASSWD:ALL
[root@localhost ~]# su - hadoop 切换到hadoop用户
二、安装及配置
1、下载安装包
wget http://archive.cloudera.com/cdh5/cdh/5/hadoop-2.6.0-cdh5.12.1.tar.gz
tar -zxf hadoop-2.6.0-cdh5.12.1.tar.gz -C ~/app 解压到家目录的app目录下
2、修改配置文件
(1) $HADOOP_HOME/etc/hadoop/hadoop-env.sh 修改JAVA_HOME为安装的jdk目录
# The java implementation to use.
export JAVA_HOME=/usr/java/jdk1.8.0_131
(2) $HADOOP_HOME/etc/hadoop/core-site.xml hadoop核心配置中增加hdfs默认的访问路径,红色部分为xin
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://bda1:9000</value>
</property>
</configuration>
(3) $HADOOP_HOME/etc/hadoop/hdfs-site.xml
<configuration>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
</configuration>
3、使用hadoop用户配置免密码登录
[root@bda1 ~]# su - hadoop
[hadoop@bda1 ~]$ ssh-keygen -t rsa 回车后,会提示三次输入信息,我们直接回车即可。(直接三次回车即可)
[hadoop@bda1 .ssh]$ cp .ssh/id_rsa.pub .ssh/iauthorized_keys
[hadoop@bda1 .ssh]$ ssh bda1 date 免密码验证,打印如下信息则配置成功
Mon Jan 15 21:22:02 CST 2018
4、格式化
[hadoop@bda1 hadoop-2.6.0-cdh5.12.1]$ bin/hdfs namenode -format
5、启动hdfs服务
[hadoop@bda1 hadoop-2.6.0-cdh5.12.1]$ sbin/start-dfs.sh
6、验证
http://192.168.237.181:50070/ 可通过web进行访问,至此hadoop单机版安装完成