1. 程式人生 > >Ubuntu下kafka集群環境搭建及測試

Ubuntu下kafka集群環境搭建及測試

delet 指定 文件中 新增 img --delete replicat pro alt

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.
[email protected]-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集群環境搭建及測試