美文网首页
Zookeeper学习笔记(6)—— 编译Zookeeper服务

Zookeeper学习笔记(6)—— 编译Zookeeper服务

作者: 曾泽浩 | 来源:发表于2021-05-05 18:59 被阅读0次
    1. 首先,从github上面克隆zookeeper的源代码。

    地址: https://github.com/apache/zookeeper.git

    Zookeeper代码结构

    可以看到zookeeper服务端的主要代码结构,其中最主要的就是zookeeper-server和zookeeper-client模块。

    zookeeper-server是zookeeper的服务端实现。

    zookeeper-client是官网提供的zookeeper客户端。

    zookeeper-jute是zookeeper的序列化与反序列化。

    zookeeper-recipes是zookeeper的菜谱,也就是常见的一些应用场景。

    1. 导入项目之后,需要为序列化与反序列化生成一些自动化的代码和版本信息。
    image-20210504164403528.png

    点击右侧Maven工具栏红色圈出的按钮。

    image-20210504170119955.png
    1. 需要把zookeeper-server模块的resources目录变成只资源模块,并且把conf目录下的log4j.properties文件拷贝过去。


      image-20210504164741211.png
    1. 设置启动类和启动参数。启动类,org.apache.zookeeper.server.quorum.QuorumPeerMain
    image-20210504164910801.png
    1. 有一些jar因为版本的问题,启动的时候会出现ClassNotFoundError,需要修改一下pom文件。在zookeeper-server模块下的pom文件最下面增加以下依赖。
        <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>
      </dependencies>
    
    1. 重新clean一下项目,并且执行第2步的自动生成代码,然后运行项目, 可以看到控制台有输出日志。
    2021-05-04 11:19:16,352 [myid:] - INFO  [main:QuorumPeerConfig@181] - Reading configuration from: conf/zoo.cfg
    2021-05-04 11:19:16,358 [myid:] - WARN  [main:VerifyingFileFactory@65] - conf/zoo.cfg is relative. Prepend ./ to indicate that you're sure!
    2021-05-04 11:19:16,386 [myid:] - INFO  [main:QuorumPeerConfig@444] - clientPortAddress is 0.0.0.0:2181
    2021-05-04 11:19:16,388 [myid:] - INFO  [main:QuorumPeerConfig@448] - secureClientPort is not set
    2021-05-04 11:19:16,388 [myid:] - INFO  [main:QuorumPeerConfig@464] - observerMasterPort is not set
    2021-05-04 11:19:16,388 [myid:] - INFO  [main:QuorumPeerConfig@481] - metricsProvider.className is org.apache.zookeeper.metrics.impl.DefaultMetricsProvider
    2021-05-04 11:19:16,456 [myid:1] - INFO  [main:DatadirCleanupManager@78] - autopurge.snapRetainCount set to 3
    2021-05-04 11:19:16,456 [myid:1] - INFO  [main:DatadirCleanupManager@79] - autopurge.purgeInterval set to 0
    2021-05-04 11:19:16,456 [myid:1] - INFO  [main:DatadirCleanupManager@101] - Purge task is not scheduled.
    2021-05-04 11:19:16,463 [myid:1] - INFO  [main:ManagedUtil@44] - Log4j 1.2 jmx support found and enabled.
    2021-05-04 11:19:16,548 [myid:1] - INFO  [main:QuorumPeerMain@155] - Starting quorum peer, myid=1
    2021-05-04 11:19:16,571 [myid:1] - INFO  [main:ServerMetrics@62] - ServerMetrics initialized with provider org.apache.zookeeper.metrics.impl.DefaultMetricsProvider@58134517
    2021-05-04 11:19:16,588 [myid:1] - INFO  [main:DigestAuthenticationProvider@47] - ACL digest algorithm is: SHA1
    2021-05-04 11:19:16,588 [myid:1] - INFO  [main:DigestAuthenticationProvider@61] - zookeeper.DigestAuthenticationProvider.enabled = true
    2021-05-04 11:19:16,596 [myid:1] - INFO  [main:ServerCnxnFactory@169] - Using org.apache.zookeeper.server.NIOServerCnxnFactory as server connection factory
    2021-05-04 11:19:16,599 [myid:1] - WARN  [main:ServerCnxnFactory@309] - maxCnxns is not configured, using default value 0.
    2021-05-04 11:19:16,603 [myid:1] - INFO  [main:NIOServerCnxnFactory@652] - Configuring NIO connection handler with 10s sessionless connection timeout, 2 selector thread(s), 16 worker threads, and 64 kB direct buffers.
    2021-05-04 11:19:16,621 [myid:1] - INFO  [main:NIOServerCnxnFactory@660] - binding to port 0.0.0.0/0.0.0.0:2181
    2021-05-04 11:19:16,645 [myid:1] - INFO  [main:QuorumPeer@808] - zookeeper.quorumCnxnTimeoutMs=-1
    2021-05-04 11:19:16,684 [myid:1] - INFO  [main:Log@169] - Logging initialized @683ms to org.eclipse.jetty.util.log.Slf4jLog
    2021-05-04 11:19:16,857 [myid:1] - WARN  [main:ContextHandler@1660] - o.e.j.s.ServletContextHandler@55b53d44{/,null,STOPPED} contextPath ends with /*
    2021-05-04 11:19:16,857 [myid:1] - WARN  [main:ContextHandler@1671] - Empty contextPath
    2021-05-04 11:19:16,895 [myid:1] - INFO  [main:X509Util@77] - Setting -D jdk.tls.rejectClientInitiatedRenegotiation=true to disable client-initiated TLS renegotiation
    2021-05-04 11:19:16,899 [myid:1] - INFO  [main:FileTxnSnapLog@126] - zookeeper.snapshot.trust.empty : false
    2021-05-04 11:19:16,904 [myid:1] - INFO  [main:QuorumPeer@1787] - Local sessions disabled
    2021-05-04 11:19:16,904 [myid:1] - INFO  [main:QuorumPeer@1798] - Local session upgrading disabled
    2021-05-04 11:19:16,905 [myid:1] - INFO  [main:QuorumPeer@1765] - tickTime set to 2000
    2021-05-04 11:19:16,905 [myid:1] - INFO  [main:QuorumPeer@1809] - minSessionTimeout set to 4000
    2021-05-04 11:19:16,905 [myid:1] - INFO  [main:QuorumPeer@1820] - maxSessionTimeout set to 40000
    2021-05-04 11:19:16,905 [myid:1] - INFO  [main:QuorumPeer@1845] - initLimit set to 10
    2021-05-04 11:19:16,905 [myid:1] - INFO  [main:QuorumPeer@2032] - syncLimit set to 5
    2021-05-04 11:19:16,905 [myid:1] - INFO  [main:QuorumPeer@2047] - connectToLearnerMasterLimit set to 0
    2021-05-04 11:19:16,943 [myid:1] - INFO  [main:ZookeeperBanner@42] - 
    2021-05-04 11:19:16,943 [myid:1] - INFO  [main:ZookeeperBanner@42] -   ______                  _                                          
    2021-05-04 11:19:16,943 [myid:1] - INFO  [main:ZookeeperBanner@42] -  |___  /                 | |                                         
    2021-05-04 11:19:16,943 [myid:1] - INFO  [main:ZookeeperBanner@42] -     / /    ___     ___   | | __   ___    ___   _ __     ___   _ __   
    2021-05-04 11:19:16,943 [myid:1] - INFO  [main:ZookeeperBanner@42] -    / /    / _ \   / _ \  | |/ /  / _ \  / _ \ | '_ \   / _ \ | '__|
    2021-05-04 11:19:16,943 [myid:1] - INFO  [main:ZookeeperBanner@42] -   / /__  | (_) | | (_) | |   <  |  __/ |  __/ | |_) | |  __/ | |    
    2021-05-04 11:19:16,943 [myid:1] - INFO  [main:ZookeeperBanner@42] -  /_____|  \___/   \___/  |_|\_\  \___|  \___| | .__/   \___| |_|
    2021-05-04 11:19:16,943 [myid:1] - INFO  [main:ZookeeperBanner@42] -                                               | |                     
    2021-05-04 11:19:16,943 [myid:1] - INFO  [main:ZookeeperBanner@42] -                                               |_|                     
    2021-05-04 11:19:16,943 [myid:1] - INFO  [main:ZookeeperBanner@42] - 
    2021-05-04 11:19:16,953 [myid:1] - INFO  [main:Environment@98] - Server environment:zookeeper.version=3.8.0-SNAPSHOT-f8ebf1a25281b2c7f48e08011918c72643313209-dirty, built on 2021-04-26 09:07 UTC
    2021-05-04 11:19:16,954 [myid:1] - INFO  [main:Environment@98] - Server environment:host.name=localhost
    2021-05-04 11:19:16,954 [myid:1] - INFO  [main:Environment@98] - Server environment:java.version=1.8.0_221
    2021-05-04 11:19:16,954 [myid:1] - INFO  [main:Environment@98] - Server environment:java.vendor=Oracle Corporation
    2021-05-04 11:19:16,954 [myid:1] - INFO  [main:Environment@98] - Server environment:java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/jre
    2021-05-04 11:19:16,954 [myid:1] - INFO  [main:Environment@98] - Server environment:java.class.path=/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/jre/lib/deploy.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/jre/lib/ext/cldrdata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/jre/lib/ext/dnsns.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/jre/lib/ext/jaccess.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/jre/lib/ext/jfxrt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/jre/lib/ext/localedata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/jre/lib/ext/nashorn.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/jre/lib/ext/sunec.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/jre/lib/ext/sunjce_provider.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/jre/lib/ext/sunpkcs11.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/jre/lib/ext/zipfs.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/jre/lib/javaws.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/jre/lib/jfxswt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/jre/lib/management-agent.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/jre/lib/plugin.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/lib/ant-javafx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/lib/dt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/lib/javafx-mx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/lib/jconsole.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/lib/packager.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/lib/sa-jdi.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/lib/tools.jar:/Users/zengzehao/IdeaProjects/zookeeper/zookeeper-server/target/classes:/Users/zengzehao/IdeaProjects/zookeeper/zookeeper-jute/target/classes:/Users/zengzehao/.m2/repository/org/apache/yetus/audience-annotations/0.12.0/audience-annotations-0.12.0.jar:/Users/zengzehao/.m2/repository/io/netty/netty-handler/4.1.63.Final/netty-handler-4.1.63.Final.jar:/Users/zengzehao/.m2/repository/io/netty/netty-common/4.1.63.Final/netty-common-4.1.63.Final.jar:/Users/zengzehao/.m2/repository/io/netty/netty-resolver/4.1.63.Final/netty-resolver-4.1.63.Final.jar:/Users/zengzehao/.m2/repository/io/netty/netty-buffer/4.1.63.Final/netty-buffer-4.1.63.Final.jar:/Users/zengzehao/.m2/repository/io/netty/netty-transport/4.1.63.Final/netty-transport-4.1.63.Final.jar:/Users/zengzehao/.m2/repository/io/netty/netty-codec/4.1.63.Final/netty-codec-4.1.63.Final.jar:/Users/zengzehao/.m2/repository/io/netty/netty-transport-native-epoll/4.1.63.Final/netty-transport-native-epoll-4.1.63.Final.jar:/Users/zengzehao/.m2/repository/io/netty/netty-transport-native-unix-common/4.1.63.Final/netty-transport-native-unix-common-4.1.63.Final.jar:/Users/zengzehao/.m2/repository/org/slf4j/slf4j-api/1.7.30/slf4j-api-1.7.30.jar:/Users/zengzehao/.m2/repository/org/slf4j/slf4j-log4j12/1.7.30/slf4j-log4j12-1.7.30.jar:/Users/zengzehao/.m2/repository/org/eclipse/jetty/jetty-server/9.4.39.v20210325/jetty-server-9.4.39.v20210325.jar:/Users/zengzehao/.m2/repository/javax/servlet/javax.servlet-api/3.1.0/javax.servlet-api-3.1.0.jar:/Users/zengzehao/.m2/repository/org/eclipse/jetty/jetty-http/9.4.39.v20210325/jetty-http-9.4.39.v20210325.jar:/Users/zengzehao/.m2/repository/org/eclipse/jetty/jetty-util/9.4.39.v20210325/jetty-util-9.4.39.v20210325.jar:/Users/zengzehao/.m2/repository/org/eclipse/jetty/jetty-io/9.4.39.v20210325/jetty-io-9.4.39.v20210325.jar:/Users/zengzehao/.m2/repository/org/eclipse/jetty/jetty-servlet/9.4.39.v20210325/jetty-servlet-9.4.39.v20210325.jar:/Users/zengzehao/.m2/repository/org/eclipse/jetty/jetty-security/9.4.39.v20210325/jetty-security-9.4.39.v20210325.jar:/Users/zengzehao/.m2/repository/org/eclipse/jetty/jetty-util-ajax/9.4.39.v20210325/jetty-util-ajax-9.4.39.v20210325.jar:/Users/zengzehao/.m2/repository/io/dropwizard/metrics/metrics-core/3.1.0/metrics-core-3.1.0.jar:/Users/zengzehao/.m2/repository/log4j/log4j/1.2.17/log4j-1.2.17.jar:/Users/zengzehao/.m2/repository/org/xerial/snappy/snappy-java/1.1.7.3/snappy-java-1.1.7.3.jar:/Users/zengzehao/.m2/repository/commons-io/commons-io/2.6/commons-io-2.6.jar:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar:/Users/zengzehao/Library/Caches/IntelliJIdea2019.1/captureAgent/debugger-agent.jar
    2021-05-04 11:19:16,954 [myid:1] - INFO  [main:Environment@98] - Server environment:java.library.path=/Users/zengzehao/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
    2021-05-04 11:19:16,954 [myid:1] - INFO  [main:Environment@98] - Server environment:java.io.tmpdir=/var/folders/xt/p72g3jsd0zncc1yv8vnzs3l00000gn/T/
    2021-05-04 11:19:16,954 [myid:1] - INFO  [main:Environment@98] - Server environment:java.compiler=<NA>
    2021-05-04 11:19:16,954 [myid:1] - INFO  [main:Environment@98] - Server environment:os.name=Mac OS X
    2021-05-04 11:19:16,955 [myid:1] - INFO  [main:Environment@98] - Server environment:os.arch=x86_64
    2021-05-04 11:19:16,955 [myid:1] - INFO  [main:Environment@98] - Server environment:os.version=10.15.6
    2021-05-04 11:19:16,955 [myid:1] - INFO  [main:Environment@98] - Server environment:user.name=zengzehao
    2021-05-04 11:19:16,955 [myid:1] - INFO  [main:Environment@98] - Server environment:user.home=/Users/zengzehao
    2021-05-04 11:19:16,955 [myid:1] - INFO  [main:Environment@98] - Server environment:user.dir=/Users/zengzehao/IdeaProjects/zookeeper
    2021-05-04 11:19:16,955 [myid:1] - INFO  [main:Environment@98] - Server environment:os.memory.free=110MB
    2021-05-04 11:19:16,955 [myid:1] - INFO  [main:Environment@98] - Server environment:os.memory.max=1820MB
    2021-05-04 11:19:16,955 [myid:1] - INFO  [main:Environment@98] - Server environment:os.memory.total=123MB
    2021-05-04 11:19:16,955 [myid:1] - INFO  [main:ZooKeeperServer@138] - zookeeper.enableEagerACLCheck = false
    2021-05-04 11:19:16,955 [myid:1] - INFO  [main:ZooKeeperServer@151] - zookeeper.digest.enabled = true
    2021-05-04 11:19:16,956 [myid:1] - INFO  [main:ZooKeeperServer@155] - zookeeper.closeSessionTxn.enabled = true
    2021-05-04 11:19:16,956 [myid:1] - INFO  [main:ZooKeeperServer@1504] - zookeeper.flushDelay = 0 ms
    2021-05-04 11:19:16,956 [myid:1] - INFO  [main:ZooKeeperServer@1513] - zookeeper.maxWriteQueuePollTime = 0 ms
    2021-05-04 11:19:16,956 [myid:1] - INFO  [main:ZooKeeperServer@1522] - zookeeper.maxBatchSize=1000
    2021-05-04 11:19:16,956 [myid:1] - INFO  [main:ZooKeeperServer@265] - zookeeper.intBufferStartingSizeBytes = 1024
    2021-05-04 11:19:16,966 [myid:1] - INFO  [main:WatchManagerFactory@42] - Using org.apache.zookeeper.server.watch.WatchManager as watch manager
    2021-05-04 11:19:16,966 [myid:1] - INFO  [main:WatchManagerFactory@42] - Using org.apache.zookeeper.server.watch.WatchManager as watch manager
    2021-05-04 11:19:16,967 [myid:1] - INFO  [main:ZKDatabase@138] - zookeeper.snapshotSizeFactor = 0.33
    2021-05-04 11:19:16,967 [myid:1] - INFO  [main:ZKDatabase@158] - zookeeper.commitLogCount=500
    2021-05-04 11:19:16,985 [myid:1] - INFO  [main:QuorumPeer@2111] - Using insecure (non-TLS) quorum communication
    2021-05-04 11:19:16,985 [myid:1] - INFO  [main:QuorumPeer@2117] - Port unification disabled
    2021-05-04 11:19:16,985 [myid:1] - INFO  [main:QuorumPeer@183] - multiAddress.enabled set to false
    2021-05-04 11:19:16,985 [myid:1] - INFO  [main:QuorumPeer@208] - multiAddress.reachabilityCheckEnabled set to true
    2021-05-04 11:19:16,985 [myid:1] - INFO  [main:QuorumPeer@195] - multiAddress.reachabilityCheckTimeoutMs set to 1000
    2021-05-04 11:19:16,986 [myid:1] - INFO  [main:QuorumPeer@2572] - QuorumPeer communication is not secured! (SASL auth disabled)
    2021-05-04 11:19:16,986 [myid:1] - INFO  [main:QuorumPeer@2597] - quorum.cnxn.threads.size set to 20
    2021-05-04 11:19:16,992 [myid:1] - INFO  [main:SnapStream@61] - zookeeper.snapshot.compression.method = CHECKED
    2021-05-04 11:19:16,997 [myid:1] - INFO  [main:FileSnap@88] - Reading snapshot /tmp/zookeeper/version-2/snapshot.900000000
    2021-05-04 11:19:17,003 [myid:1] - INFO  [main:DataTree@1742] - The digest value is empty in snapshot
    2021-05-04 11:19:17,008 [myid:1] - INFO  [main:ZKDatabase@295] - Snapshot loaded in 23 ms, highest zxid is 0x900000000, digest is 1371985504
    2021-05-04 11:19:17,020 [myid:1] - INFO  [main:Server@375] - jetty-9.4.39.v20210325; built: 2021-03-25T14:42:11.471Z; git: 9fc7ca5a922f2a37b84ec9dbc26a5168cee7e667; jvm 1.8.0_221-b11
    2021-05-04 11:19:17,075 [myid:1] - INFO  [main:DefaultSessionIdManager@334] - DefaultSessionIdManager workerName=node0
    2021-05-04 11:19:17,075 [myid:1] - INFO  [main:DefaultSessionIdManager@339] - No SessionScavenger set, using defaults
    2021-05-04 11:19:17,079 [myid:1] - INFO  [main:HouseKeeper@132] - node0 Scavenging every 600000ms
    2021-05-04 11:19:17,114 [myid:1] - WARN  [main:ConstraintSecurityHandler@759] - ServletContext@o.e.j.s.ServletContextHandler@55b53d44{/,null,STARTING} has uncovered http methods for path: /*
    2021-05-04 11:19:17,134 [myid:1] - INFO  [main:ContextHandler@916] - Started o.e.j.s.ServletContextHandler@55b53d44{/,null,AVAILABLE}
    2021-05-04 11:19:17,180 [myid:1] - INFO  [main:AbstractConnector@331] - Started ServerConnector@59309333{HTTP/1.1, (http/1.1)}{0.0.0.0:9001}
    2021-05-04 11:19:17,180 [myid:1] - INFO  [main:Server@415] - Started @1179ms
    2021-05-04 11:19:17,180 [myid:1] - INFO  [main:JettyAdminServer@190] - Started AdminServer on address 0.0.0.0, port 9001 and command URL /commands
    

    如果希望是以集群的方式运行源代码,跟之前搭建集群一样,复制多份zoo.cfg文件,新建data目录和myid文件,然后用不同的启动参数指定配置文件就可以了。

    相关文章

      网友评论

          本文标题:Zookeeper学习笔记(6)—— 编译Zookeeper服务

          本文链接:https://www.haomeiwen.com/subject/fslldltx.html