hadoop/zookeeper/hbase(HA)体系搭建

环境简介

# 三台主机信息如下
# linux version: `CentOS release 6.5 (Final)`

cat /etc/hosts

192.168.59.10 slave7 #master
192.168.59.11 slave8 #slave
192.168.59.12 slave9 #slave

配置ssh无密码访问

# 在三台机器上都创建hadoop账户

# 增加用户
useradd hadoop
# 查看用户信息
id hadoop
# 修改用户密码
password hadoop
# 没有特别说明都是在hadoop账户下操作
# 在所有机器(三台)先生成密钥对
ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa

# 把公钥文件,追加到授权文件authorized_keys中
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

# 修改权限,注意这个别遗漏了
chmod 700 ~/.ssh
chmod 644 ~/.ssh/authorized_keys

# 修改ssh配置,请切换root账户操作
vim /etc/ssh/sshd_config
把以下内容的注释取消掉
#RSAAuthentication yes # 启用 RSA 认证
#PubkeyAuthentication yes # 启用公钥私钥配对认证方式
#AuthorizedKeysFile .ssh/authorized_key #公钥文件路径

# 重启ssh服务
service sshd restart
# 退出root

# 验证本机是否无密码登录
ssh localhost

# 最后,把本机的id_rsa.pub文件里的内容追加到“其他”服务器中的~/.ssh/authorized_keys里
# 重复以上操作
# 到此,无密码访问设置完毕

配置java环境

# 解压后得到jdk目录
# /home/hadoop/jdk1.8.0_73

vim ~/.bashrc

# 设置JDK相关信息
export JAVA_HOME=/home/hadoop/jdk1.8.0_73
PATH=${JAVA_HOME}/bin:$PATH

搭建zookeeper集群

# zookeeper版本:3.4.10
# 解压zookeeper-3.4.10.tar.gz
# zookeeper顶级目录为:/home/hadoop/zookeeper-3.4.10

# 创建dataDir和dataLogDir
mkdir /home/hadoop/zookeeper-3.4.10/{datadir,datalogdir}

# 创建配置文件:zoo.cfg
cp /home/hadoop/zookeeper-3.4.10/conf/zoo_sample.cfg /home/hadoop/zookeeper-3.4.10/conf/zoo.cfg

在配置文件zoo.cfg中修改添加内容,最终结果如下

# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial 
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between 
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just 
# example sakes.
dataDir=/home/hadoop/zookeeper-3.4.10/datadir
dataLogDir=/home/hadoop/zookeeper-3.4.10/datalogdir
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the 
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
autopurge.purgeInterval=1

server.7=slave7:2888:3888
server.8=slave8:2888:3888
server.9=slave9:2888:3888
# 在datadir目录下创建myid文件

echo "7" > myid
# 上面的“7”跟配置文件中“server.7”保持一致,
# 其他机器一样是类似的修改

# 确保在每台机器上都按照上面要求创建完毕
# 并且都在相同目录下,最后,对于每台服务器都执行

# 启动zookeeper
cd ~/zookeeper-3.4.10/bin/ && ./zkServer.sh start

# 停止zookeeper命令
./zkServer.sh stop

# 查看zookeeper状态命令
./zkServer.sh status

搭建hadoop集群

# hadoop版本:2.7.3
# 解压hadoop-2.7.3.tar.gz
# hadoop顶级目录为:/home/hadoop/hadoop-2.7.3

# 先进入hadoop配置文件目录

cd /home/hadoop/hadoop-2.7.3/etc/hadoop

修改hadoop-env.sh

vim hadoop-env.sh
# 在脚本开头添加如下内容
export JAVA_HOME=/home/hadoop/jdk1.8.0_73

修改yarn-env.sh

vim yarn-env.sh
# 在脚本开头添加如下内容
export JAVA_HOME=/home/hadoop/jdk1.8.0_73

修改 core-site.xml,配置文件如下

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License. See accompanying LICENSE file.
-->

<!-- Put site-specific property overrides in this file. -->

<configuration>
    <!-- 指定hdfs的nameservice为ns1 名字随意-->
    <property>
        <name>fs.defaultFS</name>
        <value>hdfs://ns1</value>
    </property>

    <!-- 指定hadoop临时目录 -->
    <property>
        <name>hadoop.tmp.dir</name>
        <value>/home/hadoop/hadoop-2.7.3/hadoop.tmp.dir</value>
    </property>

    <!-- 指定zookeeper地址 -->
    <property>
        <name>ha.zookeeper.quorum</name>
        <value>slave7:2181,slave8:2181,slave9:2181</value>
    </property>

    <property>
        <name>io.file.buffer.size</name>
        <value>4096</value>
    </property>

</configuration>

修改hdfs-site.xml,配置文件如下

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License. See accompanying LICENSE file.
-->

<!-- Put site-specific property overrides in this file. -->

