zookeeper-3.4.6.tar.gz
hbase-1.2.4-bin.tar.gz有点乱:)
感谢zilongzilong: http://aperise.iteye.com/blog/2254460
准备四台机器HADOOP用HBASE用了前3台,操作系统都是centOS6.5[2.6.32-431.el6.x86_64],内存1G硬盘40G,角色分配如下:
ip hostname role192.168.122.51 hdp01 secondraynamenode,job tracker,namenode
192.168.122.52 hdp02 task tracker,datanode
192.168.122.53 hdp03 task tracker,datanode
192.168.122.54 hdp04 task tracker,datanode
系统环境准备:
cos65DESK.img 安装基本桌面数据库开发环境
qemu-img create -f qcow2 0.img -b ../cos65DESK.img
先0上配好基础,然后才:
cp 0.img 1.img/2.img/3.img/4.img
ssh到每台远程机器上
1)修改hostname
/etc/sysconfig/network
NETWORKING=yes
HOSTNAME=hdp01/02/03/04 <-修改为对应服务器名
NOZEROCONF=yes
2)修改名称解析
#vi /etc/hosts
127.0.0.1 localhost
192.168.122.51 hdp01
192.168.122.52 hdp02
192.168.122.53 hdp03
192.168.122.54 hdp04
3)添加HADOOP用户及用户组
groupadd hadoop
useradd hadoop -g hadoop
passwd hadoop 123456
4)每台机器上,建立相应文件夹
#
mkdir /usr/local/bg
chmod 777 -R /usr/local/bg
$
mkdir /usr/local/bg/storage
mkdir /usr/local/bg/storage/hadoop
mkdir /usr/local/bg/storage/hadoop/temp
mkdir /usr/local/bg/storage/hadoop/data
mkdir ~/.ssh
chmod 755 ~/.ssh
3.在所有的机器上安装JAVA:
$scp jdk-8u40-linux-x64.tar.gz hadoop@192.168.122.151:/usr/local/bg
$tar -zxvf jdk-8u40-linux-x64.tar.gz
设置 java 环境
#vim /etc/profile
export JAVA_HOME=/usr/local/bg/jdk1.8.0_40
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=$CLASSPATH:.:$JAVA_HOME/lib:$JRE_HOME/lib
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
立即生效:source /etc/profile
4. 在所有的机器上安装hadoop
$scp hadoop-2.7.1.CentOS6.5.[2.6.32-431.el6.x86_64].tar.gz hadoop@192.168.122.151:/usr/local/bg
$tar -zxvf hadoop-2.7.1.LiBin.CentOS6.5.[2.6.32-431.el6.x86_64].tar.gz
修改环境变量
# vim /etc/profile
# set hadoop environment
export HADOOP_HOME=/usr/local/bg/hadoop-2.7.1
export HADOOP_HOME_WARN_SUPPRESS=1
export PATH=$PATH:$HADOOP_HOME/bin
source /etc/profile
[hadoop@hdp01 hadoop]# pwd
/usr/local/bg/hadoop-2.7.1/etc/hadoop
修改/usr/local/bg/hadoop-2.7.1/etc/hadoop/文件夹下的hadoop-env.sh、yarn-env.sh的JAVA_HOME,否则启动时会报error
export JAVA_HOME=/usr/local/bg/jdk1.8.0_40/【环境已有,但还是必须设】
修改 etc/hadoop/下core-site.xml文件: :<修改XML后必须同步4服务器,否则,无法正常启动点>
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://hdp01:9000</value>
<final>true</final>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/usr/local/bg/storage/hadoop/temp</value>
</property>
<property>
<name>hadoop.native.lib</name>
<value>true</value>
<description>Should native hadoop libraries,if present,be used.</description>
</property>
</configuration>
修改 etc/hadoop/下的hdfs-site.xml
<configuration>
<property>
<name>dfs.data.dir</name>
<value>/usr/local/bg/storage/hadoop/data</value>
<final>true</final>
<description>
Determines where on the local filesystem the DFS name node should store the name table(fsimage). If this is a comma-delimited list of directories then the name table is replicated in all of the directories,for redundancy.
</description>
</property>
<property>
<name>dfs.namenode.secondary.http-address</name>
<value>hdp01:9001</value>
<final>true</final>
</property>
<property>
<name>dfs.replication</name>
<value>3</value>
<final>true</final>
<description>
Default block replication. The actual number of replications can be specified when the file is created. The default is used if replication is not specified in create time.
</description>
</property>
</configuration>
修改conf下mapred-site.xml:
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
<property>
<name>mapreduce.jobhistory.address</name>
<value>hdp01:10020</value>
</property>
<property>
<name>mapreduce.jobhistory.webapp.address</name>
<value>hdp01:19888</value>
</property>
<property>
<name>mapred.job.tracker</name>
<value>hdp01:19001</value>
<description>
The host and port that the MapReduce job tracker runs at. If "local",then jobs are run in-process as a single map and reduce task.
</description>
</property>
</configuration>
修改yarn-site.xml,加上
<configuration>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<property>
<name>yarn.nodemanager.aux-services.mapreduce.shuffle.class</name>
<value>org.apache.hadoop.mapred.ShuffleHandler</value>
</property>
<property>
<name>yarn.resourcemanager.address</name>
<value>hdp01:8032</value>
</property>
<property>
<name>yarn.resourcemanager.scheduler.address</name>
<value>hdp01:8030</value>
</property>
<property>
<name>yarn.resourcemanager.resource-tracker.address</name>
<value>hdp01:8031</value>
</property>
<property>
<name>yarn.resourcemanager.admin.address</name>
<value>hdp01:8033</value>
</property>
<property>
<name>yarn.resourcemanager.webapp.address</name>
<value>hdp01:8088</value>
</property>
</configuration>
修改etc/hadoop下slavers成:
hdp02
hdp03
hdp04
这个是决定datanode和tasktracker的
---------------------------以上4服务器一样
SSH免密码访问设置:
151:
$cd ~/.ssh
$ssh-keygen -t rsa --然后一直按回车键,将生成的密钥保存在.ssh/id_rsa文件中。
$cp id_rsa.pub authorized_keys
$scp authorized_keys hadoop@192.168.122.152:/home/hadoop/.ssh
152:
$cd ~/.ssh
$ssh-keygen -t rsa
$ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
$scp authorized_keys hadoop@192.168.122.153:/home/hadoop/.ssh
153:
$cd ~/.ssh
$ssh-keygen -t rsa
$ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
$scp authorized_keys hadoop@192.168.122.154:/home/hadoop/.ssh
154:
$cd ~/.ssh
$ssh-keygen -t rsa
$ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
$scp authorized_keys hadoop@192.168.122.151:/home/hadoop/.ssh
$scp authorized_keys hadoop@192.168.122.152:/home/hadoop/.ssh
$scp authorized_keys hadoop@192.168.122.153:/home/hadoop/.ssh
然后分别在151、152、153、154上互相$ssh hdp01、ssh hdp02、ssh hdp03、ssh hdp04访问1次后就OK
出现需要密码ssh 关闭IPTABLES与SELINUX,互相访问1次后OK
service iptables stop
chkconfig iptables off
vi /etc/selinux/config
SELINUX=disabled
非root出现需要密码,解决如下:
查看/var/log/secure
报Authentication refused: bad ownership or modes for directory /home/hadoop/.ssh/
确实是用户主目录的权限问题造成的
/home/hadoop/.ssh/ 之前是777
后来改成755后就正常了
格式化HADOOP空间
$ bin/hdfs namenode -format,注意只需要格式化一次,否则你的数据将全部丢失,还会出现datanode不能启动等一系列问题
5.启动hadoop
在主结点151上进行操作
启动:$ sbin/start-all.sh
start-dfs.sh and start-yarn.sh
关闭:$ sbin/stop-all.sh
6.测试:
在主结点151上jps
应该发现ResourceManager,SecondrayNameNode,NameNode这个3个进程
[hadoop@hdp01 bin]$ jps
3651 Jps
3224 NameNode
3577 ResourceManager
3423 SecondaryNameNode
修改测试电脑名称解析
#vi /etc/hosts
127.0.0.1 localhost
192.168.122.51 hdp01
192.168.122.52 hdp02
192.168.122.53 hdp03
192.168.122.54 hdp04
hdp01:8088查看集群信息
hdp01:50070能进行一些节点的管理
[hadoop@hdp01 ~]# mkdir test
[hadoop@hdp01 ~]# cd test
[hadoop@hdp01 test]# echo "hello world" > t1.txt
[hadoop@hdp01 test]# echo "hello hadoop" > t2.txt
[hadoop@hdp01 test]# ll
total 8
-rw-r--r-- 1 root root 12 9月 15 01:42 t1.txt
-rw-r--r-- 1 root root 13 9月 15 01:43 t2.txt
在虚拟分布式文件系统上创建2个测试目录
bin/hdfs dfs -mkdir /in
bin/hdfs dfs -mkdir /out
[hadoop@hdp01 test]# bin/hdfs dfs -put ./ /in
[hadoop@hdp01 test]# bin/hdfs dfs -ls /in/test
Found 2 items
-rw-r--r-- 3 root supergroup 12 2015-09-15 01:43 /in/test/t1.txt
-rw-r--r-- 3 root supergroup 13 2015-09-15 01:43 /in/test/t2.txt
[hadoop@hdp01 test]# bin/hdfs dfs -ls ./in
Found 2 items
-rw-r--r-- 3 root supergroup 12 2015-09-15 01:43 /user/root/in/test1.txt
-rw-r--r-- 3 root supergroup 13 2015-09-15 01:43 /user/root/in/test2.txt
[hadoop@hdp01 test]# hadoop dfs -ls
Found 1 items
drwxr-xr-x - root supergroup 0 2015-09-15 01:43 /user/root/in
[hadoop@hdp01 ~]# hadoop dfs -get ./in/* ./
[hadoop@hdp01 ~]# ls
anaconda-ks.cfg install.log install.log.syslog test test1.txt test2.txt
向hadoop提交单词统计任务:
bin/hadoop jar./share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.1.jar wordcount/tmp/LICENSE.txt /tmp-output
第一次运行用时:11mins,10sec
Hadoop报错:NoRouteToHostException: No route to host ,发现153端口被iptables封,大量错误,巨慢,停iptables继续:
bin/hadoop jar./share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.1.jar wordcount/in/test/t2.txt /out/o2
28sec 【停iptables后,非常顺利】
查看HADOOP各服务器大致情况:
hdfs dfsadmin -report
进入和退出hadoop的安全模式
hdfs dfsadmin -safemode enter
hdfs dfsadmin -safemode leave
---------------------------------
NTP服务器51:
修改/etc/ntp.conf添加到server前:
restrict 192.168.122.0 mask 255.255.255.0
server 127.127.1.0
fudge 127.127.1.0 stratum 8
#
service ntpd start
chkconfig --level 35 ntpd on
NTP客户端52/53/54:
删除其他服务器IP,添加
server 192.168.122.51
fudge 192.168.122.51 stratum 8
#
service ntpd start
chkconfig --level 35 ntpd on
---------------------------------
zookeeper3.4.6集群安装51/52/53:
下载解压zookeeper-3.4.6.tar.gz
51/52/53:cat
scp zookeeper-3.4.6.tar.gz hadoop@192.168.122.51/52/53:/usr/local/bg
[root@hdp02 hadoop]# mv /usr/local/bg/zookeeper-3.4.6.tar.gz /opt
[root@hdp01 opt]# tar -zxvf zookeeper-3.4.6.tar.gz
[root@hdp01 opt]# ll
total 17296
drwxr-xr-x. 2 root root 4096 11月 22 2013 rh
drwxr-xr-x 10 1000 1000 4096 2月 20 2014 zookeeper-3.4.6
-rwxrwxr-x 1 hadoop hadoop 17699306 11月 17 13:00 zookeeper-3.4.6.tar.gz
#chown hadoop.hadoop zookeeper-3.4.6 -R
配置/etc/hosts
192.168.122.59 hbdb1-vip
创建zookeeper数据文件
[hadoop@hdp01 bg]$ pwd
/usr/local/bg
[hadoop@hdp01 bg]$ mkdir zookeeper
配置zoo.cfg
dataDir=/usr/local/bg/zookeeper
server.1=hdp01:2888:3888
server.2=hdp02:2888:3888
server.3=hdp03:2888:3888
分发到其它zookeeper集群节点
$ scp zoo.cfg hdp02:/opt/zookeeper-3.4.6/conf/
$ scp zoo.cfg hdp03:/opt/zookeeper-3.4.6/conf/
设置myid必须为整数
51:#zookeeper集群节点之1
echo "1" > /usr/local/bg/zookeeper/myid
52:#zookeeper集群节点之2
echo "2" > /usr/local/bg/zookeeper/myid
53:#zookeeper集群节点之3
echo "3" > /usr/local/bg/zookeeper/myid
分别启动ZooKeeper集群1/2/3节点:
cd /opt/zookeeper-3.4.6
bin/zkServer.sh start
查看单机ZooKeeper是leader还是follower
[hadoop@hdp01 bin]$ ./zkServer.sh status
JMX enabled by default
Using config: /opt/zookeeper-3.4.6/bin/../conf/zoo.cfg
Mode: follower
[hadoop@hdp02 bin]$ ./zkServer.sh status
JMX enabled by default
Using config: /opt/zookeeper-3.4.6/bin/../conf/zoo.cfg
Mode: leader
客户端链接zookeeper服务端
$ ./zkCli.sh -server hdp01:2181,hdp02:2181,hdp03:2181
查看根目录下数据节点:
...
WatchedEvent state:SyncConnected type:None path:null
[zk: hdp01:2181,hdp03:2181(CONNECTED) 0] ls
[zk: hdp01:2181,hdp03:2181(CONNECTED) 1] ls /
[zookeeper]
[zk: hdp01:2181,hdp03:2181(CONNECTED) 2] ls /zookeeper
[quota]
[zk: hdp01:2181,hdp03:2181(CLOSED) 6] quit
Quitting...
-----------------------------------------
hbase安装
下载安装包hbase-1.2.4-bin.tar.gz放置于51/52/53: /opt并解压
# tar zxvf hbase-1.2.4-bin.tar.gz
# chown hadoop.hadoop hbase-1.2.4/ -R
#vi /etc/profile 添加如下内容:
#hbase:
export HBASE=/opt/hbase-1.2.4
export PATH=${HBASE}/bin:${PATH}
创建hbase临时文件夹51/52/53
$ mkdir /usr/local/bg/hbase
export JAVA_HOME=/usr/local/bg/jdk1.8.0_40/
export HBASE_CLASSPATH=/opt/hbase-1.2.4/conf
export HBASE_OPTS="$HBASE_OPTS -XX:CMSInitiatingOccupancyFraction=60"
#export HBASE_REGIONSERVER_OPTS="$HBASE_REGIONSERVER_OPTS -XX:PermSize=128m -XX:MaxPermSize=128m"
export HBASE_REGIONSERVER_OPTS="$HBASE_REGIONSERVER_OPTS -Xmx4g -Xms4g -Xmn1g -XX:SurvivorRatio=1 -XX:PermSize=128M -XX:MaxPermSize=128M -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv6Addresses=false -XX:MaxTenuringThreshold=15 -XX:+CMSParallelRemarkEnabled -XX:+UseFastAccessorMethods -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=60 -XX:+UseCMSInitiatingOccupancyOnly -XX:+UseCMSCompactAtFullCollection -XX:CMSFullGCsBeforeCompaction=0 -XX:+HeapDumpOnOutOfMemoryError -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+PrintTenuringDistribution -Xloggc:/opt/hbase-1.2.4/logs/gc-hbase-regionserver.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=1 -XX:GCLogFileSize=512M"
# export CLIENT_GC_OPTS="-verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:<FILE-PATH> -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=1 -XX:GCLogFileSize=512M"
export CLIENT_GC_OPTS="-verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:/opt/hbase-1.2.4/logs/gc-hbase-client.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=1 -XX:GCLogFileSize=512M"
# export HBASE_MANAGES_ZK=true
export HBASE_MANAGES_ZK=false
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>hbase.rootdir</name>
<value>hdfs://192.168.122.51:9000/hbase</value>
</property>
<property>
<name>hbase.cluster.distributed</name>
<value>true</value>
</property>
<property>
<name>hbase.zookeeper.quorum</name>
<value>hdp01,hdp02,hdp03</value>
</property>
<property>
<name>hbase.tmp.dir</name>
<value>/usr/local/bg/hbase/</value>
</property>
<property>
<name>hbase.master</name>
<value>hdfs://192.168.122.51:60000</value>
</property>
<property>
<name>hbase.zookeeper.property.dataDir</name>
<value>/usr/local/bg/zookeeper</value>
</property>
<property>
<name>hbase.client.write.buffer</name>
<value>5242880</value>
</property>
<property>
<name>hbase.regionserver.handler.count</name>
<value>300</value>
</property>
<property>
<name>hbase.table.sanity.checks</name>
<value>false</value>
</property>
<property>
<name>zookeeper.session.timeout</name>
<value>30000</value>
</property>
<property>
<name>hbase.hregion.max.filesize</name>
<value>1048576000</value>
</property>
<property>
<name>hbase.hregion.majorcompaction</name>
<value>0</value>
</property>
<property>
<name>dfs.replication</name>
<value>3</value>
</property>
<property>
<name>hbase.regionserver.region.split.policy</name>
<value>org.apache.hadoop.hbase.regionserver.ConstantSizeRegionSplitPolicy</value>
</property>
<property>
<name>hbase.regionserver.optionalcacheflushinterval</name>
<value>7200000</value>
</property>
<property>
<name>hfile.block.cache.size</name>
<value>0.3</value>
</property>
<property>
<name>hbase.hregion.memstore.flush.size</name>
<value>52428800</value>
</property>
<property>
<name>hbase.regionserver.global.memstore.size</name>
<value>0.5</value>
</property>
<property>
<name>hbase.regionserver.global.memstore.size.lower.limit</name>
<value>0.5</value>
</property>
<property>
<name>dfs.client.socket-timeout</name>
<value>600000</value>
</property>
</configuration>
hdp02
hdp03
[hadoop@hdp01 conf]$ scp hbase-env.sh hbase-site.xml regionservers hadoop@hdp02:/opt/hbase-1.2.4/conf
[hadoop@hdp01 conf]$ scp hbase-env.sh hbase-site.xml regionservers hadoop@hdp03:/opt/hbase-1.2.4/conf
启动和停止hbase,命令是在集群中任何机器执行都可以的,首先保证Hadoop要启动。
#启动hbase,涉及HMaster,HRegionServer
cd /opt/hbase-1.2.4/bin/
./start-hbase.sh
jps
查看hbase管理界面http://192.168.181.66:16010
[hadoop@hdp01 bin]$ jps
6785 HMaster
7284 Jps
4997 NameNode
5350 ResourceManager
5193 SecondaryNameNode
3324 QuorumPeerMain
[hadoop@hdp01 bin]$ ./start-hbase.sh
starting master,logging to /opt/hbase-1.2.4/bin/../logs/hbase-hadoop-master-hdp01.out
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0
hdp03: starting regionserver,logging to /opt/hbase-1.2.4/bin/../logs/hbase-hadoop-regionserver-hdp03.out
hdp02: starting regionserver,logging to /opt/hbase-1.2.4/bin/../logs/hbase-hadoop-regionserver-hdp02.out
hdp03: Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128M; support was removed in 8.0
hdp03: Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128M; support was removed in 8.0
hdp03: Java HotSpot(TM) 64-Bit Server VM warning: UseCMSCompactAtFullCollection is deprecated and will likely be removed in a future release.
hdp03: Java HotSpot(TM) 64-Bit Server VM warning: CMSFullGCsBeforeCompaction is deprecated and will likely be removed in a future release.
hdp02: Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128M; support was removed in 8.0
hdp02: Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128M; support was removed in 8.0
hdp02: Java HotSpot(TM) 64-Bit Server VM warning: UseCMSCompactAtFullCollection is deprecated and will likely be removed in a future release.
hdp02: Java HotSpot(TM) 64-Bit Server VM warning: CMSFullGCsBeforeCompaction is deprecated and will likely be removed in a future release.
测试:
[hadoop@hdp01 bin]$ ./hbase shell
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/hbase-1.2.4/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/bg/hadoop-2.7.1/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]
2016-11-17 15:22:49,910 WARN [main] conf.Configuration: hbase-site.xml:an attempt to override final parameter: dfs.replication; Ignoring.
2016-11-17 15:22:51,028 WARN [main] conf.Configuration: hbase-site.xml:an attempt to override final parameter: dfs.replication; Ignoring.
HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit<RETURN>" to leave the HBase Shell
Version 1.2.4,r67592f3d062743907f8c5ae00dbbe1ae4f69e5af,Tue Oct 25 18:10:20 CDT 2016
hbase(main):001:0> status
1 active master,0 backup masters,2 servers,0 dead,1.0000 average load
hbase(main):002:0> version
1.2.4,Tue Oct 25 18:10:20 CDT 2016
hbase(main):003:0> list
TABLE
0 row(s) in 0.0930 seconds
=> []
hbase(main):001:0> create 't1','c1'
0 row(s) in 50.0500 seconds
=> Hbase::Table - t1
hbase(main):003:0* list
TABLE
t1
1 row(s) in 0.0290 seconds
=> ["t1"]
hbase(main):004:0> list t1
NameError: undefined local variable or method `t1' for #<Object:0x1f992a3a>
hbase(main):005:0> list 't1'
TABLE
t1
1 row(s) in 0.0250 seconds
=> ["t1"]
hbase(main):006:0> put 't1','k1','c1:a','value1'
0 row(s) in 1.3440 seconds
hbase(main):007:0> put 't1','k2','c1:b','value2'
0 row(s) in 0.0250 seconds
hbase(main):008:0> scan 't1'
ROW COLUMN+CELL
k1 column=c1:a,timestamp=1479371230254,value=va
lue1
k2 column=c1:b,timestamp=1479371248124,value=va
lue2
2 row(s) in 0.1130 seconds
[hadoop@hdp03 bin]$ ./hbase shell
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/hbase-1.2.4/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/bg/hadoop-2.7.1/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]
2016-11-17 16:38:23,286 WARN [main] conf.Configuration: hbase-site.xml:an attempt to override final parameter: dfs.replication; Ignoring.
2016-11-17 16:38:24,858 WARN [main] conf.Configuration: hbase-site.xml:an attempt to override final parameter: dfs.replication; Ignoring.
HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit<RETURN>" to leave the HBase Shell
Version 1.2.4,Tue Oct 25 18:10:20 CDT 2016
hbase(main):001:0> list
TABLE
t1
1 row(s) in 1.0170 seconds
=> ["t1"]
hbase(main):002:0> scan 't1'
ROW COLUMN+CELL
k1 column=c1:a,value=va
lue2
2 row(s) in 0.5700 seconds
hbase(main):003:0>
配置文件解释:
<?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <configuration> <!--hbase存储在HADOOP HDFS上文件根目录路径--> <property> <name>hbase.rootdir</name> <value>hdfs://192.168.122.51:9000/hbase</value> </property> <!--采用分布式模式--> <property> <name>hbase.cluster.distributed</name> <value>true</value> </property> <!--zookeeper地址,端口不指定的话就默认为2181--> <property> <name>hbase.zookeeper.quorum</name> <value>hdp01,hdp03</value> </property> <!--hbase临时文件存储目录,比如一些数据表的预分区信息等等--> <property> <name>hbase.tmp.dir</name> <value>/usr/local/bg/hbase/</value> </property> <property> <name>hbase.master</name> <value>hdfs://192.168.122.51:60000</value> </property> <!--zookeeper存储数据位置--> <property> <name>hbase.zookeeper.property.dataDir</name> <value>/usr/local/bg/zookeeper</value> </property> <!--这里设置hbase API客户端侧缓存值,大于此值就进行一次提交,/opt/hbase-1.2.4/conf/hbase-site.xml统一配置为5M,对所有HTable都生效,那么客户端API就可不设置-> <property> <!--htable.setWriteBufferSize(5242880);//5M --> <name>hbase.client.write.buffer</name> <value>5242880</value> </property> <!--这里设置Master并发最大线程数--> <property> <name>hbase.regionserver.handler.count</name> <value>300</value> <description>Count of RPC Listener instances spun up on RegionServers.Same property is used by the Master for count of master handlers.</description> </property> <!-- hbase.table.sanity.checks是一个开关,主要用于hbase各种参数检查,当为true时候,检查步骤如下 1.check max file size,hbase.hregion.max.filesize,最小为2MB 2.check flush size,hbase.hregion.memstore.flush.size,最小为1MB 3.check that coprocessors and other specified plugin classes can be loaded 4.check compression can be loaded 5.check encryption can be loaded 6.Verify compaction policy 7.check that we have at least 1 CF 8.check blockSize 9.check versions 10.check minVersions <= maxVerions 11.check replication scope 12.check data replication factor,it can be 0(default value) when user has not explicitly set the value,in this case we use default replication factor set in the file system. 详细情况可以去查看源代码org.apache.hadoop.hbase.master.HMaster的方法sanityCheckTableDescriptor, 该代码位于hbase源码的模块hbase-server下 --> <property> <name>hbase.table.sanity.checks</name> <value>false</value> </property> <!--ZooKeeper 会话超时.HBase把这个值传递改zk集群,向他推荐一个会话的最大超时时间--> <property> <!--every 30s,the master will check regionser is working --> <name>zookeeper.session.timeout</name> <value>30000</value> </property> <!--数据表创建时会预分区,每个预分区最大大小这里设置为30G【测试为1000M】,放置频繁的split阻塞数据读写,只有当预分区超过1000M时才会进行split,正式环境应该首先预测数据存储时间内的大致数据量,然后如果每个预分区为1000M,计算出分区数,建表时指定分区设置,防后期频繁split--> <property> <!--every region max file size set to 1000M1048576000 30G32212254720 --> <name>hbase.hregion.max.filesize</name> <value>1048576000</value> </property> <!--默认hbase每24小时会进行一次major_compact,major_compact会阻塞读写,这里先禁用,但不代表这个操作不做,可以后期指定linux shell加入到cron定时任务在hbase集群空闲情况下执行--> <property> <name>hbase.hregion.majorcompaction</name> <value>0</value> </property> <!--hbase本质上可以说是HADOOP HDFS的客户端,虽然Hadoop的core-site.xml里设置了文件副本数,但是仍然是客户端传值优先,这里设置为2,意思是一个文件,最终在Hadoop上总个数为2,正式环境最好设置为3,目前发现此值小于3时,在遇到All datanodes xxx.xxx.xxx.xxx:port are bad. Aborting...错误信息时,如果某个Datanode宕机,原则上hbase调用的DFSClient会去其他Datanode 上重试写,但发现配置的值低于3就不会去尝试--> <property> <name>dfs.replication</name> <value>3</value> </property> <!-- IncreasingToUpperBoundRegionSplitPolicy策略的意思是,数据表如果预分区为2,配置的memstore flush size=128M,那么下一次分裂大小是2的平方然后乘以128MB,即2*2*128M=512MB; ConstantSizeRegionSplitPolicy策略的意思是按照上面指定的region大小超过30G才做分裂 --> <property> <name>hbase.regionserver.region.split.policy</name> <value>org.apache.hadoop.hbase.regionserver.ConstantSizeRegionSplitPolicy</value> </property> <!--一个edit版本在内存中的cache时长,默认3600000毫秒--> <property> <name>hbase.regionserver.optionalcacheflushinterval</name> <value>7200000</value> <description> Maximum amount of time an edit lives in memory before being automatically flushed. Default 1 hour. Set it to 0 to disable automatic flushing.</description> </property> <!--分配给HFile/StoreFile的block cache占最大堆(-Xmx setting)的比例。默认0.4意思是分配40%,设置为0就是禁用,但不推荐。--> <property> <name>hfile.block.cache.size</name> <value>0.3</value> <description>Percentage of maximum heap (-Xmx setting) to allocate to block cache used by HFile/StoreFile. Default of 0.4 means allocate 40%. Set to 0 to disable but it's not recommended; you need at least enough cache to hold the storefile indices.</description> </property> <!--当memstore的大小超过50M这个值的时候,会flush到磁盘。这个值被一个线程每隔hbase.server.thread.wakefrequency检查一下。--> <property> <name>hbase.hregion.memstore.flush.size</name> <value>52428800</value> </property> <!--单个region server的全部memtores的最大值。超过这个值,一个新的update操作会被挂起,强制执行flush操作。以前版本中是通过hbase.regionserver.global.memstore.upperLimit设置,老版本中含义是在hbase-env.sh中配置的HEAP_SIZE比如4G,那么以该值4G乘以配置的0.5就是2G,意思是所有memstore总和达到2G值时,阻塞所有读写,现在1.2.1版本hbase中被hbase.regionserver.global.memstore.size替代,计算方法仍然是HEAP_SIZE乘以配置的百分比比如下面的0.5,那么阻塞读写的阀值就为2G--> <property> <name>hbase.regionserver.global.memstore.size</name> <value>0.5</value> </property> <!--当强制执行flush操作的时候,当低于这个值的时候,flush会停止。默认是堆大小的 35% . 如果这个值和 hbase.regionserver.global.memstore.upperLimit 相同就意味着当update操作因为内存限制被挂起时,会尽量少的执行flush(译者注:一旦执行flush,值就会比下限要低,不再执行)。 在老版本中该值是通过hbase.regionserver.global.memstore.size.lower.limit设置,计算方法是HEAP_SIZE乘以配置的百分比比如0.3就是HEAP_SIZE4G乘以0.3=1.2G,达到这个值的话就在所有memstore中选择最大的那个做flush动作,新版本则完全不同了,首先是通过hbase.regionserver.global.memstore.lowerLimit设置,而且不是以HEAP_SIZE作为参考,二是以配置的hbase.regionserver.global.memstore.size的值再乘以配置的比例比如0.5,如果HEAP_SIZE=4G,hbase.regionserver.global.memstore.size配置为0.5,hbase.regionserver.global.memstore.size.lower.limit配置的为0.5,则计算出来的值为4G乘以0.5再乘以0.5就是1G了,达到1G就先找最大的memstore触发flush--> <property> <name>hbase.regionserver.global.memstore.size.lower.limit</name> <value>0.5</value> </property> <property> <!--这里设置HDFS客户端最大超时时间,尽量改大,后期hbase经常会因为该问题频繁宕机--> <name>dfs.client.socket-timeout</name> <value>600000</value> </property> </configuration> 原文链接:https://www.f2er.com/centos/379870.html