HBase学习资料

hbase基础学习资料 这是我学了hbase之后整理的一些简单清晰的内容关于hbase的,hbase速成方法 立即下载

HBase

一、概述

http://hbase.apache.org

Apache HBase是一个基于Hadoop的数据库,它可靠、分布式适合结构化大数据的存储。

Apache HBase是Google BigTable开源实现,它开源、分布式、数据多版本、基于列存储的非关系型数据库。HBase建立在Hadoop的HDFS的基础之上。

列存储和行存储

列存储和行存储指的是数据在存储介质中的组织方式

传统关系型数据库(行存储):Oracle、Mysql、DB2、SqlServer等

非关系型数据库(列存储):HBase等
在这里插入图片描述

HBase数据模型

在这里插入图片描述

  • 主键:rowkey 获取数据的唯一标示,不能重复,根据字典顺序自动排序,底层存储时byte[]
  • 列簇:column family 多个列的集合,通常一个列簇中存放的是一组功能相似或者业务相近的列的集合。
  • 单元格:rowkey + cf + column定位一个Cell,Cell允许有多个数据版本,默认为1个
  • 多版本:Cell允许有多个数据版本
  • 版本号:系统当前的时间戳,默认会将时间戳最新的Cell数据返回给用户
  • 列:Column 列簇中一个字段,用来存放某一类别的数据

特点

  • 大:一个表可以有上百亿行,上百万列
  • 面向列:面向列表(簇)的存储和权限控制,列(簇)独立检索。
  • 结构稀疏:对于为空(NULL)的列,并不占用存储空间,因此,表可以设计的非常稀疏。
  • 无模式:每一行都有一个可以排序的主键和任意多的列,列可以根据需要动态增加,同一张表中不同的行可
    以有截然不同的列。
  • 数据多版本:每个单元中的数据可以有多个版本,默认情况下,版本号自动分配,版本号就是单元格插入时
    的时间戳。
  • 数据类型单一:HBase中的数据在底层存储时都是byte[],可以存放任意类型的数据。

二、基本使用

环境搭建

伪分布式集群

准备工作
  • 保证HDFS集群运行正常

  • 保证ZooKeeper集群运行正常

    [root@hadoop ~]# jps
    83920 SecondaryNameNode
    83602 NameNode
    83698 DataNode
    2548 QuorumPeerMain
    
安装及配置
[root@hadoop ~]# tar -zxf hbase-1.2.4-bin.tar.gz -C /usr
  • conf/hbase-site.xml

    <property>
      <name>hbase.rootdir</name>
      <value>hdfs://hadoop:9000/hbase</value>
    </property>
    <property>
      <name>hbase.cluster.distributed</name>
      <value>true</value>
    </property>
    <property>
      <name>hbase.zookeeper.quorum</name>
      <value>hadoop</value>
    </property>
    <property>
      <name>hbase.zookeeper.property.clientPort</name>
      <value>2181</value>
    </property>
    
    
  • conf/regionservers

    hadoop
    
修改环境变量
[root@hadoop hbase-1.2.4]# vi ~/.bashrc
# 将之前的环境变量配置删除 添加如下的环境变量配置
HBASE_MANAGES_ZK=false
HBASE_HOME=/usr/hbase-1.2.4
HADOOP_HOME=/usr/hadoop-2.6.0
JAVA_HOME=/usr/java/latest
CLASSPATH=.
PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin::$HBASE_HOME/bin
export JAVA_HOME
export CLASSPATH
export PATH
export HADOOP_HOME
export HBASE_HOME
export HBASE_MANAGES_ZK
[root@hadoop hbase-1.2.4]# source ~/.bashrc
启动服务
[root@hadoop hbase-1.2.4]# start-hbase.sh
验证HBase服务是否正常

方法一:

[root@hadoop hbase-1.2.4]# jps
83920 SecondaryNameNode
85104 HRegionServer  # HBase集群的从节点
84963 HMaster  # HBase集群的主节点
83602 NameNode
83698 DataNode
2548 QuorumPeerMain
85516 Jps

方法二:

http://hadoop:16010/master-status

方法三:
在这里插入图片描述

指令操作

使用客户端指令连接hbase server
[root@hadoop hbase-1.2.4]# hbase shell
在命令窗口使用help指令查看帮助说明
hbase(main):007:0> help "get"  # help "命令"  查看指定命令的帮助说明
hbase(main):007:0> help "general"  # help "命令组"  查看指定命令组下的命令帮助说明
COMMAND GROUPS:
  Group name: general  # 通用指令
  Commands: status, table_help, version, whoami

  Group name: ddl   # 表操作指令
  Commands: alter, alter_async, alter_status, create, describe, disable, disable_all, drop, drop_all, enable, enable_all, exists, get_table, is_disabled, is_enabled, list, locate_region, show_filters

  Group name: namespace  # 类似于mysql的数据库 组织管理表
  Commands: alter_namespace, create_namespace, describe_namespace, drop_namespace, list_namespace, list_namespace_tables

  Group name: dml  # 数据的CRUD
  Commands: append, count, delete, deleteall, get, get_counter, get_splits, incr, put, scan, truncate, truncate_preserve

