下载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 配置文件,按照自己的需求修改就好了

  1. dataDir=/home/pulsar/data/zookeeper/data # 这个目录下建立myid
  2. server.1=192.168.33.3:2888:2889 #zk 集群的信息
  3. server.2=192.168.33.4:2888:2889
  4. server.3=192.168.33.5:2888:2889

【9】bookkeeper.conf

  1. advertisedAddress=192.168.33.3 # 本机地址
  2. httpServerPort=8082
  3. prometheusStatsHttpPort=8083
  4. zkServers=192.168.33.3:2181,192.168.33.4:2181,192.168.33.5:2181 #一式三份
  5. # functionsWorkerEnabled=true # pulsar func。可选,选了之后就需要配置【11】

【10】broker.conf

  1. zookeeperServers=192.168.33.3:2181,192.168.33.4:2181,192.168.33.5:2181 #一式三份
  2. configurationStoreServers=192.168.33.3:2181,192.168.33.4:2181,192.168.33.5:2181 #一式三份
  3. advertisedAddress=192.168.33.3 #本机地址
  4. clusterName=pulsar-cluster
  5. webServicePort=8081

可以先本地修改配置之后上传到服务器上

  1. # 覆盖上传
  2. rz -y

启动

  1. ### 启动 zookeeper
  2. mkdir -p /home/pulsar/data/zookeeper/data
  3. echo 1 > myid # 每台服务的不一样
  4. bin/pulsar-daemon start zookeeper
  5. # 在一台服务器上初始化原数据(先跑起来,文档上说是一次性的?等遇到问题再仔细看)
  6. # 这里有个问题 应该写zk集群的地址的吧?
  7. bin/pulsar initialize-cluster-metadata \
  8. --cluster pulsar-cluster \
  9. --zookeeper 192.168.33.3:2181 \
  10. --configuration-store 192.168.33.3:2181 \
  11. --web-service-url http://192.168.33.3:8081,192.168.33.4:8081,192.168.33.5:8081 \
  12. --broker-service-url pulsar://192.168.33.3:6650,192.168.33.4:6650,192.168.33.5:6650
  13. #org.apache.pulsar.PulsarClusterMetadataSetup - Setting up cluster
  14. ### 启动 bookie
  15. bin/bookkeeper shell metaformat # 在一台服务器执行即可
  16. #文档没说这个命令具体是干啥的,得看代码才知道吧
  17. # BookKeeper metadata driver manager initialized
  18. # 看日志是去zk里面读取数据了
  19. bin/pulsar-daemon start bookie
  20. ### 启动 broker
  21. bin/pulsar-daemon start broker
  22. ###每次执行start 命令之后可以回头检查下log
  23. less /home/pulsar/logs/pulsar-zookeeper-localhost.localdomain.out # 查看zk是否启动成功

和broker一起运行pulsar func

  1. ### 初始化func 需要的集群、ns
  2. # 创建pulsar-function集群
  3. bin/pulsar-admin --admin-url http://localhost:8081/ clusters create \
  4. --url http://192.168.33.3:8081,192.168.33.4:8081,192.168.33.5:8081 \
  5. --broker-url pulsar://192.168.33.3:6650,192.168.33.4:6650,192.168.33.5:6650 \
  6. pulsar-function
  7. # 创建pulsar-function集群下的命名空间public/functions
  8. bin/pulsar-admin --admin-url http://localhost:8081/ namespaces create public/functions --clusters pulsar-function

修改配置文件
【9】broker.conf

  1. functionsWorkerEnabled=true

【11】functions_worker.yml

  1. pulsarFunctionsNamespace: public/functions # 使用默认的配置,则需要进行初始化。这里和pulsar使用统一集群,
  2. pulsarFunctionsCluster: pulsar-function
  3. numFunctionPackageReplicas: 2

重启broker

  1. bin/pulsar-daemon stop broker
  2. bin/pulsar-daemon start broker
  3. bin/pulsar-admin --admin-url http://localhost:8081/ brokers list pulsar-cluster

单独运行 pulsar func

修改配置文件
【11】functions_worker.yml

  1. pulsarWebServiceUrl: http://localhost:8081
  2. pulsarFunctionsNamespace: public/default
  3. pulsarFunctionsCluster: pulsar-cluster
  4. numFunctionPackageReplicas: 2

启动

  1. bin/pulsar functions-worker

用到的命令

  1. bin/pulsar-daemon start zookeeper
  2. bin/pulsar zookeeper-shell
  3. bin/pulsar-daemon stop zookeeper
  4. bin/pulsar-daemon start bookie
  5. bin/bookkeeper shell bookiesanity
  6. bin/pulsar-daemon stop bookie
  7. bin/pulsar-daemon start broker
  8. bin/pulsar-admin --admin-url http://localhost:8081/ brokers list pulsar-cluster
  9. bin/pulsar-daemon stop broker
  10. bin/pulsar-admin --admin-url http://localhost:8081/ namespaces get-clusters public/functions
  11. bin/pulsar-admin --admin-url http://localhost:8081/ clusters list
  12. bin/pulsar-admin --admin-url http://localhost:8081/ namespaces list public
  13. bin/pulsar-admin --admin-url http://localhost:8081/ topics list public/default
  14. # 创建pulsar-function集群
  15. bin/pulsar-admin --admin-url http://localhost:8081/ clusters create \
  16. --url http://192.168.33.3:8081,192.168.33.4:8081,192.168.33.5:8081 \
  17. --broker-url pulsar://192.168.33.3:6650,192.168.33.4:6650,192.168.33.5:6650 \
  18. pulsar-function
  19. # 创建pulsar-function集群下的命名空间public/functions
  20. bin/pulsar-admin --admin-url http://localhost:8081/ namespaces create public/functions --clusters pulsar-function
  21. 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
  22. less logs/pulsar-broker-localhost.localdomain.out
  23. bin/pulsar-admin --admin-url http://localhost:8081/ functions list
  24. bin/pulsar-admin --admin-url http://localhost:8081/ functions restart --name distribute

鸣谢

感谢大佬的资料 https://blog.csdn.net/wzt_gjt/article/details/109465416
还有群里帮忙解决问题的小伙伴