新聞中心
一篇學(xué)會(huì) Pulsar 部署與線上配置
作者:梁勇 2022-02-21 08:48:00
前端
云原生 Apache Pulsar越來越多的公司使用,與Apache Kafka、Apache RocketMQ并列成為消息領(lǐng)域三家馬車,有必要對(duì)其研究一番。下面以筆者曾在生產(chǎn)環(huán)境使用的配置梳理,希望對(duì)大家有所幫助!

專注于為中小企業(yè)提供成都網(wǎng)站設(shè)計(jì)、網(wǎng)站建設(shè)服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)三穗免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了數(shù)千家企業(yè)的穩(wěn)健成長(zhǎng),幫助中小企業(yè)通過網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。
一、Pulsar安裝與部署
1.下載安裝包
Pulsar安裝包包含了zookeeper、broker、bookie三個(gè)組件。
下載Pulsar二進(jìn)制包
https://pulsar.apache.org/download/
解壓壓縮包
tar -zvxf apache-pulsar-2.9.1-bin.tar.gz
2.部署zookeeper
2.1 修改zookeeper配置
創(chuàng)建目錄
mkdir -p data/zookeeper
echo 1 > data/zookeeper/myid
修改zk配置,文件位于conf/zookeeper.conf
# 數(shù)據(jù)目錄
dataDir=data/zookeeper
# 日志目錄
dataLogDir=data/zookeeper/logs
# zk集群配置,server.1~n
server.1=127.0.0.1:2888:3888
2.2 后臺(tái)啟動(dòng)zookeeper
bin/pulsar-daemon start zookeeper
doing start zookeeper ...
starting zookeeper, logging to /Users/admin/work/software_install/apache-pulsar-2.9.1/logs/pulsar-zookeeper-M-C02GL1NTQ05P.log
Note: Set immediateFlush to true in conf/log4j2.yaml will guarantee the logging event is flushing to disk immediately. The default behavior is switched off due to performance considerations.
通過pulsar-daemon管理pulsar組件
bin/pulsar-daemon help
Error: no enough arguments provided.
Usage: pulsar-daemon (start|stop|restart)
where command is one of:
broker Run a broker server
bookie Run a bookie server
zookeeper Run a zookeeper server
configuration-store Run a configuration-store server
websocket Run a websocket proxy server
functions-worker Run a functions worker server
standalone Run a standalone Pulsar service
proxy Run a Proxy Pulsar service
備注:可以通過pulsar-daemon命令對(duì)broker、bookie、zookeeper等組件啟動(dòng)、關(guān)閉或者重啟。
2.3 檢查zookeeper是否啟動(dòng)成功
zookeeper啟動(dòng)日志和查看zookeeper進(jìn)程
ps axu | grep zookeeper
3.元數(shù)據(jù)初始化
3.1 初始化命令說明
bin/pulsar initialize-cluster-metadata \
--cluster pulsar-cluster-1 \
--zookeeper 127.0.0.1:2181 \
--configuration-store 127.0.0.1:2181 \
--web-service-url http://127.0.0.1:8080 \
--web-service-url-tls https://127.0.0.1:8443 \
--broker-service-url pulsar://127.0.0.1:6650 \
--broker-service-url-tls pulsar+ssl://127.0.0.1:6651
參數(shù)說明
參數(shù)說明
|
參數(shù) |
說明 |
|
cluster |
默認(rèn)集群名稱 |
|
zookeeper |
本地集群使用的zk地址 |
|
configuration-store |
多個(gè)集群全局的zk集群地址,各個(gè)集群之間同步數(shù)據(jù),單機(jī)群地址同上面參數(shù)zookeeper即可 |
|
web-service-url |
Broker的管理流地址,例如創(chuàng)建刪除主題等 |
|
web-service-url-tls |
Broker開啟TLS,管理流則使用該地址 |
|
broker-service-url |
Broker數(shù)據(jù)流地址,發(fā)送接受消息等 |
|
broker-service-url-tls |
Broker開啟TLS,數(shù)據(jù)流則使用該地址 |
備注:生產(chǎn)環(huán)境可以使用域名。
3.2 查看初始化結(jié)果
bin/pulsar zookeeper-shell
[zk: localhost:2181(CONNECTED) 1] ls /
[admin, bookies, ledgers, pulsar, stream, zookeeper]
4.部署B(yǎng)ookKeeper集群
4.1 配置修改
bindAddress=127.0.0.1
advertisedAddress=127.0.0.1
zkServers=127.0.0.1:2181
參數(shù)說明
|
參數(shù) |
說明 |
|
bindAddress |
服務(wù)監(jiān)聽的地址,默認(rèn) 0.0.0.0 |
|
advertisedAddress |
服務(wù)向外發(fā)布的主機(jī)名或者IP,默認(rèn)為IntetAddress.getLocalHost().getHostName |
|
zkServers |
zk集群地址,可與broker共用 |
4.2 命令啟動(dòng)
bin/pulsar-daemon start bookie
doing start bookie ...
starting bookie, logging to /Users/admin/work/software_install/apache-pulsar-2.9.1/logs/pulsar-bookie-M-C02GL1NTQ05P.log
Note: Set immediateFlush to true in conf/log4j2.yaml will guarantee the logging event is flushing to disk immediately. The default behavior is switched off due to performance considerations.
4.3 測(cè)試bookie集群
bin/bookkeeper shell simpletest --ensemble 1 --writeQuorum 1 --ackQuorum 1 -- numEntries 1000
...
2022-02-19T23:43:03,391+0800 [main] INFO org.apache.bookkeeper.tools.cli.commands.client.SimpleTestCommand - 722 entries written
2022-02-19T23:43:03,983+0800 [main] INFO org.apache.bookkeeper.tools.cli.commands.client.SimpleTestCommand - 1000 entries written to ledger 0
2022-02-19T23:43:04,041+0800 [main] INFO org.apache.bookkeeper.proto.PerChannelBookieClient - Closing the per channel bookie client for 127.0.0.1:3181
...
備注:通過simpletest命令向bookie集群寫入測(cè)試數(shù)據(jù),完成測(cè)試后會(huì)自動(dòng)刪除。
5.部署B(yǎng)roker集群
5.1 修改配置
zookeeperServers=127.0.0.1:2181
configurationStoreServers=127.0.0.1:2181
bindAddress=127.0.0.1
# 默認(rèn)InetAddress.getLocalHost().getHostName()
advertisedAddress=127.0.0.1
clusterName=pulsar-cluster-1
5.2 啟動(dòng)broker
bin/pulsar-daemon start broker
doing start broker ...
starting broker, logging to /Users/admin/work/software_install/apache-pulsar-2.9.1/logs/pulsar-broker-M-C02GL1NTQ05P.log
Note: Set immediateFlush to true in conf/log4j2.yaml will guarantee the logging event is flushing to disk immediately. The default behavior is switched off due to performance considerations.
5.3 驗(yàn)證集群
查看集群節(jié)點(diǎn)
bin/pulsar-admin brokers list cluster-1
"172.17.13.184:8080"
發(fā)送測(cè)試消息
bin/pulsar-client produce persistent://public/default/test -n 1 -m "Hello Pulsar"
...
2022-02-20T13:31:18,469+0800 [main] INFO org.apache.pulsar.client.cli.PulsarClientTool - 1 messages successfully produced
...
消費(fèi)測(cè)試消息
bin/pulsar-client consume persistent://public/default/test -n 100 -s "consumer-test" -t "Exclusive"
...
----- got message -----
key:[null], properties:[], content:Hello Pulsar
...
小結(jié):至此測(cè)試集群搭建完成,下文將介紹生產(chǎn)環(huán)境配置的調(diào)整項(xiàng)。
二、生產(chǎn)環(huán)境配置
1.機(jī)器配置
下面為生產(chǎn)環(huán)境搭建Pulsar集群,由3個(gè)zookeeper節(jié)點(diǎn)、3個(gè)broker節(jié)點(diǎn)和5個(gè)bookie節(jié)點(diǎn)構(gòu)成。
組件配置
組件 配置
zookeeper 4C8G100G * 3
broker 16C64G500G * 3
bookie 16C64G500G * 5
備注:每個(gè)組件集群部署時(shí)可以同城跨可用區(qū)部署,提高高可用。broker不存儲(chǔ)消息100G即可,bookie存儲(chǔ)消息通常需要較大磁盤,比如3T,具體根據(jù)消息量計(jì)算。
2.內(nèi)存優(yōu)化
|
配置項(xiàng) |
內(nèi)存大小或者比例,總大小 |
|
系統(tǒng)OS緩存 |
1~2G |
|
Jvm內(nèi)存和堆外內(nèi)存 |
1/2(除去系統(tǒng)緩存后剩余緩存的一半),其中Jvm heap占1/3,堆外內(nèi)存Direct Memory占2/3 |
|
PageCache內(nèi)存大小 |
1/2(除去系統(tǒng)緩存后剩余緩存的一半) |
2.1 broker內(nèi)存調(diào)整
以內(nèi)存64G大小,在文件conf/pulsar_env.sh修改如下內(nèi)容:
PULSAR_MEM=${PULSAR_MEM:-"-Xms10g -Xmx10g -XX:MaxDirectMemorySize=20g"}
2.2 bookie內(nèi)存調(diào)整
以內(nèi)存64G大小,在文件conf/bkenv.sh修改如下內(nèi)容:
BOOKIE_MEM=${BOOKIE_MEM:-${PULSAR_MEM:-"-Xms10g -Xmx10g -XX:MaxDirectMemorySize=20g"}}
3.Broker調(diào)整項(xiàng)
|
配置項(xiàng) |
說明 |
|
zookeeperServers=x.x.x.x:2181,x.x.x.x:2181,x.x.x.x:2181 |
本地zookeeper集群地址 |
|
configurationStoreServers=x.x.x.x:2181,x.x.x.x:2181,x.x.x.x:2181 |
配置存儲(chǔ)Zookeeper集群地址 |
|
bindAddress=x.x.x.x |
服務(wù)監(jiān)聽的地址,可以為本機(jī)IP,默認(rèn)為0.0.0.0 |
|
advertisedAddress=x.x.x.x |
服務(wù)向外發(fā)布的主機(jī)名或者IP,默認(rèn)為IntetAddress.getLocalHost().getHostName |
|
clusterName=cluster-xxx |
集群名稱 |
|
brokerDeleteInactiveTopicsEnabled=false |
關(guān)閉自動(dòng)刪除不活動(dòng)的主題 |
|
defaultNumberOfNamespaceBundles=12 |
Bundle的數(shù)量應(yīng)為broker數(shù)量的整數(shù)倍,默認(rèn)為4 |
|
defaultRetentionSizeInMB=1T |
消費(fèi)確認(rèn)過的消息超過該??后會(huì)觸發(fā)刪除策略 |
|
defaultRetentionTimeInMinutes=1w |
消費(fèi)確認(rèn)過的消息超過指定時(shí)間后觸發(fā)刪除策略 |
|
backlogQuotaDefaultLimitGB=-1 |
保持默認(rèn),未被消費(fèi)確認(rèn)的消息?存儲(chǔ)?? 默認(rèn)為-1表示沒有限制,可以通過set-message-ttl設(shè)置過期時(shí)間,防?磁盤爆滿 |
|
backlogQuotaDefaultRetentionPolicy=producer_request_hold |
保持默認(rèn),未被消費(fèi)確認(rèn)的消息超過存儲(chǔ)??的策略 |
|
managedLedgerDefaultEnsembleSize=3 |
創(chuàng)建Ledger時(shí)指定Ensemble的?? |
|
managedLedgerDefaultWriteQuorum=3 |
創(chuàng)建Ledger時(shí)指定Quorum的?? |
|
managedLedgerDefaultAckQuorum=2 |
創(chuàng)建Ledger時(shí)指定ack Quorum的?? |
|
dispatcherMaxReadBatchSize=500 |
?次從bookkeeper讀取的數(shù)量,默認(rèn)為100條 |
|
loadBalancerAutoBundleSplitEnabled=false |
關(guān)閉auto bundle split功能,提?客戶端穩(wěn)定性 |
|
loadBalancerAutoUnloadSplitBundlesEnabled=false |
關(guān)閉auto bundle split功能,提?客戶端穩(wěn)定性 |
|
loadBalancerSheddingEnabled=false |
禁?Pulsar?動(dòng)均衡 |
|
loadBalancerEnabled=false |
禁?Pulsar?動(dòng)均衡 |
備注:參數(shù)根據(jù)實(shí)際情況調(diào)整,在線上開啟負(fù)載均衡時(shí),發(fā)現(xiàn)有重復(fù)消息,此處先將其關(guān)閉。
4.Bookie調(diào)整項(xiàng)
配置項(xiàng)說明
|
配置項(xiàng) |
說明 |
|
zkServers=x.x.x.x:2181,x.x.x.x:2181,x.x.x.x:2181 |
本地zookeeper集群地址 |
|
journalDirectory=/data/bookkeeper/journal01,/data/bookkeeper/journal02 |
BookKeeper存儲(chǔ)其預(yù)寫?志的?錄,多個(gè)?錄逗號(hào)進(jìn)?分割,防?線程阻塞 |
|
ledgerDirectories=/data/bookkeeper/ledgers01,/data/bookkeeper/ledgers02 |
指定存儲(chǔ)BookKeeper輸出ledger的?錄。多個(gè)ledger?錄,需要使?逗號(hào)分割 |
備注:journalDirectory和ledgerDirectories在條件允許的情況可以配置到不同的磁盤。
本文轉(zhuǎn)載自微信公眾號(hào)「瓜農(nóng)老梁」,可以通過以下二維碼關(guān)注。轉(zhuǎn)載本文請(qǐng)聯(lián)系瓜農(nóng)老梁公眾號(hào)。
當(dāng)前題目:一篇學(xué)會(huì)Pulsar部署與線上配置
鏈接URL:http://www.dlmjj.cn/article/djihhoh.html


咨詢
建站咨詢
