Hadoop 2.7.1 搭建

1 目的
将hadoop 2.7.1 安装到 166、167、168 三台机器上
2 提供环境
练习环境
192.168.0.166 master 192.168.0.167 slave01 192.168.0.168 slave02 user:hadoop passwd: hadoop
3 准备工作
检查环境
1)服务器是否可登录
三台可正常登录
ssh user@ip 输入 passwd

2)是否有权限进行写操作
有权限
3)硬盘是否有空间供操作
df -lh
4)检查hadoop环境依赖
[hadoop@master ~]$uname -a Linux 2.6.32-504.30.3.el6.x86_64

[hadoop@master ~]$ java -version java version "1.8.0_60" Java(TM) SE Runtime Environment (build 1.8.0_60-b27) Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)

openssh

准备安装文件
jdk-8u60-linux-x64.rpm hadoop-2.7.1.tar.gz
会用到命令
scp rpm ssh
配置hostname
三台机器配置一样
vi /etc/hosts 192.168.0.166 master 192.168.0.167 slave01 192.168.0.168 slave02
master
[hadoop@master backup]$ cat /etc/sysconfig/network NETWORKING=yes HOSTNAME=master
slave01
[hadoop@slave01 logs]$ cat /etc/sysconfig/network NETWORKING=yes HOSTNAME=slave01
slave02
[hadoop@slave02 ~]$ cat /etc/sysconfig/network NETWORKING=yes HOSTNAME=slave02

4 正式安装
配置环境变量
vi .bashrc export JAVA_HOME=/usr/java/jdk1.8.0_60 export HADOOP_HOME=/home/hadoop/bigdata/hadoop export HADOOP_USER_NAME=hadoop export PATH=$JAVA_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$PATH
JAVA_HOME 表示java 安装目录
HADOOP_HOME 表示hadoop 安装目录
HADOOP_USER_NAME 表示安装hadoop时 需要用到的用户
source .bashrc
验证环境变量
[hadoop@master ~]$ echo $HADOOP_HOME /home/hadoop/bigdata/hadoop [hadoop@master ~]$ echo $JAVA_HOME /usr/java/jdk1.8.0_60 [hadoop@master ~]$ java -version java version "1.8.0_60" Java(TM) SE Runtime Environment (build 1.8.0_60-b27) Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
拷贝到slave机器
scp .bashrc hadoop@192.168.0.167:/home/hadoop/ scp .bashrc hadoop@192.168.0.168:/home/hadoop/
验证slave 配置
slave01
ssh hadoop@192.168.0.167 source .bashrc [hadoop@slave01 ~]$ echo $HADOOP_HOME /home/hadoop/bigdata/hadoop [hadoop@slave01 ~]$ [hadoop@slave01 ~]$ echo $JAVA_HOME /usr/java/jdk1.8.0_60 [hadoop@slave01 ~]$ java -version java version "1.8.0_60" Java(TM) SE Runtime Environment (build 1.8.0_60-b27) Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)

