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
- Decompression Apache Zookeeper binary package.
- Configure _zoo.cfg _with your own custom parameters.
- Ship the first directory to another two nodes.
- 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
<a name="dH87M"></a>#### Ship to next 2 nodesCopy to generante the next 2 nodes. The directory now looks below.```shell.├── zk1├── zk2└── zk3
We change the next 2 nodes using same rule.
# zk1clientPort=12181admin.serverPort=15678# zk2clientPort=22181admin.serverPort=25678# zk3clientPort=32181admin.serverPort=35678
Give each zk node myid.
echo "1" > zk1/data/myidecho "2" > zk2/data/myidecho "3" > zk3/data/myid
Now we know the zookeeper hierarchy connect address is : macmini:12181,macmini:22181,macmini:32181
Check all three nodes
➜ pulsar3nodes cat zk1/conf/zoo.cfg |grep -v "#" | grep -E "dataDir|clientPort|admin.enableServer|admin.serverPort|server."dataDir=/Users/futeng/workspaces/binft/pulsar3nodes/zk1/dataclientPort=12181admin.enableServer=trueadmin.serverPort=15678server.1=macmini:12888:13888server.2=macmini:22888:23888server.3=macmini:32888:33888➜ pulsar3nodes cat zk2/conf/zoo.cfg |grep -v "#" | grep -E "dataDir|clientPort|admin.enableServer|admin.serverPort|server."dataDir=/Users/futeng/workspaces/binft/pulsar3nodes/zk2/dataclientPort=22181admin.enableServer=trueadmin.serverPort=25678server.1=macmini:12888:13889server.2=macmini:22888:23889server.3=macmini:32888:33889➜ pulsar3nodes cat zk3/conf/zoo.cfg |grep -v "#" | grep -E "dataDir|clientPort|admin.enableServer|admin.serverPort|server."dataDir=/Users/futeng/workspaces/binft/pulsar3nodes/zk3/dataclientPort=32181admin.enableServer=trueadmin.serverPort=35678server.1=macmini:12888:13889server.2=macmini:22888:23889server.3=macmini:32888:33889
Start zk cluster and test it
Using shell script to boots faster.
# start zk#!/bin/bashzk1/bin/zkServer.sh startzk2/bin/zkServer.sh startzk3/bin/zkServer.sh startzk1/bin/zkCli.sh -server macmini:12181,macmini:22181,macmini:32181# stop zk#!/bin/bashzk1/bin/zkServer.sh stopzk2/bin/zkServer.sh stopzk3/bin/zkServer.sh stop
Deploy Pulsar in pseudo mode
Quick view:
- Configure one pulsar node(broker and bookie).
- Ship to the next two nodes
- Initialize metadata
- Start all broker and bookie service.
- 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.
cat pulsar-1/conf/broker.conf \| grep -v "#" \| grep -E "zookeeperServers|configurationStoreServers|clusterName|brokerServicePort|brokerServicePortTls|webServicePort|webServicePortTls|bookkeeperMetadataServiceUri|managedLedgerDefaultEnsembleSize|managedLedgerDefaultWriteQuorum|managedLedgerDefaultAckQuorum"zookeeperServers=macmini:12181,macmini:22181,macmini:32181/pulsar-metadata-storeconfigurationStoreServers=macmini:12181,macmini:22181,macmini:32181/pulsar-configuration-metadata-storebrokerServicePort=16650brokerServicePortTls=16651webServicePort=18080webServicePortTls=18443clusterName=minimanagedLedgerDefaultEnsembleSize=2managedLedgerDefaultWriteQuorum=2managedLedgerDefaultAckQuorum=2
Config bookkeeper.conf
Tell the BookKeeper(also know as bookie) which ZK he report.
cat conf/bookkeeper.conf | grep -v "#" \| grep -E "bookiePort|zkServers|zkLedgersRootPath|journalDirectory|ledgerDirectories"bookiePort=13181journalDirectory=data/bookkeeper/journalledgerDirectories=data/bookkeeper/ledgerszkLedgersRootPath=/pulsar-metadata-store/ledgerszkServers=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.
immediateFlush: true
Ship to another
Simplly copy all to the next 2 nodes.
cp -r pulsar-1 pulsar-2cp -r pulsar-1 pulsar-3
Different port in borker.conf
The core setting to deploy a pesude cluster is change different port.
# command to show different port$ cat conf/broker.conf \| grep -v "#" \| grep -E "brokerServicePort|brokerServicePortTls|webServicePort|webServicePortTls"# pulsar-1brokerServicePort=16650brokerServicePortTls=16651webServicePort=18080webServicePortTls=18443# pulsar-2brokerServicePort=26650brokerServicePortTls=26651webServicePort=28080webServicePortTls=28443# pular-3brokerServicePort=36650brokerServicePortTls=36651webServicePort=38080webServicePortTls=38443
Different port in bookkeeper.com
# Command to show$ cat pulsar-1/conf/bookkeeper.conf | grep -v "#" \| grep -E "bookiePort|prometheusStatsHttpPort"# pulsar-1bookiePort=13181prometheusStatsHttpPort=18000# pulsar-2bookiePort=23181prometheusStatsHttpPort=28000# pulsar-3bookiePort=33181prometheusStatsHttpPort=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).
pulsar-1/bin/pulsar initialize-cluster-metadata \--cluster mini \--zookeeper macmini:12181/pulsar-metadata-store \--configuration-store macmini:12181/pulsar-configuration-metadata-store \--web-service-url http://macmini:12181:18080 \--web-service-url-tls https://macmini:12181:18443 \--broker-service-url pulsar://macmini:12181:16650 \--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.
[zk: localhost:2181(CONNECTED) 2] ls /[pulsar-configuration-metadata-store, pulsar-metadata-store, zookeeper][zk: localhost:2181(CONNECTED) 3] ls /pulsar-metadata-store[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.
# start service on shell command, check it firstpulsar-1/bin/pulsar broker# start service on daemonpulsar-1/bin/pulsar-daemon start broker# start all$ cat broker-all-start.sh#!/bin/bashpulsar-1/bin/pulsar-daemon start brokerpulsar-2/bin/pulsar-daemon start brokerpulsar-3/bin/pulsar-daemon start broker# stop allcat broker-all-stop.sh#!/bin/bashpulsar-1/bin/pulsar-daemon stop brokerpulsar-2/bin/pulsar-daemon stop brokerpulsar-3/bin/pulsar-daemon stop broker
Start BookKeeper
Start the BookKeeper thread in foreground for test.
# foregroundpulsar-1/bin/pulsar bookie# backgroundpulsar-1/bin/pulsar-daemon start bookie# start allcat bookie-all-start.sh#!/bin/bashpulsar-1/bin/pulsar-daemon start bookiepulsar-2/bin/pulsar-daemon start bookiepulsar-3/bin/pulsar-daemon start bookie# stop all$ cat bookie-all-stop.sh#!/bin/bashpulsar-1/bin/pulsar-daemon stop bookiepulsar-2/bin/pulsar-daemon stop bookiepulsar-3/bin/pulsar-daemon stop bookie
Test
Check jps
➜ pulsar3nodes jps# three zk4530 QuorumPeerMain2798 QuorumPeerMain2822 QuorumPeerMain# three broker5319 PulsarBrokerStarter5533 PulsarBrokerStarter5582 PulsarBrokerStarter# three bookie5690 BookieServer5653 BookieServer5622 BookieServer
Check metadata from Zookeeper
Get bookie info from ZK:
[zk: localhost:2181(CONNECTED) 181] ls /pulsar-metadata-store/ledgers/available[192.1.216.107:3181, readonly]
Get broker info from ZK:
[zk: localhost:2181(CONNECTED) 184] ls /pulsar-metadata-store/namespace/pulsar/mini[macmini:58080][zk: localhost:2181(CONNECTED) 186] get /pulsar-metadata-store/namespace/pulsar/mini/macmini:58080/0x00000000_0xffffffff{"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
cat conf/client.conf | grep -v "#" \| grep -E "webServiceUrl|brokerServiceUrl"webServiceUrl=http://localhost:58080/brokerServiceUrl=pulsar://localhost:56650/
Test with pub-sub
pulsar-1/bin/pulsar-client consume \persistent://public/default/test \-n 100 \-s "consumer-test" \-t "Exclusive"pulsar-1/bin/pulsar-client produce \persistent://public/default/test \-n 1 \-f /etc/hosts
Check stats-internal
bin/pulsar-admin topics stats-internal \persistent://public/default/test{"entriesAddedCounter" : 3,"numberOfEntries" : 3,"totalSize" : 1392,"currentLedgerEntries" : 3,"currentLedgerSize" : 1392,"lastLedgerCreatedTimestamp" : "2022-03-17T10:16:15.201+08:00","waitingCursorsCount" : 1,"pendingAddEntriesCount" : 0,"lastConfirmedEntry" : "0:2","state" : "LedgerOpened","ledgers" : [ {"ledgerId" : 0,"entries" : 0,"size" : 0,"offloaded" : false} ],"cursors" : {"consumer-test" : {"markDeletePosition" : "0:2","readPosition" : "0:3","waitingReadOp" : false,"pendingReadOps" : 0,"messagesConsumedCounter" : 3,"cursorLedger" : 1,"cursorLedgerLastEntry" : 3,"individuallyDeletedMessages" : "[]","lastLedgerSwitchTimestamp" : "2022-03-17T10:16:15.266+08:00","state" : "Open","numberOfEntriesSinceFirstNotAckedMessage" : 1,"totalNonContiguousDeletedMessagesRange" : 0,"properties" : { }}}}
Clean
Clean all data is alwasy in danger, but also help you quick reinstall your cluster.
clean metadata in Zookeeper
deleteall /countersdeleteall /loadbalancedeleteall /managed-ledgersdeleteall /namespacedeleteall /schemasdeleteall /admin# may change znodedeleteall /pulsar-configuration-metadata-storedeleteall /pulsar-metadata-store
clean BookKeeper data
mv pulsar-1/data pulsar-1/databakmv pulsar-2/data pulsar-2/databakmv pulsar-3/data pulsar-3/databak
Others
- first init, not admin znode created.
- published in mudium: https://medium.com/@ifuteng/pulsar-pseudo-cluster-deployment-fcb8214360ea
