Set up a standalone Pulsar locally
本教程将详细介绍安装的每一步。
Pulsar is currently available for MacOS and Linux. To use Pulsar, you need to install Java 8 from .
Tip
By default, Pulsar allocates 2G JVM heap memory to start. It can be changed in file under
PULSAR_MEM
. This is extra options passed into JVM.
安装二进制版本 Pulsar
首先,通过以下方式下载二进制安装包:
下载好压缩文件后,解压缩并使用 cd
命令进入文件所在位置:
$ tar xvfz apache-pulsar-2.7.0-bin.tar.gz
$ cd apache-pulsar-2.7.0
软件包包含的内容:
Pulsar 二进制包包含下列目录:
运行 Pulsar 会立即生成以下目录。
目录 | 内容 |
---|---|
data | ZooKeeper和BookKeeper使用的数据存储目录 |
instances | 为 Pulsar Functions 创建的组件。 |
logs | 安装时生成的日志文件 |
Tip
If you want to use builtin connectors and tiered storage offloaders, you can install them according to the following instructions:
Otherwise, skip this step and perform the next step Start Pulsar standalone. Pulsar can be successfully installed without installing bulitin connectors and tiered storage offloaders.
download from the Apache mirror * 从 Pulsar 官网下载页下载
从 Pulsar 下载
使用 wget 命令下载:
$ wget https://archive.apache.org/dist/pulsar/pulsar-2.7.0/connectors/{connector}-2.7.0.nar
下载 nar 文件后,将其复制到 pulsar 目录下的 connectors
目录中。 比如,要下载 pulsar-io-aerospike-2.7.0.nar
连接器文件,则输入以下命令:
$ mkdir connectors
$ ls connectors
pulsar-io-aerospike-2.7.0.nar
...
安装分层存储卸载程序(可选)
Tip
Since
2.2.0
release, Pulsar releases a separate binary distribution, containing the tiered storage offloaders. To enable tiered storage feature, follow the instructions below; otherwise skip this section.
要使用,需要在所有 broker 节点上下载卸载程序的压缩文件,下载方式有以下几种:
download from the Apache mirror Pulsar Tiered Storage Offloaders 2.7.0 release* 从 Pulsar 官网下载
使用 wget 命令下载:
下载卸载程序压缩包后,解压缩,并将卸载程序复制为 offloaders
存储在 pulsar 目录中:
$ tar xvfz apache-pulsar-offloaders-2.7.0-bin.tar.gz
// you will find a directory named `apache-pulsar-offloaders-2.7.0` in the pulsar directory
// then copy the offloaders
$ mv apache-pulsar-offloaders-2.7.0/offloaders offloaders
$ ls offloaders
tiered-storage-jcloud-2.7.0.nar
关于如何配置分层存储的详细信息,请参阅。
Note
If you are running Pulsar in a bare metal cluster, make sure that
offloaders
tarball is unzipped in every broker’s pulsar directory.
当有最新版本的本地副本后,可以使用 命令启动本地集群(该命令存储在 bin
目录中),并且可以指定为以单机模式启动 Pulsar。
$ bin/pulsar standalone
成功启动 Pulsar 后,可以看到如下所示的 INFO
级日志消息:
2017-06-01 14:46:29,192 - INFO - [main:WebSocketService@95] - Configuration Store cache started
2017-06-01 14:46:29,192 - INFO - [main:AuthenticationService@61] - Authentication is disabled
2017-06-01 14:46:29,192 - INFO - [main:WebSocketService@108] - Pulsar WebSocket Service started
Pulsar 中有一个名为 pulsar-client
的 CLI 工具。 Pulsar-client 工具允许使用者在运行的集群中 consume 并 produce 消息到 Pulsar topic。
在 first-subscription
订阅中 consume 一条消息到 my-topic
的命令如下所示:
如果消息成功发送到 topic,则会在 pulsar-client
日志中出现一个确认,如下所示:
09:56:55.566 [pulsar-client-io-1-1] INFO org.apache.pulsar.client.impl.MultiTopicsConsumerImpl - [TopicsConsumerFakeTopicNamee2df9] [first-subscription] Success subscribe new topic my-topic in topics consumer, partitions: 4, allTopicPartitionsNumber: 4
Tip
As you have noticed that we do not explicitly create the
my-topic
topic, to which we consume the message. When you consume a message to a topic that does not yet exist, Pulsar creates that topic for you automatically. Producing a message to a topic that does not exist will automatically create that topic for you as well.
Produce 一条消息
向名称为 my-topic
的 topic 发送一条简单的消息 hello-pulsar
,命令如下所示:
如果消息成功发送到 topic,则会在 pulsar-client
日志中出现一个确认,如下所示:
13:09:39.356 [main] INFO org.apache.pulsar.client.cli.PulsarClientTool - 1 messages successfully produced
使用 Ctrl+C
终止单机模式 Pulsar 的运行。
Tip
If the service runs as a background process using the
pulsar-daemon start standalone
command, then use the command to stop the service.For more information, see pulsar-daemon.