安装hadoop

总体的流程如下:
1、实现ssh无密码验证配置
2、安装jdk,并配好环境变量
3、安装与配置Hadoop
4、格式化与启动

**5、验证是否启动

一.主机之间SSH无密码验证
利用 : ssh-kengen –t rsa 命令产生公钥,将个主机之间的公钥,相互拷贝到authorized_keys文件内。

二.安装JDK
安装好后,用java -version 检验下

配置环境变量: **

  1. ###set java_env
  2. export JAVA_HOME=/usr/java/jdk1.8.0_25/
  3. export JRE_HOME=/usr/java/jdk1.8.0_25/jre
  4. export CLASS_PATH=.:$CLASS_PATH:$JAVA_HOME/lib:$JRE_HOME/lib
  5. export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
  6. ###set hadoop_env
  7. export HADOOP_HOME=/home/zhang/hadoop-2.5.2
  8. export HADOOP_COMMON_HOME=$HADOOP_HOME
  9. export HADOOP_HDFS_HOME=$HADOOP_HOME
  10. export HADOOP_MAPRED_HOME=$HADOOP_HOME
  11. export HADOOP_YARN_HOME=$HADOOP_HOME
  12. export HADOOP_CONF_DIR=$HADOOP_HOME/etc/hadoop
  13. export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$HADOOP_HOME/lib
  14. export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_HOME/lib/native
  15. export HADOOP_OPTS=\"-Djava.library.path=$HADOOP_HOME/lib\"

**
三.部署配置Hadoop
解压Hadoop 到 自己的hadoop 目录

配置相关的配置文件
2.5.x版本的配置文件在:$Hadoop_Home/etc/hadoop 目录下
2.X版本较1.X版本改动很大,主要是用Hadoop MapReduceV2(Yarn) 框架代替了一代的架构,其中JobTracker 和 TaskTracker 不见了,取而代之的是 ResourceManager, ApplicationMaster 与 NodeManager 三个部分,而具体的配置文件位置与内容也都有了相应变化,具体的可参考文献:http://www.ibm.com/developerworks/cn/opensource/os-cn-hadoop-yarn/

(1)hadoop/etc/hadoop/hadoop-env.sh 与 hadoop/etc/hadoop/yarn-env.sh来配置两个文件里的JAVA_HOME

(2)etc/hadoop/core-site.xml,配置为:
**

<configuration>
<property>
<name>hadoop.tmp.dir</name>
<value>/root/hadoop-2.5.2/tmp</value>
<description>A base for other temporary directories.</description>
</property>
<property>
<name>fs.default.name</name>
<value>hdfs://localhost:9000</value>
</property>
<property>
<name>io.file.buffer.size</name>
<value>131072</value>
</property>
<property>
<name>hadoop.proxyuser.root.hosts</name>
<value>localhost</value>
</property>
<property>
<name>hadoop.proxyuser.root.groups</name>
<value>*</value>
</property>
</configuration>

(3)etc/hadoop/hdfs-site.xml,配置为: (注意:这里需要自己手动用mkdir创建name和data文件夹,具体位置也可以自己选择,其中dfs.replication的值建议配置为与分布式 cluster 中实际的 DataNode 主机数一致。)

<configuration>
<property>
<name>dfs.namenode.name.dir</name>
<value>/root/hadoop-2.5.2/hdfs/name</value>
<final>true</final>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>/root/hadoop-2.5.2/hdfs/data</value>
<final>true</final>
</property>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
<property>
<name>dfs.permissions</name>
<value>false</value>
</property>
</configuration>

(4)etc/hadoop/mapred-site.xml,配置为:

<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>Yarn</value>
</property>
<property>
<name>mapreduce.jobhistory.address</name>
<value>localhost:10020</value>
</property>
<property>
<name>mapreduce.jobhistory.webapp.address</name>
<value>localhost:19888</value>
</property>
<property>
<name>mapreduce.jobhistory.intermediate-done-dir</name>
<value>/mr-history/tmp</value>
</property>
<property>
<name>mapreduce.jobhistory.done-dir</name>
<value>/mr-history/done</value>
</property>
</configuration>

(5)etc/hadoop/yarn-site.xml对yarn进行配置:

