Py学习  »  docker

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

大钦差 • 5 年前 • 324 次点击  
阅读 4

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

为了本地开发和测试,我们可以建立一个伪集群。伪集群一样包含 Pulsar broker, ZooKeeper, BookKeeper.

生产环境

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

手动安装Pulsar伪集群

系统要求:

Pulsar当前可以运行在Macos与linux系统,而且必须安装java8.

安装:

通过以下方法下载二进制包

  • 从Apache官网的镜像下载:

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

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

  • 使用wget:

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

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

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

包内都包含哪些内容:

二进制包最初包含以下目录:

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

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

DirectoryContains
dataZooKeeper and BookKeeper 数据存储目录
instancesPulsar 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;
}复制代码



今天看啥 - 高品质阅读平台
本文地址:http://www.jintiankansha.me/t/ChpFNzoLml
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/27114
 
324 次点击