导语
Apache 依赖于 Zookeeper 作为元数据存储,使用 BookKeeper 作为流存储,本文介绍如何在 Bare Metal 模式部署 Pulsar 集群。
Pulsar 集群部署步骤
Pulsar 集群搭建需要首先完成 Zookeeper 和 BookKeeper 的部署。
Zookeeper 部署
- 修改 conf/zookeeper.conf, 跟zk配置类似,设置dataDir, server,myid等
以zookeeper 3.5.7为例,修改以下配置:
dataDir=/data11/
zookeeperdataLogDir=/data11/zookeeper/zklog
admin.serverPort=8888
zookeeper目录
mkdir -p /data11/zookeeper
echo 1 > /data11/zookeeper/myid
注意: 如果是多个zk节点,myid不能重复,并且需要配置server列表
server.1=xxxx:2888:3888
server.2=xxxx:2888:3888
server.3=xxxx:2888:3888
启动zookeeper
zkServer.sh start
BookKeeper 部署 (100.115.158.201,100.115.158.202)
修改conf/bk_server.conf
# 修改metadataServiceUri字段(zk集群地址 ),ledgers上一级路径需要存在
metadataServiceUri=zk+hierarchical://x.x.x.x:2181/bktest/ledgers
# 修改advertisedAddress为本机地址(x.x.x.x形式)
advertiseAddress=x.x.x.x
# 设置journalDirectories(journal日志目录,量小,读写频繁,ts50设置3个盘)
journalDirectories=
# 设置ledgerDirectories参数(ledger目录,量大,flush data,ts50设置8个盘)
ledgerDirectories=
# 设置index存储类型
ledgerStorageClass=org.apache.bookkeeper.bookie.storage.ldb.DbLedgerStorage
# 设置autorecovery 并发度
rereplicationEntryBatchSize=1
# 设置autorecovery delay时间
lostBookieRecoveryDelay=3600
设置内存
1/2 filesystem, 1/6 bookie heap, 1/3 bookie direct memory
假设机器内存为64GB,则可以按照以下配置来分配内存
10g(heap)+20g(directMemory)
在conf/bkenv.sh里面
BOOKIE_MAX_HEAP_MEMORY=10g
BOOKIE_MIN_HEAP_MEMORY=10g
BOOKIE_MAX_DIRECT_MEMORY=20g
初始化Bookkeeper
bookkeeper-server/bin/bookkeeper shell initnewcluster
启动bookkeeper
bin/bookkeeper-daemon.sh start bookie
Pulsar brokers 部署
修改conf/broker.conf
主要有如下几个字段,kop 有一些特殊配置需要注意
#设置zookeeperServers (zk集群地址)
zookeeperServers=x.x.x.x:2181,x.x.x.x:2181,x.x.x.x:2181/ss_share_pulsar
#设置configurationStoreServers (zk集群地址)
configurationStoreServers=x.x.x.x:2181,x.x.x.x:2181,x.x.x.x:2181/ss_share_pulsar
# 设置bookie metadata server地址(和bookkeeper的配置保持一致)
bookkeeperMetadataServiceUri=zk+hierarchical://x.x.x.x:2181/bktest/ledgers,zk+hierarchical://x.x.x.x:2181/bktest/ledgers,zk+hierarchical://x.x.x.x:2181/bktest/ledgers
#设置advertisedAddress (本机ip)
advertisedAddress=
#设置clusterName (集群)
clusterName=testPulsarEnv (bin/pulsar-admin clusters list, print出来的cluster名字,写到该处)
#设置副本数:
# Number of bookies to use when creating a ledger
managedLedgerDefaultEnsembleSize=1
# Number of copies to store for each message
managedLedgerDefaultWriteQuorum=1
# Number of guaranteed copies (acks to wait before write is complete)
managedLedgerDefaultAckQuorum=1
# 设置是否允许自动创建Topic
allowAutoTopicCreation=false
# 设置生产缓冲区最大DirectMemory大小(大概为DirectMemory的1/5 – 1/4)
maxMessagePublishBufferSizeInMB=3172
# 设置是否自动删除不活跃的topic
brokerDeleteInactiveTopicsEnabled=false
# 设置默认数据保存周期
ttlDurationDefaultInSeconds=259200
# 设置默认bundle数量(一般为broker数的3-4倍)
defaultNumberOfNamespaceBundles=12
# 设置是否打开bundle auto split
loadBalancerAutoBundleSplitEnabled=false
# 设置是否打开自动unload split的bundle
loadBalancerAutoUnloadSplitBundlesEnabled=false
# 设置是否自动创建消费组
allowAutoSubscriptionCreation=false
# 设置默认数据过期时间
defaultRetentionTimeInMinutes=4320
# 设置默认数据过期大小(-1表示不限制大小)
defaultRetentionSizeInMB= -1
# **注意** 如果是KOP环境,需要配置一下参数
# 开启 连续offset 特性
brokerEntryMetadataInterceptors=org.apache.pulsar.common.intercept.AppendIndexMetadataInterceptor
# 设置支持自动创建消费组
allowAutoSubscriptionCreation=true
# 使用 kafka format
entryFormat=kafka
设置内存
按照实际内存配置,下面是一个示例,在conf/pulsar_env.sh里面
PULSAR_MEM=${PULSAR_MEM:-“-Xms8g -Xmx8g -XX:MaxDirectMemorySize=16g”}
/pulsar initialize-cluster-metadata \
--cluster testPulsarEnv \
--zookeeper 127.0.0.1:2181,127.0.0.2:2181,127.0.0.3:2181/local \
--configuration-store 127.0.0.1:2181,127.0.0.2:2181,127.0.0.3:2181/local/global \
--web-service-url http://192.168.0.1:8080 \
--web-service-url-tls https://192.168.0.1:8443 \
--broker-service-url pulsar://192.168.0.1:6650 \
--broker-service-url-tls pulsar+ssl://192.168.0.1:6651
启动broker
bin/pulsar-daemon start broker
Pulsar DiscoveryService 部署
修改conf/discovery.conf
zookeeperServers
configurationStoreServers
servicePort
servicePortTls
webServicePort
webServicePortTls
启动DiscoveryService
bin/pulsar-daemon start discovery
使用自带的pulsar-client生产消费
首先修改conf/client.conf
生产
bin/pulsar-client produce persistent://100.115.158.201:6650/tenantTest/namespaceTest/test -m “hello-pulsar-test-201801151605”
消费
bin/pulsar-client consume persistent://100.115.158.201:6650/tenantTest/namespaceTest/test -s consumer1
多pulsar集群共用bookie配置
##pulsar zk配置信息每个集群需要不一样
zookeeperServers=ip1:2181,ip2:2181,ip3:2181/new_pulsar_local
##global zk配置信息每个集群需要不一样
configurationStoreServers=ip1:2181,ip2:2181,ip3:2181/new_pulsar_global
##bookie服务发现地址指向同一个
bookkeeperMetadataServiceUri=zk+hierarchical://ip3:2181/tdbank_bookie/ledgers