CentOS搭建Hadoop单机版遇到的坑

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/madonghyu/article/details/81013581

Hadoop安装

1.hadoop官网
2.选择合适的版本的binary版本,这里博主选择的是hadoop-2.9.0,Linux下使用wget命令直接下载
3.解压tar zxf hadoop-2.9.0.tar.gz


Hadoop启动

1.配置免密登陆,这样启动hadoop就不用每一次都输密码

[root@VM_16_11_centos ~]# ssh-keygen -t rsa -P ""
#在根目录下找到.ssh文件夹,找到id_rsa.pub文件
[root@VM_16_11_centos .ssh]# cat id_rsa.pub > authorized_keys

2.修改hosts文件,这里修改文件十分重要,由于博主只有一台主机,所以没有设置子节点的host名,但是自己主机的host名也要指定,如果按照Linux默认的127.0.0.1的ip访问的话,那么部分节点可能无法访问导致任务失败。

[root@VM_16_11_centos ~]# vim /etc/hosts
127.0.0.1 VM_16_11_centos VM_16_11_centos
127.0.0.1 localhost.localdomain localhost
127.0.0.1 localhost4.localdomain4 localhost4
139.199.158.210 VM_16_11_centos VM_16_11_centos
#加上自己的主机名和ip
#xxx.xxx.xxx.xxx 主机名

# The following lines are desirable for IPv6 capable hosts
::1 VM_16_11_centos VM_16_11_centos
::1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6

3.配置文件
略,由于网上的例子很多,基本上每个版本的配置都差不多,这里就不张贴了,目前还没有遇到过什么大的坑。。。
4.格式化节点hdfs namenode -format,hdfs文件在bin文件夹下。
5.运行,在sbin文件夹下面,这里附上/etc/profile文件的配置,可以不用在hadoop的安装目录下去找到脚本运行

#set hadoop
#自己的hadoop的安装目录
HADOOP_PATH=/usr/local/hadoop-2.9.0
PATH=$PATH:$HADOOP_PATH/sbin
export HADOOP_PATH  PATH
PATH=$PATH:$HADOOP_PATH/bin
export PATH

下面是要运行的两个脚本

start-dfs.sh 
start-yarn.sh

Hadoop的坑

这里在进行上述操作时,可能会遇到一些问题
1. 文件无法修改,即使你是以root用户运行,这个时候用命令chattr -i 文件名就可以了。
2. hadoop启动成功后运行任务的时候莫名其妙就失败了,找不到原因,这个时候我们可以改一下Hadoop的日志输出等级,这里提供一个临时方案export HADOOP_ROOT_LOGGER=DEBUG,console,这样在当前的窗口(并非全局)下hadoop运行的debug日志也将输出,如果要改成全局的话可以修改/etc/profile文件,在里面加入这句话就可以了。


Hadoop检查是否成功配置启动

首先上传个文件到hdfs服务器上,autoClean.sh为上传的文件

[root@VM_16_11_centos ~]# hdfs dfs -put autoClean.sh /test.txt

然后找到hadoop安装目录下的例子,博主的路径是/hadoop-2.9.0/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.9.0.jar
运行hadoop程序,该程序在bin文件夹下

[root@VM_16_11_centos hadoop-2.9.0]# hadoop jar /usr/local/hadoop-2.9.0/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.9.0.jar wordcount  /test.txt /result.txt

猜你喜欢

转载自blog.csdn.net/madonghyu/article/details/81013581