由于前面试验过,单机版的hadoop+hbase总是无法开启zookeeper,所以临时放弃单机版的配置,转而改配伪随机版。
首先,说明一下我是用的安装文件版本:hadoop-1.0.3 hbase-0.90.6 (由于后面需要安装nutch2,而nutch2是基于hbase-0.90.4开发的,所以hbase只安装了0.90.*,不敢再安装更改的版本了,否则nutch2运行不正常)。
一、前提准备工作
提醒:jdk一定要安装1.6版本的,1.7版本的貌似hadoop的支持并不太好,编译时常会出错。
用如下命令来确认能否不输入口令就用ssh登录localhost:
如果不输入口令就无法用ssh登陆localhost,执行下面的命令,已完成免密钥配置:
二、hadoop安装及配置工作
Java代码
- $ ssh localhost
如果不输入口令就无法用ssh登陆localhost,执行下面的命令,已完成免密钥配置:
Java代码
- $ ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa
- $ cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
二、hadoop安装及配置工作
1.下载及安装
2.配置conf/中的相关文件
按下列说明,仔细配置这6个文件,如果这些文件不配置的话,系统会采用默认配置,默认配置在这里。当然,你可以根据你的版本不同,访问这里找到针对你版本的默认配置文件,也可以直接更改连接http://hadoop.apache.org/docs/r1.0.3/hdfs-default.html 中的版本。
2.1, hadoop-env.sh 文件
Java代码
- export JAVA_HOME=/usr/java/jdk1.6.0_29
- export HADOOP_SSH_OPTS="-p 22"
2.2, core-site.xml 文件
Java代码
- <configuration>
- <!-- In: conf/core-site.xml -->
- <property>
- <name>hadoop.tmp.dir</name>
- <value>/hadoop/hdata/tmp</value>
- <description>A base for other temporary directories.</description>
- </property>
- <property>
- <name>fs.default.name</name>
- <value>hdfs://localhost:9000</value>
- <description>The name of the default file system. A URI whose
- scheme and authority determine the FileSystem implementation. The
- uri's scheme determines the config property (fs.SCHEME.impl) naming
- the FileSystem implementation class. The uri's authority is used to
- determine the host, port, etc. for a filesystem.</description>
- </property>
- <property>
- <name>fs.checkpoint.dir</name>
- <value>/hadoop/hdata/secondname</value>
- <description>Determines where on the local filesystem the DFS secondary
- name node should store the temporary images to merge.
- If this is a comma-delimited list of directories then the image is
- replicated in all of the directories for redundancy.
- </description>
- </property>
- <property>
- <name>dfs.http.address</name>
- <value>localhost:50070</value>
- <description>
- The address and the base port where the dfs namenode web ui will listen on.
- If the port is 0 then the server will start on a free port.
- </description>
- </property>
- </configuration>
其默认配置在这里。
2.4, mapred-site.xml 文件
Java代码
- <configuration>
- <!-- In: conf/hdfs-site.xml -->
- <property>
- <name>dfs.name.dir</name>
- <value>/hadoop/hdata/name</value>
- </property>
- <property>
- <name>dfs.data.dir</name>
- <value>/hadoop/hdata/data</value>
- </property>
- <property>
- <name>dfs.replication</name>
- <value>3</value>
- <description>Default block replication.
- The actual number of replications can be specified when the file is created.
- The default is used if replication is not specified in create time.
- </description>
- </property>
- <property>
- <name>dfs.datanode.max.xcievers</name>
- <value>4096</value>
- </property>
- <property>
- <name>dfs.support.append</name>
- <value>true</value>
- </property>
- </configuration>
其默认配置在这里。
2.5, masters 文件
2.6, slaves 文件
3.运行hadoop并检验配置效果
3.1 初次运行,格式化hdfs文件系统
Java代码
- <configuration>
- <!-- In: conf/mapred-site.xml -->
- <property>
- <name>mapred.job.tracker</name>
- <value>localhost:10001</value>
- <description>The host and port that the MapReduce job tracker runs
- at. If "local", then jobs are run in-process as a single map
- and reduce task.
- </description>
- </property>
- </configuration>
Java代码
- localhost
Java代码
- localhost
3.1 初次运行,格式化hdfs文件系统
初次运行一定要格式化hdfs文件系统,使用如下命令进行格式化一个新的分布式文件系统:
Java代码
回车,会出下如下响应界面:
- $ bin/hadoop namenode -format

会出现一次交互,输入Y<Enter>。(注意一定要是大写的Y,小写的不行)
3.2 启动和关闭Hadoop
利用如下命令启动和关闭Hadoop守护进程:(此步要在格式化hdfs之后,否则hadoop无法正常启动)
Java代码
开启Hadoop守护进城后,用jps查看当前活跃进程,你会发现会多出5个新进程(
三、hbase安装及配置工作
- $ bin/start-all.sh
- $ bin/stop-all.sh
3.3 在hdfs根目录下创建一个文件夹hbase
此步的目的是为后面hbase的安装做准备的,执行如下命令,以在hdfs根目录下创建一个名为habse的文件夹并查看结果。
Java代码
- $ bin/hadoop dfs -mkdir /hbase
- $ bin/hadoop dfs -ls /
三、hbase安装及配置工作
1.下载及安装
2.2, hbase-site.xml 文件
2.3,regionservers 文件
3.运行hbase并检验配置效果
到http://apache.etoak.com/hbase/下载一个压缩包hbase-0.**.*.tar.gz,然后解压到特定目录。
2.配置conf/中的相关文件
按下列说明,仔细配置这3个文件
2.1, hbase-env.sh 文件Java代码
- export JAVA_HOME=/usr/java/jdk1.7.0_09
- export HBASE_SSH_OPTS="-p 22"
- export HBASE_CLASSPATH=/hadoop/hadoop-1.0.3/
- export HBASE_MANAGES_ZK=true
Java代码
- <configuration>
- <property>
- <name>hbase.rootdir</name>
- <value>hdfs://localhost:9000/hbase</value>
- </property>
- <property>
- <name>hbase.cluster.distributed</name>
- <value>true</value>
- <description>The mode the cluster will be in. Possible values are
- false: standalone and pseudo-distributed setups with managed Zookeeper
- true: fully-distributed with unmanaged Zookeeper Quorum (see hbase-env.sh)
- </description>
- </property>
- <property>
- <name>hbase.master</name>
- <value>localhost:60000</value>
- </property>
- <property>
- <name>hbase.zookeeper.quorum</name>
- <value>localhost</value>
- </property>
- <property>
- <name>hbase.zookeeper.property.dataDir</name>
- <value>/hadoop/hdata/zookeeper</value>
- <description>Property from ZooKeeper's config zoo.cfg.
- The directory where the snapshot is stored.
- </description>
- </property>
- <property>
- <name>zookeeper.session.timeout</name>
- <value>60000</value>
- </property>
- <property>
- <name>hbase.zookeeper.property.clientPort</name>
- <value>2181</value>
- </property>
- <property>
- <name>hbase.regionserver.restart.on.zk.expire</name>
- <value>true</value>
- </property>
- <property>
- <name>dfs.support.append</name>
- <value>true</value>
- </property>
- </configuration>
Java代码
- localhost
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代码
开启hbase守护进城后,用jps查看当前活跃进程,你会发现会多出3个新进程(HQuorumPeer、HMaster、HRegionServer)。
- $ bin/start-hbase.sh
- $ bin/stop-hbase.sh
浙公网安备 33010602011771号