一、Zookeeper的安装

  1.http://www-us.apache.org/dist/zookeeper/stable/下载Zookeeper安装包,并将zookeeper-3.4.12.tar.gz复制到/home/jun下并解压

[jun@master ~]$ cd zookeeper-3.4./
[jun@master zookeeper-3.4.]$ ls -l
total
drwxr-xr-x. jun jun Mar : bin
-rw-rw-r--. jun jun Mar : build.xml
drwxr-xr-x. jun jun Mar : conf
drwxr-xr-x. jun jun Mar : contrib
drwxr-xr-x. jun jun Mar : dist-maven
drwxr-xr-x. jun jun Mar : docs
-rw-rw-r--. jun jun Mar : ivysettings.xml
-rw-rw-r--. jun jun Mar : ivy.xml
drwxr-xr-x. jun jun Mar : lib
-rw-rw-r--. jun jun Mar : LICENSE.txt
-rw-rw-r--. jun jun Mar : NOTICE.txt
-rw-rw-r--. jun jun Mar : README.md
-rw-rw-r--. jun jun Mar : README_packaging.txt
drwxr-xr-x. jun jun Mar : recipes
drwxr-xr-x. jun jun Mar : src
-rw-rw-r--. jun jun Mar : zookeeper-3.4..jar
-rw-rw-r--. jun jun Mar : zookeeper-3.4..jar.asc
-rw-rw-r--. jun jun Mar : zookeeper-3.4..jar.md5
-rw-rw-r--. jun jun Mar : zookeeper-3.4..jar.sha1

  2.使用gedit编辑zoo.cfg配置文件

[jun@master zookeeper-3.4.]$ cp /home/jun/zookeeper-3.4./conf/zoo_sample.cfg  /home/jun/zookeeper-3.4./conf/zoo.cfg
[jun@master zookeeper-3.4.]$ gedit /home/jun/zookeeper-3.4./conf/zoo.cfg

  将下面的配置增加到最后面,配置的意思是“服务器编号、服务器地址、LF通信端口(Leader与Follower)、选举端口”

server.=master::
server.=slave0::
server.=slave1::

  3.创建节点标志文件  

  由于在zoo.cfg当中配置了三台服务器,每一台服务器本地也需要一个myid文件,里面包含服务器的ID号,需要在三台机器上都创建myid文件。以master为例:

  首先递归创建目录(-p)

[jun@master zookeeper-3.4.]$ mkdir -p /tmp/zookeeper
[jun@master zookeeper-3.4.]$ gedit /tmp/zookeeper/myid

  然后新建myid文件并输入对应的id号,只输入一个1即可。

[jun@master zookeeper-3.4.]$ cat /tmp/zookeeper/myid

  另外两台机器同理。

  4.将Zookeeper安装文件从master复制到slave上(-r的意思是拷贝所有的文件和文件夹)

[jun@master zookeeper-3.4.]$ scp -r /home/jun/zookeeper-3.4./   slave0:~
[jun@master zookeeper-3.4.]$ scp -r /home/jun/zookeeper-3.4./ slave1:~

  5.Zookeeper集群的启动

  (1)需要在三个节点上分别执行启动操作

[jun@master zookeeper-3.4.]$ /home/jun/zookeeper-3.4./bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /home/jun/zookeeper-3.4./bin/../conf/zoo.cfg
Starting zookeeper ... STARTED [jun@slave0 ~]$ /home/jun/zookeeper-3.4.12/bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /home/jun/zookeeper-3.4.12/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED [jun@slave1 ~]$ /home/jun/zookeeper-3.4.12/bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /home/jun/zookeeper-3.4.12/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

  (2)至少启动两台服务器后,集群才会开始选举leader节点,可以在三台服务器上分别查看集群的状态,可以看到slave0节点是leader节点。

[jun@master ~]$ /home/jun/zookeeper-3.4./bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/jun/zookeeper-3.4./bin/../conf/zoo.cfg
Mode: follower [jun@slave0 ~]$ /home/jun/zookeeper-3.4./bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/jun/zookeeper-3.4./bin/../conf/zoo.cfg
Mode: leader [jun@slave1 ~]$ /home/jun/zookeeper-3.4./bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/jun/zookeeper-3.4./bin/../conf/zoo.cfg
Mode: follower

  (3)Zookeeper客户端交互式操作