General指令
  • status

    hbase(main):010:0* status
    1 active master, 0 backup masters, 1 servers, 0 dead, 2.0000 average load
    
  • version

    hbase(main):013:0* version
    1.2.4, rUnknown, Wed Feb 15 18:58:00 CST 2017
    
  • whoami

    hbase(main):014:0> whoami
    root (auth:SIMPLE)
        groups: root
    
NameSpace指令

Namespace非常类似于mysql中的数据库,是用来组织管理HBase表的,在HBase有一个默认的Namespace叫做default

  • alter_namespace

    hbase(main):022:0* alter_namespace 'dingl',{METHOD=>'set', 'AUTHOR'=>'GAOZHY'}
    0 row(s) in 0.0440 seconds
    
  • create_namespace

    hbase(main):017:0> create_namespace 'dingl'
    0 row(s) in 0.0690 seconds
    
  • describe_namespace

    hbase(main):019:0> describe_namespace 'dingl'
    DESCRIPTION
    {NAME => 'dingl'}
    1 row(s) in 0.0210 seconds
    
  • drop_namespace

    hbase(main):026:0> drop_namespace 'dingl'
    0 row(s) in 0.0460 seconds
    
  • list_namespace

    hbase(main):027:0> list_namespace
    NAMESPACE
    default
    hbase
    2 row(s) in 0.0480 seconds
    
  • list_namespace_tables

    hbase(main):025:0> list_namespace_tables 'hbase'
    TABLE
    meta
    namespace
    2 row(s) in 0.0280 seconds
    
DDL指令

表相关的操作

  • 创建表:create

    # 1. 语法: create '表名','列簇1',’列簇2‘...
    # 2. 语法: create 'namespace:表名',{NAME=>'列簇名',VERSIONS=>Cell允许出现的最多版本}
    hbase(main):002:0> create 't_user','cf1'
    0 row(s) in 1.6240 seconds
    
    => Hbase::Table - t_user
    hbase(main):003:0> create 't_order',{NAME=>'cf1',VERSIONS=>3}
    0 row(s) in 1.3200 seconds
    
  • 展示列表: list

    => Hbase::Table - t_order
    hbase(main):004:0> list
    TABLE
    t_order
    t_user
    2 row(s) in 0.0510 seconds
    
    => ["t_order", "t_user"]
    
  • 修改表:alter

    hbase(main):005:0* alter 't_user',NAME=>'cf1',TTL=>1800
    Updating all regions with the new schema...
    1/1 regions updated.
    Done.
    0 row(s) in 2.3520 seconds
    
    hbase(main):006:0> describe 't_user'
    Table t_user is ENABLED
    t_user
    COLUMN FAMILIES DESCRIPTION
    {NAME => 'cf1', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCOD
    ING => 'NONE', TTL => '1800 SECONDS (30 MINUTES)', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSI
    ZE => '65536', REPLICATION_SCOPE => '0'}
    1 row(s) in 0.0340 seconds
    
    hbase(main):008:0* alter 't_user',{NAME=>'cf1',VERSIONS=>3}
    Updating all regions with the new schema...
    1/1 regions updated.
    Done.
    0 row(s) in 1.9960 seconds
    
    hbase(main):009:0> describe 't_user'
    Table t_user is ENABLED
    t_user
    COLUMN FAMILIES DESCRIPTION
    {NAME => 'cf1', BLOOMFILTER => 'ROW', VERSIONS => '3', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCOD
    ING => 'NONE', TTL => '1800 SECONDS (30 MINUTES)', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSI
    ZE => '65536', REPLICATION_SCOPE => '0'}
    1 row(s) in 0.0370 seconds
    
  • 描述表:describe

hbase(main):001:0> describe 't_user'
Table t_user is ENABLED
t_user
COLUMN FAMILIES DESCRIPTION
{NAME => 'cf1', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCOD
ING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REP
LICATION_SCOPE => '0'}
  • 禁用表:disable, disable_all
hbase(main):011:0* disable 't_user'
0 row(s) in 2.3580 seconds
  • 删除表:drop, drop_all
# 删除表时 首先需要禁用表
hbase(main):018:0> drop 't_user'

ERROR: Table t_user is enabled. Disable it first.

Here is some help for this command:
Drop the named table. Table must first be disabled:
  hbase> drop 't1'
  hbase> drop 'ns1:t1'


hbase(main):019:0> disable 't_user'
0 row(s) in 2.2830 seconds

hbase(main):020:0> drop 't_user'
0 row(s) in 1.3090 seconds
  • 启动表:enable, enable_all
hbase(main):017:0* enable 't_user'
0 row(s) in 1.3400 seconds
  • 判断表是否存在:exists

    hbase(main):021:0> exists 't_user'
    Table t_user does not exist
    0 row(s) in 0.0240 seconds
    
    hbase(main):022:0> exists 't_order'
    Table t_order does exist
    0 row(s) in 0.0240 seconds
    
  • 是不是:is_disabled, is_enabled

    hbase(main):023:0> is_disabled 't_order'
    false
    0 row(s) in 0.0150 seconds
    
DML指令(重点)

