1.安装 jdk 配置环境变量
apt-get install openJdk8
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
使全局变量生效
source /etc/profile
2.下载 Hadoop
wget address
3.减压 tar.gz
tar -zxvf hadoop.2.6.1tar.gz
4.hadoop安装
创建数据存放的文件夹
/home/hadoop
/home/hadoop/tmp
/home/hadoop/hdfs
/home/hadoop/hdfs/data
/home/hadoop/hdfs/name
5.创建目录
mkdir /usr/local/hadoop
hadoop-2.6.1.tar.gz解压至/usr/local/hadoop/下
6.配置各机器hosts
vi /etc/hosts
ip 机器名
ip 机器名
7.配置hadoop参数
7.1配置hadoop-2.6.1/etc/hadoop/core-site.xml
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://hadoop:9000</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>file:/home/hadoop/tmp</value>
</property>
<property>
<name>io.file.buffer.size</name>
<value>131702</value>
</property>
</configuration>
7.2配置hadoop-2.6.1/etc/hadoop/hdfs-site.xml
<configuration>
<property>
<name>dfs.namenode.name.dir</name>
<value>file:/home/hadoop/hdfs/name</value>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>file:/home/hadoop/hdfs/data</value>
</property>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
<property>
<name>dfs.namenode.secondary.http-address</name>
<value>hadoop:9001</value>
</property>
<property>
<name>dfs.webhdfs.enabled</name>
<value>true</value>
</property>
</configuration>
7.3配置hadoop-2.6.1/etc/hadoop/mapred-site.xml
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
<property>
<name>mapreduce.jobhistory.address</name>
<value>hadoop:10020</value>
</property>
<property>
<name>mapreduce.jobhistory.webapp.address</name>
<value>hadoop:19888</value>
</property>
</configuration>
42.62.73.147
7.4配置hadoop-2.6.1/etc/hadoop/yarn-site.xml
<configuration>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<property>
<name>yarn.nodemanager.auxservices.mapreduce.shuffle.class</name>
<value>org.apache.hadoop.mapred.ShuffleHandler</value>
</property>
<property>
<name>yarn.resourcemanager.address</name>
<value>hadoop:8032</value>
</property>
<property>
<name>yarn.resourcemanager.scheduler.address</name>
<value>hadoop:8030</value>
</property>
<property>
<name>yarn.resourcemanager.resource-tracker.address</name>
<value>hadoop:8031</value>
</property>
<property>
<name>yarn.resourcemanager.admin.address</name>
<value>hadoop:8033</value>
</property>
<property>
<name>yarn.resourcemanager.webapp.address</name>
<value>hadoop:8088</value>
</property>
<property>
<name>yarn.nodemanager.resource.memory-mb</name>
<value>22528</value>
</property>
</configuration>
7.5配置hadoop-2.6.1/etc/hadoop/hadoop-env.sh和hadoop-2.6.1/etc/hadoop/yarn-env.sh
export JAVA_HOME=/usr/local/jdk/jdk1.7.0_79
7.6配置slaves 添加从节点
vi hadoop-2.6.1/etc/hadoop/slaves
8.命令
初始化
bin/hdfs namenode -format
sbin/start-dfs.sh
sbin/start-yarn.sh
sbin/stop-dfs.sh
sbin/stop-yarn.sh
输入命令jps可以看到相关信息
执行jar
hadoop jar xxxxx.jar arg1 arg2
** hdfs命令 **
列出目录下文件
hadoop fs -ls /
创建目录
hadoop fs -mkdir /newdir
本地文件复制到HDFS
hadoop fs -copyFromLocal /home/input/a.txt /input/a.txt
HDFS文件复制到本地
hadoop fs -copyToLocal /input/a.txt /home/input/a.txt
删除HDFS目录及其中文件
hadoop fs -rm -f -r /output1
移动文件
hadoop fs -mv URI [URI …] <dest>
停止job
hadoop job -kill <id>
关闭安全模式
hadoop dfsadmin -safemode leave
Cluster查看
http://192.168.1.100:8088/
HDFS查看
http://192.168.1.100:50070/
9.错误
初始化报错
host = java.net.UnknownHostException: centos: centos
查看/etc/sysconfig/network文件
NETWORKING=yes
HOSTNAME=centos
HOSTNAME是centos, 无法在/etc/hosts中找到对应IP
vi /etc/hosts,添加:
127.0.0.1 centos
启动报错:
/hadoop-2.6.1/sbin/hadoop-daemon.sh: Permission denied
从节点hadoop目录要有执行权限
chmod -R 755 hadoop-2.6.1
ShuffleError
Error: org.apache.hadoop.mapreduce.task.reduce.Shuffle$ShuffleError: error in shuffle in fetcher#3
at org.apache.hadoop.mapreduce.task.reduce.Shuffle.run(Shuffle.java:134)
at org.apache.hadoop.mapred.ReduceTask.run(ReduceTask.java:376)
at org.apache.hadoop.mapred.YarnChild$2.run(YarnChild.java:163)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:415)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1656)
at org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:158)
Caused by: java.lang.OutOfMemoryError: Java heap space
at org.apache.hadoop.io.BoundedByteArrayOutputStream.<init>(BoundedByteArrayOutputStream.java:56)
at org.apache.hadoop.io.BoundedByteArrayOutputStream.<init>(BoundedByteArrayOutputStream.java:46)
at org.apache.hadoop.mapreduce.task.reduce.InMemoryMapOutput.<init>(InMemoryMapOutput.java:63)
at org.apache.hadoop.mapreduce.task.reduce.MergeManagerImpl.unconditionalReserve(MergeManagerImpl.java:305)
at org.apache.hadoop.mapreduce.task.reduce.MergeManagerImpl.reserve(MergeManagerImpl.java:295)
at org.apache.hadoop.mapreduce.task.reduce.Fetcher.copyMapOutput(Fetcher.java:514)
at org.apache.hadoop.mapreduce.task.reduce.Fetcher.copyFromHost(Fetcher.java:336)
at org.apache.hadoop.mapreduce.task.reduce.Fetcher.run(Fetcher.java:193)
解决方法:在mapred-size.xml添加配置
<property>
<name>mapreduce.reduce.shuffle.memory.limit.percent</name>
<value>0.10</value>
</property>
15/11/30 20:15:46 INFO hdfs.DFSClient: Exception in createBlockOutputStream
java.io.IOException: Bad connect ack with firstBadLink as 192.168.1.200:50010
at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.createBlockOutputStream(DFSOutputStream.java:1460)
at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.nextBlockOutputStream(DFSOutputStream.java:1361)
at org.apache.hadoop.hdfs.DFSOutputStream$DataStreamer.run(DFSOutputStream.java:588)
解决方法:打开192.168.1.200 50010端口防火墙