君子博学而日参省乎己 则知明而行无过矣

博客园 首页 新随笔 联系 订阅 管理
由于前面试验过,单机版的hadoop+hbase总是无法开启zookeeper,所以临时放弃单机版的配置,转而改配伪随机版。
首先,说明一下我是用的安装文件版本:hadoop-1.0.3  hbase-0.90.6 (由于后面需要安装nutch2,而nutch2是基于hbase-0.90.4开发的,所以hbase只安装了0.90.*,不敢再安装更改的版本了,否则nutch2运行不正常)。
 

一、前提准备工作

这部分跟单机版hadoop的安装准备工作是一样的,包括安装JDK修改机器名安装ssh并设置免密钥登陆。当然,如果这部分准备工作已经完成,可直接跳过。
提醒:jdk一定要安装1.6版本的,1.7版本的貌似hadoop的支持并不太好,编译时常会出错。
用如下命令来确认能否不输入口令就用ssh登录localhost: 
Java代码  
  1. $ ssh localhost  

如果不输入口令就无法用ssh登陆localhost,执行下面的命令,已完成免密钥配置: 
Java代码  
  1. $ ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa   
  2. $ cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys  

二、hadoop安装及配置工作
1.下载及安装
http://apache.dataguru.cn/hadoop/common/下载一个压缩包hadoop-*.*.*-alpha.tar.gz,然后解压到特定目录。
 
2.配置conf/中的相关文件
按下列说明,仔细配置这6个文件,如果这些文件不配置的话,系统会采用默认配置,默认配置在这里。当然,你可以根据你的版本不同,访问这里找到针对你版本的默认配置文件,也可以直接更改连接http://hadoop.apache.org/docs/r1.0.3/hdfs-default.html 中的版本
2.1, hadoop-env.sh 文件
Java代码  
  1. export JAVA_HOME=/usr/java/jdk1.6.0_29  
  2.  export HADOOP_SSH_OPTS="-p 22" 
2.2, core-site.xml 文件
  其默认配置在这里
Java代码  
  1. <configuration>  
  2.     <!-- In: conf/core-site.xml -->  
  3.     <property>  
  4.       <name>hadoop.tmp.dir</name>  
  5.       <value>/hadoop/hdata/tmp</value>  
  6.       <description>A base for other temporary directories.</description>  
  7.     </property>  
  8.   
  9.     <property>  
  10.       <name>fs.default.name</name>  
  11.       <value>hdfs://localhost:9000</value>  
  12.       <description>The name of the default file system.  A URI whose  
  13.       scheme and authority determine the FileSystem implementation.  The  
  14.       uri's scheme determines the config property (fs.SCHEME.impl) naming  
  15.       the FileSystem implementation class.  The uri's authority is used to  
  16.       determine the host, port, etc. for a filesystem.</description>  
  17.     </property>  
  18.   
  19.     <property>  
  20.       <name>fs.checkpoint.dir</name>  
  21.       <value>/hadoop/hdata/secondname</value>  
  22.       <description>Determines where on the local filesystem the DFS secondary  
  23.           name node should store the temporary images to merge.  
  24.           If this is a comma-delimited list of directories then the image is  
  25.           replicated in all of the directories for redundancy.  
  26.       </description>  
  27.     </property>  
  28.   
  29.     <property>  
  30.       <name>dfs.http.address</name>  
  31.       <value>localhost:50070</value>  
  32.       <description>  
  33.         The address and the base port where the dfs namenode web ui will listen on.  
  34.         If the port is 0 then the server will start on a free port.  
  35.       </description>  
  36.     </property>  
  37. </configuration>  
2.3, hdfs-site.xml 文件
  其默认配置在这里
Java代码  
  1. <configuration>  
  2.     <!-- In: conf/hdfs-site.xml -->  
  3.     <property>  
  4.        <name>dfs.name.dir</name>  
  5.        <value>/hadoop/hdata/name</value>  
  6.     </property>  
  7.     <property>  
  8.        <name>dfs.data.dir</name>  
  9.        <value>/hadoop/hdata/data</value>  
  10.     </property>  
  11.     <property>  
  12.       <name>dfs.replication</name>  
  13.       <value>3</value>  
  14.       <description>Default block replication.  
  15.       The actual number of replications can be specified when the file is created.  
  16.       The default is used if replication is not specified in create time.  
  17.       </description>  
  18.     </property>  
  19.     <property>    
  20.       <name>dfs.datanode.max.xcievers</name>    
  21.       <value>4096</value>    
  22.     </property> 
  23.  
  24.   <property>  
  25.       <name>dfs.support.append</name>  
  26.       <value>true</value>  
  27.   </property>
  28.    
  29. </configuration>  
2.4, mapred-site.xml 文件
  其默认配置在这里
Java代码  
  1. <configuration>  
  2.     <!-- In: conf/mapred-site.xml -->  
  3.     <property>  
  4.       <name>mapred.job.tracker</name>  
  5.       <value>localhost:10001</value>  
  6.       <description>The host and port that the MapReduce job tracker runs  
  7.       at.  If "local", then jobs are run in-process as a single map  
  8.       and reduce task.  
  9.       </description>  
  10.     </property>  
  11. </configuration>  
