下载apache-pulsar-2.7.0-bin.tar
用到的默认端口号
zookeeper 2181
zookeeper-admin 9990
bookie 3181
broker 6650
brokerWebServer 8080
bookeeper-prometheus 9000
准备三台服务器
这里用的是centos 7
192.168.33.3
192.168.33.4
192.168.33.5
关闭防火墙
#查看防火墙状态
firewall-cmd —state
#关闭防火墙
systemctl stop firewalld.service
执行开机禁用防火墙自启命令
systemctl disable firewalld.service
上传apache-pulsar-2.7.0-bin.tar 到服务器 /home下
查看安装目录
解压后的目录,解压后的路径 /home/pulsar
.
├── LICENSE
├── NOTICE
├── README
├── bin 执行文件
├── bookkeeper
├── function-localrunner
├── proto
│ ├── MLDataFormatspb2.py
│ └── _init.py
├── pulsar【2】
├── pulsar-admin【3】
├── pulsar-admin-common.sh
├── pulsar-client【4】
├── pulsar-daemon
├── pulsar-managed-ledger-admin
└── pulsar-perf
├── conf 【5】
├── data bookkeeper的数据文件存放目录
├── examples 【6】
├── instances
├── lib
├── licenses
└── logs
【2】pulsar
启动命令,用来启动zookeeper,broker 等,设置一些环境变量
【3】pulsar-admin
pulsar暴露的restful接口,可以查看一些pulsar的信息(pulsarctl似乎操作起来顺手些)
【4】pulsar-client
用来模拟生产者和消费者
【6】examples
pulsar-function 的一些测试案例
【5】conf
配置文件。解压后的没有这么多,这里是运行过之后的
.
├── bkenv.sh
├── bookkeeper.conf【10】
├── broker.conf【9】
├── client.conf
├── discovery.conf
├── filesystem_offload_core_site.xml
├── functions-logging
│ ├── console_logging_config.ini
│ └── logging_config.ini
├── functions_worker.yml 【11】
├── global_zookeeper.conf
├── log4j2-scripts
│ └── filter.js
├── log4j2.yaml
├── presto
│ ├── catalog
│ │ └── pulsar.properties
│ ├── config.properties
│ ├── jvm.config
│ └── log.properties
├── proxy.conf
├── pulsar_env.sh
├── pulsar_tools_env.sh
├── schema_example.conf
├── standalone.conf
├── websocket.conf
└── zookeeper.conf 【7】
修改配置文件
用的都是基本配置,先跑起来。。。 这里把默认的默认的8080端口都改掉了,避免一些不必要的问题
【7】zookeeper 配置文件,按照自己的需求修改就好了
dataDir=/home/pulsar/data/zookeeper/data # 这个目录下建立myid
server.1=192.168.33.3:2888:2889 #zk 集群的信息
server.2=192.168.33.4:2888:2889
server.3=192.168.33.5:2888:2889
【9】bookkeeper.conf
advertisedAddress=192.168.33.3 # 本机地址
httpServerPort=8082
prometheusStatsHttpPort=8083
zkServers=192.168.33.3:2181,192.168.33.4:2181,192.168.33.5:2181 #一式三份
# functionsWorkerEnabled=true # pulsar func。可选,选了之后就需要配置【11】
【10】broker.conf
zookeeperServers=192.168.33.3:2181,192.168.33.4:2181,192.168.33.5:2181 #一式三份
configurationStoreServers=192.168.33.3:2181,192.168.33.4:2181,192.168.33.5:2181 #一式三份
advertisedAddress=192.168.33.3 #本机地址
clusterName=pulsar-cluster
webServicePort=8081
可以先本地修改配置之后上传到服务器上
# 覆盖上传
rz -y
启动
### 启动 zookeeper
mkdir -p /home/pulsar/data/zookeeper/data
echo 1 > myid # 每台服务的不一样
bin/pulsar-daemon start zookeeper
# 在一台服务器上初始化原数据(先跑起来,文档上说是一次性的?等遇到问题再仔细看)
# 这里有个问题 应该写zk集群的地址的吧?
bin/pulsar initialize-cluster-metadata \
--cluster pulsar-cluster \
--zookeeper 192.168.33.3:2181 \
--configuration-store 192.168.33.3:2181 \
--web-service-url http://192.168.33.3:8081,192.168.33.4:8081,192.168.33.5:8081 \
--broker-service-url pulsar://192.168.33.3:6650,192.168.33.4:6650,192.168.33.5:6650
#org.apache.pulsar.PulsarClusterMetadataSetup - Setting up cluster
### 启动 bookie
bin/bookkeeper shell metaformat # 在一台服务器执行即可
#文档没说这个命令具体是干啥的,得看代码才知道吧
# BookKeeper metadata driver manager initialized
# 看日志是去zk里面读取数据了
bin/pulsar-daemon start bookie
### 启动 broker
bin/pulsar-daemon start broker
###每次执行start 命令之后可以回头检查下log
less /home/pulsar/logs/pulsar-zookeeper-localhost.localdomain.out # 查看zk是否启动成功
和broker一起运行pulsar func
### 初始化func 需要的集群、ns
# 创建pulsar-function集群
bin/pulsar-admin --admin-url http://localhost:8081/ clusters create \
--url http://192.168.33.3:8081,192.168.33.4:8081,192.168.33.5:8081 \
--broker-url pulsar://192.168.33.3:6650,192.168.33.4:6650,192.168.33.5:6650 \
pulsar-function
# 创建pulsar-function集群下的命名空间public/functions
bin/pulsar-admin --admin-url http://localhost:8081/ namespaces create public/functions --clusters pulsar-function
修改配置文件
【9】broker.conf
functionsWorkerEnabled=true
【11】functions_worker.yml
pulsarFunctionsNamespace: public/functions # 使用默认的配置,则需要进行初始化。这里和pulsar使用统一集群,
pulsarFunctionsCluster: pulsar-function
numFunctionPackageReplicas: 2
重启broker
bin/pulsar-daemon stop broker
bin/pulsar-daemon start broker
bin/pulsar-admin --admin-url http://localhost:8081/ brokers list pulsar-cluster
单独运行 pulsar func
修改配置文件
【11】functions_worker.yml
pulsarWebServiceUrl: http://localhost:8081
pulsarFunctionsNamespace: public/default
pulsarFunctionsCluster: pulsar-cluster
numFunctionPackageReplicas: 2
启动
bin/pulsar functions-worker
用到的命令
bin/pulsar-daemon start zookeeper
bin/pulsar zookeeper-shell
bin/pulsar-daemon stop zookeeper
bin/pulsar-daemon start bookie
bin/bookkeeper shell bookiesanity
bin/pulsar-daemon stop bookie
bin/pulsar-daemon start broker
bin/pulsar-admin --admin-url http://localhost:8081/ brokers list pulsar-cluster
bin/pulsar-daemon stop broker
bin/pulsar-admin --admin-url http://localhost:8081/ namespaces get-clusters public/functions
bin/pulsar-admin --admin-url http://localhost:8081/ clusters list
bin/pulsar-admin --admin-url http://localhost:8081/ namespaces list public
bin/pulsar-admin --admin-url http://localhost:8081/ topics list public/default
# 创建pulsar-function集群
bin/pulsar-admin --admin-url http://localhost:8081/ clusters create \
--url http://192.168.33.3:8081,192.168.33.4:8081,192.168.33.5:8081 \
--broker-url pulsar://192.168.33.3:6650,192.168.33.4:6650,192.168.33.5:6650 \
pulsar-function
# 创建pulsar-function集群下的命名空间public/functions
bin/pulsar-admin --admin-url http://localhost:8081/ namespaces create public/functions --clusters pulsar-function
bin/pulsar-admin --admin-url http://localhost:8081/ functions create --go ./func/distribute --inputs persistent://public/default/topic-05 --tenant public --namespace public/default --name distribute
less logs/pulsar-broker-localhost.localdomain.out
bin/pulsar-admin --admin-url http://localhost:8081/ functions list
bin/pulsar-admin --admin-url http://localhost:8081/ functions restart --name distribute
鸣谢
感谢大佬的资料 https://blog.csdn.net/wzt_gjt/article/details/109465416
还有群里帮忙解决问题的小伙伴