BigTable中的数据的增删改查操作

  • 获得总记录数:count

    hbase(main):051:0> count 'default:t_order'
    2 row(s) in 0.0570 seconds
    
    => 2
    
  • 删除: delete, deleteall

    # delete指令用来删除某一个单元格数据
    # deleteall 删除一行数据的
    hbase(main):053:0> delete 't_order','order102','cf1:count'
    0 row(s) in 0.0470 seconds
    
    hbase(main):054:0> get 'default:t_order','order102',{COLUMN=>'cf1',VERSIONS=>3}
    COLUMN                           CELL
     cf1:name                        timestamp=1566374163173, value=vivo
     cf1:name                        timestamp=1566374139746, value=oppo
     cf1:name                        timestamp=1566374045248, value=mix2s
    3 row(s) in 0.0440 seconds
    
    hbase(main):055:0> delete 't_order','order102','cf1:name',1566374045248
    0 row(s) in 0.0340 seconds
    
    hbase(main):056:0> get 'default:t_order','order102',{COLUMN=>'cf1',VERSIONS=>3}
    COLUMN                           CELL
     cf1:name                        timestamp=1566374163173, value=vivo
     cf1:name                        timestamp=1566374139746, value=oppo
    2 row(s) in 0.0160 seconds
    
    hbase(main):059:0> deleteall 't_order','order102'
    0 row(s) in 0.0140 seconds
    
    hbase(main):060:0> get 'default:t_order','order102',{COLUMN=>'cf1',VERSIONS=>3}
    COLUMN                           CELL
    0 row(s) in 0.0220 seconds
    
    
  • 获得数据:get

    # get 'namespace:table','rowkey num'
    hbase(main):033:0* get 'default:t_order','order101'
    COLUMN                           CELL
     cf1:count                       timestamp=1566373554307, value=2
     cf1:name                        timestamp=1566373502504, value=iphone
     cf1:price                       timestamp=1566373537106, value=1999
    3 row(s) in 0.0560 seconds
    
    hbase(main):034:0> get 'default:t_order','order102'
    COLUMN                           CELL
     cf1:count                       timestamp=1566373582394, value=1
     cf1:name                        timestamp=1566373615024, value=HUAWEI P30
    
    # 查看指定列簇中的所有列的数据
    hbase(main):037:0> get 'default:t_order','order102',{COLUMN=>'cf1'}
    
    # 获取多版本数据
    hbase(main):047:0> get 'default:t_order','order102',{COLUMN=>'cf1',VERSIONS=>3}
    COLUMN                           CELL
     cf1:count                       timestamp=1566373582394, value=1
     cf1:name                        timestamp=1566374163173, value=vivo
     cf1:name                        timestamp=1566374139746, value=oppo
     cf1:name                        timestamp=1566374045248, value=mix2s
    
    # 获取指定版本的单元格数据
    hbase(main):048:0> get 'default:t_order','order102',{COLUMN=>'cf1',TIMESTAMP=>1566374045248 ,VERSIONS=>3}
    COLUMN                           CELL
     cf1:name                        timestamp=1566374045248, value=mix2s
    1 row(s) in 0.0240 seconds
    
    
  • 新增(修改)数据:put

    hbase(main):026:0* put 'default:t_order','order101','cf1:name','iphone'
    0 row(s) in 0.1220 seconds
    
    hbase(main):027:0> put 'default:t_order','order101','cf1:price',1999
    0 row(s) in 0.0370 seconds
    
    hbase(main):028:0> put 'default:t_order','order101','cf1:count',2
    0 row(s) in 0.0330 seconds
    
    hbase(main):029:0> put 'default:t_order','order102','cf1:count',1
    0 row(s) in 0.0230 seconds
    
    hbase(main):030:0> put 'default:t_order','order102','cf1:name','HUAWEI P30'
    
  • 扫描表: scan

    # 类似于查询所有
    hbase(main):063:0> scan 't_order'
    ROW                              COLUMN+CELL
     order101                        column=cf1:count, timestamp=1566373554307, value=2
     order101                        column=cf1:name, timestamp=1566373502504, value=iphone
     order101                        column=cf1:price, timestamp=1566373537106, value=1999
     order103                        column=cf1:name, timestamp=1566374793825, value=Apple Watch
    
  • 截断表:truncate

    截断指的删除表中的所有数据

    hbase(main):065:0> truncate 't_order'
    truncate            truncate_preserve
    hbase(main):065:0> truncate 't_order'
    Truncating 't_order' table (it may take a while):
     - Disabling table...
     - Truncating table...
    0 row(s) in 3.5150 seconds
    
    hbase(main):066:0> scan 't_order'
    ROW                              COLUMN+CELL
    0 row(s) in 0.1550 seconds
    

JAVA API

Maven依赖
<dependency>
    <groupId>org.apache.hbase</groupId>
    <artifactId>hbase-client</artifactId>
    <version>1.2.4</version>
</dependency>
<dependency>
    <groupId>org.apache.hbase</groupId>
    <artifactId>hbase-common</artifactId>
    <version>1.2.4</version>
</dependency>
<dependency>
    <groupId>org.apache.hbase</groupId>
    <artifactId>hbase-protocol</artifactId>
    <version>1.2.4</version>
