hadoop1.2.1+zk-3.4.5+hbase-0.94.1集群安装过程详解
see:
http://www.cnblogs.com/wanghetao/p/3595442.html
节点:
192.168.12.66 hadoop1
192.168.12.67 hadoop2
192.168.12.69 hadoop3
<!--more-->
hadoop1是master,配置NameNode和JobTracker的角色
hadoop安装目录:/usr/local
hadoop用户: hadoop
安装分为3部分,
1)hadoop-1.2.1
2) zookeeper-3.4.6
3) hbase-0.94.27
环境准备:
root job:
1) 时间同步
*/5 * * * * /usr/sbin/ntpdate -u cn.pool.ntp.org
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
第一部分:安装hadoop
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1. 3台机器安装JDK 1.7.0_51
vi /etc/profile
JAVA_HOME=/usr/jdk
PATH=$JAVA_HOME/bin:$PATH
export PATH
2. 3台机器创建hadoop账户。
3.做三台机器之间做双机互信,
原因master通过远程启动datanode进程和tasktracker进程,如果不做双机互信,会导致每次启动集群服务都会需要密码
3.1 hadoop1/hadoop2/hadoop3
hadoop$ ssh-keygen -t rsa
3.2 将公钥copy到其他2台主机上,做到互信
hadoop1:
[hadoop@test67 ~]$ ssh-copy-id -i hadoop2
[hadoop@test67 ~]$ ssh-copy-id -i hadoop3
hadoop2:
[hadoop@test67 ~]$ ssh-copy-id -i hadoop1
[hadoop@test67 ~]$ ssh-copy-id -i hadoop3
hadoop3:
[hadoop@test67 ~]$ ssh-copy-id -i hadoop1
[hadoop@test67 ~]$ ssh-copy-id -i hadoop2
4. 将hadoop1.2.1放到/usr/local下,且授权给hadoop用户
hadoop1/hadoop2/hadoop3:
[root@test66 local]# chown -R hadoop.hadoop /usr/local/hadoop-1.2.1/
5. 修改参数文件 (先再hadoop1上配置hadoop,然后将hadoop目录传递到hadoop2,hadoop3上)
5.0 3台主机上创建hadoop目录
mkdir -p /hadoop/tmp && mkdir -p /hadoop/data && chown -R hadoop.hadoop /hadoop && chmod g-w /hadoop/data/
5.1 hadoop-env.sh
echo "export JAVA_HOME=/usr/jdk" >> /usr/local/hadoop-1.2.1/conf/hadoop-env.sh
5.2 vim /usr/local/hadoop-1.2.1/conf/core-site.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
<name>hadoop.tmp.dir</name>
<value>/hadoop/tmp</value>
</property>
<property>
<name>fs.default.name</name>
<value>hdfs://hadoop1:9000</value>
</property>
</configuration>
5.2 vim /usr/local/hadoop-1.2.1/conf/hdfs-site.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
<name>dfs.data.dir</name>
<value>/hadoop/data</value>
</property>
<property>
<name>dfs.replication</name>
<value>2</value>
</property>
</configuration>
5.3 vim /usr/local/hadoop-1.2.1/conf/mapred-site.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
<name>mapred.job.tracker</name>
<value>http://hadoop1:9001</value>
</property>
</configuration>
5.4 vim /usr/local/hadoop-1.2.1/conf/masters ( masters 用于指定,辅助名称节点(SecondaryNameNode)的主机名或主机地址)
hadoop1
5.4 vim /usr/local/hadoop-1.2.1/conf/slaves (用于指定各从服务器(TaskTracker或DataNode)的主机名或主机地址)
hadoop2
hadoop3
5.6 配置slave:将配置的hadoop整个目录复制到hadoop2,haoop3
hadoop1 # scp -rp /usr/local/hadoop-1.2.1 hadoop2:/usr/local/
hadoop1 # scp -rp /usr/local/hadoop-1.2.1 hadoop3:/usr/local/
hadoop2 # chown -R hadoop:hadoop /usr/local/hadoop-1.2.1/
hadoop3 # chown -R hadoop:hadoop /usr/local/hadoop-1.2.1/
6. 启动集群
6.1 格式化名称节点( hadoop1上执行 )
与普通文件系统一样,HDFS文件系统必须要先格式化,创建元数据数据结构以后才能使用。
hadoop $ /usr/local/hadoop-1.2.1/bin/hadoop namenode -format
6.2 启动集群
/usr/local/hadoop-1.2.1/bin/start-all.sh
6.3 查看集群是否启动
[hadoop@test66 hadoop]$ jps
5722 Jps
5510 SecondaryNameNode
5602 JobTracker
5327 NameNode
验证:
/usr/local/hadoop-1.2.1/bin/hadoop dfsadmin -report
数据节点上:
[hadoop@test69 ~]$ jps
1749 Jps
1574 DataNode
1673 TaskTracker
7. 各端口解释
dfs.http.address:NameNode的HTTP服务器地址和端口,默认为0.0.0.0:50070;
dfs.secondary.http.address:SecondaryNameNode的HTTP服务器地址和端口,默认为0.0.0.0:50090;
mapred.job.tracker.http.addrss:JobTracker的HTTP服务器地址和端口,默认为0.0.0.0:50030;
dfs.datanode.http.address:DataNode的HTTP服务器地址和端口,默认为0.0.0.0:50075;
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
第二部分:安装zookeeper
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ZooKeeper是一个分布式开源框架,提供了协调分布式应用的基本服务,它向外部应用暴露一组通用服务——分布式同步(Distributed Synchronization)、命名服务(Naming Service)、集群维护(Group Maintenance)等,简化分布式应用协调及其管理的难度,提供高性能的分布式服务。ZooKeeper本身可以以Standalone模式安装运行,不过它的长处在于通过分布式ZooKeeper集群(一个Leader,多个Follower),基于一定的策略来保证ZooKeeper集群的稳定性和可用性,从而实现分布式应用的可靠性。
hadoop1为zookeeper1,hadoop2为zookeeper2,hadoop33为zookeeper3。
1,下载zookeeper-3.4.4解压到/usr/local/下,并修改权限
# cd /usr/local/ && wget http://apache.fayea.com/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
# chown -R hadoop:hadoop /usr/local/zookeeper-3.4.6/
2. 配置zookeeper
vi /usr/local/zookeeper-3.4.6/zoo.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/hadoop/zookeeper
clientPort=2181
server.1=hadoop1:28888:38888
server.2=hadoop2:28888:38888
server.3=hadoop3:28888:38888
3.3台机器上创建snap目录
hadoop$ mkdir -p /hadoop/zookeeper/
hadoop1$ echo "1" > /hadoop/zookeeper/myid
hadoop2$ echo "2" > /hadoop/zookeeper/myid
hadoop3$ echo "3" > /hadoop/zookeeper/myid
4. 复制zookeeper主目录到 hadoop2/hadoop3
# scp -rp /usr/local/zookeeper-3.4.6 hadoop2:/usr/local/
# scp -rp /usr/local/zookeeper-3.4.6 hadoop3:/usr/local/
hadoop1/hadoop2/hadoop3/:
# chown -R hadoop:hadoop /usr/local/zookeeper-3.4.6/
5.在对应的节点上启动服务 (3个节点都需启动)
[hadoop@hadoop01 zookeeper-3.4.4]$ sh /usr/local/zookeeper-3.4.6/bin/zkServer.sh start
三个节点启动完之后,查看
[hadoop@test66 zookeeper-3.4.6]$ jps
3564 QuorumPeerMain
2845 NameNode
3030 SecondaryNameNode
3126 JobTracker
3587 Jps
查看状态
[hadoop@hadoop01 zookeeper-3.4.4]$ sh /usr/local/zookeeper-3.4.6/bin/zkServer.sh status
Mode: follower --表示是跟从
或者
Mode: leader
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
第三步:安装HBase
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1. download hbase (hadoop1)
# cd /usr/local/ && wget http://mirror.bit.edu.cn/apache/hbase/hbase-0.94.27/hbase-0.94.27.tar.gz && tar -zxvf hbase-0.94.27.tar.gz && rm hbase-0.94.27.tar.gz
# chown -R hadoop.hadoop /usr/local/hbase-0.94.27
2.修改配置文件 - hbase-env.sh
vi /usr/local/hbase-0.94.27/conf/hbase-env.sh
export JAVA_HOME=/usr/local/jdk
export HBASE_CLASSPATH=/usr/local/hadoop-1.2.1/conf
#不是hbase自带的zookeeper
export HBASE_MANAGES_ZK=false
export HBASE_HEAPSIZE=1024
3. hbase-site.xml
hadoop $ mkdir -p /hadoop/hbase #3台主机执行。
[hadoop@test66 conf]$ cp /usr/local/hbase-0.94.27/src/main/resources/hbase-default.xml ./hbase-site.xml
修改1:
<name>hbase.tmp.dir</name>
<value>/hadoop/hbase</value>
修改2:
<name>hbase.zookeeper.quorum</name>
<value>hadoop1,hadoop2,hadoop3</value>
修改3:
<name>hbase.cluster.distributed</name>
<value>true</value>
修改4:
<name>hbase.rootdir</name>
<value>hdfs://hadoop01:9000/hbase</value>
#hbase.rootdir : /hbase是 hbase在hdfs的实际存储为止,namenode运营在hadoop1的9000端口
#hbase.cluster.distributed: false,单机模式,true,分布式模式.如果是false则zk和hbase运行在同一个JVM
4. hadoop2/hadoop3不是hbase
[root@test66 local]# scp -rp /usr/local/hbase-0.94.27/ hadoop2:/usr/local
[root@test66 local]# scp -rp /usr/local/hbase-0.94.27/ hadoop3:/usr/local
hadoop2/hadoop3
[root@test67 ~]# chown -R hadoop.hadoop /usr/local/hbase-0.94.27/
4.启动hbase
[hadoop@test66 logs]$ /usr/local/hbase-0.94.27/bin/start-hbase.sh
5.停止hbase
[hadoop@test66 logs]$ /usr/local/hbase-0.94.27/bin/stop-hbase.sh
HBase HMaster查看hbase信息
http://192.168.12.66:60010/master-status
###
hbase异常
###
[hadoop@test66 conf]$ /usr/local/hbase-0.94.27/bin/start-hbase.sh
Exception in thread "main" java.lang.RuntimeException: hbase-default.xml file seems to be for and old version of HBase (@@@VERSION@@@), this version is 0.94.27
at org.apache.hadoop.hbase.HBaseConfiguration.checkDefaultsVersion(HBaseConfiguration.java:68)
at org.apache.hadoop.hbase.HBaseConfiguration.addHbaseResources(HBaseConfiguration.java:100
解决办法:
打开hbase-site.xml
查找 hbase.defaults.for.version.skip
将值设为true
5,连接hbase创建表
/usr/local/hbase-0.94.27/bin/hbase shell
创建一个名为 small的表,这个表只有一个 column family 为 cf。可以列出所有的表来检查创建情况,然后插入些值。
hbase(main):002:0> create 'small', 'cf'
hbase(main):006:0> list
TABLE
small
1 row(s) in 0.0300 seconds
插入一些数据
hbase(main):007:0> put 'small','r1','cf:a','v1'
0 row(s) in 0.0800 seconds
hbase(main):008:0> put 'small','r2','cf:b','v2'
0 row(s) in 0.0110 seconds
hbase(main):009:0> put 'small','r3','cf:c','v3'
0 row(s) in 0.0040 seconds
查询small表数据
hbase(main):010:0> scan 'small'
ROW COLUMN+CELL
r1 column=cf:a, timestamp=1436252912994, value=v1
r2 column=cf:b, timestamp=1436252921003, value=v2
r3 column=cf:c, timestamp=1436252925324, value=v3
3 row(s) in 0.0290 seconds
行键、列族名、限定符、时间戳唯一标识
查询一行
hbase(main):011:0> get 'small', 'r1'
COLUMN CELL
cf:a timestamp=1436252912994, value=v1
1 row(s) in 0.0150 seconds
disable 再 drop 这张表,可以清除你刚刚的操作
hbase(main):012:0> disable 'small'
0 row(s) in 1.0930 seconds
hbase(main):013:0> drop 'small'
0 row(s) in 0.0770 seconds
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
启动HBASE
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1,启动 hadoop (只在hmaster上启动)
/usr/local/hadoop-1.2.1/bin/start-all.sh
2.启动zk (3台都需要启动)
sh /usr/local/zookeeper-3.4.6/bin/zkServer.sh start
3.启动hbase (只在hmaster上启动)
/usr/local/hbase-0.94.27/bin/start-hbase.shVC HGFD V
-
Hadoop
86 引用 • 122 回帖 • 625 关注
Hadoop 是由 Apache 基金会所开发的一个分布式系统基础架构。用户可以在不了解分布式底层细节的情况下,开发分布式程序。充分利用集群的威力进行高速运算和存储。
-
ZooKeeper
59 引用 • 29 回帖 • 5 关注
ZooKeeper 是一个分布式的,开放源码的分布式应用程序协调服务,是 Google 的 Chubby 一个开源的实现,是 Hadoop 和 HBase 的重要组件。它是一个为分布式应用提供一致性服务的软件,提供的功能包括:配置维护、域名服务、分布式同步、组服务等。
-
HBase
17 引用 • 6 回帖 • 73 关注
HBase 是一个分布式的、面向列的开源数据库,该技术来源于 Fay Chang 所撰写的 Google 论文 “Bigtable:一个结构化数据的分布式存储系统”。就像 Bigtable 利用了 Google 文件系统所提供的分布式数据存储一样,HBase 在 Hadoop 之上提供了类似于 Bigtable 的能力。
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于