Hadoop 2.8的安装、配置与启动
source link: https://note.qidong.name/2018/12/install-hadoop-2.8.5/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Hadoop 2.8的安装、配置与启动
2018-12-18 21:19:41 +08 字数:3143 标签: Hadoop Ansible
简介 ¶
The Apache™ Hadoop® project develops open-source software for reliable, scalable, distributed computing.
Hadoop是Apache旗下的一个开源项目。 2006年项目发布之初,这个项目仅有HDFS和MapReduce两个组件; 而今,这个项目已经有了四个核心组件,加一个Alpha阶段的子项目。
- Hadoop Common: The common utilities that support the other Hadoop modules.
- Hadoop Distributed File System (HDFS™): A distributed file system that provides high-throughput access to application data.
- Hadoop YARN: A framework for job scheduling and cluster resource management.
- Hadoop MapReduce: A YARN-based system for parallel processing of large data sets.
- Hadoop Ozone: An object store for Hadoop.
Hadoop是一个为了大数据存储(HDFS)和处理(MapReduce)而设计的软件。 它部署在多台计算机上,把它们连接成一个集群,并提供分布式的存储、计算解决方案与框架。 现在,这个名称更是代表了一个基于其分布式、集群化理念的生态,包括了Apache旗下的很多其它项目。
但是,无论这个东西在大数据时代有多么好用,基于其分布式特性,安装过程是非常繁琐的。 (在我这,不能容器化简单部署的,都叫繁琐。毕竟我不是专业运维。) 主要分几步:
- 分发并准备各节点
下载 ¶
在Apache Hadoop Dowload页面,下载Hadoop软件包。 目前可选的稳定版有五个。
Version Release 2.9.2 2018-11-19 2.8.5 2018-09-15 3.1.1 2018-08-08 2.7.7 2018-05-31 3.0.3 2018-05-31因为某些原因,选择了2.8.5之后,解压得到如下目录。
$ ls hadoop-2.8.5
bin etc include lib libexec LICENSE.txt NOTICE.txt README.txt sbin share
接下来,需要修改etc
目录下的配置文件。
配置 ¶
默认情况下,Hadoop的配置都在etc/hadoop/
中,有默认值。
参考example-confs,从中选取需要的配置,改改就好。
这里还为了Hadoop准备了几个域名。
hadoop.example.com
,指向Master节点。预计在80端口反向代理管理页面。hdfs.example.com
,指向Master节点。预计在80端口反向代理HDFS目录页面。dn0.example.com
,指向DataNode。dn1.example.com
,指向DataNode。dn2.example.com
,指向DataNode。
简单部署三个节点,不做多余而复杂的事,那么一共有五个配置文件需要修改。
core-site.xml ¶
core-site.xml
主要是指定NameNode的位置。
<configuration>
<property>
<name>local.namenode</name>
<value>hadoop.example.com</value>
</property>
<property>
<name>fs.default.name</name>
<value>hdfs://${local.namenode}:8020</value>
<description>The name of the default file system. Either the
literal string "local" or a host:port for NDFS.
</description>
<final>true</final>
</property>
</configuration>
更多配置参考:https://hadoop.apache.org/docs/r2.8.5/hadoop-project-dist/hadoop-common/core-default.xml
hdfs-site.xml ¶
hdfs-site.xml
是指定DataNode的情况。
<configuration>
<property>
<name>dfs.replication</name>
<value>2</value>
</property>
<property>
<name>dfs.name.dir</name>
<value>/home/hadoop/hdfs/name</value>
<description>Determines where on the local filesystem the DFS name node
should store the name table. If this is a comma-delimited list
of directories then the name table is replicated in all of the
directories, for redundancy. </description>
<final>true</final>
</property>
<property>
<name>dfs.data.dir</name>
<value>/data/hadoop/hdfs/data</value>
<description>Determines where on the local filesystem an DFS data node
should store its blocks. If this is a comma-delimited
list of directories, then data will be stored in all named
directories, typically on different devices.
Directories that do not exist are ignored.
</description>
<final>true</final>
</property>
<property>
<name>dfs.heartbeat.interval</name>
<value>3</value>
<description>Determines datanode heartbeat interval in seconds.
</description>
</property>
<property>
<name>dfs.http.address</name>
<value>0.0.0.0:50070</value>
<description>The name of the default file system. Either the
literal string "local" or a host:port for NDFS.
</description>
<final>true</final>
</property>
<property>
<name>dfs.datanode.ipc.address</name>
<value>0.0.0.0:8025</value>
<description>
The datanode ipc server address and port.
If the port is 0 then the server will start on a free port.
</description>
</property>
</configuration>
其中,dfs.replication
是副本数量,默认3
;这里是小集群,所以选择2
。
通常,副本数量就是在1、2、3、4中选择,再多并无意义。
dfs.data.dir
也很重要,需要指定为机器最大的硬盘,并确保Hadoop的运行用户(一般命名为hadoop
)对这个位置有读写权限。
比如,这里挂载了一块很大的硬盘到/data
下,所以就选择/data/hadoop/hdfs/data
。
如果集群中的大硬盘分区不同,需要针对性地去按节点修改。
更多配置参考:https://hadoop.apache.org/docs/r2.8.5/hadoop-project-dist/hadoop-hdfs/hdfs-default.xml
yarn-site.xml ¶
yarn-site.xml
是Yarn框架的配置,这里主要是指定yarn.resourcemanager.hostname
。
<configuration>
<property>
<name>yarn.resourcemanager.hostname</name>
<value>hadoop.example.com</value>
</property>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<property>
<name>yarn.log-aggregation-enable</name>
<value>true</value>
</property>
</configuration>
更多配置参考:https://hadoop.apache.org/docs/r2.8.5/hadoop-yarn/hadoop-yarn-common/yarn-default.xml
slaves ¶
slaves
文件主要是指定奴隶们……呃不,slave节点。
可以通过IP、域名、hostname(需要修改/etc/hosts
)的方式指定,这里用的是域名。
dn0.example.com
dn1.example.com
dn2.example.com
hadoop-env.sh ¶
hadoop-env.sh
是指定Hadoop的运行环境。
这里有一个不指定就跑不起来的环境变量——JAVA_HOME
。
--- a/hadoop-2.8.5/etc/hadoop/hadoop-env.sh
+++ b/hadoop-2.8.5/etc/hadoop/hadoop-env.sh
@@ -22,7 +22,7 @@
# remote nodes.
# The java implementation to use.
-export JAVA_HOME=${JAVA_HOME}
+export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
# The jsvc implementation to use. Jsvc is required to run secure datanodes
# that bind to privileged ports to provide authentication of data transfer
/usr/lib/jvm/java-8-openjdk-amd64
是Ubuntu 16.04上安装openjdk-8-jdk
的默认位置。
分发与准备各节点 ¶
分发,就是把前面改过配置的整个软件包,复制到所有节点上。
以下为ansible-playbook
示例。
---
- name: Create the user hadoop
user:
name: hadoop
shell: /bin/bash
generate_ssh_key: yes
ssh_key_bits: 2048
# Configurate every ssh public key to every node
# with `ansible -m authorized_key`.
# For example:
# ansible hadoop -m authorized_key -a 'user=hadoop key="ssh-rsa A-COMPLEX-PUBLIC-KEY ansible-generated on HOSTNAME"'
- name: Disable ssh host checking
shell: sed -i 's/# StrictHostKeyChecking ask/ StrictHostKeyChecking no/g' /etc/ssh/ssh_config
- name: Copy hadoop
copy:
src: /tmp/hadoop-2.8.5
dest: /opt/
owner: hadoop
group: hadoop
- name: Install openjdk-8-jdk
apt:
name: openjdk-8-jdk
- name: Add hadoop to PATH
shell: echo 'export PATH=$PATH:/opt/hadoop-2.8.5/bin' > /etc/profile
最大的难点,是在每个节点都配置所有节点的ssh公钥,即注释内容。 先要获取所有节点的公钥,然后再循环配置。
要注意,前面提到了一些节点会有不同的配置,比如dfs.data.dir
需要指定在节点最大的硬盘上。
这需要到对应节点去单独修改配置。
还有,为了保证DataNode在下载时显示正确的域名,需要把相关的节点hostname设置为对应的域名。
启动 ¶
安装和配置完成,就可以启动。 启动前,需要初始化NameNode。
hadoop namenode -format
初始化仅需要做一次,而启动关闭则可以反复执行。
# Start
/opt/hadoop-2.8.5/sbin/start-all.sh
# Stop
/opt/hadoop-2.8.5/sbin/stop-all.sh
这两个脚本都有Deprecated
提示,但当前版本可以忽略。
他们的主要功能,是启动、关闭DFS和Yarn。
本节命令,都需要在新建的
hadoop
用户下执行。
配置systemd ¶
在systemd中配置Hadoop,可以实现开机自启、方便管理。
添加一个/etc/systemd/system/hadoop.service
文件:
[Unit]
Description=Hadoop start/stop
[Service]
User=hadoop
Group=hadoop
Type=oneshot
ExecStart=/opt/hadoop-2.8.5/sbin/start-all.sh
ExecStop=/opt/hadoop-2.8.5/sbin/stop-all.sh
RemainAfterExit=yes
Restart=on-failure
RestartSec=30
[Install]
WantedBy=multi-user.target
重载后生效。
systemctl daemon-reload
systemctl enable hadoop
此后,Hadoop操作可以通过systemctl
来管理。
systemctl start hadoop
systemctl stop hadoop
systemctl restart hadoop
本节命令,都需要在
root
用户下执行。
结果检查 ¶
Hadoop启动后,有两类方式可以检查HDFS是否有效。 一是命令行,二是网页。
命令行可以检查进程是否正常启动。
比如,Master上可执行jps
查看Java进程:
$ jps
5426 NameNode
6386 NodeManager
5895 SecondaryNameNode
27177 Jps
6203 ResourceManager
5628 DataNode
通过保存一个文件,可以测试HDFS是否正常工作。
hdfs dfs -put test.file /
通过50070
端口(本例为http://hadoop.example.com:50070),可以在网页访问Hadoop的信息查看页面。
问题 ¶
反复部署 ¶
在修改配置文件etc/hadoop/*.xml
,调试刚启动的Hadoop时,有时也需要清理数据才能生效。
可能需要频繁执行hadoop namenode -format
进行初始化。
还有些情况,需要删除所有节点的dfs.data.dir
才能生效。
此乃天坑,切记勿乱。
反向DNS查询 ¶
一般的DNS查询,也就是正向查询,是指从域名取IP。 反向DNS查询,就是从IP取域名。
在Hadoop的配置中,即使给dfs.http.address
配置域名,也会被替换为IP。
而对于不支持反向查询的DNS服务器来说,查不到域名,最终会有host=<ip>
的错误。
这会导致DataNode启动成功,却无法连接、显示、使用。
为了避免这个问题,可以在Master节点的/etc/hosts
中配置相关DataNode。
...
10.1.1.1 dn0.example.com
10.1.1.2 dn1.example.com
10.1.1.3 dn2.example.com
参考 ¶
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK