搭建 Hbase 集群
在内容开始之前需要了解一下几个方面的知识会更好的帮助学习和搭建Hbase集群
- Hadoop:Hbase 是建立在 Hadoop基础之上的分布式数据库。了解 Hadoop 的基本概念和架构将有助于您理解 Hbase 的工作原理。
- 分布式系统:Hbase是一个分布式数据库,它将数据存储在多台服务器上。了解分布式系统的概念、优点、挑战和常见的解决方案,将帮助您更好地理解和管理 Hbase集群。
- ZooKeeper:Hbase 使用 ZooKeeper 来协调和管理集群中的各个节点。了解 ZooKeeper的基本概念、角色和功能,以及如何安装、配置和运行 ZooKeeper,将有助于您正确地配置和管理 Hbase 的 ZooKeeper。
- 网络和主机配置:在搭建 Hbase集群之前,需要确保服务器之间能够相互通信,并具有足够的网络带宽和稳定性。此外,还需要了解如何设置主机名解析和网络配置,以便在集群中使用主机名进行通信。
- 数据模型和表设计:Hbase 使用键值对存储和访问数据,了解如何设计良好的数据模型和表结构将有助于提高性能和查询效率。
- 安全性配置:在生产环境中搭建 Hbase集群时,安全性是一个重要的考虑因素。了解如何配置安全认证和访问控制,以保护您的数据和集群是很重要的。
一、准备工作
- Hadoop 官方网站 https://archive.apache.org/dist/hadoop/common/
- Hbase:官方网站 https://archive.apache.org/dist/hbase/
- ZooKeeper:Hbase 使用 ZooKeeper进行协调和管理。官方网站:https://archive.apache.org/dist/zookeeper/
- HDFS:Hbase 使用 Hadoop HDFS存储其数据。因此,您需要安装和配置 Hadoop HDFS。一般情况下,Hadoop 的安装包中已经包含了 HDFS。
- JDK:确保服务器上安装了 Java Development Kit(JDK)。Hadoop 和 Hbase 都需要运行在 Java环境中,因此需要安装并正确配置 JDK。
我们在这里使用的是一下版本:
lvrensun-server1
[root@lvrensun-server1 soft]# pwd
/root/soft
[root@lvrensun-server1 soft]# ll -h
总用量 700M
-rw-r--r--. 1 root root 396M 2月 223:09 hadoop-2.10.2.tar.gz
-rw-r--r--. 1 root root 79M 1月 30 01:50 hbase-0.98.6-hadoop2-bin.tar.gz
-rw-r--r--. 1 root root 177M 3月 162017 jdk-8u131-linux-x64.tar.gz
-rw-r--r--. 1 root root 16M 1月 30 01:50 zookeeper-3.4.5.tar.gz
[root@lvrensun-server1 soft]#
lvrensun-server2
[root@lvrensun-server2 soft]# pwd
/root/soft
[root@lvrensun-server2 soft]# ll -h
总用量 0[root@lvrensun-server2 soft]#
lvrensun-server3
[root@lvrensun-server3 soft]# pwd
/root/soft
[root@lvrensun-server3 soft]# ll -h
总用量 0[root@lvrensun-server3 soft]#
可以看到上方显示有三台服务器分别是:
hostnameIP资源路径是否有资源包lvrensun-server1192.168.0.11/root/soft是lvrensun-server2192.168.0.22/root/soft否lvrensun-server3192.168.0.33/root/soft否
二、三台服务器之间的 SSH 免密登录
1.修改hosts文件添加DNS映射
vim/etc/hosts
如下图所示
2.在每台服务器上生成 SSH 密钥对
[root@lvrensun-server1soft]#ssh-keygen-trsa
[root@lvrensun-server2soft]#ssh-keygen-trsa
[root@lvrensun-server3soft]#ssh-keygen-trsa
在生成密钥对时,您可以选择存储位置和设置密钥的密码。如果留空密码,则可以实现完全无密码的免密登录。
3.将公共密钥(通常为 ~/.ssh/id_rsa.pub)复制到目标服务器上
[root@lvrensun-server1~]#[email protected][root@lvrensun-server1~]#[email protected][root@lvrensun-server1~]#[email protected]
[root@lvrensun-server2~]#[email protected][root@lvrensun-server2~]#[email protected][root@lvrensun-server2~]#[email protected]
[root@lvrensun-server3~]#[email protected][root@lvrensun-server3~]#[email protected][root@lvrensun-server3~]#[email protected]
前两步其中一台服务器详细执行步骤如下:
[root@lvrensun-server1soft]#ssh-keygen-trsaGeneratingpublic/privatersakeypair.Enterfileinwhichtosavethekey(/root/.ssh/id_rsa):Enterpassphrase(emptyfornopassphrase):Entersamepassphraseagain:Youridentificationhasbeensavedin/root/.ssh/id_rsa.Yourpublickeyhasbeensavedin/root/.ssh/id_rsa.pub.Thekeyfingerprintis:SHA256:QeDtQ6BMG5mIM2rk2DjM87H5Qe9uCv2i16bF55CI3fIroot@lvrensun-server1Thekey'srandomartimageis:+---[RSA2048]----+|..ooo..||+..oo=+||B=+.+||=*...o.||..o=.S||++.+...||o.=+*.||.+==+||.ooBE.|+----[SHA256]-----+[root@lvrensun-server1~]#cat~/.ssh/id_rsa.pubssh-rsaAAAAB3NzaC1yc2EAAAADAQABAAABAQDNW0i7f2CAa/rq55WqUtJBc8igbOSTrsJGlFjX2s1XmONL1nPHk3eKEy1HrqC5kpEwgjYcIawtIq/apERkjqeGNRbjV9/Sq7zUvwiONA1+WJTwI80RyH84ZhV6aHuXTrly+9cx8UF1TbVRh0WgWZcjzFZdzDVIcB18zsBmWXZsGZxxVYD4fjkfXjMKJwOcAGXlUWb3J7O30uB9GcJhasTN98QcFmVp+cGldNJbTlXgUSUffD0HTOAPhlWDgWI3dFq+jCnCI4XzugyF0vU4dv81FiBTgcTxJ25tJvnw2PwtxhSEpklfK9UuYLBrOlDMsDBlkKBITTddJkLOvCsLr1Srroot@lvrensun-server1[root@lvrensun-server1~]#[email protected]/usr/bin/ssh-copy-id:INFO:Sourceofkey(s)tobeinstalled:"/root/.ssh/id_rsa.pub"Theauthenticityofhost '192.168.0.11(192.168.0.11)' can'tbeestablished.ECDSAkeyfingerprintisSHA256:SPQuwBgvdNmYL9PVBgcGTkuynS9iqvn3pBvXv6ZcePw.ECDSAkeyfingerprintisMD5:db:a1:53:83:6c:52:e5:6c:d8:75:6a:05:47:b7:26:5b.Areyousureyouwanttocontinueconnecting(yes/no)?yes/usr/bin/ssh-copy-id:INFO:attemptingtologinwiththenewkey(s),tofilteroutanythatarealreadyinstalled/usr/bin/ssh-copy-id:INFO:1key(s)remaintobeinstalled-- if you are prompted now it is to install the new [email protected]'spassword:Numberofkey(s)added:1Nowtryloggingintothemachine,with:"ssh '[email protected]'"andchecktomakesurethatonlythekey(s)youwantedwereadded.[root@lvrensun-server1~]#[email protected]/usr/bin/ssh-copy-id:INFO:Sourceofkey(s)tobeinstalled:"/root/.ssh/id_rsa.pub"Theauthenticityofhost '192.168.0.22(192.168.0.22)' can'tbeestablished.ECDSAkeyfingerprintisSHA256:SPQuwBgvdNmYL9PVBgcGTkuynS9iqvn3pBvXv6ZcePw.ECDSAkeyfingerprintisMD5:db:a1:53:83:6c:52:e5:6c:d8:75:6a:05:47:b7:26:5b.Areyousureyouwanttocontinueconnecting(yes/no)?yes/usr/bin/ssh-copy-id:INFO:attemptingtologinwiththenewkey(s),tofilteroutanythatarealreadyinstalled/usr/bin/ssh-copy-id:INFO:1key(s)remaintobeinstalled-- if you are prompted now it is to install the new [email protected]'spassword:Numberofkey(s)added:1Nowtryloggingintothemachine,with:"ssh '[email protected]'"andchecktomakesurethatonlythekey(s)youwantedwereadded.[root@lvrensun-server1~]#[email protected]/usr/bin/ssh-copy-id:INFO:Sourceofkey(s)tobeinstalled:"/root/.ssh/id_rsa.pub"Theauthenticityofhost '192.168.0.33(192.168.0.33)' can'tbeestablished.ECDSAkeyfingerprintisSHA256:SPQuwBgvdNmYL9PVBgcGTkuynS9iqvn3pBvXv6ZcePw.ECDSAkeyfingerprintisMD5:db:a1:53:83:6c:52:e5:6c:d8:75:6a:05:47:b7:26:5b.Areyousureyouwanttocontinueconnecting(yes/no)?yes/usr/bin/ssh-copy-id:INFO:attemptingtologinwiththenewkey(s),tofilteroutanythatarealreadyinstalled/usr/bin/ssh-copy-id:INFO:1key(s)remaintobeinstalled-- if you are prompted now it is to install the new [email protected]'spassword:Numberofkey(s)added:1Nowtryloggingintothemachine,with:"ssh '[email protected]'"andchecktomakesurethatonlythekey(s)youwantedwereadded.[root@lvrensun-server1~]#
4.从本地使用 SSH 命令无需密码连接到目标服务器
lvrensun-server1
[root@lvrensun-server1~]#sshlvrensun-server1Lastlogin:FriFeb212:54:382024fromlvrensun-server2[root@lvrensun-server1~]#exit
登出
Connectiontolvrensun-server1closed.[root@lvrensun-server1~]#sshlvrensun-server2Lastlogin:FriFeb212:54:512024fromlvrensun-server2[root@lvrensun-server2~]#exit
登出
Connectiontolvrensun-server2closed.[root@lvrensun-server1~]#sshlvrensun-server3Lastlogin:FriFeb212:55:142024fromlvrensun-server2[root@lvrensun-server3~]#
lvrensun-server2
[root@lvrensun-server2~]#sshlvrensun-server1Lastlogin:FriFeb212:53:502024fromlvrensun-server2[root@lvrensun-server1~]#exit
登出
Connectiontolvrensun-server1closed.[root@lvrensun-server2~]#sshlvrensun-server2Lastlogin:FriFeb212:54:092024fromlvrensun-server2[root@lvrensun-server2~]#exit
登出
Connectiontolvrensun-server2closed.[root@lvrensun-server2~]#sshlvrensun-server3Lastlogin:FriFeb212:54:212024fromlvrensun-server2[root@lvrensun-server3~]#
lvrensun-server3
[root@lvrensun-server3~]#sshlvrensun-server1Lastlogin:FriFeb212:56:092024fromlvrensun-server1[root@lvrensun-server1~]#exit
登出
Connectiontolvrensun-server1closed.[root@lvrensun-server3~]#sshlvrensun-server2Lastlogin:FriFeb212:56:192024fromlvrensun-server1[root@lvrensun-server2~]#exit
登出
Connectiontolvrensun-server2closed.[root@lvrensun-server3~]#sshlvrensun-server3Lastlogin:FriFeb212:56:272024fromlvrensun-server1[root@lvrensun-server3~]#
二、安装JDK
Hadoop 和 Hbase 都需要运行在 Java环境中因此JDK属于基础环境
1.执行解压更名
tar-xzvfjdk-8u131-linux-x64.tar.gzmvjdk-1.8.0-u131/jdk1.8
如下:
-rw-r--r--. 1 root root 34687765 1月 30 01:50 hadoop-2.10.2-site.tar.gz-rw-r--r--. 1 root root 82347017 1月 30 01:50 hbase-0.98.6-hadoop2-bin.tar.gzdrwxr-xr-x.8101432553月 152017jdk1.8-rw-r--r--. 1 root root 185540433 3月 16 2017 jdk-8u131-linux-x64.tar.gz-rw-r--r--. 1 root root 16402010 1月 30 01:50 zookeeper-3.4.5.tar.gz
2.配置环境 source生效
vim /etc/profile
[root@lvrensun-server1soft]#vim/etc/profile
添加配置
exportJAVA_HOME=/root/soft/jdk1.8exportPATH=$PATH:$JAVA_HOME/bin
source生效
[root@lvrensun-server1soft]#source/etc/profile[root@lvrensun-server1soft]#java-versionjavaversion"1.8.0_131"Java(TM)SERuntimeEnvironment(build1.8.0_131-b11)JavaHotSpot(TM)64-BitServerVM(build25.131-b11,mixedmode)[root@lvrensun-server1soft]#
3.分发环境配置
分发JDK
[root@lvrensun-server1soft]#scp-rjdk1.8/lvrensun-server2:/root/soft/
[root@lvrensun-server1soft]#scp-rjdk1.8/lvrensun-server3:/root/soft/
分发环境变量
[root@lvrensun-server1soft]#scp/etc/profilelvrensun-server2:/etc/
[root@lvrensun-server1soft]#scp/etc/profilelvrensun-server3:/etc/
再到 lvresun-server2、lvrensun-server3 source生效环境变量
[root@lvrensun-server2~]#source/etc/profile[root@lvrensun-server2~]#java-versionjavaversion"1.8.0_131"Java(TM)SERuntimeEnvironment(build1.8.0_131-b11)JavaHotSpot(TM)64-BitServerVM(build25.131-b11,mixedmode)[root@lvrensun-server2~]#
[root@lvrensun-server3soft]#source/etc/profile[root@lvrensun-server3soft]#java-versionjavaversion"1.8.0_131"Java(TM)SERuntimeEnvironment(build1.8.0_131-b11)JavaHotSpot(TM)64-BitServerVM(build25.131-b11,mixedmode)[root@lvrensun-server3soft]#
三、安装ZooKeeper 来协调和管理集群中的各个节点
1.解压更名
[root@lvrensun-server1soft]#tar-xzvfzookeeper-3.4.5.tar.gz.......-rw-r--r--. 1 root root 34687765 1月 30 01:50 hadoop-2.10.2-site.tar.gz-rw-r--r--. 1 root root 82347017 1月 30 01:50 hbase-0.98.6-hadoop2-bin.tar.gzdrwxr-xr-x.8101432553月 152017jdk1.8-rw-r--r--. 1 root root 185540433 3月 16 2017 jdk-8u131-linux-x64.tar.gzdrwxr-xr-x.10501games409611月 52012zookeeper-3.4.5-rw-r--r--. 1 root root 16402010 1月 30 01:50 zookeeper-3.4.5.tar.gz[root@lvrensun-server1soft]#mvzookeeper-3.4.5zookeeper[root@lvrensun-server1soft]#ll
总用量 311512-rw-r--r--. 1 root root 34687765 1月 30 01:50 hadoop-2.10.2-site.tar.gz-rw-r--r--. 1 root root 82347017 1月 30 01:50 hbase-0.98.6-hadoop2-bin.tar.gzdrwxr-xr-x.8101432553月 152017jdk1.8-rw-r--r--. 1 root root 185540433 3月 16 2017 jdk-8u131-linux-x64.tar.gzdrwxr-xr-x.10501games409611月 52012zookeeper-rw-r--r--. 1 root root 16402010 1月 30 01:50 zookeeper-3.4.5.tar.gz[root@lvrensun-server1soft]#
2.修改配置文件
2-1.配置文件更名修改配置
[root@lvrensun-server1conf]#pwd/root/soft/zookeeper/conf[root@lvrensun-server1conf]#mvzoo_sample.cfgzoo.cfg[root@lvrensun-server1conf]#vimzoo.cfg
zoo.cfg 修改内容如下:
#ThenumberofmillisecondsofeachticktickTime=2000#Thenumberofticksthattheinitial#synchronizationphasecantakeinitLimit=10#Thenumberofticksthatcanpassbetween#sendingarequestandgettinganacknowledgementsyncLimit=5#thedirectorywherethesnapshotisstored.#donotuse/tmpforstorage,/tmphereisjust#examplesakes.dataDir=/root/soft/zookeeper/datadataLogDir=/root/soft/zookeeper/log#theportatwhichtheclientswillconnectclientPort=2181##Besuretoreadthemaintenancesectionofthe#administratorguidebeforeturningonautopurge.##http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance##ThenumberofsnapshotstoretainindataDir#autopurge.snapRetainCount=3#Purgetaskintervalinhours#Setto"0"todisableautopurgefeature#autopurge.purgeInterval=1server.1=lvrensun-server1:2888:2299server.2=lvrensun-server2:2888:2299server.3=lvrensun-server3:2888:2299
2-2.根据配置创建数据所需文件夹
[root@lvrensun-server1conf]#mkdir-p/root/soft/zookeeper/data[root@lvrensun-server1conf]#mkdir-p/root/soft/zookeeper/log[root@lvrensun-server1conf]#ll../
总用量 1488drwxr-xr-x.2501games1492月 213:18bin-rw-r--r--. 1 501 games 75988 10月 1 2012 build.xml-rw-r--r--. 1 501 games 70223 10月 1 2012 CHANGES.txtdrwxr-xr-x.2501games702月 213:32confdrwxr-xr-x.10501games1302月 213:18contribdrwxr-xr-x.2rootroot62月 213:34datadrwxr-xr-x.2501games40962月 213:18dist-mavendrwxr-xr-x.6501games40962月 213:18docs-rw-r--r--. 1 501 games 1953 10月 1 2012 ivysettings.xml-rw-r--r--. 1 501 games 3120 10月 1 2012 ivy.xmldrwxr-xr-x.4501games2352月 213:18lib-rw-r--r--. 1 501 games 11358 10月 1 2012 LICENSE.txtdrwxr-xr-x.2rootroot62月 213:34log-rw-r--r--. 1 501 games 170 10月 1 2012 NOTICE.txt-rw-r--r--. 1 501 games 1770 10月 1 2012 README_packaging.txt-rw-r--r--. 1 501 games 1585 10月 1 2012 README.txtdrwxr-xr-x.5501games472月 213:18recipesdrwxr-xr-x.8501games1542月 213:18src-rw-r--r--. 1 501 games 1315806 11月 5 2012 zookeeper-3.4.5.jar-rw-r--r--. 1 501 games 833 11月 5 2012 zookeeper-3.4.5.jar.asc-rw-r--r--. 1 501 games 33 11月 5 2012 zookeeper-3.4.5.jar.md5-rw-r--r--. 1 501 games 41 11月 5 2012 zookeeper-3.4.5.jar.sha1[root@lvrensun-server1conf]#
3.配置环境
[root@lvrensun-server1zookeeper]#vim/etc/profile
添加内容:
exportZOOKEEPER_HOME=/root/soft/zookeeperexportPATH=$PATH:$ZOOKEEPER_HOME/bin
生效
[root@lvrensun-server1zookeeper]#source/etc/profile
4.分发环境
分发包:
[root@lvrensun-server1soft]#pwd/root/soft[root@lvrensun-server1soft]#scp-rzookeeperlvrensun-server2:/root/soft/......[root@lvrensun-server1soft]#scp-rzookeeperlvrensun-server3:/root/soft/......[root@lvrensun-server1soft]#
5.分发环境
5-1.文件远程拷贝
[root@lvrensun-server1soft]#scp/etc/profilelvrensun-server2:/etc/
[root@lvrensun-server1soft]#scp/etc/profilelvrensun-server3:/etc/
5-2. lvresun-server2、lvrensun-server3 source生效环境变量
[root@lvrensun-server2soft]#source/etc/profile
[root@lvrensun-server3soft]#source/etc/profile
6. 每台zookeeper服务分配myid
[root@lvrensun-server1bin]#echo"1">/root/soft/zookeeper/data/myid
[root@lvrensun-server2bin]#echo"2">/root/soft/zookeeper/data/myid
[root@lvrensun-server3bin]#echo"3">/root/soft/zookeeper/data/myid
其中 myid中的 1、2、3 分别对应的是 zoo.cfg 文件中配置项server.1、server.2、server.3中一一对应的数字,知道就行了,对应即可
7.启动验证
从
[root@lvrensun-server1bin]#cd/root/soft/zookeeper/bin/[root@lvrensun-server1bin]#zkServer.shstartJMXenabledbydefaultUsingconfig:/root/soft/zookeeper/bin/../conf/zoo.cfgStartingzookeeper...STARTED[root@lvrensun-server1bin]#zkServer.shstatusJMXenabledbydefaultUsingconfig:/root/soft/zookeeper/bin/../conf/zoo.cfgMode:follower[root@lvrensun-server1bin]#
从
[root@lvrensun-server2bin]#cd/root/soft/zookeeper/bin/[root@lvrensun-server2bin]#zkServer.shstartJMXenabledbydefaultUsingconfig:/root/soft/zookeeper/bin/../conf/zoo.cfgStartingzookeeper...STARTED[root@lvrensun-server2bin]#zkServer.shstatusJMXenabledbydefaultUsingconfig:/root/soft/zookeeper/bin/../conf/zoo.cfgMode:follower[root@lvrensun-server2bin]#
主
[root@lvrensun-server3bin]#cd/root/soft/zookeeper//bin/[root@lvrensun-server3bin]#zkServer.shstartJMXenabledbydefaultUsingconfig:/root/soft/zookeeper/bin/../conf/zoo.cfgStartingzookeeper...STARTED[root@lvrensun-server3bin]#zkServer.shstatusJMXenabledbydefaultUsingconfig:/root/soft/zookeeper/bin/../conf/zoo.cfgMode:leader
启动一切正产 lvrensun-server3 为主节点
8.验证宕机选举是否正常
把主服务器停掉
[root@lvrensun-server3bin]#./zkServer.shstopJMXenabledbydefaultUsingconfig:/root/soft/zookeeper/bin/../conf/zoo.cfgStoppingzookeeper...STOPPED[root@lvrensun-server3bin]#
查看其他两台状态
从
[root@lvrensun-server1bin]#zkServer.shstatusJMXenabledbydefaultUsingconfig:/root/soft/zookeeper/bin/../conf/zoo.cfgMode:follower[root@lvrensun-server1bin]#
主
[root@lvrensun-server2bin]#zkServer.shstatusJMXenabledbydefaultUsingconfig:/root/soft/zookeeper/bin/../conf/zoo.cfgMode:leader[root@lvrensun-server2bin]#
可以看到 lvrensun-server2 服务器中zookeeper节点已经被选为主服务节点
四、安装 Hadoop Hbase 是建立在 Hadoop基础之上的分布式数据库
版权归原作者 小驴程序源 所有, 如有侵权,请联系我们删除。