idea zookeeper的使用_编译运行Zookeeper源码

本文介绍了如何在IDEA中编译并运行Zookeeper源码。首先从GitHub获取Zookeeper项目,将其作为Maven项目导入。接着,拷贝配置文件到指定位置,并创建data目录。然后,在pom文件中修改scope,注释掉特定依赖。通过设置启动项和参数,可以执行Zookeeper的server和client。最后,启动Zookeeper服务并进行客户端连接,完成源码运行。
摘要由CSDN通过智能技术生成

GitHub地址:

https://github.com/apache/zookeeper

最新版本的 zookeeper 已经使用了 maven 进行管理了、不再需要安装 Ant

下载完成之后、使用 Idea 作为一个 maven 项目打开

拷贝配置文件

  • 拷贝zoo_sample.cfg文件至相同文件夹下,名为:zoo.cfg,配置全部使用默认;
  • 创建 /tmp/zookeeper 目录、用于存放 zk 数据.
  • 拷贝log4j.properties文件至:zookeeper-server/src/main/resources,文件名还是log4j.properties不变.
  • resource 标记为 Resources Root

增加启动项

找到类 org.apache.zookeeper.server.quorum.QuorumPeerMain

在参数中加上 conf/zoo.cfg

389cb15d463bc97d94f6ca39b135d684.png

修改pom文件中scope

scope 注释掉

<dependency>
    <groupId>io.dropwizard.metrics</groupId>
    <artifactId>metrics-core</artifactId>
    <version>3.1.0</version>
</dependency>
<dependency>
  <groupId>org.xerial.snappy</groupId>
  <artifactId>snappy-java</artifactId>
  <version>1.1.7.3</version>
</dependency>
<dependency>
  <groupId>org.eclipse.jetty</groupId>
  <artifactId>jetty-server</artifactId>
</dependency>
<dependency>
  <groupId>org.eclipse.jetty</groupId>
  <artifactId>jetty-servlet</artifactId>
</dependency>

执行server

执行 main 方法前建议执行命令 mvn clean install -DskipTests

2020-05-11 23:51:27,731 [myid:] - INFO  [main:NIOServerCnxnFactory@664] - binding to port 0.0.0.0/0.0.0.0:2181
2020-05-11 23:51:27,751 [myid:] - INFO  [main:WatchManagerFactory@42] - Using org.apache.zookeeper.server.watch.WatchManager as watchmanager
2020-05-11 23:51:27,751 [myid:] - INFO  [main:WatchManagerFactory@42] - Using org.apache.zookeeper.server.watch.WatchManager as watchmanager
2020-05-11 23:51:27,751 [myid:] - INFO  [main:ZKDatabase@132] - zookeeper.snapshotSizeFactor = 0.33
2020-05-11 23:51:27,751 [myid:] - INFO  [main:ZKDatabase@152] - zookeeper.commitLogCount=500
2020-05-11 23:51:27,757 [myid:] - INFO  [main:SnapStream@61] - zookeeper.snapshot.compression.method = CHECKED
2020-05-11 23:51:27,759 [myid:] - INFO  [main:FileSnap@85] - Reading snapshot /tmp/zookeeper/version-2/snapshot.3
2020-05-11 23:51:27,763 [myid:] - INFO  [main:DataTree@1730] - The digest in the snapshot has digest version of 2, , with zxid as 0x3, and digest value as 1371985504
2020-05-11 23:51:27,774 [myid:] - INFO  [main:FileTxnSnapLog@363] - 1 txns loaded in 5 ms
2020-05-11 23:51:27,774 [myid:] - INFO  [main:ZKDatabase@289] - Snapshot loaded in 23 ms, highest zxid is 0x4, digest is 1371985504
2020-05-11 23:51:27,774 [myid:] - INFO  [main:FileTxnSnapLog@470] - Snapshotting: 0x4 to /tmp/zookeeper/version-2/snapshot.4
2020-05-11 23:51:27,775 [myid:] - INFO  [main:ZooKeeperServer@522] - Snapshot taken in 1 ms
2020-05-11 23:51:27,788 [myid:] - INFO  [main:RequestThrottler@75] - zookeeper.request_throttler.shutdownTimeout = 10000
2020-05-11 23:51:27,802 [myid:] - INFO  [main:ContainerManager@83] - Using checkIntervalMs=60000 maxPerMinute=10000 maxNeverUsedIntervalMs=0
2020-05-11 23:51:27,803 [myid:] - INFO  [main:ZKAuditProvider@42] - ZooKeeper audit is disabled.
2020-05-11 23:51:58,403 [myid:] - INFO  [SessionTracker:ZooKeeperServer@603] - Expiring session 0x100016819530000, timeout of 30000ms exceeded
2020-05-11 23:51:58,404 [myid:] - INFO  [SessionTracker:ZooKeeperServer@603] - Expiring session 0x10001651fa70000, timeout of 30000ms exceeded
2020-05-11 23:51:58,407 [myid:] - INFO  [SyncThread:0:FileTxnLog@284] - Creating new log file: log.5

启动成功

执行client

如 server 一般、配置入口类 org.apache.zookeeper.ZooKeeperMain

将下面的依赖的 scope 注释掉

<dependency>  
<groupId>commons-cli</groupId>  
<artifactId>commons-cli</artifactId>
</dependency>

启动

Welcome to ZooKeeper!JLine support is disabled
2020-05-11 23:54:50,732 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1169] - Opening socket connection to server localhost/127.0.0.1:2181.
2020-05-11 23:54:50,732 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1171] - SASL config status: Will not attempt to authenticate using SASL (unknown error)
2020-05-11 23:54:50,748 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1001] - Socket connection established, initiating session, client: /127.0.0.1:59060, server: localhost/127.0.0.1:2181
2020-05-11 23:54:50,769 [myid:localhost:2181] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1436] - Session establishment complete on server localhost/127.0.0.1:2181, session id = 0x10001a019010000, negotiated timeout = 30000WATCHER::WatchedEvent state:SyncConnected type:None path:nullls /[zookeeper]ls /zookeeper[config, quota]

至此,已成功编译运行 zookeeper的源码

fecf483ac8982f40b9f799cc3ac85298.png
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值