hadoop/zookeeper/hbase(HA)体系搭建
2018-03-29 本文已影响87人
安静1337
环境简介
# 三台主机信息如下
# 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集群
参考文档