Linux MacBook单机部署Pulsar并开启认证功能

Pulsar简单介绍

Pulsar 是一个用于服务器到服务器的消息系统,具有多租户、高性能等优势。 Pulsar 最初由 Yahoo 开发,目前由 Apache 软件基金会管理。

Pulsar 的关键特性如下:

  • Pulsar 的单个实例原生支持多个集群,可跨机房在集群间无缝地完成消息复制。

  • 极低的发布延迟和端到端延迟。

  • 可无缝扩展到超过一百万个 topic。

  • 简单的客户端 API,支持 Java、Go、Python 和 C++。

  • 支持多种 topic 订阅模式(独占订阅、共享订阅、故障转移订阅)。

  • 通过 Apache BookKeeper 提供的持久化消息存储机制保证消息传递 。

  • 由轻量级的 serverless 计算框架 Pulsar Functions 实现流原生的数据处理。

  • 基于 Pulsar Functions 的 serverless connector 框架 Pulsar IO 使得数据更易移入、移出 Apache Pulsar。

  • 分层式存储可在数据陈旧时,将数据从热存储卸载到冷/长期存储(如S3、GCS)中。

官方文档地址:https://pulsar.apache.org/docs/zh-CN/concepts-overview/

Pulsar在Linux或MacBook上安装

Pulsar是java开发的,只需要安装jdk环境

MacBook安装jdk8

Linux卸载openjdk并安装Oracle jdk

官方下载地址:https://pulsar.apache.org/zh-CN/download/

#下载pulsar
wget https://archive.apache.org/dist/pulsar/pulsar-2.8.0/apache-pulsar-2.8.0-bin.tar.gz

#解压
tar xvfz apache-pulsar-2.8.0-bin.tar.gz

#进入目录
cd apache-pulsar-2.8.0

#启动单机模式 Pulsar  会自动启动一个zookeeper
bin/pulsar standalone

发送和订阅数据

使用Pulsar-client 工具

#进入目录
cd apache-pulsar-2.8.0

#消费者订阅: 在first-subscription 订阅中 consume 一条消息到topic:my-topic 的命令
bin/pulsar-client consume my-topic -s "first-subscription"

#开启另一个终端发送数据,注意观察订阅者收到数据:content:hello-pulsar
#生产者发送: 向名称为 my-topic 的 topic 发送一条简单的消息 hello-pulsar
bin/pulsar-client produce my-topic --messages "hello-pulsar"

开启认证功能

#生成秘钥
bin/pulsar tokens create-secret-key --output /Users/liang/software/apache-pulsar-2.8.0/my-secret.key --base64

#创建Token,记住生成的token
bin/pulsar tokens create --secret-key file:///Users/liang/software/apache-pulsar-2.8.0/my-secret.key --subject admin
eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZG1pbiJ9.UCsEs8p8E_7OiTvCuf0rRvGP26ZPFunnSEbjGsynVqM

#修改配置,开启token认证
vim conf/standalone.conf

#启用认证
authenticationEnabled=true
authenticationProviders=org.apache.pulsar.broker.authentication.AuthenticationProviderToken

tokenSecretKey=file:///Users/liang/software/apache-pulsar-2.8.0/my-secret.key

#broker与broker之间的相互通信(如果不配置报错:HTTP 401 Unauthorized BookKeeper client is closed)
brokerClientAuthenticationPlugin=org.apache.pulsar.client.impl.auth.AuthenticationToken
brokerClientAuthenticationParameters=token:eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZG1pbiJ9.UCsEs8p8E_7OiTvCuf0rRvGP26ZPFunnSEbjGsynVqM

#重启standalone
bin/pulsar standalone

#在次执行订阅报错: Unable to authenticate 没有权限
bin/pulsar-client consume my-topic -s "first-subscription"

#执行:获取租户列表: HTTP 401 Unauthorized
bin/pulsar-admin tenants list

#修改客户端配置
vim conf/client.conf
authPlugin=org.apache.pulsar.client.impl.auth.AuthenticationToken
authParams=token:eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZG1pbiJ9.UCsEs8p8E_7OiTvCuf0rRvGP26ZPFunnSEbjGsynVqM

#在次执行订阅成功
bin/pulsar-client consume my-topic -s "first-subscription"

#执行:获取租户列表成功
bin/pulsar-admin tenants list
#成功显示
"public"
"sample"

参考链接:
https://www.jianshu.com/p/dd328bdd2a32
https://blog.csdn.net/wt334502157/article/details/117414153

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值