5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

hadoop cluster@docker container

Last updated at Posted at 2015-12-20

・hadoopを1から勉強する為に、とりあえずコンテナ上に環境構築
・手間を省くためsequenceiq/hadoop-dockerを利用する
・下記構成で構築

node name 役割
hadoop1 Namenode/ResourceManager/datanode/NodeManager
hadoop2 datanode/NodeManager
hadoop3 datanode/NodeManager

コンテナイメージを入手

docker pull sequenceiq/hadoop-docker

1ノード目起動

docker run -it --name hadoop1 -h hadoop1 -p 50070:50070 -p 8088:8088 sequenceiq/hadoop-docker /etc/bootstrap.sh -bash
/
Starting sshd:                                             [  OK  ]
Starting namenodes on [hadoop1]
hadoop1: starting namenode, logging to /usr/local/hadoop/logs/hadoop-root-namenode-hadoop1.out
localhost: starting datanode, logging to /usr/local/hadoop/logs/hadoop-root-datanode-hadoop1.out
Starting secondary namenodes [0.0.0.0]
0.0.0.0: starting secondarynamenode, logging to /usr/local/hadoop/logs/hadoop-root-secondarynamenode-hadoop1.out
starting yarn daemons
starting resourcemanager, logging to /usr/local/hadoop/logs/yarn--resourcemanager-hadoop1.out
localhost: starting nodemanager, logging to /usr/local/hadoop/logs/yarn-root-nodemanager-hadoop1.out
bash-4.1# 

2ノード目起動

docker run -it --name hadoop2 -h hadoop2 sequenceiq/hadoop-docker /etc/bootstrap.sh -bash

3ノード目起動

docker run -it --name hadoop3 -h hadoop3 sequenceiq/hadoop-docker /etc/bootstrap.sh -bash

管理画面見ると自動ではクラスタにはならない。。。

停止

bootstrapで単体起動してるので、とりあえずそれぞれ落とす

$HADOOP_PREFIX/sbin/stop-all.sh

hosts設定

それぞれのコンテナで各コンテナのIPを記述

vi /etc/hosts
172.17.0.2	hadoop1
172.17.0.3	hadoop2
172.17.0.4	hadoop3

HDFS設定

以下、masterとなる1号機で実施

データディレクトリ作成

mkdir -p /hdfs/data1

core-site.xml修正

作成したディレクトリの記述を追記

vi /usr/local/hadoop/etc/hadoop/core-site.xml 
<configuration>
   <property>
      <name>fs.defaultFS</name>
      <value>hdfs://hadoop1:9000</value>
   </property>
   <property>
      <name>hadoop.tmp.dir</name>
      <value>/hdfs/data1</value>
   </property>
</configuration>

mapred-site.xml修正

下記を追記

vi mapred-site.xml
    <name>mapred.job.tracker</name>
    <value>hadoop1:8021</value>
    <final>true</final>
  </property>

yarn-site.xml修正

下記を追記

vi yarn-site.xml 
  <property>
   <name>yarn.resourcemanager.resource-tracker.address</name>
   <value>hadoop1:8031</value>
  </property>

slave修正

vi slaves
hadoop1
hadoop2
hadoop3

2〜3ノード目にコピー

rsyncでコピー

rsync -av /usr/local/hadoop/etc/hadoop/ hadoop2:/usr/local/hadoop/etc/hadoop/

rsync -av /usr/local/hadoop/etc/hadoop/ hadoop3:/usr/local/hadoop/etc/hadoop/

初期化

$HADOOP_PREFIX/bin/hadoop namenode -format

起動

1号機で起動

$HADOOP_PREFIX/sbin/start-all.sh

起動確認

jpsコマンドで確認

node1

jps
218 NameNode
769 NodeManager
349 DataNode
663 ResourceManager
481 SecondaryNameNode
1089 Jps

node2〜3

jps
260 Jps
162 NodeManager
61 DataNode

起動確認@WebUI

とりあえず、3台クラスタ構成で起動した

http://192.168.99.100:8088/cluster/nodes
hadoop1.png

http://192.168.99.100:50070/
hadoop2.png

コンテナ再起動対応

bootstrapコメントアウト

コンテナ再起動でコンフィグ初期化&無駄に起動するので動かないようにする。

vi /etc/bootstrap.sh
#!/bin/bash

: ${HADOOP_PREFIX:=/usr/local/hadoop}

$HADOOP_PREFIX/etc/hadoop/hadoop-env.sh

rm /tmp/*.pid

# installing libraries if any - (resource urls added comma separated to the ACP system variable)
cd $HADOOP_PREFIX/share/hadoop/common ; for cp in ${ACP//,/ }; do  echo == $cp; curl -LO $cp ; done; cd -

# altering the core-site configuration
#sed s/HOSTNAME/$HOSTNAME/ /usr/local/hadoop/etc/hadoop/core-site.xml.template > /usr/local/hadoop/etc/hadoop/core-site.xml


service sshd start
#$HADOOP_PREFIX/sbin/start-dfs.sh
#$HADOOP_PREFIX/sbin/start-yarn.sh

if [[ $1 == "-d" ]]; then
  while true; do sleep 1000; done
fi

if [[ $1 == "-bash" ]]; then
  /bin/bash
fi

あとはhostsが毎回初期化される&IP変わるからどーしよ。。
一応コンテナ再起動後、hosts書き換えてnode1でstart-all.sh 叩けばクラスタ状態で起動する。

5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?