得意淡然,失意坦然;喜而不狂,忧而不伤。

Kafka单机版安装过程中的一些配置关键点

大数据 admin 46次浏览 未收录 0个评论 扫描二维码

因为公司项目中需要用到kafka, 安排一同事安装,结果好几天都没法正常连接,在安装机器可以生产和消费,但是在本地始终无法连接消费。

telnet 是可以处于连接状态的,查了一些资料发现在配置上官网并没有明确指出。

官网单机版安装地址:http://kafka.apache.org/quickstart

以下标红部分是需要单独配置的。

 

Step 1: Download the code

Download the 2.1.0 release and un-tar it.

1
2
> tar -xzf kafka_2.11-2.1.0.tgz
> cd kafka_2.11-2.1.0

 

再Step1和Step2之间,需要单独配置两个listeners

listeners=PLAINTEXT://0.0.0.0:9092

advertised.listeners=PLAINTEXT://外网IP:9092

 

Step 2: Start the server

Kafka uses ZooKeeper so you need to first start a ZooKeeper server if you don’t already have one. You can use the convenience script packaged with kafka to get a quick-and-dirty single-node ZooKeeper instance.

1
2
3
> bin/zookeeper-server-start.sh config/zookeeper.properties
[2013-04-22 15:01:37,495] INFO Reading configuration from: config/zookeeper.properties (org.apache.zookeeper.server.quorum.QuorumPeerConfig)
...

Now start the Kafka server:

1
2
3
4
> bin/kafka-server-start.sh config/server.properties
[2013-04-22 15:01:47,028] INFO Verifying properties (kafka.utils.VerifiableProperties)
[2013-04-22 15:01:47,051] INFO Property socket.send.buffer.bytes is overridden to 1048576 (kafka.utils.VerifiableProperties)
...

Step 3: Create a topic

Let’s create a topic named “test” with a single partition and only one replica:

1
> bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test

We can now see that topic if we run the list topic command:

1
2
> bin/kafka-topics.sh --list --zookeeper localhost:2181
test

Alternatively, instead of manually creating topics you can also configure your brokers to auto-create topics when a non-existent topic is published to.

Step 4: Send some messages

Kafka comes with a command line client that will take input from a file or from standard input and send it out as messages to the Kafka cluster. By default, each line will be sent as a separate message.

Run the producer and then type a few messages into the console to send to the server.

1
2
3
> bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
This is a message
This is another message

Step 5: Start a consumer

Kafka also has a command line consumer that will dump out messages to standard output.

1
2
3
> bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
This is a message
This is another message

If you have each of the above commands running in a different terminal then you should now be able to type messages into the producer terminal and see them appear in the consumer terminal.

All of the command line tools have additional options; running the command with no arguments will display usage information documenting them in more detail.


pitata技术乐园 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明Kafka单机版安装过程中的一些配置关键点
喜欢 (0)
[103531948@qq.com]
分享 (0)
发表我的评论
取消评论
表情 斜体

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址