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]$

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 203,324评论 5 476
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,303评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,192评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,555评论 1 273
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,569评论 5 365
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,566评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,927评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,583评论 0 257
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,827评论 1 297
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,590评论 2 320
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,669评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,365评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,941评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,928评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,159评论 1 259
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,880评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,399评论 2 342

推荐阅读更多精彩内容