pulsar集群搭建_亲测成功
单机运行请看:
Linux MacBook单机部署Pulsar并开启认证功能
集群组成
- 搭建 Pulsar 集群至少需要 3 个组件:ZooKeeper 集群、BookKeeper 集群和 broker 集群(Broker 是 Pulsar 的自身实例)。这三个集群组件如下:
-
ZooKeeper 集群(3(或多) 个 ZooKeeper 节点组成) -
bookie 集群(也称为 BookKeeper 集群,3(或多) 个 BookKeeper 节点组成) -
broker 集群(3(或多) 个 Pulsar 节点组成)
- Pulsar 的安装包已包含了搭建集群所需的各个组件库。无需单独下载 ZooKeeper 安装包和 BookKeeper 安装包。
环境准备
安装JDK
在所需服务器上安装 JDK(要求版本不低于 JDK 8)安装请看:
Linux卸载openjdk并安装Oracle jdk
MacBook安装jdk8
下载最新版本pulsar 官方下载地址:https://pulsar.apache.org/download/ 上传至服务器
解压安装包到指定目录
tar -zxvf apache-pulsar-2.8.0-bin.tar.gz -C /home/software
安装建议
官方建议需要6台机器:
-
3台用于运行Zookeeper集群, 建议使用性能较弱的机器, Pulsar仅将Zookeeper用于与协调有关的定期任务和与配置有关的任务,而不用于基本操作. -
3台用于运行bookie集群和broker集群,建议使用性能强劲的机器.
但是也可以在一台机器上同时部署Zookeeper,bookie,broker,也就是最少需要三台机器就可以部署一个Pulsar集群.
其实也还可以在3台机器上部署Zookeeper集群,另外3台机器部署bookie集群,在另外3台机器部署broker集群,也就是一共需要消耗9台机器.
总结: 部署一个Pulsar集群(包含一个Zookeeper集群(3个Zookeeper节点组成), 一个bookie集群(也称为Bookeeper集群,3个Bookeeper节点组成), 一个broker集群(3个Pulsar节点组成)), 最少需要3台机器, 官方建议6台机器, 最多需要9台机器.
3台机器集群为例
192.168.1.17
192.168.1.18
192.168.1.19
先搭建zookeeper的集群
mkdir -pv /home/software/zookeeper/logs
echo 1 > /home/software/zookeeper/myid
echo 2 > /home/software/zookeeper/myid
echo 3 > /home/software/zookeeper/myid
vim /home/software/apache-pulsar-2.8.0/conf/zookeeper.conf
dataDir=/home/software/zookeeper
dataLogDir=/home/software/zookeeper/logs
clientPort=12181
server.1=192.168.1.17:12888:13888
server.2=192.168.1.18:12888:13888
server.3=192.168.1.19:12888:13888
bin/pulsar-daemon start zookeeper
bin/pulsar-daemon stop zookeeper
ps aux|grep pulsar
netstat -tpnl |grep 12181
netstat -tpnl |grep 2181
最后验证 ZooKeeper 节点是否启动成功
bin/pulsar zookeeper-shell
bin/pulsar zookeeper-shell -server 192.168.1.17:12181
bin/pulsar zookeeper-shell -server 192.168.1.18:12181
bin/pulsar zookeeper-shell -server 192.168.1.19:12181
ls /
[zookeeper]
初始化集群元数据
netstat -tpnl |grep 8080
netstat -tpnl |grep 8443
netstat -tpnl |grep 6650
netstat -tpnl |grep 6651
bin/pulsar initialize-cluster-metadata \
--cluster pulsar-cluster-iot \
--zookeeper 192.168.1.18:12181 \
--configuration-store 192.168.1.18:12181 \
--web-service-url http://192.168.1.17:18080,192.168.1.18:1808,192.168.1.19:1808 \
--web-service-url-tls https://192.168.1.17:8443,192.168.1.18:8443,192.168.1.19:8443 \
--broker-service-url pulsar://192.168.1.17:6650,192.168.1.18:6650,192.168.1.19:6650 \
--broker-service-url-tls pulsar+ssl://192.168.1.17:6651,192.168.1.18:6651,192.168.1.19:6651
bin/pulsar initialize-cluster-metadata \
--cluster pulsar-cluster-iot \
--zookeeper 192.168.1.18:12181 \
--configuration-store 192.168.1.18:12181 \
--web-service-url http://192.168.1.18:18080 \
--web-service-url-tls https://192.168.1.18:8443 \
--broker-service-url pulsar://192.168.1.18:6650 \
--broker-service-url-tls pulsar+ssl://192.168.1.18:6651
bin/pulsar zookeeper-shell -server 192.168.1.17:12181
ls /
[admin, bookies, ledgers, managed-ledgers, namespace, pulsar, stream, zookeeper]
重新初始化或删除数据时
建议: 先停掉zookeeper, 然后直接删除三台zookeeper数据目录,然后在重新启动
重新初始化,删除zookeeper里的数据, 除了这个zookeeper不删除
这样删除启动bookie 报错,把zookeeper集群停了,删除目录数据
delete /bookies
delete /counters
报错:
Node not empty: /counters
deleteall /counters
配置部署 BookKeeper 集群
mkdir -pv /home/software/bookkeeper/tmp/journal
mkdir -pv /home/software/bookkeeper/tmp/ledger
vim bookkeeper.conf
advertisedAddress=192.168.1.17
journalDirectory=/home/software/bookkeeper/tmp/journal
ledgerDirectories=/home/software/bookkeeper/tmp/ledger
zkServers=192.168.1.17:12181,192.168.1.18:12181,192.168.1.19:12181
netstat -tpnl |grep 8000
prometheusStatsHttpPort=8100
bin/bookkeeper shell metaformat
vim bookkeeper.conf
prometheusStatsHttpPort=8100
bin/pulsar-daemon stop bookie
bin/pulsar-daemon start bookie
vim logs/pulsar-bookie-rabbitmq1.log
Caused by: java.io.IOException: Failed to bind to /0.0.0.0:8000
Caused by: java.net.BindException: 地址已在使用
bin/bookkeeper shell bookiesanity
Bookie sanity test succeeded
部署配置 Broker 集群
vim conf/broker.conf
clusterName=pulsar-cluster-iot
configurationStoreServers=192.168.1.17:12181,192.168.1.18:12181,192.168.1.19:12181
advertisedAddress=192.168.1.17
webServicePort=18080
bin/pulsar-daemon start broker
bin/pulsar-daemon stop broker
bin/pulsar-admin brokers list pulsar-cluster-iot
HTTP 404 Not Found
vim conf/client.conf
修改为18080端口
webServiceUrl=http://localhost:18080/
bin/pulsar-admin brokers list pulsar-cluster-iot
bin/pulsar-admin brokers list pulsar-cluster
bin/pulsar-admin --admin-url http://192.168.1.17:18080 brokers list pulsar-cluster-iot
"192.168.1.17:18080"
"192.168.1.18:18080"
"192.168.1.19:18080"
netstat -tpnl |grep 8080
netstat -tpnl |grep 18080
Caused by: java.io.IOException: Failed to bind to /0.0.0.0:8080
Caused by: java.net.BindException: 地址已在使用
测试
bin/pulsar-client consume \
persistent://public/default/test \
-n 100 \
-s "consumer-test" \
-t "Exclusive"
bin/pulsar-client produce \
persistent://public/default/test \
-n 1 \
-m "Hello Pulsar"
----- 收到消息 -----
Hello Pulsar
参考链接: https://www.jianshu.com/p/715ead13ecce https://blog.51cto.com/u_536410/2408686 https://blog.csdn.net/daydreameri/article/details/105031977 https://www.jianshu.com/p/dd328bdd2a32
|