zookeeper、hadoop、hbase單機僞分佈式環境搭建(虛擬機vmware)

zookeeper單機多實例
其實就是跑多個zk服務,以zkServer1爲例,配置以下:其中192.168.29.128爲虛擬機ip 很重要java

dataDir=/virgil/zooserver/server1/data
dataLogDir=/virgil/zooserver/server1/logs 
clientPort=2181
server.1=192.168.29.128:2888:3888
server.2=192.168.29.128:2889:3889
server.3=192.168.29.128:2890:3890

其他實例只須要保證clientPort,dataDir,dataLogDir,不同便可
hadoop關鍵配置
寫在前面:配置時最好寫具體的ip,不要用localhost或者127.0.0.1,否則本地機器訪問不到虛擬機
core-site.xml配置node

<property>
        <name>hadoop.tmp.dir</name>
        <value>file:/virgil/hadoop/tmp</value>
        <description>Abase for other temporary directories.</description>
    </property>
    <property>
        <name>fs.defaultFS</name>
        <value>hdfs://192.168.29.128:9000/hbase</value>
    </property>

hdfs-site.xml配置oop

<property>
        <name>dfs.replication</name>
        <value>1</value>
    </property>
    <property>
        <name>dfs.namenode.name.dir</name>
        <value>file:/virgil/hadoop/tmp/dfs/name</value>
    </property>
    <property>
        <name>dfs.datanode.data.dir</name>
        <value>file:/virgil/hadoop/tmp/dfs/data</value>
    </property>

hbase配置
hbase-site.xml配置code

<property>
        <name>hbase.cluster.distributed</name>
        <value>true</value>
    </property>
    <property>
        <name>hbase.master.info.port</name>
        <value>60010</value>
    </property>
    <property>
        <name>hbase.rootdir</name>
        <value>hdfs://192.168.29.128:9000/hbase</value>
    </property>

    <property>
        <name>hbase.zookeeper.property.dataDir</name>
        <value>/virgil/zooserver/data</value>
    </property>
    <property>
        <name>hbase.zookeeper.quorum</name>
        <value>192.168.29.128</value>
    </property>
    <property>
        <name>hbase.zookeeper.property.clientPort</name>
        <value>2181</value>
    </property>
    <property>
        <name>hbase.zookeeper.property.dataDir</name>
        <value>/virgil/zooserver/data</value>
    </property>

java API訪問位於虛擬機中的hbase
依次啓動zookeeper、hadoop、hbase後server

Configuration HBASE_CONFIG = new Configuration();

        HBASE_CONFIG.set("hbase.zookeeper.quorum", "192.168.29.128");

        HBASE_CONFIG.set("hbase.zookeeper.property.clientPort", "2181");

        HBaseConfiguration cfg = new HBaseConfiguration(HBASE_CONFIG);

        HBaseAdmin admin = new HBaseAdmin(cfg);

        System.out.println(admin.tableExists("tableName"));
相關文章
相關標籤/搜索