最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

docker?部署hbase并且java?Api連接的操作過程

 更新時間:2023年11月23日 11:35:32   作者:藍胖子不是胖子  
這篇文章主要介紹了docker?部署hbase并且java?Api連接的操作過程,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友參考下吧

1.首先先運行容器

docker run -d --name hbase -p 2181:2181 -p 16010:16010 -p16000:16000 -p 16020:16020 -p 16030:16030 harisekhon/hbase

2.在本機的hosts中注冊docker的id
因為docker內部集成了其他環(huán)境而其他環(huán)境 中的ip是docker id 所以需要在hosts中轉換

192.168.80.120	dockerhbase sa445is094a

3.客戶端連接依賴

<dependencies>
            <!--        hbaseClient依賴包,需要排除日志log4j,不然和springboot的沖突了-->
                <!-- https://mvnrepository.com/artifact/org.apache.hbase/hbase-client -->
                <dependency>
                    <groupId>org.apache.hbase</groupId>
                    <artifactId>hbase-client</artifactId>
                    <version>2.5.4</version>
                    <exclusions>
                        <exclusion>
                            <groupId>org.slf4j</groupId>
                            <artifactId>slf4j-log4j12</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>
                <!-- https://mvnrepository.com/artifact/org.apache.hbase/hbase -->
                <dependency>
                    <groupId>org.apache.hbase</groupId>
                    <artifactId>hbase</artifactId>
                    <version>2.5.4</version>
                    <type>pom</type>
                </dependency>
            <dependency>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
                <version>1.2.17</version>
            </dependency>
        </dependencies>

倆個依賴出現log4j的依賴申明錯誤,所以這里需要排除,并且新建一個properties后綴的配置文件

log4j.rootLogger=debug, stdout, R
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=example.log
log4j.appender.R.MaxFileSize=100KB
# Keep one backup file
log4j.appender.R.MaxBackupIndex=5
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n

4.java api 調用

public class Practice4 {
        public static Configuration configuration;
        public static Connection connection;
        public static Admin admin;
        public static void main(String[] args)throws IOException{
            init();
            createTable("student",new String[]{"score"});
            insertData("student","zhangsan","score","English","69");
            insertData("student","zhangsan","score","Math","86");
            insertData("student","zhangsan","score","Computer","77");
            getData("student", "zhangsan", "score","English");
            close();
        }
        public static void init(){
            configuration  = HBaseConfiguration.create();
//            configuration.set("hbase.rootdir","hdfs://192.168.249.132:8020/");
            configuration.set("hbase.zookeeper.quorum", "192.168.249.132");
            configuration.set("hbase.zookeeper.property.clientPort", "2181");
            try{
                connection = ConnectionFactory.createConnection(configuration);
                admin = connection.getAdmin();
            }catch (IOException e){
                e.printStackTrace();
            }
        }
        public static void close(){
            try{
                if(admin != null){
                    admin.close();
                }
                if(null != connection){
                    connection.close();
                }
            }catch (IOException e){
                e.printStackTrace();
            }
        }
        public static void createTable(String myTableName,String[] colFamily) throws IOException {
            TableName tableName = TableName.valueOf(myTableName);
            if(admin.tableExists(tableName)){
                System.out.println("talbe is exists!");
            }else {
                TableDescriptorBuilder tableDescriptor = TableDescriptorBuilder.newBuilder(tableName);
                for(String str:colFamily){
                    ColumnFamilyDescriptor family =
                            ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(str)).build();
                    tableDescriptor.setColumnFamily(family);
                }
                admin.createTable(tableDescriptor.build());
            }
        }
        public static void insertData(String tableName,String rowKey,String colFamily,String col,String val) throws IOException {
            Table table = connection.getTable(TableName.valueOf(tableName));
            Put put = new Put(rowKey.getBytes());
            put.addColumn(colFamily.getBytes(),col.getBytes(), val.getBytes());
            table.put(put);
            table.close();
        }
        public static void getData(String tableName,String rowKey,String colFamily, String col)throws  IOException{
            Table table = connection.getTable(TableName.valueOf(tableName));
            Get get = new Get(rowKey.getBytes());
            get.addColumn(colFamily.getBytes(),col.getBytes());
            Result result = table.get(get);
            System.out.println(new String(result.getValue(colFamily.getBytes(),col==null?null:col.getBytes())));
            table.close();
        }
    }

到此這篇關于docker 部署hbase 并且java Api連接的文章就介紹到這了,更多相關docker 部署hbase內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

最新評論

延边| 福海县| 茶陵县| 肇东市| 吉水县| 佛山市| 璧山县| 潜江市| 洛扎县| 来宾市| 霞浦县| 师宗县| 江西省| 南开区| 阿勒泰市| 体育| 正安县| 泰宁县| 兴文县| 东乡| 宜阳县| 武威市| 新平| 固镇县| 镇雄县| 万全县| 尼勒克县| 兴国县| 上思县| 陇西县| 靖州| 建始县| 蒲江县| 延吉市| 丹阳市| 左权县| 黄山市| 敦化市| 仙桃市| 青海省| 平顶山市|