33
31

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.

CentOS 6 に Hadoop をインストールしてみる

Last updated at Posted at 2014-07-24

ESXi 上で CentOS 6.5 x86_64 を使用

Java インストール

今回は jre を RPM でインストールする(jdk の方がいいのか?)
Linux x64 RPMをダウンロード
###RPM インストール

 # wget -4 -P /usr/local/src/ [RPM_URL]
 # mv /usr/local/src/[RPM_URL] /usr/local/src/jre-7-linux-x64.rpm
 # rpm -ivh /usr/local/src/jre-7u65-linux-x64.rpm

###環境変数設定(/etc/profile に追記)

export JAVA_HOME=/usr/java/default
export PATH=$PATH:$JAVA_HOME/bin

Hadoop インストール

###SSH を鍵認証に変更しておく(/etc/ssh/sshd_config)

PasswordAuthentication no
 # /etc/init.d/sshd restart

###hadoop ユーザー作成

 # groupadd hadoop
 # useradd -d /home/hadoop -g hadoop -m hadoop
 # passwd hadoop

###公開鍵設定

 # mkdir /home/hadoop/.ssh
 # chmod 700 /home/hadoop/.ssh
 # ssh-keygen -t rsa -P '' -f /home/hadoop/.ssh/id_rsa
 # cp /home/hadoop/.ssh/id_rsa.pub /home/hadoop/.ssh/authorized_keys
 # chmod 600 /home/hadoop/.ssh/*
 # chown -R hadoop. /home/hadoop/.ssh

パスワードを聞かれずにログイン出来るか確認(hadoop ユーザーで)

 $ ssh localhost
 $
 $ exit

###Hadoop をダウンロード
現在、2 系の RPM が無いため hadoop-2.4.1.tar.gz を使用する

 # wget -4 -P /usr/local/src/ [Hadoop URL]

Hadoop 設置(今回は /usr/local/ に置く)

 # tar zxvf /usr/local/src/hadoop-2.4.1.tar.gz
 # chown -R hadoop. /usr/local/src/hadoop-2.4.1
 # mv /usr/local/src/hadoop-2.4.1 /usr/local/hadoop

###環境変数設定(/etc/profile に追記)

export HADOOP_HOME=/usr/local/hadoop
export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_HOME/lib/native
export HADOOP_OPTS="-Djava.library.path=$HADOOP_HOME/lib"
export PATH=$PATH:$HADOOP_HOME/bin

###Hadoop 設定
/usr/local/hadoop/etc/hadoop/core-site.xml

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
    <property>
        <name>fs.default.name</name>
        <value>hdfs://[HOST]:9000</value>
    </property>
</configuration>

/usr/local/hadoop/etc/hadoop/hadoop-env.sh(何故か JAVA_HOME を認識しないので、追記)

export JAVA_HOME=/usr/java/default

/usr/local/hadoop/etc/hadoop/hdfs-site.xml

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
    <property>
        <name>dfs.replication</name>
        <value>1</value>
    </property>
</configuration>

/usr/local/hadoop/etc/hadoop/mapred-site.xml

 # cp /usr/local/hadoop/etc/hadoop/mapred-site.xml.tmplate /usr/local/hadoop/etc/hadoop/mapred-site.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
    <property>
        <name>mapred.job.tracker</name>
        <value>[HOST]:9001</value>
    </property>
</configuration>

/usr/local/hadoop/etc/hadoop/masters 作成

localhost

/usr/local/hadoop/etc/hadoop/slaves 作成

localhost

sh ファイルのパーミッション変更

 # chmod +x /usr/local/hadoop/etc/hadoop/*.sh

/etc/hosts に追記(ホスト名は example.com とする)

[IP]  example example.com localdomain

###hadoop ユーザーで実行
HDFSのフォーマット

 $ hadoop namenode -format

Hadoopの起動

/usr/local/hadoop/sbin/start-all.sh

###Webコンソールで確認
http://[HOST]:50070 にアクセスし、表示されれば完了

#追記(何かエラー出てる)
jdk に変えて、とりあえず動かしてみたら

WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
WARN conf.Configuration: file:/tmp/hadoop-hadoop/mapred/staging/hadoop429899473/.staging/job_local429899473_0001/job.xml:an attempt to override final parameter: mapreduce.job.end-notification.max.retry.interval;  Ignoring.
WARN conf.Configuration: file:/tmp/hadoop-hadoop/mapred/staging/hadoop429899473/.staging/job_local429899473_0001/job.xml:an attempt to override final parameter: mapreduce.job.end-notification.max.attempts;  Ignoring.
WARN conf.Configuration: file:/tmp/hadoop-hadoop/mapred/local/localRunner/hadoop/job_local429899473_0001/job_local429899473_0001.xml:an attempt to override final parameter: mapreduce.job.end-notification.max.retry.interval;  Ignoring.
WARN conf.Configuration: file:/tmp/hadoop-hadoop/mapred/local/localRunner/hadoop/job_local429899473_0001/job_local429899473_0001.xml:an attempt to override final parameter: mapreduce.job.end-notification.max.attempts;  Ignoring.

こんなの出るし、解析結果 0 バイトで空だし・・・
どうしようか・・・

#さらに追記

サンプルを動かしてみる

hadoop ユーザーで以下を実行

$ hadoop jar /usr/local/hadoop/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.4.1.jar wordcount /input output.wordcount
$ hadoop fs -cat /user/hadoop/output.wordcount

おー、サンプル動いた!
input に置いたテキストから単語出現回数が表示された

33
31
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
33
31

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?