What can you get from this article:

  • 3 nodes Zookeeper in pseudo cluster
  • 3 nodes Pulsar in pesudo cluster(Optional change different znode)

    Prerequisites

  • deploy enviroment

    • Mac Mini M1
    • hostname is macmini
    • JDK: 1.8.0_311
    • Deploy path: /Users/futeng/workspaces/binft/pulsar3nodes
  • pulsar and zk
    • Pulsar version : 2.6.1
    • œœZookeeper version : 3.6.1

      Deploy 3 nodes Zoopkeeper pseudo-cluster

      Preview about how to delpoy Zookeeper:
  1. Decompression Apache Zookeeper binary package.
  2. Configure _zoo.cfg _with your own custom parameters.
  3. Ship the first directory to another two nodes.
  4. Start the zkServer.sh and test the cluster.

    Configure the first ZK node

    We need change different port to allow 3 ZK in single host. The first configuration like below: ```shell cat conf/zoo.cfg |grep -v “#” | grep -E “dataDir|clientPort|admin.enableServer|admin.serverPort|server.”

dataDir=/Users/futeng/workspaces/binft/pulsar3nodes/zk1/data clientPort=12181 admin.enableServer=true admin.serverPort=15678 server.1=macmini:12888:13888 server.2=macmini:22888:23888 server.3=macmini:32888:33888

  1. <a name="dH87M"></a>
  2. #### Ship to next 2 nodes
  3. Copy to generante the next 2 nodes. The directory now looks below.
  4. ```shell
  5. .
  6. ├── zk1
  7. ├── zk2
  8. └── zk3

We change the next 2 nodes using same rule.

  1. # zk1
  2. clientPort=12181
  3. admin.serverPort=15678
  4. # zk2
  5. clientPort=22181
  6. admin.serverPort=25678
  7. # zk3
  8. clientPort=32181
  9. admin.serverPort=35678

Give each zk node myid.

  1. echo "1" > zk1/data/myid
  2. echo "2" > zk2/data/myid
  3. echo "3" > zk3/data/myid

Now we know the zookeeper hierarchy connect address is : macmini:12181,macmini:22181,macmini:32181

Check all three nodes

  1. pulsar3nodes cat zk1/conf/zoo.cfg |grep -v "#" | grep -E "dataDir|clientPort|admin.enableServer|admin.serverPort|server."
  2. dataDir=/Users/futeng/workspaces/binft/pulsar3nodes/zk1/data
  3. clientPort=12181
  4. admin.enableServer=true
  5. admin.serverPort=15678
  6. server.1=macmini:12888:13888
  7. server.2=macmini:22888:23888
  8. server.3=macmini:32888:33888
  9. pulsar3nodes cat zk2/conf/zoo.cfg |grep -v "#" | grep -E "dataDir|clientPort|admin.enableServer|admin.serverPort|server."
  10. dataDir=/Users/futeng/workspaces/binft/pulsar3nodes/zk2/data
  11. clientPort=22181
  12. admin.enableServer=true
  13. admin.serverPort=25678
  14. server.1=macmini:12888:13889
  15. server.2=macmini:22888:23889
  16. server.3=macmini:32888:33889
  17. pulsar3nodes cat zk3/conf/zoo.cfg |grep -v "#" | grep -E "dataDir|clientPort|admin.enableServer|admin.serverPort|server."
  18. dataDir=/Users/futeng/workspaces/binft/pulsar3nodes/zk3/data
  19. clientPort=32181
  20. admin.enableServer=true
  21. admin.serverPort=35678
  22. server.1=macmini:12888:13889
  23. server.2=macmini:22888:23889
  24. server.3=macmini:32888:33889

Start zk cluster and test it

Using shell script to boots faster.

  1. # start zk
  2. #!/bin/bash
  3. zk1/bin/zkServer.sh start
  4. zk2/bin/zkServer.sh start
  5. zk3/bin/zkServer.sh start
  6. zk1/bin/zkCli.sh -server macmini:12181,macmini:22181,macmini:32181
  7. # stop zk
  8. #!/bin/bash
  9. zk1/bin/zkServer.sh stop
  10. zk2/bin/zkServer.sh stop
  11. zk3/bin/zkServer.sh stop

Deploy Pulsar in pseudo mode

Quick view:

  1. Configure one pulsar node(broker and bookie).
  2. Ship to the next two nodes
  3. Initialize metadata
  4. Start all broker and bookie service.
  5. Test Pulsar using pulsar cli and pulsar-perf

Decompression Apache Pulsar binary package. Still we deploy in single host. So the first node could named like pulsar-1, ane the next two nodes will call pulsar-2 and pulsar-3 . All of them put in same directory.
We need prepare one Cluster name, and this moment I call it mini.
And for the clean of Zookeeper root path, I also choice another znode to store Pulsar metastore. More info in How to choice another znode when deploy pulsar.

Configure one pulsar node

Configure broker.confg

