hbase 搭建
docker run -tdi -p 2181:2181 -p 8030:8030 -p 8031:8031 -p 8032:8032 -p 8033:8033 -p 8040:8040 -p 8088:8088 -p 9000:9000 -p 9864:9864 -p 9866:9866 -p 9867:9867 -p 9868:9868 -p 9870:9870 -p 13562:13562 -p 16000:16000 -p 16010:16010 -p 16020:16020 -p 16030:16030 -p 19888:19888 --hostname hbase0 --privileged -e "container=docker" --name hbaseweifb registry.cn-hangzhou.aliyuncs.com/mkmk/hadoop:hbaseweifbv4 init | docker exec hbaseweifb /bin/bash -c ' /starthadoop.sh'
使用 java api 端口 9000
hadoop web 9870
hbase web 16010
javaapi 创建表格
这里就填写你 docker 容器所在的 ip地址即可
configuration.set(“hbase.rootdir”,“hdfs://127.0.0.1:9000/hbase”);
configuration.set(“hbase.zookeeper.quorum”, “127.0.0.1”);
package main.java; import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.*; import org.apache.hadoop.hbase.io.compress.Compression.Algorithm; import org.apache.log4j.BasicConfigurator; public class connectHbase { public static Configuration configuration; //配置对象,用于管理配置信息(类似hbase-site.xml) public static Connection connection; //连接对象,用于连接数据库 public static Admin admin; //管理对象,用于管理表(如对表的增删改查) public static void init(){ //1.根据hbase-site.xml文件初始化Configuration对象 configuration = HBaseConfiguration.create(); configuration.set("hbase.rootdir","hdfs://127.0.0.1:9000/hbase"); configuration.set("hbase.zookeeper.quorum", "127.0.0.1"); configuration.set("hbase.zookeeper.property.clientPort", "2181"); try{ //2.根据Configuration对象初始化Connection对象 connection = ConnectionFactory.createConnection(configuration); //3.根据Connection对象获取Admin对象 admin = connection.getAdmin(); System.out.println("连接HBase成功."); }catch (IOException e){ System.err.println("连接HBase失败."); } } 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 { init(); //创建连接 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 columnfamily = ColumnFamilyDescriptorBuilder.of(str); //根据字符串列簇名分别创建新的列簇 tableDescriptor.setColumnFamily(columnfamily); //把新列簇依次添加到新表实例中 } admin.createTable(tableDescriptor.build()); //把创建的新表实例添加到HBase中 System.out.println("create table success"); } close(); //关闭连接 } public static void main(String... args) throws IOException { BasicConfigurator.configure(); createTable("lmk",new String[]{"col1","col2"}); } }
常用命令
查看所有活动端口
netstat -ntlp
查看大小
du -shm * | sort -nr
查看jps 活动
jps
压缩文件
nohup tar cvpzf /backup20200406.tgz --exclude=/proc --exclude=/nohup.out --exclude=/backup20200406.tgz --exclude=/mnt --exclude=/sys/ --exclude=/run / &
docker run -tdi -p 2181:2181 -p 8030:8030 -p 8031:8031 -p 8032:8032 -p 8033:8033 -p 8040:8040 -p 8088:8088 -p 9000:9000 -p 9864:9864 -p 9866:9866 -p 9867:9867 -p 9868:9868 -p 9870:9870 -p 13562:13562 -p 16010:16010 -p 16030:16030 -p 19888:19888 -p 33933:33933 --hostname localhost --privileged -e "container=docker" --name hbaseweifb registry.cn-hangzhou.aliyuncs.com/mkmk/hadoop:hbaseweifb init | docker exec hbaseweifb /bin/bash -c ' /starthadoop.sh '
常见报错
Connection refused: no further information: localhost/127.0.0.1:16020
请参考