hadoop-使用Java远程访问HBase表列表


0
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.HBaseAdmin;

public class ListTables {

    public static void main(String args[])throws MasterNotRunningException, IOException {
        ConnectionFactory.createConnection();
        System.out.println("stage 1. . . . ");
        Configuration conf =  HBaseConfiguration.create();
        conf.set("hbase.zookeeper.quorum", "192.168.*.***");
        conf.set("hbase.master", "192.168.*.***:60000");
        conf.set("hbase.zookeeper.property.clientPort","2181");
        conf.set("zookeeper.znode.parent","/hbase-unsecure");
        Connection connection = ConnectionFactory.createConnection(conf);

        try {
            HBaseAdmin admin1 = (HBaseAdmin)connection.getAdmin();
            System.out.println("stage 3. . . . ");
            HTableDescriptor tableDescriptor[] = admin1.listTables();
            for (int i=0; i<tableDescriptor.length; i++) {
                System.out.println(tableDescriptor[i].getNameAsString());
            }
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}

输出

log4j:WARN No appenders could be found for logger (org.apache.hadoop.metrics2.lib.MutableMetricsFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
stage 1. . . . 
stage 3. . . . 

这就是错误

排队之后,我等了很长时间,但没有回应。

1 答案


0

我也有同样的错误,我必须创建log4j.properties,这是因为Hadoop使用log4j来编写日志:

Java项目:resources/log4j.properties

# Root logger option
log4j.rootLogger=DEBUG, stdout, file

Redirect log messages to console

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

Redirect log messages to a log file, support file rolling.

log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=C:\path of your enter code herefile\pruebas\log\log.log
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

我希望这对你有帮助。


我来回答

写文章

提问题

面试题