</dependency>
<dependency>
    <groupId>org.apache.hbase</groupId>
    <artifactId>hbase-server</artifactId>
    <version>1.2.4</version>
</dependency>
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
</dependency>
测试代码
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.*;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

public class HBaseClientTest {

    // 管理员对象(负责DDL操作)
    private Admin admin;

    // 连接对象(负责DML操作)
    private Connection connection;

    @Before
    public void doBefore() throws IOException {
        // 配置对象
        Configuration configuration = HBaseConfiguration.create();
        // 声明HBase的连接参数
        // HBase集群的入口信息 保存在ZK
        configuration.set(HConstants.ZOOKEEPER_QUORUM, "hadoop:2181");
        connection = ConnectionFactory.createConnection(configuration);
        admin = connection.getAdmin();
    }

    /**
     * 创建namespace
     * @throws IOException
     */
    @Test
    public void testCreateNamespace() throws IOException {
        NamespaceDescriptor namespaceDescriptor = NamespaceDescriptor.create("dingl").addConfiguration("author", "gaozhy").build();
        admin.createNamespace(namespaceDescriptor);
    }

    /**
     * 创建table
     */
    @Test
    public void testCreateTable() throws IOException {
        HTableDescriptor hTableDescriptor = new HTableDescriptor(TableName.valueOf("dingl:t_user"));
        HColumnDescriptor cf1 = new HColumnDescriptor("cf1");
        cf1.setMaxVersions(5); // cell最多保留5个历史版本
        HColumnDescriptor cf2 = new HColumnDescriptor("cf2");
        cf2.setTimeToLive(3600); // ttl=1hours
        hTableDescriptor.addFamily(cf1);
        hTableDescriptor.addFamily(cf2);
        admin.createTable(hTableDescriptor);
    }

    /**
     * 新增(修改)数据 :
     *      put指令: put 'namespace:table','rowkey','cf1:name','value'
     * @throws IOException
     */
    @Test
    public void testInsert() throws IOException {
        Table table = connection.getTable(TableName.valueOf("dingl:t_user"));
        // Put put = new Put("user101".getBytes()); // rowkey
        Put put = new Put(Bytes.toBytes("user103")); // HBase为了简化字节操作,提供了工具类 Bytes
        put.addColumn(Bytes.toBytes("cf1"),Bytes.toBytes("name"),Bytes.toBytes("小胖子"));
        table.put(put);
    }

    /**
     * 获得数据:
     *      get指令:get 'namespace:table','rowkey','cf:column'
     */
    @Test
    public void testSelect() throws IOException {
        Table table = connection.getTable(TableName.valueOf("dingl:t_user"));
        Get get = new Get("user101".getBytes());
        // 查询指定单元格数据
        // get.addColumn("cf1".getBytes(),"name".getBytes());
        // 查指定列簇所有列数据
        // get.addFamily("cf1".getBytes())
        Result result = table.get(get);
        String name = Bytes.toString(result.getValue(Bytes.toBytes("cf1"), Bytes.toBytes("name")));
        System.out.println(name);
    }

    /**
     * 测试删除数据:
     *    delete
     *    deleteall
     */
    @Test
    public void testDelete() throws IOException {
        Table table = connection.getTable(TableName.valueOf("dingl:t_user"));
        Delete delete = new Delete(Bytes.toBytes("user101"));
        ArrayList<Delete> list = new ArrayList<Delete>();
        list.add(delete);
        table.delete(list);
    }

    /**
     * 扫描表
     *  scan 'namespace:table'
     */
    @Test
    public void testScan() throws IOException {
        Table table = connection.getTable(TableName.valueOf("dingl:t_user"));
        Scan scan = new Scan();
        // 包含start  不包含stop
        scan.setStartRow(Bytes.toBytes("user101"));
        scan.setStopRow(Bytes.toBytes("user103"));

        ResultScanner rs = table.getScanner(scan);
        Iterator<Result> iterator = rs.iterator();
        while(iterator.hasNext()){
            Result result = iterator.next();
            String rowkey = Bytes.toString(result.getRow());
            String name = Bytes.toString(result.getValue(Bytes.toBytes("cf1"), Bytes.toBytes("name")));
            System.out.println(rowkey + " | " +name);
        }
    }

    @After
    public void doAfter() throws IOException {
        if(admin != null) admin.close();
        if(connection != null) connection.close();
    }
}
作业
  1. 使用HBase作为数据存储,完成用户信息的增删改查
  2. 预习明天要讲的内容

三、HBase On MapReduce

在这里插入图片描述

Maven依赖

<dependencies>
    <!--mapreduce + hbase-->
    <dependency>
        <groupId>org.apache.hadoop</groupId>
        <artifactId>hadoop-common</artifactId>
        <version>2.6.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.hadoop</groupId>
        <artifactId>hadoop-hdfs</artifactId>
        <version>2.6.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.hadoop</groupId>
        <artifactId>hadoop-mapreduce-client-common</artifactId>
        <version>2.6.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.hadoop</groupId>
        <artifactId>hadoop-mapreduce-client-core</artifactId>
        <version>2.6.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.hadoop</groupId>
        <artifactId>hadoop-mapreduce-client-jobclient</artifactId>
        <version>2.6.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.hbase</groupId>
        <artifactId>hbase-server</artifactId>
        <version>1.2.4</version>
    </dependency>