<configuration>
<!-- Site specific YARN configuration properties -->
<property>
<name>Yarn.nodemanager.aux-services</name>
<value>mapreduce.shuffle</value>
</property>
<property>
<name>Yarn.resourcemanager.address</name>
<value>localhost:18040</value>
</property>
<property>
<name>Yarn.resourcemanager.scheduler.address</name>
<value>localhost:18030</value>
</property>
<property>
<name>Yarn.resourcemanager.resource-tracker.address</name>
<value>localhost:18025</value>
</property>
<property>
<name>Yarn.resourcemanager.admin.address</name>
<value>localhost:18041</value>
</property>
<property>
<name>Yarn.resourcemanager.webapp.address</name>
<value>localhost:8088</value>
</property>
<property>
<name>Yarn.nodemanager.local-dirs</name>
<value>/root/hadoop-2.5.2/mynode/my</value>
</property>
<property>
<name>Yarn.nodemanager.log-dirs</name>
<value>/root/hadoop-2.5.2/mynode/logs</value>
</property>
<property>
<name>Yarn.nodemanager.log.retain-seconds</name>
<value>10800</value>
</property>
<property>
<name>Yarn.nodemanager.remote-app-log-dir</name>
<value>/logs</value>
</property>
<property>
<name>Yarn.nodemanager.remote-app-log-dir-suffix</name>
<value>logs</value>
</property>
<property>
<name>Yarn.log-aggregation.retain-seconds</name>
<value>-1</value>
</property>
<property>
<name>Yarn.log-aggregation.retain-check-interval-seconds</name>
<value>-1</value>
</property>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
</configuration>

**四.启动测试
(1)用scp 命令将hadoop文件夹拷贝到所有的节点机器相同路径上。
(2)验证一下SSH 无密码访问已经没有问题了
(3)关闭防火墙
如果不关闭的话可能造成,无法访问端口的问题。不关闭防火墙也可以将对应的相关端口打开比如 namenode上:9000端口
方法:http://blog.itpub.net/28929558/viewspace-1353996/

(4)启动测试
格式化namdenode
hadoop/bin/hadoop namenode -format

查看打印信息的倒数第三行:Storage directory ~/hadoop-2.5.2/hdfs/name has been successfully formatted
则说明成功了!

启动 hdfs :
sbin/start-dfs.sh
jps 查看 namenode 上: NameNode SecondaryNameNode
datanode shang : DataNode

启动 yarn :start-yarn.sh
jps 查看 namenode 上: NameNode SecondaryNameNode ResourceManager
datanode shang : DataNode NodeManager

用 hdfs dfsadmin -report 检验一下
9189 NameNode
[zhang@namenode sbin]$ hdfs dfsadmin -report
14/12/01 23:19:15 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform… using builtin-java classes where applicable
Configured Capacity: 8177262592 (7.62 GB)
Present Capacity: 4473057280 (4.17 GB)
DFS Remaining: 4473032704 (4.17 GB)
DFS Used: 24576 (24 KB)
DFS Used%: 0.00%
Under replicated blocks: 0
Blocks with corrupt replicas: 0
Missing blocks: 0

————————————————————————-
Live datanodes (1):

Name: 10.0.128.124:50010 (datanode01)
Hostname: datanode01
Decommission Status : Normal
Configured Capacity: 8177262592 (7.62 GB)
DFS Used: 24576 (24 KB)
Non DFS Used: 3704205312 (3.45 GB)
DFS Remaining: 4473032704 (4.17 GB)
DFS Used%: 0.00%
DFS Remaining%: 54.70%
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: Mon Dec 01 23:19:15 PST 2014

测试放入数据文件,并查看:

[zhang@namenode sbin]$ hadoop fs -put ../../input/ /input
14/12/02 00:18:01 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform… using builtin-java classes where applicable
[zhang@namenode sbin]$ hadoop fs -cat /input/test.txt
14/12/02 00:18:35 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform… using builtin-java classes where applicable
hello word !

验证完毕!

安装hbase

hbase-site.xml

<configuration>
<property>
    <name>hbase.rootdir</name>
    <value>hdfs://localhost:9000/hbase</value>
</property>
<property>
    <name>hbase.master</name>
        <value>hdfs://localhost:60000</value>
        </property>
<property>
    <name>hbase.cluster.distributed</name>
    <value>true</value>
</property>
</configuration>

hbase-env.sh

export HBASE_OPTS="-XX:+UseConcMarkSweepGC"
export JAVA_HOME=/usr/java/jdk1.8.0_231
export HBASE_CLASSPATH=/root/hbase/conf
# The directory where pid files are stored. /tmp by default.
export HBASE_PID_DIR=/var/hadoop/pids

export HBASE_MANAGES_ZK=true

开启hbase

./start-hbase.sh

运行jps,查看java进程

13857 HRegionServer
12834 NodeManager
12229 DataNode
12136 NameNode
15579 Jps
12732 ResourceManager
12461 SecondaryNameNode
13759 HMaster
13663 HQuorumPeer

参考链接

https://www.iteye.com/blog/zh-ka-163-com-2230226