<configuration>

    <!--指定hdfs的nameservice为ns1,需要和core-site.xml中的保持一致 -->
    <property>
        <name>dfs.nameservices</name>
        <value>ns1</value>
    </property>

    <!-- ns1下面有两个NameNode,分别是nn1,nn2(名字随意起,但是要与下面一致)-->
    <property>
        <name>dfs.ha.namenodes.ns1</name>
        <value>nn1,nn2</value>
    </property>

    <!-- nn1的RPC通信地址 -->
    <property>
        <name>dfs.namenode.rpc-address.ns1.nn1</name>
        <value>slave7:9000</value>
    </property>

    <!-- nn1的http通信地址 -->
    <property>
        <name>dfs.namenode.http-address.ns1.nn1</name>
        <value>slave7:50070</value>
    </property>

    <!-- nn2的RPC通信地址 -->
    <property>
        <name>dfs.namenode.rpc-address.ns1.nn2</name>
        <value>slave8:9000</value>
    </property>

    <!-- nn2的http通信地址 -->
    <property>
        <name>dfs.namenode.http-address.ns1.nn2</name>
        <value>slave8:50070</value>
    </property>

    <!-- 指定NameNode的元数据在JournalNode上的存放位置 -->
    <property>
        <name>dfs.namenode.shared.edits.dir</name>
        <value>qjournal://slave7:8485;slave8:8485;slave9:8485/ns1</value>
    </property>

    <!-- 指定JournalNode在本地磁盘存放数据的位置 -->
    <property>
        <name>dfs.journalnode.edits.dir</name>
        <value>/home/hadoop/hadoop-2.7.3/journaldata</value>
    </property>

    <!-- 开启NameNode失败自动切换 -->
    <property>
        <name>dfs.ha.automatic-failover.enabled</name>
        <value>true</value>
    </property>

    <!-- 配置失败自动切换实现方式 -->
    <property>
        <name>dfs.client.failover.proxy.provider.ns1</name>
        <value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value>
    </property>

    <!-- 配置隔离机制方法,多个机制用换行分割,即每个机制暂用一行-->
    <property>
        <name>dfs.ha.fencing.methods</name>
        <value>
            sshfence
            shell(/bin/true)
        </value>
    </property>

    <!-- 使用sshfence隔离机制时需要ssh免登陆 -->
    <property>
        <name>dfs.ha.fencing.ssh.private-key-files</name>
        <value>/home/hadoop/.ssh/id_rsa</value>
    </property>

    <!-- 配置sshfence隔离机制超时时间 -->
    <property>
        <name>dfs.ha.fencing.ssh.connect-timeout</name>
        <value>30000</value>
    </property>

    <!-- 指定HDFS副本的数量 -->
    <property>
        <name>dfs.replication</name>
        <value>2</value>
    </property>

    <!-- HDFS文件系统的元信息保存目录-->
    <property>
        <name>dfs.namenode.name.dir</name>
        <value>file:///home/hadoop/hadoop-2.7.3/namenode_dir</value>
    </property>

    <!-- HDFS文件系统的数据保存目录 -->
    <property>
        <name>dfs.datanode.data.dir</name>
        <value>file:///home/hadoop/hadoop-2.7.3/datanode_dir</value>
    </property>

    <!-- 在NN和DN上开启WebHDFS (REST API)功能,不是必须 -->
    <property>
        <name>dfs.webhdfs.enabled</name>
        <value>true</value>
    </property>

    <property>
        <name>dfs.permissions</name>
        <value>false</value>
        <description>
        If "true", enable permission checking in HDFS.
        If "false", permission checking is turned off,
        but all other behavior is unchanged.
        Switching from one parameter value to the other does not change the mode,
        owner or group of files or directories.
        </description>
    </property>

</configuration>

修改mapred-site.xml,配置文件如下

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License. See accompanying LICENSE file.
-->

<!-- Put site-specific property overrides in this file. -->

<configuration>
    <!-- 指定mr框架为yarn方式 -->
    <property>
        <name>mapreduce.framework.name</name>
        <value>yarn</value>
    </property>
</configuration>

修改yarn-site.xml,配置文件如下

<?xml version="1.0"?>
<!--
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License. See accompanying LICENSE file.
-->
<configuration>

<!-- Site specific YARN configuration properties -->

    <!-- 指定nodemanager启动时加载server的方式为shuffle server -->
    <property>
        <name>yarn.nodemanager.aux-services</name>
        <value>mapreduce_shuffle</value>
    </property>
    
    <!-- 指定resourcemanager地址 -->
    <property>
        <name>yarn.resourcemanager.hostname</name>
        <value>slave9</value>
    </property>

</configuration>

修改slaves文件,配置文件如下

slave7
slave8
slave9

最后,将hadoop2.7.3目录同步复制到所有服务器上

启动hadoop集群(如果是首次启动会特别标注说明,关闭集群顺序刚好相反)

# 确保zookeeper集群先启动,在本教程中,分别到slave7,slave8,slave9上在zookeeper目录下执行:
./zkServer.sh start
# 关闭
./zkServer.sh stop

