Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp6 0 0 :::47457 :::* LISTEN 6582/java
tcp6 0 0 172.16.81.131:9092 :::* LISTEN 9260/java
tcp6 0 0 :::2181 :::* LISTEN 6582/java
tcp6 0 0 :::33230 :::* LISTEN 9260/java
tcp6 0 0 172.16.81.131:3888 :::* LISTEN 6582/java
[root@kafka2 ~]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp6 0 0 172.16.81.132:9092 :::* LISTEN 9395/java
tcp6 0 0 :::42884 :::* LISTEN 6779/java
tcp6 0 0 :::2181 :::* LISTEN 6779/java
tcp6 0 0 172.16.81.132:2888 :::* LISTEN 6779/java
tcp6 0 0 172.16.81.132:3888 :::* LISTEN 6779/java
tcp6 0 0 :::38557 :::* LISTEN 9395/java
4、测试zookeeper和kafka是否正常
(1)建立一个主题
[root@kafka2 ~]# /opt/kafka/bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 2 --partitions 1 --topic summer
Created topic "summer".
#注意:factor大小不能超过broker数,否则报错,当前集群broker值值为2
(2)查看有哪些主题已经创建
[root@kafka2 ~]# /opt/kafka/bin/kafka-topics.sh --list --zookeeper 172.16.81.132:2181
summer
[root@kafka1 ~]# /opt/kafka/bin/kafka-topics.sh --list --zookeeper 172.16.81.131:2181
summer
(3)查看topic的详情
[root@kafka2 ~]# /opt/kafka/bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic summer
Topic:summer PartitionCount:1 ReplicationFactor:2 Configs:
Topic: summer Partition: 0 Leader: 2 Replicas: 2,1 Isr: 2,1
#主题名称:summer
#Partition:只有一个,从0开始
#leader :id为2的broker
#Replicas 副本存在于broker id为2,1的上面
#Isr:活跃状态的broker
(4)发送消息,这里使用的是生产者角色
[root@kafka2 ~]# /bin/bash /opt/kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic summer
>Hello,wangyanlin
>I am from china.
>
>
>;
>^C[root@kafka2 ~]#
(5)接收消息,这里使用的是消费者角色
[root@kafka2 ~]# /opt/kafka/bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic summer --from-beginning