</dependencies>

测试数据

@Test
    public void testInsertSampleData() throws IOException {
        Table table = connection.getTable(TableName.valueOf("t_order"));
        Put put1 = new Put(Bytes.toBytes("1:20181010153020100"));
        put1.addColumn(Bytes.toBytes("cf1"), Bytes.toBytes("money"), Bytes.toBytes(2500.0D));
        put1.addColumn(Bytes.toBytes("cf1"), Bytes.toBytes("product"), Bytes.toBytes("p20"));
        put1.addColumn(Bytes.toBytes("cf1"), Bytes.toBytes("count"), Bytes.toBytes(1));
        Put put2 = new Put(Bytes.toBytes("2:20180510121011233 "));
        put2.addColumn(Bytes.toBytes("cf1"), Bytes.toBytes("money"), Bytes.toBytes(199.0D));
        put2.addColumn(Bytes.toBytes("cf1"), Bytes.toBytes("product"), Bytes.toBytes("连衣裙"));
        put2.addColumn(Bytes.toBytes("cf1"), Bytes.toBytes("count"), Bytes.toBytes(1));
        Put put3 = new Put(Bytes.toBytes("3:20180612111111111"));
        put3.addColumn(Bytes.toBytes("cf1"), Bytes.toBytes("money"), Bytes.toBytes(999.9D));
        put3.addColumn(Bytes.toBytes("cf1"), Bytes.toBytes("product"), Bytes.toBytes("小天鹅洗衣机"));
        put3.addColumn(Bytes.toBytes("cf1"), Bytes.toBytes("count"), Bytes.toBytes(1));
        Put put4 = new Put(Bytes.toBytes("1:20181212011011111"));
        put4.addColumn(Bytes.toBytes("cf1"), Bytes.toBytes("money"), Bytes.toBytes(200.0D));
        put4.addColumn(Bytes.toBytes("cf1"), Bytes.toBytes("product"), Bytes.toBytes("搓衣板"));
        put4.addColumn(Bytes.toBytes("cf1"), Bytes.toBytes("count"), Bytes.toBytes(1));
        Put put5 = new Put(Bytes.toBytes("1:20190206101010101"));
        put5.addColumn(Bytes.toBytes("cf1"), Bytes.toBytes("money"), Bytes.toBytes(10D));
        put5.addColumn(Bytes.toBytes("cf1"), Bytes.toBytes("product"), Bytes.toBytes("钢丝球"));
        put5.addColumn(Bytes.toBytes("cf1"), Bytes.toBytes("count"), Bytes.toBytes(1));
        Put put6 = new Put(Bytes.toBytes("2:20180306101010101"));
        put6.addColumn(Bytes.toBytes("cf1"), Bytes.toBytes("money"), Bytes.toBytes(9.9D));
        put6.addColumn(Bytes.toBytes("cf1"), Bytes.toBytes("product"), Bytes.toBytes("丝袜"));
        put6.addColumn(Bytes.toBytes("cf1"), Bytes.toBytes("count"), Bytes.toBytes(1));
        ArrayList<Put> puts = new ArrayList<Put>();
        puts.add(put1);
        puts.add(put2);
        puts.add(put3);
        puts.add(put4);
        puts.add(put5);
        puts.add(put6);
        table.put(puts);
    }

创建输入表

@Test
public void testCreateOrderTable() throws IOException {
    boolean exists = admin.tableExists(TableName.valueOf("t_order"));
    if (exists) {
        admin.disableTable(TableName.valueOf("t_order"));
        admin.deleteTable(TableName.valueOf("t_order"));
    }
    HTableDescriptor hTableDescriptor = new HTableDescriptor(TableName.valueOf("t_order"));
    HColumnDescriptor cf1 = new HColumnDescriptor("cf1");
    hTableDescriptor.addFamily(cf1);
    admin.createTable(hTableDescriptor);
}

自定义Mapper

package com.dingl;

import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.mapreduce.TableInputFormat;
import org.apache.hadoop.hbase.mapreduce.TableMapper;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @Author:Gaozhy
 */