# 格式化zookeeper集群,在slave7上执行(仅限首次启动):
bin/hdfs zkfc -formatZK

# 启动JournalNode集群
# 在slave7上执行:
sbin/hadoop-daemons.sh start journalnode
# 关闭
sbin/hadoop-daemons.sh stop journalnode
# 或者在slave7,slave8,slave9上分别都执行(注意daemons.sh和daemon.sh的区别):
sbin/hadoop-daemon.sh start journalnode
# 关闭
sbin/hadoop-daemon.sh stop journalnode

# 格式化集群的namenode(hdfs) (仅限首次启动)
bin/hadoop namenode -format

# 启动namenode(1),在slave7上执行:
sbin/hadoop-daemon.sh start namenode
# 关闭
sbin/hadoop-daemon.sh stop namenode

# 同步namenode(1)到namenode(2),并启动namenode(2),在slave8上执行:
bin/hdfs namenode –bootstrapStandby
sbin/hadoop-daemon.sh start namenode
# 关闭
sbin/hadoop-daemon.sh stop namenode

# 启动所有datanode,在slave7上执行:
sbin/hadoop-daemons.sh start datanode
# 关闭
sbin/hadoop-daemons.sh stop datanode

# 启动yarn,在作为资源管理器上的slave9机器上执行启动:
sbin/start-yarn.sh
# 关闭
sbin/stop-yarn.sh

# 启动zkfc集群,在slave7上执行:
sbin/hadoop-daemons.sh start zkfc
# 关闭
sbin/hadoop-daemons.sh stop zkfc

搭建hbase集群

# hbase版本:1.2.5
# 解压hbase-1.2.5-bin.tar.gz
# hbase顶级目录为:/home/hadoop/hbase-1.2.5
# 首先,进入hbase配置文件目录
cd /home/hadoop/hbase-1.2.5

打开hbase-env.sh,添加如下信息:

export JAVA_HOME=/home/hadoop/jdk1.8.0_73
export HBASE_LOG_DIR=${HBASE_HOME}/logs
# 不使用自带的zookeeper
export HBASE_MANAGES_ZK=false

配置hbase-site.xml,最终内容如下:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
/**
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
-->
<configuration>

    <property>
        <name>hbase.tmp.dir</name>
        <value>/home/hadoop/hbase-1.2.5/hbase.tmp.dir</value>
    </property>

    <!-- 设置HRegionServers共享目录 -->  
    <property>
        <name>hbase.rootdir</name>
        <value>hdfs://slave7:9000/hbase</value>
        <description>Hbase data director</description>
    </property>

    <!-- 开启分布式模式 -->
    <property>
        <name>hbase.cluster.distributed</name>
        <value>true</value>
    </property>

    <!-- 设置HMaster的rpc端口, 由于采用的是HA模式,这里只写端口就可以了,不需要再写主机名-->
    <property>
        <name>hbase.master.port</name>
        <value>60000</value>
    </property>
    <!-- 对比参考
    <property>
        <name>hbase.master</name>
        <value>hdfs://master:60000</value>
    </property>
    -->

    <!-- 设置HMaster的http web console端口 --> 
    <property>
        <name>hbase.master.info.port</name>
        <value>16010</value>
    </property>

    <!--zookeeper设置,依赖zookeeper集群设置-->
    <!--zookeeper集群信息设置-->
    <property>
        <name>hbase.zookeeper.quorum</name>
        <value>slave7,slave8,slave9</value>
    </property>

    <!--zookeeper端口-->
    <property>
        <name>hbase.zookeeper.property.clientPort</name>
        <value>2181</value>
    </property>

    <!--请参考zookeeper配置文件zoo.cfg中dataDir的值 -->
    <property>
        <name>hbase.zookeeper.property.dataDir</name>
        <value>/home/hadoop/zookeeper-3.4.10/datadir</value>
    </property>

</configuration>

配置regionservers,内容如下:

slave8
slave9

scp hbase目录到所有服务器(slave7,slave8,slave9)

启动hbase集群:

# 首先确保hadoop集群启动

# 启动hbase集群,在slave7上执行:
bin/start-hbase.sh
# 关闭
bin/stop-hbase.sh

后记:整个集群的启动先后顺序

zookeeper -> hadoop -> hbase

多次格式化集群,最后phoenix连接时,报错:

org.apache.phoenix.exception.PhoenixIOException: SYSTEM.CATALOG
//解决方法,停止hbase集群,执行 bin/hbase clean --cleanZk,然后启动hbase集群

参考文档

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 220,137评论 6 511
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 93,824评论 3 396
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 166,465评论 0 357
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 59,131评论 1 295
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 68,140评论 6 397
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,895评论 1 308
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,535评论 3 420
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,435评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,952评论 1 319
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 38,081评论 3 340
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 40,210评论 1 352
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,896评论 5 347
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,552评论 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 32,089评论 0 23
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,198评论 1 272
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,531评论 3 375
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 45,209评论 2 357

推荐阅读更多精彩内容