Tell the broker which cluster he belongs to.
Caution: Don’t changet bookkeeperMetadataServiceUri , still don’t know the reason.

  1. cat pulsar-1/conf/broker.conf \
  2. | grep -v "#" \
  3. | grep -E "zookeeperServers|configurationStoreServers|clusterName|brokerServicePort|brokerServicePortTls|webServicePort|webServicePortTls|bookkeeperMetadataServiceUri|managedLedgerDefaultEnsembleSize|managedLedgerDefaultWriteQuorum|managedLedgerDefaultAckQuorum"
  4. zookeeperServers=macmini:12181,macmini:22181,macmini:32181/pulsar-metadata-store
  5. configurationStoreServers=macmini:12181,macmini:22181,macmini:32181/pulsar-configuration-metadata-store
  6. brokerServicePort=16650
  7. brokerServicePortTls=16651
  8. webServicePort=18080
  9. webServicePortTls=18443
  10. clusterName=mini
  11. managedLedgerDefaultEnsembleSize=2
  12. managedLedgerDefaultWriteQuorum=2
  13. managedLedgerDefaultAckQuorum=2

Config bookkeeper.conf

Tell the BookKeeper(also know as bookie) which ZK he report.

  1. cat conf/bookkeeper.conf | grep -v "#" \
  2. | grep -E "bookiePort|zkServers|zkLedgersRootPath|journalDirectory|ledgerDirectories"
  3. bookiePort=13181
  4. journalDirectory=data/bookkeeper/journal
  5. ledgerDirectories=data/bookkeeper/ledgers
  6. zkLedgersRootPath=/pulsar-metadata-store/ledgers
  7. zkServers=macmini:12181,macmini:22181,macmini:32181

(optional) config log4j2

Open flush mode in log4j2.yamlfor log output, it’s optional but useful in dev enviroment.

  1. immediateFlush: true

Ship to another

Simplly copy all to the next 2 nodes.

  1. cp -r pulsar-1 pulsar-2
  2. cp -r pulsar-1 pulsar-3

Different port in borker.conf

The core setting to deploy a pesude cluster is change different port.

  1. # command to show different port
  2. $ cat conf/broker.conf \
  3. | grep -v "#" \
  4. | grep -E "brokerServicePort|brokerServicePortTls|webServicePort|webServicePortTls"
  5. # pulsar-1
  6. brokerServicePort=16650
  7. brokerServicePortTls=16651
  8. webServicePort=18080
  9. webServicePortTls=18443
  10. # pulsar-2
  11. brokerServicePort=26650
  12. brokerServicePortTls=26651
  13. webServicePort=28080
  14. webServicePortTls=28443
  15. # pular-3
  16. brokerServicePort=36650
  17. brokerServicePortTls=36651
  18. webServicePort=38080
  19. webServicePortTls=38443

Different port in bookkeeper.com

  1. # Command to show
  2. $ cat pulsar-1/conf/bookkeeper.conf | grep -v "#" \
  3. | grep -E "bookiePort|prometheusStatsHttpPort"
  4. # pulsar-1
  5. bookiePort=13181
  6. prometheusStatsHttpPort=18000
  7. # pulsar-2
  8. bookiePort=23181
  9. prometheusStatsHttpPort=28000
  10. # pulsar-3
  11. bookiePort=33181
  12. prometheusStatsHttpPort=38000

Initialize metadata

Be sure keep the consitency of metadata. We all know the TLS service is not use, but please keep it in the initialize command for good ( can not execute if not).

  1. pulsar-1/bin/pulsar initialize-cluster-metadata \
  2. --cluster mini \
  3. --zookeeper macmini:12181/pulsar-metadata-store \
  4. --configuration-store macmini:12181/pulsar-configuration-metadata-store \
  5. --web-service-url http://macmini:12181:18080 \
  6. --web-service-url-tls https://macmini:12181:18443 \
  7. --broker-service-url pulsar://macmini:12181:16650 \
  8. --broker-service-url-tls pulsar+ssl://macmini:12181:16651

You’ll know your cluster is ready by telled the init status from screen log, like Cluster metadata for 'mini' setup correctly.
You can list the zookeeper znode, and all we need is /pulsar-metadata-storefor now.

  1. [zk: localhost:2181(CONNECTED) 2] ls /
  2. [pulsar-configuration-metadata-store, pulsar-metadata-store, zookeeper]
  3. [zk: localhost:2181(CONNECTED) 3] ls /pulsar-metadata-store
  4. [bookies, ledgers, managed-ledgers, namespace, stream]

Start service

Start broker deamon

Start the broker foreground for the best practise, and it means good if you get the message like PulsarService started. Then start broker on daemon.

  1. # start service on shell command, check it first
  2. pulsar-1/bin/pulsar broker
  3. # start service on daemon
  4. pulsar-1/bin/pulsar-daemon start broker
  5. # start all
  6. $ cat broker-all-start.sh
  7. #!/bin/bash
  8. pulsar-1/bin/pulsar-daemon start broker
  9. pulsar-2/bin/pulsar-daemon start broker
  10. pulsar-3/bin/pulsar-daemon start broker
  11. # stop all
  12. cat broker-all-stop.sh
  13. #!/bin/bash
  14. pulsar-1/bin/pulsar-daemon stop broker
  15. pulsar-2/bin/pulsar-daemon stop broker
  16. pulsar-3/bin/pulsar-daemon stop broker