slave02
ssh hadoop@192.168.0.168 source .bashrc [hadoop@slave02 ~]$ echo $HADOOP_HOME /home/hadoop/bigdata/hadoop [hadoop@slave02 ~]$ [hadoop@slave02 ~]$ echo $JAVA_HOME /usr/java/jdk1.8.0_60 [hadoop@slave02 ~]$ java -version java version "1.8.0_60" Java(TM) SE Runtime Environment (build 1.8.0_60-b27) Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode) [hadoop@slave02 ~]$
配置无密码登录
目的
登录方便
传输文件方便
master
操作目录 /home/hadoop/.ssh
+-生成公钥
[hadoop@master .ssh]$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/home/hadoop/.ssh/id_rsa): /home/hadoop/.ssh/id_rsa already exists. Overwrite (y/n)? y Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/hadoop/.ssh/id_rsa. Your public key has been saved in /home/hadoop/.ssh/id_rsa.pub. The key fingerprint is: 26:88:c4:9e:98:cb:b5:ff:36:ee:36:9d:8b:15:f4:48 hadoop@master The key's randomart image is: +--[ RSA 2048]----+ | | | . | | o E | | = o . o o | |o +.. . So . | |... . o . | |.. . ... | | . =oo | | .*=o.. | +-----------------+ [hadoop@master .ssh]$ ls -lh total 16K -rwxrwx---. 1 hadoop hadoop 396 Jan 16 04:06 authorized_keys -rw-------. 1 hadoop hadoop 1.7K Jan 16 12:39 id_rsa -rw-r--r--. 1 hadoop hadoop 395 Jan 16 12:39 id_rsa.pub -rw-r--r--. 1 hadoop hadoop 2.7K Jan 14 15:11 known_hosts [hadoop@master .ssh]$ date Sat Jan 16 12:43:06 CST 2016 [hadoop@master .ssh]$
拷贝slave01 slave02 到master
复制slave01 机器上的id_rsa.pub 的内容 到master 的 authorized_keys 文件中
复制slave02 机器上的id_rsa.pub 的内容 到master 的 authorized_keys 文件中
scp hadoop@192.168.0.167:/home/hadoop/.ssh/id_rsa.pub /home/hadoop/.ssh/167.pub scp hadoop@192.168.0.168:/home/hadoop/.ssh/id_rsa.pub /home/hadoop/.ssh/168.pub cat 167.pub >> /home/hadoop/.ssh/authorized_keys cat 168.pub >> /home/hadoop/.ssh/authorized_keys
设置权限
chmod 600 authorized_keys
验证 无密码登录
ssh 192.168.0.167 ssh 192.168.0.168
slave01
操作目录 /home/hadoop/.ssh
生成公钥
ssh-keygen
拷贝master slave02 到slave01
复制master 机器上的id_rsa.pub 的内容 到slave01 的 authorized_keys 文件中
复制slave02 机器上的id_rsa.pub 的内容 到slave01 的 authorized_keys 文件中
scp hadoop@192.168.0.166:/home/hadoop/.ssh/id_rsa.pub /home/hadoop/.ssh/166.pub scp hadoop@192.168.0.168:/home/hadoop/.ssh/id_rsa.pub /home/hadoop/.ssh/168.pub cat 166.pub >> /home/hadoop/.ssh/authorized_keys cat 168.pub >> /home/hadoop/.ssh/authorized_keys
设置权限
chmod 600 authorized_keys
验证 无密码登录
ssh 192.168.0.166 ssh 192.168.0.168
slave02
操作目录 /home/hadoop/.ssh
生成公钥
ssh-keygen
拷贝master slave01 到slave02
复制master 机器上的id_rsa.pub 的内容 到slave02 的 authorized_keys 文件中
复制slave01 机器上的id_rsa.pub 的内容 到slave02的 authorized_keys 文件中
scp hadoop@192.168.0.166:/home/hadoop/.ssh/id_rsa.pub /home/hadoop/.ssh/166.pub scp hadoop@192.168.0.167:/home/hadoop/.ssh/id_rsa.pub /home/hadoop/.ssh/167.pub cat 166.pub >> /home/hadoop/.ssh/authorized_keys cat 167.pub >> /home/hadoop/.ssh/authorized_keys
设置权限
chmod 600 authorized_keys
验证 无密码登录
ssh 192.168.0.166 ssh 192.168.0.167
配置hadoop
将hadoop 安装文件复制到 master机器
scp hadoop-2.7.1.tar.gz hadoop@192.168.0.166:/home/hadoop/
解压缩和改目录
tar -zxf hadoop-2.7.1.tar.gz mkdir bigdata mv hadoop-2.7.1 bigdata/ cd bigdata/ mv hadoop-2.7.1 hadoop
配置文件
文件在/home/hadoop/bigdata/hadoop/etc/hadoop
需修改的文件
core-site.xml
<configuration> <property> <name>fs.defaultFS</name> <value>hdfs://192.168.0.166:9000/</value> </property> <property> <name>hadoop.tmp.dir</name> <value>/home/hadoop/bigdata/data/hadoop/tmp</value>    </property> </configuration>
hdfs-site.xml
<configuration> <property> <name>dfs.namenode.secondary.http-address</name> <value>master:9001</value> </property> <property> <name>dfs.datanode.data.dir</name> <value>file:/home/hadoop/bigdata/data/hadoop/hdfs/datanode</value> </property> <property> <name>dfs.namenode.name.dir</name> <value>file:/home/hadoop/bigdata/data/hadoop/hdfs/namenode</value> </property> <property> <name>dfs.replication</name> <value>3</value> </property> </configuration>

mapred-site.xml
<configuration> <property> <name>mapreduce.framework.name</name> <value>yarn</value> </property> </configuration>

yarn-site.xml
<configuration> <property> <name>yarn.resourcemanager.hostname</name> <value>master</value> </property> <property> <name>yarn.nodemanager.aux-services</name> <value>mapreduce_shuffle</value> </property> </configuration>

slaves
slave01 slave02

