docker 安裝html
https://hub.docker.com/editions/community/docker-ce-desktop-mac 下載地址java
下載完以後,安裝app同樣安裝就好docker
安裝完 配置 Docker 鏡像站shell
mac 國內鏡像站 http://f1361db2.m.daocloud.io
hbase 安裝apache
https://www.jianshu.com/p/71db312807c7 參考鏈接vim
docker search hbase # 查找hbase dokcker pull harisekhon/hbase # 選擇最火的版本安裝 docker run -d -h myhbase -p 2181:2181 -p 8080:8080 -p 8085:8085 -p 9090:9090 -p 9095:9095 -p 16000:16000 -p 16010:16010 -p 16201:16201 -p 16301:16301 --name hbase harisekhon/hbase:1.3 # 運行habse docker exec -it hbase bash # 進入bash hbase shell # 進入hbase命令行 list # 查看錶列表 scan '表名' , {LIMIT=>1} # 掃描表
hadoop 安裝bash
http://www.javashuo.com/article/p-cctgspcn-gc.html (參考連接)app
java鏈接hbasemaven
第一步,須要在hosts 裏面加上對應的hbase名稱oop
sudo vim sudo /private/etc/hosts
第二步 添加依賴包(maven項目)
<dependency> <groupId>org.apache.hbase</groupId> <artifactId>hbase-client</artifactId> <version>1.3.3</version> </dependency> <dependency> <groupId>org.apache.hbase</groupId> <artifactId>hbase-server</artifactId> <version>1.3.3</version> </dependency>
第三步 寫代碼鏈接
package org.myorg.quickstart.hbase_tool; import org.apache.commons.net.ntp.TimeStamp; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.*; import org.apache.hadoop.hbase.util.Bytes; import org.junit.Test; import java.io.IOException; import java.util.ArrayList; import java.util.Date; import java.util.Properties; public class TestHbase { private static String zkServer = "localhost"; private static Integer port = 9095; private static TableName tableName = TableName.valueOf("testflink"); private static final String cf = "ke"; @Test public void testWH() throws IOException{ write2HBase("test"); } public static void write2HBase(String value) throws IOException { Configuration config = HBaseConfiguration.create(); config.set("hbase.zookeeper.quorum","myhbase"); config.set("hbase.zookeeper.property.clientPort","2181"); System.out.println("開始鏈接hbase"); Connection connect = ConnectionFactory.createConnection(config); System.out.println(connect.isClosed()); Admin admin = connect.getAdmin(); System.out.println("鏈接成功"); // admin.listTableNames(); // Table table = connect.getTable(TableName.valueOf("midas_ctr_test")); System.out.println("獲取表數據成功"); // for i :table.getScanner().iterator(); if (!admin.tableExists(tableName)) { admin.createTable(new HTableDescriptor(tableName).addFamily(new HColumnDescriptor(cf))); } System.out.println("建表數據成功"); Table table = connect.getTable(tableName); TimeStamp ts = new TimeStamp(new Date()); Date date = ts.getDate(); Put put = new Put(Bytes.toBytes(date.getTime())); put.addColumn(Bytes.toBytes(cf), Bytes.toBytes("test"), Bytes.toBytes(value)); table.put(put); table.close(); connect.close(); } }