Start BookKeeper

Start the BookKeeper thread in foreground for test.

  1. # foreground
  2. pulsar-1/bin/pulsar bookie
  3. # background
  4. pulsar-1/bin/pulsar-daemon start bookie
  5. # start all
  6. cat bookie-all-start.sh
  7. #!/bin/bash
  8. pulsar-1/bin/pulsar-daemon start bookie
  9. pulsar-2/bin/pulsar-daemon start bookie
  10. pulsar-3/bin/pulsar-daemon start bookie
  11. # stop all
  12. $ cat bookie-all-stop.sh
  13. #!/bin/bash
  14. pulsar-1/bin/pulsar-daemon stop bookie
  15. pulsar-2/bin/pulsar-daemon stop bookie
  16. pulsar-3/bin/pulsar-daemon stop bookie

Test

Check jps

  1. pulsar3nodes jps
  2. # three zk
  3. 4530 QuorumPeerMain
  4. 2798 QuorumPeerMain
  5. 2822 QuorumPeerMain
  6. # three broker
  7. 5319 PulsarBrokerStarter
  8. 5533 PulsarBrokerStarter
  9. 5582 PulsarBrokerStarter
  10. # three bookie
  11. 5690 BookieServer
  12. 5653 BookieServer
  13. 5622 BookieServer

Check metadata from Zookeeper

Get bookie info from ZK:

  1. [zk: localhost:2181(CONNECTED) 181] ls /pulsar-metadata-store/ledgers/available
  2. [192.1.216.107:3181, readonly]

Get broker info from ZK:

  1. [zk: localhost:2181(CONNECTED) 184] ls /pulsar-metadata-store/namespace/pulsar/mini
  2. [macmini:58080]
  3. [zk: localhost:2181(CONNECTED) 186] get /pulsar-metadata-store/namespace/pulsar/mini/macmini:58080/0x00000000_0xffffffff
  4. {"nativeUrl":"pulsar://macmini:56650","nativeUrlTls":"pulsar+ssl://macmini:56651","httpUrl":"http://macmini:58080","httpUrlTls":"https://macmini:58443","disabled":false,"advertisedListeners":{}}

Test with pulsar client

Config pulsar client

  1. cat conf/client.conf | grep -v "#" \
  2. | grep -E "webServiceUrl|brokerServiceUrl"
  3. webServiceUrl=http://localhost:58080/
  4. brokerServiceUrl=pulsar://localhost:56650/

Test with pub-sub

  1. pulsar-1/bin/pulsar-client consume \
  2. persistent://public/default/test \
  3. -n 100 \
  4. -s "consumer-test" \
  5. -t "Exclusive"
  6. pulsar-1/bin/pulsar-client produce \
  7. persistent://public/default/test \
  8. -n 1 \
  9. -f /etc/hosts

Check stats-internal

  1. bin/pulsar-admin topics stats-internal \
  2. persistent://public/default/test
  3. {
  4. "entriesAddedCounter" : 3,
  5. "numberOfEntries" : 3,
  6. "totalSize" : 1392,
  7. "currentLedgerEntries" : 3,
  8. "currentLedgerSize" : 1392,
  9. "lastLedgerCreatedTimestamp" : "2022-03-17T10:16:15.201+08:00",
  10. "waitingCursorsCount" : 1,
  11. "pendingAddEntriesCount" : 0,
  12. "lastConfirmedEntry" : "0:2",
  13. "state" : "LedgerOpened",
  14. "ledgers" : [ {
  15. "ledgerId" : 0,
  16. "entries" : 0,
  17. "size" : 0,
  18. "offloaded" : false
  19. } ],
  20. "cursors" : {
  21. "consumer-test" : {
  22. "markDeletePosition" : "0:2",
  23. "readPosition" : "0:3",
  24. "waitingReadOp" : false,
  25. "pendingReadOps" : 0,
  26. "messagesConsumedCounter" : 3,
  27. "cursorLedger" : 1,
  28. "cursorLedgerLastEntry" : 3,
  29. "individuallyDeletedMessages" : "[]",
  30. "lastLedgerSwitchTimestamp" : "2022-03-17T10:16:15.266+08:00",
  31. "state" : "Open",
  32. "numberOfEntriesSinceFirstNotAckedMessage" : 1,
  33. "totalNonContiguousDeletedMessagesRange" : 0,
  34. "properties" : { }
  35. }
  36. }
  37. }

Clean

Clean all data is alwasy in danger, but also help you quick reinstall your cluster.

clean metadata in Zookeeper

  1. deleteall /counters
  2. deleteall /loadbalance
  3. deleteall /managed-ledgers
  4. deleteall /namespace
  5. deleteall /schemas
  6. deleteall /admin
  7. # may change znode
  8. deleteall /pulsar-configuration-metadata-store
  9. deleteall /pulsar-metadata-store

clean BookKeeper data

  1. mv pulsar-1/data pulsar-1/databak
  2. mv pulsar-2/data pulsar-2/databak
  3. mv pulsar-3/data pulsar-3/databak

Others

  1. first init, not admin znode created.