+-将配置好的复制到slave
chmod -R 777 /home/hadoop/bigdata/data/hadoop/tmp cd /home/hadoop tar -czf bigdata.tar.gz bigdata/ scp bigdata.tar.gz 192.168.0.167:/home/hadoop/ scp bigdata.tar.gz 192.168.0.168:/home/hadoop/
slave01
tar -zxf bigdata.tar.gz
slave02
tar -zxf bigdata.tar.gz
+-启动hadoop
启动命令在:/home/hadoop/bigdata/hadoop/sbin
[hadoop@master sbin]$ hdfs namenode -format [hadoop@master sbin]$ ./start-all.sh This script is Deprecated. Instead use start-dfs.sh and start-yarn.sh 16/01/16 15:13:44 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable Starting namenodes on [master] master: starting namenode, logging to /home/hadoop/bigdata/hadoop/logs/hadoop-hadoop-namenode-master.out slave02: starting datanode, logging to /home/hadoop/bigdata/hadoop/logs/hadoop-hadoop-datanode-slave02.out slave01: starting datanode, logging to /home/hadoop/bigdata/hadoop/logs/hadoop-hadoop-datanode-slave01.out Starting secondary namenodes [master] master: starting secondarynamenode, logging to /home/hadoop/bigdata/hadoop/logs/hadoop-hadoop-secondarynamenode-master.out 16/01/16 15:15:01 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable starting yarn daemons starting resourcemanager, logging to /home/hadoop/bigdata/hadoop/logs/yarn-hadoop-resourcemanager-master.out slave02: starting nodemanager, logging to /home/hadoop/bigdata/hadoop/logs/yarn-hadoop-nodemanager-slave02.out slave01: starting nodemanager, logging to /home/hadoop/bigdata/hadoop/logs/yarn-hadoop-nodemanager-slave01.out [hadoop@master sbin]$

master
[hadoop@master sbin]$ jps 13952 Jps 13350 NameNode 13543 SecondaryNameNode 13695 ResourceManager
slave01
[hadoop@slave01 logs]$ jps 3664 NodeManager 3560 DataNode 3800 Jps
slave02
[hadoop@slave02 ~]$ jps 3907 Jps 3875 NodeManager 3771 DataNode
+-遇到的问题
Could not resolve hostname localhost: Name or service not known
slaves 没有配置
slave 没有启动
/etc/hosts 没有配置
2016-01-16 14:52:06,957 ERROR org.apache.hadoop.hdfs.server.namenode.NameNode: Failed to start namenode. java.io.IOException: NameNode is not formatted. at org.apache.hadoop.hdfs.server.namenode.FSImage.recoverTransitionRead(FSImage.java:225) at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.loadFSImage(FSNamesystem.java:975) at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.loadFromDisk(FSNamesystem.java:681) at org.apache.hadoop.hdfs.server.namenode.NameNode.loadNamesystem(NameNode.java:584) at org.apache.hadoop.hdfs.server.namenode.NameNode.initialize(NameNode.java:644) at org.apache.hadoop.hdfs.server.namenode.NameNode.(NameNode.java:811) at org.apache.hadoop.hdfs.server.namenode.NameNode.(NameNode.java:795) at org.apache.hadoop.hdfs.server.namenode.NameNode.createNameNode(NameNode.java:1488) at org.apache.hadoop.hdfs.server.namenode.NameNode.main(NameNode.java:1554) 2016-01-16 14:52:06,963 INFO org.apache.hadoop.util.ExitUtil: Exiting with status 1
namenode 没有格式化
hdfs namenode -format

5 验证
master
[hadoop@master sbin]$ hdfs dfsadmin -report 16/01/16 15:16:52 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable Configured Capacity: 19391348736 (18.06 GB) Present Capacity: 12925202432 (12.04 GB) DFS Remaining: 12925153280 (12.04 GB) DFS Used: 49152 (48 KB) DFS Used%: 0.00% Under replicated blocks: 0 Blocks with corrupt replicas: 0 Missing blocks: 0

Missing blocks (with replication factor 1): 0 Live datanodes (2): Name: 192.168.0.167:50010 (slave01) Hostname: slave01 Decommission Status : Normal Configured Capacity: 9695674368 (9.03 GB) DFS Used: 24576 (24 KB) Non DFS Used: 3649736704 (3.40 GB) DFS Remaining: 6045913088 (5.63 GB) DFS Used%: 0.00% DFS Remaining%: 62.36% Configured Cache Capacity: 0 (0 B) Cache Used: 0 (0 B) Cache Remaining: 0 (0 B) Cache Used%: 100.00% Cache Remaining%: 0.00% Xceivers: 1 Last contact: Sat Jan 16 15:16:53 CST 2016 Name: 192.168.0.168:50010 (slave02) Hostname: slave02 Decommission Status : Normal Configured Capacity: 9695674368 (9.03 GB) DFS Used: 24576 (24 KB) Non DFS Used: 2816409600 (2.62 GB) DFS Remaining: 6879240192 (6.41 GB) DFS Used%: 0.00% DFS Remaining%: 70.95% Configured Cache Capacity: 0 (0 B) Cache Used: 0 (0 B) Cache Remaining: 0 (0 B) Cache Used%: 100.00% Cache Remaining%: 0.00% Xceivers: 1 Last contact: Sat Jan 16 15:16:53 CST 2016

