码迷,mamicode.com
首页 > 系统相关 > 详细

Ubuntu下kafka集群环境搭建及测试

时间:2017-07-12 19:57:43      阅读:261      评论:0      收藏:0      [点我收藏+]

标签:pac   nbsp   标记   com   ip地址   启动   world   ade   usr   

1,解压

root@Ubuntu-1:/usr/local# tar zxvf kafka_2.11-0.8.2.2.tgz

2,重命名

root@Ubuntu-1:/usr/local# mv /usr/local/kafka_2.11-0.8.2.2 /usr/local/kafka

3,起zookeeper集群到指定后台文件(不占用页面)

root@Ubuntu-1:/usr/local/kafka# bin/zookeeper-server-start.sh config/zookeeper.properties > logs/kafka131-1.log >&1 &

4,起kafka集群到指定后台文件(不占用页面)

bin/kafka-server-start.sh config/server.properties >logs/kafka131-server-1.log >&1 &

5,查看zookeeper和kafka启动情况

root@Ubuntu-1:/usr/local/kafka# jps
3104 QuorumPeerMain
5048 Kafka
5064 Jps

6,新增一个topic

root@Ubuntu-1:/usr/local/kafka# bin/kafka-topics.sh --create --topic huxing --zookeeper localhost:2181 --partitions 2 --replication 1
Created topic "huxing".

7,所有可以使用的topic

root@Ubuntu-1:/usr/local/kafka# bin/kafka-topics.sh --list --zookeeper localhost:2181
huxing

8,查询某个topic的信息

root@Ubuntu-1:/usr/local/kafka# bin/kafka-topics.sh --describe --topic huxing --zookeeper localhost:2181
Topic:huxing    PartitionCount:2    ReplicationFactor:1    Configs:
    Topic: huxing    Partition: 0    Leader: 0    Replicas: 0    Isr: 0
    Topic: huxing    Partition: 1    Leader: 0    Replicas: 0    Isr: 0

9,删除某个topic

在此之前需要在server.properties的配置文件中加入一行

delete.topic.enable=true

重启,然后执行代码

root@Ubuntu-1:/usr/local/kafka# bin/kafka-topics.sh --delete --topic huxing --zookeeper localhost:2181
Topic huxing is marked for deletion.
Note: This will have no impact if delete.topic.enable is not set to true.
root@Ubuntu-1:/usr/local/kafka# bin/kafka-topics.sh --list --zookeeper localhost:2181
hello
world

在jps中可以查询到确实已经被删除了

10,创建producer和consumer用户

在创建producer用户时,出现下列错误:技术分享

解决办法:在server.properties的配置文件中加入一行

advertised.host.name=192.168.22.131

在server.properties 上该参数用来配置返回的host.name值,把这个参数配置为外网IP地址。
这个参数默认没有启用,默认是返回的 java.net.InetAddress.getCanonicalHostName 的值,这个值并不等于 hostname 的值而是返回IP,但在linux上这个值就是 hostname 的值。

 配置好后重启,在两个shell框中输入下列命令:

producer:

root@Ubuntu-1:/usr/local/kafka# bin/kafka-console-producer.sh --topic hello --broker-list localhost:9092
[2017-07-12 18:27:09,916] WARN Property topic is not valid (kafka.utils.VerifiableProperties)
aa
aaa
1
222

consumer:

root@Ubuntu-1:/usr/local/kafka# bin/kafka-console-consumer.sh --topic hello --zookeeper localhost:2181

于是,在producer的shell框中输入的内容将会同步更新到consumer中

标记删除的topic也可以使用

技术分享

Ubuntu下kafka集群环境搭建及测试

标签:pac   nbsp   标记   com   ip地址   启动   world   ade   usr   

原文地址:http://www.cnblogs.com/huxinga/p/7153104.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!