public class OrderMapper extends TableMapper< Text, DoubleWritable> {
    /**
     * @param key     rowkey
     * @param result   hbase中的一行记录
     * @param context
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    protected void map(ImmutableBytesWritable key, Result result, Context context) throws IOException, InterruptedException {
        String rowkey = Bytes.toString(key.get());
        String userId = rowkey.split(":")[0];
        double money = Bytes.toDouble(result.getValue(Bytes.toBytes("cf1"), Bytes.toBytes("money")));
        context.write(new Text(userId), new DoubleWritable(money));
    }
}

自定义Reducer

package com.dingl;

import org.apache.hadoop.hbase.client.Mutation;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.mapreduce.TableReducer;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;
import java.util.Iterator;

public class OrderReducer extends TableReducer<Text, DoubleWritable, NullWritable>{
    /**
     * @param key     userId
     * @param values  本年度的订单金额集合
     * @param context
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    protected void reduce(Text key, Iterable<DoubleWritable> values, Context context) throws IOException, InterruptedException {
        Double sum = 0.0D;
        Iterator<DoubleWritable> iterator = values.iterator();
        while (iterator.hasNext()) {
            sum += iterator.next().get();
        }
        // 1:2018
        Put put = new Put((key.toString() + ":2018").getBytes());
        put.addColumn(Bytes.toBytes("cf1"), Bytes.toBytes("total"), Bytes.toBytes(sum));
        context.write(null, put);
    }
}

自定义初始化类

package com.dingl;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.filter.*;
import org.apache.hadoop.hbase.mapreduce.TableInputFormat;
import org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil;
import org.apache.hadoop.hbase.mapreduce.TableOutputFormat;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;

import java.io.IOException;

public class OrderComputeApplication {

    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {

        Configuration configuration = HBaseConfiguration.create();
        configuration.set(HConstants.ZOOKEEPER_QUORUM, "hadoop:2181");
        Job job = Job.getInstance(configuration, "order compute");
        job.setJarByClass(OrderComputeApplication.class);

        job.setInputFormatClass(TableInputFormat.class);
        job.setOutputFormatClass(TableOutputFormat.class);

        // map任务的初始化
        Scan scan = new Scan();
        // 2018年度的账单统计
        // 正则表达式过滤符合条件的结果:^.*:2018.*$
        RowFilter filter = new RowFilter(CompareFilter.CompareOp.EQUAL, new RegexStringComparator("^.*:2018.*$"));
        scan.setFilter(filter);
        // 3-5步
        TableMapReduceUtil.initTableMapperJob(TableName.valueOf("t_order"), scan, OrderMapper.class, Text.class, DoubleWritable.class, job);
        TableMapReduceUtil.initTableReducerJob("t_result", OrderReducer.class, job);
        job.waitForCompletion(true);
    }
}

本地计算+查看计算结果

@Test
public void testGetOrderTotal() throws IOException {
    Table table = connection.getTable(TableName.valueOf("t_result"));
    Result result = table.get(new Get(Bytes.toBytes("2:2018")));
    double total = Bytes.toDouble(result.getValue(Bytes.toBytes("cf1"), Bytes.toBytes("total")));
    System.out.println("2号用户在2018年的年度消费账单为:"+total);
}

在这里插入图片描述

远程计算

开发完成HBase On MapReduce应用运行在远程的YARN集群中运行

将应用打成JAR包
运行时依赖

应用在YARN集群中运行时需要依赖第三方的JAR包
在这里插入图片描述

解决方案
  • 将HBase应用依赖的jar包拷贝到share/hadoop/yarn/lib

  • 配置HADOOP_CLASSPATH环境变量

    [root@hadoop ~]# vi .bashrc
    # 在配置文件的末尾添加如下的第三方依赖的路径
    export HADOOP_CLASSPATH=/usr/hbase-1.2.4/lib/*
    [root@hadoop ~]# source .bashrc
    

四、HBase完全分布式集群

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-3NbSg3QZ-1570097086250)(assets/1566458592865.png)]

准备工作

  • 启动之前搭建的Hadoop完全分布式集群
  • ZooKeeper集群服务运行正常
  • HDFS集群服务运行正常

环境搭建

  • 时钟同步

    注意: HBase集群节点和节点之间的时间误差最大允许为30s,如果大于30s需要对集群内的节点进行时间同步

    [root@nodex ~]# date
    2019年 08月 20日 星期二 17:13:53 CST
    [root@nodex ~]# date -s '2019-08-22 15:49:00'
    2019年 08月 22日 星期四 15:49:00 CST
    [root@nodex ~]# date
    2019年 08月 22日 星期四 15:49:03 CST
    [root@nodex ~]# clock -w
    
  • 上传HBase安装包

    [root@node1 ~]# scp hbase-1.2.4-bin.tar.gz root@node2:~
    hbase-1.2.4-bin.tar.gz                                                                    100%   74MB 100.8MB/s   00:00
    [root@node1 ~]# scp hbase-1.2.4-bin.tar.gz root@node3:~
    hbase-1.2.4-bin.tar.gz 
    
  • 解压缩安装HBase

    [root@nodex ~]# tar -zxf hbase-1.2.4-bin.tar.gz -C /usr
    
  • 修改配置文件hbase-site.xml

    [root@nodex ~]# vi /usr/hbase-1.2.4/conf/hbase-site.xml
    <property>
        <name>hbase.rootdir</name>
        <value>hdfs://mycluster/hbase</value>
    </property>
    <property>
        <name>hbase.cluster.distributed</name>
        <value>true</value>
    </property>
    <property>
        <name>hbase.zookeeper.quorum</name>
        <value>node1,node2,node3</value>
    </property>
    <property>
        <name>hbase.zookeeper.property.clientPort</name>
        <value>2181</value>
    </property>
    
  • 修改配置文件regionservers

    [root@nodex ~]# vi /usr/hbase-1.2.4/conf/regionservers
    node1
    node2
    node3
    
  • 修改用户环境变量文件.bashrc

    [root@nodex ~]# vi .bashrc
    HBASE_MANAGES_ZK=false
    HBASE_HOME=/usr/hbase-1.2.4
    HADOOP_HOME=/usr/hadoop-2.6.0
    JAVA_HOME=/usr/java/latest
    CLASSPATH=.
    PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$HBASE_HOME/bin
    export JAVA_HOME
    export CLASSPATH
    export PATH
    export HADOOP_HOME
    export HBASE_HOME
    export HBASE_MANAGES_ZK
    [root@nodex ~]# source .bashrc
    

启动服务

  • 启动HMaster

    [root@nodex ~]# hbase-daemon.sh start master
    
  • 启动HRegionServer

    [root@nodex ~]# hbase-daemon.sh start regionserver
    

验证结果

在这里插入图片描述

五、HBase架构详解

在这里插入图片描述

HBase采用Master/Slave架构搭建集群,它隶属于Hadoop生态系统,由一下类型节点组成: HMaster 节点、HRegionServer 节点、 ZooKeeper 集群,而在底层,它将数据存储于HDFS中,因而涉及到HDFS的NameNode、DataNode等,总体结构如下:

HMaster节点用于:

  • 管理HRegionServer,实现其负载均衡。

  • 管理和分配HRegion,比如在HRegion Split时分配新的HRegion;

  • 在HRegionServer退出时迁移其内的HRegion到其他HRegionServer上。

  • 实现DDL操作(Data Definition Language,namespace和table的增删改,column familiy的增删改等)。

  • 管理namespace和table的元数据(实际存储在HDFS上)。

  • 权限控制(ACL)。

HRegionServer节点用于:

  • 存放和管理本地HRegion。

  • 读写HDFS,管理Table中的数据。

  • Client直接通过HRegionServer读写数据(从HMaster中获取元数据,找到RowKey所在的HRegion/HRegionServer后)。

ZooKeeper集群用于:

  • 存放整个 HBase集群的元数据以及集群的状态信息。

  • 实现HMaster主从节点的failover

Hbase学习分享资料 本文首先简单介绍了HBase,然后重点讲述了HBase的高并发和实时处理数据 、HBase数据模型、HBase物理存储、HBase系统架构,HBase调优、HBase Shell访问等。 立即下载

相关推荐

cpp-crossing:我的C ++学习资料库

cpp穿越 我的C ++学习资料库

HBase 入门学习

这意味着,往 HBase写入数据时,字段可以动态、按需指定。因此,和关系型数据库相比,HBase能够轻松应对字段变更的场景。(3)RowHBase 表中的每行数据都由一个RowKey和多个 Column(列)组成,数据是按照 RowKey的。

weixin_44361163的博客 936

戴尔PowerEdge服务器R450 RAID配置步骤

戴尔PowerEdge服务器R450 RAID配置步骤

且听风呤tmj的博客 6917

HBase基本知识和应用场景

HBase基本知识和应用场景

伟庭的博客 3085

Unity技能系统核心:从理论到实践构建可扩展的Buff管理器

本文深入探讨了Unity游戏开发中构建可扩展技能系统的核心——Buff管理器。通过剖析三层架构(数据、逻辑、渲染)与独立组件管理模式,提供了从Buff数据定义、管理器核心实现到可视化编辑器搭建的完整实践方案,旨在解决技能系统维护难题,提升开发效率与代码质量。

weixin_29002209的博客 256

从波士顿动力SpotMini拆解看四足机器人机械设计:关节布局与电机选型的5个关键决策点

本文深入解析波士顿动力SpotMini四足机器人的机械设计,聚焦关节布局与电机选型的5个关键决策点。通过拆解髋关节偏移距、膝关节传动链、电机热管理等核心设计,揭示商业级四足机器人的工程智慧,为工业巡检、物流机器人等应用提供实用参考。

postgres8guard的博客 896

【2022持续更新】大数据最全知识点整理-HBase篇

大数据最全知识点整理-HBase篇基础问题:1、Hbase是什么2、Hbase架构3、Hbase数据模型4、Hbase和hive的区别5、Hbase特点6、数据同样存在HDFS,为什么HBase支持在线查询,且效率比Hive快很多7、Hbase适用场景8、RowKey的设计原则9、HBase中scan和get的功能以及实现的异同?10、Scan的setCache和setBatchsetCachesetBatch11、HBase 写流程12、HBase 读流程13、HBase中Zookeeper的作用14、S

欢迎来到李奇峰的数据世界 3465

同花顺API实战指南:从零搭建股票数据自动化采集系统

本文提供了一份详尽的同花顺API实战指南,手把手教你从零开始搭建股票数据自动化采集系统。内容涵盖API权限申请、Python环境配置、数据采集与存储脚本编写、自动化定时任务实现以及数据清洗等核心环节,旨在帮助量化交易与数据分析爱好者构建稳定可靠的数据源,解放双手,提升研究效率。

weixin_29200741的博客 2428

大数据知识总结(八):HBase分布式数据库入门到精通

HBase是一个高可靠性、高性能、面向列、可伸缩、实时读写的分布式 NOSQL 数据库。当你需要随机、实时读/写访问大数据时,请使用 Apache HBase。

Lansonli(蓝深李)的博客 3359

基于simulink的BMS系统中电池单体故障隔离与恢复建模

本文介绍了使用Simulink构建BMS电池单体故障诊断与容错控制模型的方法。主要内容包括:1)搭建12串锂电池组模型;2)实现单体故障注入(过压、断线等);3)设计故障诊断与隔离模块(采用Stateflow状态机);4)开发恢复判断逻辑(需满足电压、温度等条件);5)系统监控与仿真设置。文章还提供了工程实践建议,如防环流设计、通信冗余等,并指出进阶方向(多故障处理、AI预警等)。该模型适用于新能源汽车、储能系统的BMS设计,可提高系统可靠性和安全性。

xiaoheshang_123的博客 141

3.摄像头组件- CVP (ISP)

本文介绍 车载摄像头组件-ISP

2401_83458819的博客 1619

Hbase学习资料汇总

本文内容摘录自网上多路大神的博客,转载只为收藏,在此感谢多位博主的分享 HBase简介 HBase的名字的来源于Hadoop database,即hadoop数据库,不同于一般的关系数据库,它是一个适合于非结构化数据存储的数据库,而且它是基于列的而不是基于行的模式。 HBase是一个分布式的、面向列的开源数据库,源于google的一篇论文《bigtable:一个结构化数据的分布式存储系统》。...

来玩儿8的博客 680

单反相机物镜设计[DG-10]

REAR(要打在像面,操作数要找像面对应位置15):以透镜单位表示的真实光线径向坐标,波长由Wave定义,参见“Hx、Hy、Px和Py”。最小玻璃厚度最小不能小于semi-dia的1/10,要根据layout看有没有过厚过薄,反复调节。PROD:两个操作数的乘积(操作#1 X操作#2)。3x4就是57.3x0.41=23.5。拦光一般在第一面和最后一面操作,减少边缘无用光线。光阑面与镜面贴近,要调距离,同时设置光阑像差。后截距是指从镜头后表面到焦点的距离。CONS:弧度转为角度。镜头相互嵌入,有错误。

weixin_72050316的博客 600

HBase全网最佳学习资料汇总

HBase全网最佳学习资料汇总 封神 2017-08-13 19:11:08 浏览1653 评论0 大数据 监控 阿里云 hbase HTTPS Apache http 互联网 阿里巴巴 集群 aliyun 物联网 报表html 存储 摘要: HBase这几年在国内使用的越来越广泛,在一定规模的企业中几乎是必备存储引擎,互联网企业阿里巴巴、百度、腾讯、京东、小米都有数千台

hayaqi0504的博客 633

大数据运营可视化:Tableau+PowerBI数据看板搭建教程

当企业数据量从“GB级”跃升到“TB级”,运营人员面临的最大挑战不再是“如何收集数据”,而是“如何让数据说话”。数据看板作为“运营指挥中心的仪表盘”,能将零散的用户行为、业务指标、流量趋势浓缩成可快速解读的视觉语言。本文结合Tableau(自由探索的“数据瑞士军刀”)与PowerBI(微软生态的“组合家具”)两大工具,从需求分析→数据准备→指标设计→视图搭建→ dashboard 组合,一步步教你搭建符合业务逻辑的运营看板。

AI智能探索者的博客 1367

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Hbase学习资料和相关书籍 全

百度网盘提取链接:https://pan.baidu.com/s/1-S5H1Y6D5ZjMxvppJOSpCA 提取码:i5nq

weixin_44674253的博客 1273

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

HBase & Hadoop学习资料汇总

汇总下近一周学习HBase和hadoop的学习资料   下载链接: http://archive.cloudera.com/cdh/3/ HBase总体架构介绍:可以反复研究,有助于理解整体框架 http://www.searchtb.com/2011/01/understanding-hbase.html 中文的官方文档:比较简单的文档,具体API和细节还得参考HBase The D

mmf0932021的专栏 470

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

hbase学习资料整理

hbase整理 1:hbase是啥: HBase(Hadoop Ddatabase)是一个开源的、面向列,适用于海量数据存储(TB、PB)的、具备高可用、高性能、可灵活扩展伸缩的、支持实时数据读写的分布式存储系统。 2:hbase适用场景: 1.海量数据:TB,PB级别的  2.高吞吐量:HBase支持高并发读写,通过使用日志文件(HLOG)和内存存储来将随机写转换成顺序写,保证稳定的数据插入...

qq_20672581的博客 563

hbase学习资料

1>.http://database.51cto.com/art/201211/364810.htm 2>.http://abloz.com/hbase/book.html 3>http://rdc.taobao.com/team/jm/archives/975 4>http://www.searchtb.com/2011/01/understanding-hbase.html 5>htt...

人生何处不相逢 215

HBase全网最佳学习资料汇总笔记

HBase全网最佳学习资料汇总 https://yq.aliyun.com/articles/169085?spm=5176.100239.blogrightarea176102.19.pH0StL 学术界关于HBase在物联网/车联网/互联网/金融/高能物理等八大场景的理论研究 https://yq.aliyun.com/articles/214619?spm=a2c4e.11153940...

github_28583061的博客 591
上一篇: zookeeper学习资料
下一篇: flume学习资料
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值