搭建ZooKeeper Standalone环境

无干货,仅供复制

1.
下载、解压

2.
配置

引用

#conf/zoo.cfg

tickTime=2000

dataDir=/home/kent/dev/hadoop/zookeeper-3.4.5/dataStore

clientPort=2181

3.
启动

引用

$zkServer.sh start-foreground 

4.
验证

引用

$telnet localhost 2181

$>ruok  #zookeeper支持的四字短语之一

5.
用Java API创建一个结点

<!--pom.xml-->
<dependency>
  <groupId>org.apache.zookeeper</groupId>
  <artifactId>zookeeper</artifactId>
  <version>3.4.5</version>
</dependency>
public class FirstNode {

    public static void main(String[] args) throws Exception {

        ZooKeeper zk = new ZooKeeper("localhost", 1000, null);
        while (zk.getState() != States.CONNECTED) {
            ;//wait
        }
        String path = zk.create("/firstNode", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        System.out.println("The node " + path + " has been created");

    }
}

6.
用zookeeper命令行工具查看结点

引用

$zkCli.sh -localhost

$> ls /

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.