[jun@master ~]$ /home/jun/zookeeper-3.4./bin/zkCli.sh -server master:
Connecting to master:
-- ::, [myid:] - INFO [main:Environment@] - Client environment:zookeeper.version=3.4.-e5259e437540f349646870ea94dc2658c4e44b3b, built on // : GMT
-- ::, [myid:] - INFO [main:Environment@] - Client environment:host.name=master
-- ::, [myid:] - INFO [main:Environment@] - Client environment:java.version=1.8.0_171
-- ::, [myid:] - INFO [main:Environment@] - Client environment:java.vendor=Oracle Corporation
-- ::, [myid:] - INFO [main:Environment@] - Client environment:java.home=/usr/java/jdk1..0_171/jre
-- ::, [myid:] - INFO [main:Environment@] - Client environment:java.class.path=/home/jun/zookeeper-3.4./bin/../build/classes:/home/jun/zookeeper-3.4./bin/../build/lib/*.jar:/home/jun/zookeeper-3.4.12/bin/../lib/slf4j-log4j12-1.7.25.jar:/home/jun/zookeeper-3.4.12/bin/../lib/slf4j-api-1.7.25.jar:/home/jun/zookeeper-3.4.12/bin/../lib/netty-3.10.6.Final.jar:/home/jun/zookeeper-3.4.12/bin/../lib/log4j-1.2.17.jar:/home/jun/zookeeper-3.4.12/bin/../lib/jline-0.9.94.jar:/home/jun/zookeeper-3.4.12/bin/../lib/audience-annotations-0.5.0.jar:/home/jun/zookeeper-3.4.12/bin/../zookeeper-3.4.12.jar:/home/jun/zookeeper-3.4.12/bin/../src/java/lib/*.jar:/home/jun/zookeeper-3.4.12/bin/../conf:
2018-07-23 14:06:51,051 [myid:] - INFO [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2018-07-23 14:06:51,051 [myid:] - INFO [main:Environment@100] - Client environment:java.io.tmpdir=/tmp
2018-07-23 14:06:51,051 [myid:] - INFO [main:Environment@100] - Client environment:java.compiler=<NA>
2018-07-23 14:06:51,052 [myid:] - INFO [main:Environment@100] - Client environment:os.name=Linux
2018-07-23 14:06:51,052 [myid:] - INFO [main:Environment@100] - Client environment:os.arch=amd64
2018-07-23 14:06:51,052 [myid:] - INFO [main:Environment@100] - Client environment:os.version=3.10.0-862.el7.x86_64
2018-07-23 14:06:51,052 [myid:] - INFO [main:Environment@100] - Client environment:user.name=jun
2018-07-23 14:06:51,052 [myid:] - INFO [main:Environment@100] - Client environment:user.home=/home/jun
2018-07-23 14:06:51,052 [myid:] - INFO [main:Environment@100] - Client environment:user.dir=/home/jun
2018-07-23 14:06:51,053 [myid:] - INFO [main:ZooKeeper@441] - Initiating client connection, connectString=master:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@799f7e29
Welcome to ZooKeeper!
2018-07-23 14:06:51,111 [myid:] - INFO [main-SendThread(master:2181):ClientCnxn$SendThread@1028] - Opening socket connection to server master/192.168.1.100:2181. Will not attempt to authenticate using SASL (unknown error)
JLine support is enabled
2018-07-23 14:06:51,191 [myid:] - INFO [main-SendThread(master:2181):ClientCnxn$SendThread@878] - Socket connection established to master/192.168.1.100:2181, initiating session
[zk: master:2181(CONNECTING) 0] 2018-07-23 14:06:51,269 [myid:] - INFO [main-SendThread(master:2181):ClientCnxn$SendThread@1302] - Session establishment complete on server master/192.168.1.100:2181, sessionid = 0x1000005d8900000, negotiated timeout = 30000 WATCHER:: WatchedEvent state:SyncConnected type:None path:null [zk: master:2181(CONNECTED) 0] help
ZooKeeper -server host:port cmd args
stat path [watch]
set path data [version]
ls path [watch]
delquota [-n|-b] path
ls2 path [watch]
setAcl path acl
setquota -n|-b val path
history
redo cmdno
printwatches on|off
delete path [version]
sync path
listquota path
rmr path
get path [watch]
create [-s] [-e] path data acl
addauth scheme auth
quit
getAcl path
close
connect host:port
[zk: master:2181(CONNECTED) 1] quit
Quitting...
2018-07-23 14:07:36,575 [myid:] - INFO [main:ZooKeeper@687] - Session: 0x1000005d8900000 closed
2018-07-23 14:07:36,577 [myid:] - INFO [main-EventThread:ClientCnxn$EventThread@521] - EventThread shut down for session: 0x1000005d8900000

  

  二、HBase的安装

  1.从http://apache.fayea.com/hbase/stable/下载hbase-1.2.6.1-bin.tar.gz并赋值到/home/jun下并解压。、

[jun@master ~]$ cd hbase-1.2.6.1/
[jun@master hbase-1.2.6.1]$ ls -l
total
drwxr-xr-x. jun jun Jun : bin
-rw-r--r--. jun jun Jun : CHANGES.txt
drwxr-xr-x. jun jun Jun : conf
drwxr-xr-x. jun jun Jun : docs
drwxr-xr-x. jun jun Jun : hbase-webapps
-rw-rw-r--. jun jun Jun : LEGAL
drwxrwxr-x. jun jun Jul : lib
-rw-rw-r--. jun jun Jun : LICENSE.txt
-rw-rw-r--. jun jun Jun : NOTICE.txt
-rw-r--r--. jun jun Jun : README.txt

  2.修改conf文件夹下的环境变量hbase-env.sh

# The java implementation to use.  Java 1.7+ required.
export JAVA_HOME=/usr/java/jdk1..0_171/

  由于使用的jdk1.8,因此还需要将下面两行注释掉:

# Configure PermSize. Only needed in JDK7. You can safely remove it for JDK8+
#export HBASE_MASTER_OPTS="$HBASE_MASTER_OPTS -XX:PermSize=128m -XX:MaxPermSize=128m"
#export HBASE_REGIONSERVER_OPTS="$HBASE_REGIONSERVER_OPTS -XX:PermSize=128m -XX:MaxPermSize=128m"

  3.修改conf文件夹下的配置文件hbase-site.xml

<configuration>

    <property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property> <property>
<name>hbase.rootdir</name>
<value>hdfs://master:9000/hbase</value>
</property> <property>
<name>hbase.zookeeper.quorum</name>
<value>master</value>
</property> <property>
<name>hbase.master.info.port</name>
<value></value>
</property> </configuration>

  4.设置conf文件夹下的regionservers

  regionservers文件类似Hadoop的slaves文件,其中保存了rigionserver的列表,启动HBase的时候,系统将根据该文件建立HBase集群。需要先删除localhost并添加两条配置

slave0
slave1

  5.设置linux环境变量并source生效

#hbase
export HBASE_HOME=/home/jun/hbase-1.2.6.1/
export PATH=$HBASE_HOME/bin:$PATH
export HADOOP_CLASSPATH=$HBASE_HOME/lib/*

  6.将HBase安装文件复制到slave节点

[jun@master conf]$ scp -r /home/jun/hbase-1.2.6.1/  slave0:~/
[jun@master conf]$ scp -r /home/jun/hbase-1.2.6.1/ slave1:~/

  7.启动并验证HBase

  (1)执行start-hbase.sh启动HBase,可以看到,系统首先启动HBase自带的ZooKeeper,然后启动HBase的HMaster,接着分别启动slave节点上的regionservers。

[jun@master conf]$ start-hbase.sh
master: starting zookeeper, logging to /home/jun/hbase-1.2.6.1/bin/../logs/hbase-jun-zookeeper-master.out
starting master, logging to /home/jun/hbase-1.2.6.1//logs/hbase-jun-master-master.out
slave0: starting regionserver, logging to /home/jun/hbase-1.2.6.1/bin/../logs/hbase-jun-regionserver-slave0.out
slave1: starting regionserver, logging to /home/jun/hbase-1.2.6.1/bin/../logs/hbase-jun-regionserver-slave1.out

  (2)查看各结点的jps,其中HMaster是HBase的主控节点进程,HQuorumPeer是HBase的ZooKeeper进程(即HBase内置的ZooKeeper)。

[jun@master ~]$ jps
Jps
SecondaryNameNode
ResourceManager
HMaster
HQuorumPeer
NameNode [jun@slave0 ~]$ jps
NodeManager
HRegionServer
QuorumPeerMain
DataNode
Jps [jun@slave1 ~]$ jps
DataNode
Jps
QuorumPeerMain
HRegionServer
NodeManager

  (3)使用Web方式查看HBase系统的运行状态,访问http://master:60010

  三、HBase的Shell命令

  执行hbase shell即可进入HBase Shell

  1.创建表,其中第一个参数是表名,f1和f12是列名

hbase(main)::> create "test1", {NAME => 'f1', VERSION => }
Unknown argument ignored for column family f1: 1.8.
row(s) in 2.6300 seconds => Hbase::Table - test1
hbase(main)::> create 'test2', 'f12'
row(s) in 2.2360 seconds => Hbase::Table - test2

  2.查看列表

hbase(main)::> list
TABLE
test1
test2
row(s) in 0.0270 seconds => ["test1", "test2"]

  3.插入数据,其中test1是表名,id001是行键(row key),f1是列族名,uid是属性名,001是属性值

hbase(main)::> put 'test1', 'id001', 'f1:uid', ''
row(s) in 0.2300 seconds

  4.扫描查询数据

hbase(main)::> scan 'test1'
ROW COLUMN+CELL
id001 column=f1:uid, timestamp=, value=
row(s) in 0.0750 seconds

  5.查看表结构

hbase(main)::> describe 'test1'
Table test1 is ENABLED
test1
COLUMN FAMILIES DESCRIPTION
{NAME => 'f1', BLOOMFILTER => 'ROW', VERSIONS => '', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => '
FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '', BLOCKCACHE => 'true', BLOCKSIZE => '', REPLICATION_SCOPE => ''}
row(s) in 0.0310 seconds hbase(main)::> describe 'test2'
Table test2 is ENABLED
test2
COLUMN FAMILIES DESCRIPTION
{NAME => 'f12', BLOOMFILTER => 'ROW', VERSIONS => '', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL =>
'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '', BLOCKCACHE => 'true', BLOCKSIZE => '', REPLICATION_SCOPE => ''}
row(s) in 0.0140 seconds

  6.删除表

hbase(main)::> list
TABLE
test1
test2
row(s) in 0.0100 seconds => ["test1", "test2"]
hbase(main)::> disable 'test2'
row(s) in 2.2890 seconds hbase(main)::> drop 'test2'
row(s) in 1.2660 seconds hbase(main)::> list
TABLE
test1
row(s) in 0.0110 seconds => ["test1"]

  7.退出HBase Shell

hbase(main)::> exit

  四、HBase和ZooKeeper的关系

  如果用户在使用HBase自带的ZooKeeper的时候出现异常,导致HBase不能正常工作,这时可以停止使用自带的Zookeeper,转而启动独立安装的ZooKeeper,并重启HBase,可以快速解决上述问题。

  要想让HBase使用独立安装的Zookeeper,需要对HBase进行一些配置上的修改。

  1.修改conf/hbase-env.sh文件,添加如下代码(true表示使用自带的ZooKeeper)

export HBASE_MANAGES_ZK=false

  2.将Zookeeper配置文件复制到HBase的CLASSPATH

cp /home/jun/zookeeper-3.4./conf/zoo.cfg  /home/jun/hbase-1.2.6.1/conf

  3.重启HBase即可

Zookeeper与HBase的安装的更多相关文章

  1. Hadoop、Zookeeper、Hbase分布式安装教程

    参考: Hadoop安装教程_伪分布式配置_CentOS6.4/Hadoop2.6.0   Hadoop集群安装配置教程_Hadoop2.6.0_Ubuntu/CentOS ZooKeeper-3.3 ...

  2. mysql 和 hive 和分布式zookeeper和HBASE分布式安装教程

    一,mysql 安装mysql5.7完整教程1. yum -y install mysql-server直接执行语句后等待就好已安装: mysql-community-server.x86_64 0: ...

  3. Hbase的安装测试工作

    Hbase的安装测试工作: 安装:http://www.cnblogs.com/neverwinter/archive/2013/03/28/2985798.html 测试:http://www.cn ...

  4. HBase 的安装与配置

    实验简介 本次实验学习和了解 HBase 在不同模式下的配置和安装,以及 HBase 后续的启动和停止等. 一.实验环境说明 1. 环境登录 无需密码自动登录,系统用户名shiyanlou,密码shi ...

  5. HBASE的安装

    HBASE的安装: 安装的软件版本:hbase-0.98.4-hadoop2.tar.gz 下载链接:http://www.apache.org/dist/hbase/hbase-0.98.4/ 1. ...

  6. 一、Hbase的安装

    一.Hbase配置 这个是我从网上找的一个版本,网上说配置成功. 先决条件: (1)hadoop的版本与hbase的版本要对应,主要是hadoop目录下的hadoop-core-1.0.4.jar的版 ...

  7. Centos7上HBase的安装和配置

    注意事项 HBase配置必须使用主机名,不支持直接配置IP地址.我尝试过,如果不使用主机名直接用IP,会导致HBase连接zk超时. > 设置主机名 hostnamectl set-hostna ...

  8. Hbase简介安装配置

    HBase —— Hadoop Database的简称 ,hbase 是分布式,稀疏的,持久化的,多维有序映射,它基于行键rowkey,列键column key,时间戳timestamp建立索引.它是 ...

  9. Hbase的安装和基本使用

    Hbase介绍 HBase是一个开源的非关系型分布式数据库(NoSQL),它参考了谷歌的BigTable建模,实现的编程语言为 Java.它是Apache软件基金会的Hadoop项目的一部分,运行于H ...

随机推荐

  1. asp.net core IdentityServer4 实现 implicit(隐式许可)实现第三方登录

    前言 OAuth 2.0默认四种授权模式(GrantType) 授权码模式(authorization_code) 简化模式(implicit) 密码模式(resource owner passwor ...

  2. 阿里云服务器CentOS6.9安装Tomcat

    上篇讲了CentOS6.9安装jdk,这篇来讲Tomcat的安装,本来准备使用yum命令安装的,但是通过 yum search tomcat 发现只有tomcat6,所以就在官网下了一个tomcat8 ...

  3. 利用threading模块开线程

    一多线程的概念介绍 threading模块介绍 threading模块和multiprocessing模块在使用层面,有很大的相似性. 二.开启多线程的两种方式 1.创建线程的开销比创建进程的开销小, ...

  4. [LeetCode] 1137. N-th Tribonacci Number

    Description e Tribonacci sequence Tn is defined as follows: T0 = 0, T1 = 1, T2 = 1, and Tn+3 = Tn + ...

  5. MySql 8.0.12安装、配置

    1. 参考:① 菜鸟教程下载安装MySQl ② 8.0.12安装方法 以下是我遇到的问题: 2.执行 mysqd --initialize --console 后,这个时候运行突然报"无法启 ...

  6. python爬虫入门10分钟爬取一个网站

    一.基础入门 1.1什么是爬虫 爬虫(spider,又网络爬虫),是指向网站/网络发起请求,获取资源后分析并提取有用数据的程序. 从技术层面来说就是 通过程序模拟浏览器请求站点的行为,把站点返回的HT ...

  7. 03 python基础作业(一)

    1.将['alex','eric',’rain’]用下划线拼接成字符串.(['alex','eric',123]呢?) li=['alex','eric','rain'] v='_'.join(li) ...

  8. 利用npm安装/删除/查看包信息

    查看远程服务器上的包的版本信息 npm view webpack version //查看npm服务器上包webpack的最新版本 npm view webpack versions //查看服务器上 ...

  9. 浅谈json web token及应用

    Json Web Token (JWT),是一个非常轻巧的规范,这个规范允许在网络应用环境间客户端和服务器间较安全的传递信息.该token被设计为紧凑且安全的,特别适用于分布式站点的单点登录(SSO) ...

  10. Linux快速入门

    一.Linux介绍 1.Linux是基于Unix的开源免费的操作系统 2.Linux的分类: (1)Linux根据市场需求不同,基本分为两个方向: 1)图形化界面版:注重用户体验,类似window操作 ...