内容简介:为了本地开发和测试,我们可以建立一个伪集群。伪集群一样包含 Pulsar broker, ZooKeeper, BookKeeper.Pulsar当前可以运行在Macos与linux系统,而且必须安装java8.通过以下方法下载二进制包
为了本地开发和测试,我们可以建立一个伪集群。伪集群一样包含 Pulsar broker, ZooKeeper, BookKeeper.
生产环境
如果想运行一个完整的生产pulsar安装, 查看http://pulsar.apache.org/docs/en/deploy-bare-metal
手动安装Pulsar伪集群
系统要求:
Pulsar当前可以运行在Macos与 linux 系统,而且必须安装 java 8.
安装:
通过以下方法下载二进制包
-
从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 复制代码
包内都包含哪些内容:
二进制包最初包含以下目录:
| 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;
}复制代码
以上所述就是小编给大家介绍的《Pulsar本地单机(伪)集群 (裸机安装与docker方式安装) 2.2.0》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:- [译] Cloudera 手册:CDH 集群裸机部署参考
- 黑客或可将隐形恶意软件植入“裸机”云主机当中
- 超长干货!在裸机上配置高可用 K3s,部署生产就绪工作负载
- 民生银行:基于 Ironic 实现 X86 裸机自动化装机实践与优化
- 浪潮InCloud OpenStack将升级至Rocky版本 提供高效裸机云与AI云部署
- Golang入门:从安装、部署以及GoLand的安装开始
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Head First HTML5 Programming
Eric Freeman、Elisabeth Robson / O'Reilly Media / 2011-10-18 / USD 49.99
What can HTML5 do for you? If you're a web developer looking to use this new version of HTML, you might be wondering how much has really changed. Head First HTML5 Programming introduces the key featur......一起来看看 《Head First HTML5 Programming》 这本书的介绍吧!