标签:port root ping nod serve 自动 传输 scores 需要
Hadoop2.7.3+HBase1.2.5+ZooKeeper3.4.6搭建分布式集群环境
一、环境说明
个人理解:
zookeeper可以独立搭建集群,hbase本身不能独立搭建集群需要和hadoop和hdfs整合
集群环境至少需要3个节点(也就是3台服务器设备):1个Master,2个Slave,节点之间局域网连接,可以相互ping通,下面举例说明,配置节点IP分配如下:
IP 角色
10.10.50.133 master
10.10.125.156 slave1
10.10.114.112 slave2
三个节点均使用CentOS 6.5系统,为了便于维护,集群环境配置项最好使用相同用户名、用户密码、相同Hadoop、Hbase、zookeeper目录结构。
注:
主机名和角色最好保持一致,如果不同也没关系,只需要在/etc/hosts中配置好对应关系即可
可以通过编辑/etc/sysconfig/network文件来修改 hostname
软件包下载准备:
hadoop-2.7.3.tar.gz
hbase-1.2.5-bin.tar.gz
zookeeper-3.4.6.tar.gz
jdk-8u111-linux-x64.rpm
因为是测试环境此次都使用root来操作,如果是生产环境建议使用其他用户如hadoop,需要给目录授权为hadoop
chown -R hadoop.hadoop /data/yunva
二、准备工作
2.1 安装JDK
在三台机器上配置JDK环境,下载 jdk-8u111-linux-x64.rpm 文件直接安装:
# rpm -ivh jdk-8u111-linux-x64.rpm
修改配置文件 vim /etc/profile:
export JAVA_HOME=/usr/java/jdk1.8.0_111 # 不同的jdk路径需要修改此项
export PATH=$JAVA_HOME/bin:$PATH
export HADOOP_HOME=/data/yunva/hadoop-2.7.3
export HADOOP_INSTALL=$HADOOP_HOME
export HADOOP_MAPRED_HOME=$HADOOP_HOME
export HADOOP_COMMON_HOME=$HADOOP_HOME
export HADOOP_HDFS_HOME=$HADOOP_HOME
export YARN_HOME=$HADOOP_HOME
export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_HOME/lib/native
export PATH=$PATH:$HADOOP_HOME/sbin:$HADOOP_HOME/bin
export HADOOP_SSH_OPTS="-p 48490" # 非默认ssh的22号端口需要添加此项,表示端口为48490
因本次部署环境,jdk不同所以需要单独修改配置:
master
export JAVA_HOME=/usr/java/jdk1.8.0_111
slave1
export JAVA_HOME=/usr/java/jdk1.8.0_65
slave2
export JAVA_HOME=/usr/java/jdk1.8.0_102
然后重新加载配置文件使之生效:
# source /etc/profile
2.2 添加Hosts映射关系
分别在三个节点上添加hosts映射关系:
# vim /etc/hosts
添加的内容如下:
10.10.50.133 master
10.10.125.156 slave1
10.10.114.112 slave2
2.3 集群之间SSH无密码登陆
CentOS默认安装了ssh,如果没有你需要先安装ssh 。
集群环境的使用必须通过ssh无密码登陆来执行,本机登陆本机必须无密码登陆,主机与从机之间必须可以双向无密码登陆,从机与从机之间无限制。
2.3.1 设置master无密码自动登陆slave1和slave2
主要有三步:
①生成公钥和私钥
②导入公钥到认证文件
③更改权限
# ssh-keygen -t rsa
# cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
# chmod 700 ~/.ssh && chmod 600 ~/.ssh/*
测试,第一次登录可能需要yes确认,之后就可以直接登录了:
# ssh master
# ssh slave1
# ssh slave2
对于 slave1 和 slave2,进行无密码自登陆设置,操作同上。
也有个快捷的操作方式,当所有的服务器都ssh-keygen -t rsa生成公钥后,在master上操作无密码登陆master/slave1/slave2成功后,直接拷贝给其他主机即可
然后,将证书文件复制到其他机器的用户主目录下
# scp -P 48490 authorized_keys master:/root/.ssh/
# scp -P 48490 authorized_keys slave1:/root/.ssh/
# scp -P 48490 authorized_keys slave2:/root/.ssh/
三、Hadoop集群安装配置
这里会将hadoop、hbase、zookeeper的安装包都解压到/data/yunva/文件夹下,并重命名
安装目录如下:
/data/yunva/hadoop-2.7.3
/data/yunva/hbase-1.2.5
/data/yunva/zookeeper-3.4.6
3.1 修改hadoop配置
配置文件都在/data/yunva/hadoop-2.7.3/etc/hadoop/目录下
3.1.1 core-site.xml
<configuration>
<property>
<name>fs.default.name</name>
<value>hdfs://master:9000</value>
</property>
</configuration>
3.1.2 hadoop-env.sh
添加JDK路径,如果不同的服务器jdk路径不同需要单独修改:
export JAVA_HOME=/usr/java/jdk1.8.0_111
3.1.3 hdfs-site.xml
# 创建hadoop的数据和用户目录
# mkdir -p /data/yunva/hadoop-2.7.3/hadoop/name
# mkdir -p /data/yunva/hadoop-2.7.3/hadoop/data
<configuration>
<property>
<name>dfs.name.dir</name>
<value>/data/yunva/hadoop-2.7.3/hadoop/name</value>
</property>
<property>
<name>dfs.data.dir</name>
<value>/data/yunva/hadoop-2.7.3/hadoop/data</value>
</property>
<property>
<name>dfs.replication</name>
<value>3</value>
</property>
</configuration>
3.1.4 mapred-site.xml
# mv mapred-site.xml.template mapred-site.xml
<configuration>
<property>
<name>mapred.job.tracker</name>
<value>master:9001</value>
</property>
</configuration>
3.1.5 修改slaves文件,localhost改为
# cat /data/yunva/hadoop-2.7.3/etc/hadoop/slaves
slave1
slave2
注意:三台机器上都进行相同的配置,都放在相同的路径下(如果jdk路径不同需要单独修改)
使用scp命令进行从本地到远程(或远程到本地)的轻松文件传输操作:
scp -r /data/yunva/hadoop-2.7.3/ slave1:/data/yunva
scp -r /data/yunva/hadoop-2.7.3/ slave2:/data/yunva
3.2 启动hadoop集群
进入master的/data/yunva/hadoop-2.7.3/目录,执行以下操作:
# bin/hadoop namenode -format
格式化namenode,第一次启动服务前执行的操作,以后不需要执行。
然后启动hadoop:
# sbin/start-all.sh
通过jps命令能看到除jps外有3个进程:
# jps
30613 NameNode
30807 SecondaryNameNode
887 Jps
30972 ResourceManager
hbase-env.sh(java路径不同需要修改)
master
export JAVA_HOME=/usr/java/jdk1.8.0_111
export HBASE_CLASSPATH=/data/yunva/hadoop-2.7.3/etc/hadoop/
export HBASE_MANAGES_ZK=false
export HBASE_SSH_OPTS="-p 48490" # 非默认ssh的22端口需要添加此项表示ssh为48490
slave1
export JAVA_HOME=/usr/java/jdk1.8.0_65
export HBASE_CLASSPATH=/data/yunva/hadoop-2.7.3/etc/hadoop/
export HBASE_MANAGES_ZK=false
export HBASE_SSH_OPTS="-p 48490"
slave2
export JAVA_HOME=/usr/java/jdk1.8.0_102
export HBASE_CLASSPATH=/data/yunva/hadoop-2.7.3/etc/hadoop/
export HBASE_MANAGES_ZK=false
export HBASE_SSH_OPTS="-p 48490"
四、ZooKeeper集群安装配置
可参考 centos6.5环境下zookeeper-3.4.6集群环境部署及单机部署详解http://blog.csdn.net/reblue520/article/details/52279486
五、HBase集群安装配置
配置文件目录/data/yunva/hbase-1.2.5/conf
5.1 hbase-env.sh
export JAVA_HOME=/usr/java/jdk1.8.0_111 # 如果jdk路径不同需要单独配置
export HBASE_CLASSPATH=/data/yunva/hadoop-2.7.3/etc/hadoop/
export HBASE_MANAGES_ZK=false
export HBASE_SSH_OPTS="-p 48490" # ssh端口非默认22需要修改
5.2 hbase-site.xml(保持一致)
<configuration>
<property>
<name>hbase.rootdir</name>
<value>hdfs://master:9000/hbase</value>
</property>
<property>
<name>hbase.master</name>
<value>master</value>
</property>
<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>
<property>
<name>hbase.zookeeper.property.clientPort</name>
<value>2181</value>
</property>
<property>
<name>hbase.zookeeper.quorum</name>
<value>master,slave1,slave2</value>
</property>
<property>
<name>zookeeper.session.timeout</name>
<value>60000000</value>
</property>
<property>
<name>dfs.support.append</name>
<value>true</value>
</property>
</configuration>
5.3 更改 regionservers
在 regionservers 文件中添加slave列表:
slave1
slave2
5.4 分发并同步安装包
将整个hbase安装目录都拷贝到所有slave服务器:
$ scp -P 48490 -r /data/yunva/hbase-1.2.5 slave1:/data/yunva/
$ scp -P 48490 -r /data/yunva/hbase-1.2.5 slave2:/data/yunva/
六、启动集群
1. 启动ZooKeeper
/data/yunva/zookeeper-3.4.6/bin/zkServer.sh start
2. 启动hadoop
/data/yunva/hadoop-2.7.3/sbin/start-all.sh
3. 启动hbase
/data/yunva/hbase-1.2.5/bin/start-hbase.sh
4. 启动后,master上进程和slave进程列表
[root@master ~]# jps
Jps
SecondaryNameNode # hadoop进程
NameNode # hadoop master进程
ResourceManager # hadoop进程
HMaster # hbase master进程
ZooKeeperMain # zookeeper进程
[root@slave1 ~]# jps
Jps
ZooKeeperMain # zookeeper进程
DataNode # hadoop slave进程
HRegionServer # hbase slave进程
5. 进入hbase shell进行验证
# cd /data/yunva/hbase-1.2.5/
[root@test6_vedio hbase-1.2.5]# bin/hbase shell
2017-04-28 09:51:51,479 WARN [main] util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/data/yunva/hbase-1.2.5/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/data/yunva/hadoop-2.7.3/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
HBase Shell; enter ‘help<RETURN>‘ for list of supported commands.
Type "exit<RETURN>" to leave the HBase Shell
Version 1.2.5, rd7b05f79dee10e0ada614765bb354b93d615a157, Wed Mar 1 00:34:48 CST 2017
hbase(main):001:0> list
TABLE
0 row(s) in 0.2620 seconds
=> []
hbase(main):003:0> create ‘scores‘, ‘grade‘, ‘course‘
0 row(s) in 1.3300 seconds
=> Hbase::Table - scores
hbase(main):004:0> list
TABLE
scores
1 row(s) in 0.0100 seconds
=> ["scores"]
6. 进入zookeeper shell进行验证
[root@test6_vedio zookeeper-3.4.6]# bin/zkCli.sh -server
2017-04-28 10:04:33,083 [myid:] - INFO [main:Environment@100] - Client environment:zookeeper.version=3.4.6-1569965, built on 02/20/2014 09:09 GMT
2017-04-28 10:04:33,088 [myid:] - INFO [main:Environment@100] - Client environment:host.name=test6_vedio
2017-04-28 10:04:33,088 [myid:] - INFO [main:Environment@100] - Client environment:java.version=1.8.0_111
2017-04-28 10:04:33,091 [myid:] - INFO [main:Environment@100] - Client environment:java.vendor=Oracle Corporation
2017-04-28 10:04:33,091 [myid:] - INFO [main:Environment@100] - Client environment:java.home=/usr/java/jdk1.8.0_111/jre
2017-04-28 10:04:33,091 [myid:] - INFO [main:Environment@100] - Client environment:java.class.path=/data/yunva/zookeeper-3.4.6/bin/../build/classes:/data/yunva/zookeeper-3.4.6/bin/../build/lib/*.jar:/data/yunva/zookeeper-3.4.6/bin/../lib/slf4j-log4j12-1.6.1.jar:/data/yunva/zookeeper-3.4.6/bin/../lib/slf4j-api-1.6.1.jar:/data/yunva/zookeeper-3.4.6/bin/../lib/netty-3.7.0.Final.jar:/data/yunva/zookeeper-3.4.6/bin/../lib/log4j-1.2.16.jar:/data/yunva/zookeeper-3.4.6/bin/../lib/jline-0.9.94.jar:/data/yunva/zookeeper-3.4.6/bin/../zookeeper-3.4.6.jar:/data/yunva/zookeeper-3.4.6/bin/../src/java/lib/*.jar:/data/yunva/zookeeper-3.4.6/bin/../conf:
2017-04-28 10:04:33,091 [myid:] - INFO [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2017-04-28 10:04:33,091 [myid:] - INFO [main:Environment@100] - Client environment:java.io.tmpdir=/tmp
2017-04-28 10:04:33,091 [myid:] - INFO [main:Environment@100] - Client environment:java.compiler=<NA>
2017-04-28 10:04:33,092 [myid:] - INFO [main:Environment@100] - Client environment:os.name=Linux
2017-04-28 10:04:33,092 [myid:] - INFO [main:Environment@100] - Client environment:os.arch=amd64
2017-04-28 10:04:33,092 [myid:] - INFO [main:Environment@100] - Client environment:os.version=2.6.32-431.11.25.el6.ucloud.x86_64
2017-04-28 10:04:33,092 [myid:] - INFO [main:Environment@100] - Client environment:user.name=root
2017-04-28 10:04:33,092 [myid:] - INFO [main:Environment@100] - Client environment:user.home=/root
2017-04-28 10:04:33,092 [myid:] - INFO [main:Environment@100] - Client environment:user.dir=/data/yunva/zookeeper-3.4.6
2017-04-28 10:04:33,094 [myid:] - INFO [main:ZooKeeper@438] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@446cdf90
Welcome to ZooKeeper!
2017-04-28 10:04:33,128 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@975] - Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)
JLine support is enabled
2017-04-28 10:04:33,209 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@852] - Socket connection established to localhost/127.0.0.1:2181, initiating session
2017-04-28 10:04:33,218 [myid:] - INFO [main-SendThread(localhost:2181):ClientCnxn$SendThread@1235] - Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x35bb23d68ba0003, negotiated timeout = 30000
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[zk: localhost:2181(CONNECTED) 0] ls /
zookeeper hbase
[zk: localhost:2181(CONNECTED) 0] ls /hbase
[replication, meta-region-server, rs, splitWAL, backup-masters, table-lock, flush-table-proc, region-in-transition, online-snapshot, master, running, recovering-regions, draining, namespace, hbaseid, table]
如果访问默认的http管理端口页面可以看到集群的情况
hadoop:
http://IP:8088/cluster/cluster
hbase:
http://IP:16010/master-status
hdfs:
http://IP:50070/dfshealth.html#tab-overview
---------------------
作者:郑子明
来源:CSDN
原文:https://blog.csdn.net/reblue520/article/details/70888850
Hadoop2.7.3+HBase1.2.5+ZooKeeper3.4.6搭建分布式集群环境
标签:port root ping nod serve 自动 传输 scores 需要
原文地址:https://www.cnblogs.com/shizhijie/p/9916315.html