2.5, masters 文件
Java代码  
  1. localhost
2.6, slaves 文件
Java代码  
  1. localhost
 
3.运行hadoop并检验配置效果
3.1 初次运行,格式化hdfs文件系统
初次运行一定要格式化hdfs文件系统,使用如下命令进行格式化一个新的分布式文件系统:
Java代码  
  1. $ bin/hadoop namenode -format
回车,会出下如下响应界面:
会出现一次交互,输入Y<Enter>。(注意一定要是大写的Y,小写的不行)
3.2 启动和关闭Hadoop
利用如下命令启动和关闭Hadoop守护进程:(此步要在格式化hdfs之后,否则hadoop无法正常启动)
Java代码  
  1. $ bin/start-all.sh
  2. $ bin/stop-all.sh
开启Hadoop守护进城后,用jps查看当前活跃进程,你会发现会多出5个新进程(
3.3 在hdfs根目录下创建一个文件夹hbase
此步的目的是为后面hbase的安装做准备的,执行如下命令,以在hdfs根目录下创建一个名为habse的文件夹并查看结果。
Java代码  
  1. $ bin/hadoop dfs -mkdir /hbase
  2. $ bin/hadoop dfs -ls /

三、hbase安装及配置工作
 1.下载及安装
http://apache.etoak.com/hbase/下载一个压缩包hbase-0.**.*.tar.gz,然后解压到特定目录。
 
 
2.配置conf/中的相关文件
按下列说明,仔细配置这3个文件
2.1, hbase-env.sh 文件
Java代码  
  1. export JAVA_HOME=/usr/java/jdk1.7.0_09
  2. export HBASE_SSH_OPTS="-p 22"  
  3. export HBASE_CLASSPATH=/hadoop/hadoop-1.0.3/
  4. export HBASE_MANAGES_ZK=true  
2.2, hbase-site.xml 文件
Java代码  
  1. <configuration>  
  2.   <property>  
  3.     <name>hbase.rootdir</name>  
  4.     <value>hdfs://localhost:9000/hbase</value>  
  5.   </property>  
  6.   
  7.   <property>  
  8.       <name>hbase.cluster.distributed</name>  
  9.       <value>true</value>  
  10.       <description>The mode the cluster will be in. Possible values are  
  11.               false: standalone and pseudo-distributed setups with managed Zookeeper  
  12.              true: fully-distributed with unmanaged Zookeeper Quorum (see hbase-env.sh)  
  13.       </description>  
  14.   </property>  
  15.   
  16.   <property>  
  17.       <name>hbase.master</name>  
  18.       <value>localhost:60000</value>  
  19.   </property>  
  20.   
  21.   <property>  
  22.       <name>hbase.zookeeper.quorum</name>  
  23.       <value>localhost</value>  
  24.   </property>  
  25.   
  26.   <property>  
  27.       <name>hbase.zookeeper.property.dataDir</name>  
  28.       <value>/hadoop/hdata/zookeeper</value>  
  29.       <description>Property from ZooKeeper's config zoo.cfg.  
  30.           The directory where the snapshot is stored.  
  31.       </description>  
  32.   </property>  
  33.   
  34.   <property>  
  35.       <name>zookeeper.session.timeout</name>  
  36.       <value>60000</value>  
  37.   </property>  
  38.   
  39.   <property>  
  40.       <name>hbase.zookeeper.property.clientPort</name>  
  41.       <value>2181</value>  
  42.   </property>  
  43.   
  44.   <property>  
  45.       <name>hbase.regionserver.restart.on.zk.expire</name>  
  46.       <value>true</value>  
  47.   </property> 
  48.   <property>  
  49.       <name>dfs.support.append</name>  
  50.       <value>true</value>  
  51.   </property>
  52. </configuration>  
2.3,regionservers 文件
Java代码  
  1. localhost
 
3.运行hbase并检验配置效果
3.1 hadoop和hbase兼容性调整
如果现在区开启hbase可能会出错导致失败(我在hadoop0.20.203.0环境下搭hbase0.90.4就出现过这种问题,hadoop1.0.0没测试,直接做了下面的步骤),这时需要将$HADOOP_HOME目录下的hadoop-core-1.0.0.jar和$HADOOP_HOME/lib目录下的commons-configuration-1.6.jar拷贝到$HBASE_HOME/lib目录下,删除$HBASE_HOME/lib目录下的hadoop-core-0.20-append-r1056497.jar,使hadoop和hbase的客户端协议一致,从而避免版本冲突和不兼容。
3.2 运行hbase
利用如下命令启动和关闭hbase守护进程:
Java代码  
  1. $ bin/start-hbase.sh
  2. $ bin/stop-hbase.sh
开启hbase守护进城后,用jps查看当前活跃进程,你会发现会多出3个新进程(HQuorumPeer、HMaster、HRegionServer)。
posted on 2013-06-17 02:27  刺猬的温驯  阅读(310)  评论(0)    收藏  举报