测试存储
[hadoop@master hadoop]$hdfs dfs -mkdir /test [hadoop@master hadoop]$ hdfs dfs -ls / drwxr-xr-x - hadoop supergroup 0 2016-01-16 15:19 /test [hadoop@master hadoop]$ hdfs dfs -copyFromLocal ./NOTICE.txt /test [hadoop@master hadoop]$ [hadoop@master hadoop]$ hdfs dfs -ls /test Found 1 items -rw-r--r-- 3 hadoop supergroup 101 2016-01-16 15:21 /test/NOTICE.txt

测试计算
[hadoop@master hadoop]$ hadoop jar ./share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.1.jar wordcount /test/NOTICE.txt /output03 16/01/16 15:24:58 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable 16/01/16 15:25:00 INFO client.RMProxy: Connecting to ResourceManager at master/192.168.0.166:8032 16/01/16 15:25:02 INFO input.FileInputFormat: Total input paths to process : 1 16/01/16 15:25:03 INFO mapreduce.JobSubmitter: number of splits:1 16/01/16 15:25:03 INFO mapreduce.JobSubmitter: Submitting tokens for job: job_1452928505894_0001 16/01/16 15:25:04 INFO impl.YarnClientImpl: Submitted application application_1452928505894_0001 16/01/16 15:25:04 INFO mapreduce.Job: The url to track the job: http://master:8088/proxy/application_1452928505894_0001/ 16/01/16 15:25:04 INFO mapreduce.Job: Running job: job_1452928505894_0001 16/01/16 15:25:22 INFO mapreduce.Job: Job job_1452928505894_0001 running in uber mode : false 16/01/16 15:25:22 INFO mapreduce.Job: map 0% reduce 0% 16/01/16 15:25:30 INFO mapreduce.Job: map 100% reduce 0% 16/01/16 15:25:43 INFO mapreduce.Job: map 100% reduce 100% 16/01/16 15:25:43 INFO mapreduce.Job: Job job_1452928505894_0001 completed successfully 16/01/16 15:25:44 INFO mapreduce.Job: Counters: 49 File System Counters FILE: Number of bytes read=173 FILE: Number of bytes written=231305 FILE: Number of read operations=0 FILE: Number of large read operations=0 FILE: Number of write operations=0 HDFS: Number of bytes read=207 HDFS: Number of bytes written=123 HDFS: Number of read operations=6 HDFS: Number of large read operations=0 HDFS: Number of write operations=2 Job Counters Launched map tasks=1 Launched reduce tasks=1 Data-local map tasks=1 Total time spent by all maps in occupied slots (ms)=6503 Total time spent by all reduces in occupied slots (ms)=9816 Total time spent by all map tasks (ms)=6503 Total time spent by all reduce tasks (ms)=9816 Total vcore-seconds taken by all map tasks=6503 Total vcore-seconds taken by all reduce tasks=9816 Total megabyte-seconds taken by all map tasks=6659072 Total megabyte-seconds taken by all reduce tasks=10051584 Map-Reduce Framework Map input records=2 Map output records=11 Map output bytes=145 Map output materialized bytes=173 Input split bytes=106 Combine input records=11 Combine output records=11 Reduce input groups=11 Reduce shuffle bytes=173 Reduce input records=11 Reduce output records=11 Spilled Records=22 Shuffled Maps =1 Failed Shuffles=0 Merged Map outputs=1 GC time elapsed (ms)=257 CPU time spent (ms)=1870 Physical memory (bytes) snapshot=288600064 Virtual memory (bytes) snapshot=4119134208 Total committed heap usage (bytes)=138178560 Shuffle Errors BAD_ID=0 CONNECTION=0 IO_ERROR=0 WRONG_LENGTH=0 WRONG_MAP=0 WRONG_REDUCE=0 File Input Format Counters Bytes Read=101 File Output Format Counters Bytes Written=123 [hadoop@master hadoop]$

    原文作者:灼灼2015
    原文地址: https://www.jianshu.com/p/57ffe2e3a092
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