Pulsar本地单机(伪)集群 (裸机安装与docker方式安装) 2.2.0

为了本地开发和测试,咱们能够创建一个伪集群。伪集群同样包含 Pulsar broker, ZooKeeper, BookKeeper.java

生产环境

若是想运行一个完整的生产pulsar安装, 查看http://pulsar.apache.org/docs/en/deploy-bare-metalpython

手动安装Pulsar伪集群

系统要求:

Pulsar当前能够运行在Macos与linux系统,并且必须安装java8.linux

安装:

经过如下方法下载二进制包git

  • 从Apache官网的镜像下载:github

    • https://archive.apache.org/dist/pulsar/pulsar-2.2.0/apache-pulsar-2.2.0-bin.tar.gz
  • 从Pulsar官网下载页下载 pulsar.apache.org/download/docker

  • 从Pulsar的github发布页下载:https://github.com/apache/pulsar/releases/tag/v2.2.0apache

  • 使用wget:浏览器

    $ wget https://archive.apache.org/dist/pulsar/pulsar-2.2.0/apache-pulsar-2.2.0-bin.tar.gz
    Copy复制代码

下载完成后解压到自定目录:bash

$ tar xvfz apache-pulsar-2.2.0-bin.tar.gz
$ cd apache-pulsar-2.2.0
复制代码

包内都包含哪些内容:

二进制包最初包含如下目录:工具

Directory Contains
bin Pulsar的命令行工具, 如 pulsar 和 pulsar-admin
conf Pulsar的配置文件, 包含配置 broker configuration, ZooKeeper configuration, 等
examples 一个关于Pulsar Functions的例子
lib Pulsar所依赖的一些jar包
licenses 一些许可文件

一旦运行Pulsar,一下文件夹会被建立:

Directory Contains
data ZooKeeper and BookKeeper 数据存储目录
instances Pulsar Functions 须要的目录
logs 安装时建立的一些日志

安装内置的链接器(connector):

从2.1.0-incubating开始,connector单独发布。若是想要使用须要单独下载。经过如下方式下载

  • 从Apache镜像下载:

  • 从Pulsar 下载页下载:http://pulsar.apache.org/download

  • 从 Pulsar的github的发布页下载:https://github.com/apache/pulsar/releases/latest 

  • 使用 wget:

    $ wget https://archive.apache.org/dist/pulsar/pulsar-2.2.0/apache-pulsar-io-connectors-2.2.0-bin.tar.gz
    复制代码

一旦下载完成,解压下载的压缩包,并把下载的东西拷贝到 pulsar 文件夹下的connectors下(若是没有此目录,能够直接建立):

/pulsar

         /bin

         /lib

          /conf

          /data

          /connectors

$ tar xvfz /path/to/apache-pulsar-io-connectors-2.2.0-bin.tar.gz

// you will find a directory named `apache-pulsar-io-connectors-2.2.0` in the pulsar directory
// then copy the connectors

$ cd apache-pulsar-io-connectors-2.2.0/connectors connectors

$ ls connectors
pulsar-io-aerospike-2.2.0.nar
pulsar-io-cassandra-2.2.0.nar
pulsar-io-kafka-2.2.0.nar
pulsar-io-kinesis-2.2.0.nar
pulsar-io-rabbitmq-2.2.0.nar
pulsar-io-twitter-2.2.0.nar
...
Copy复制代码


启动:

进入咱们刚才解压pulsar/bin/ 文件夹下,执行以下的命令

$ bin/pulsar standalone
复制代码

若是正常启动会看到相似下面的信息:

2017-06-01 14:46:29,192 - INFO  - [main:WebSocketService@95] - Global Zookeeper 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
Copy复制代码


使用Docker安装pulsar的伪集群

咱们也能够经过docker安装一个pulsar的伪集群

docker run -it -p 80:80 -p 8080:8080 -p 6650:6650 apachepulsar/pulsar-standalone
Copy复制代码

几个端口的做用:

  • 80: pulsar的仪表板
  • 8080: pulsar经过http对外提供服务的端口
  • 6650: pulsar经过二进制协议对完提供的端口

启动完成后,咱们经过浏览器就能够访问http://localhost .

测试Pulsar的集群

Pulsar提供了一个命令行的 pulsar-client工具,下面的语句使用pulsar-client 往my-topic发送一条消息:

$ bin/pulsar-client produce my-topic --messages "hello-pulsar"复制代码

若是发送成功,咱们会看到下面的一条消息

13:09:39.356 [main] INFO  org.apache.pulsar.client.cli.PulsarClientTool - 1 messages successfully produced

复制代码

不须要显式地建立新主题

也许你注意到了,咱们发送消息以前并无事前建立my-topic。若是咱们往一个topic发送消息,若是topic事前并无建立,Pulsar会自动为咱们建立。

使用Pulsar的客户端

集群创建后咱们能够经过Pulsar提供的客户端(java, python, c ++, go 等)与 Pulsar交互了

  • http://localhost:8080
  • pulsar://localhost:6650

Java 客户端生产者的例子:

String localClusterUrl = "pulsar://localhost:6650";

PulsarClient client = PulsarClient.builder().serviceURL(localClusterUrl).build();
Producer<byte[]> producer = client.newProducer().topic("my-topic").create();

复制代码

Python 生产者的例子:

import pulsar

client = pulsar.Client('pulsar://localhost:6650')
producer = client.create_producer('my-topic')

复制代码

C++ 生产者例子:

Client client("pulsar://localhost:6650");
Producer producer;
Result result = client.createProducer("my-topic", producer);
if (result != ResultOk) {
    LOG_ERROR("Error creating producer: " << result);
    return -1;
}复制代码
相关文章
相关标签/搜索