Kafka学习之(二)Centos下安装Kafka

环境:Centos6.4,官方下载地址:http://kafka.apache.org/downloads  ,前提是还需要安装了Java环境,本博客http://www.cnblogs.com/wt645631686/p/8267239.html有安装方法

# wget https://archive.apache.org/dist/kafka/0.10.1.0/kafka_2.10-0.10.1.0.tgz
# tar zxvf kafka_2.10-0.10.1.0.tgz
# mv ./kafka_2.10-0.10.1.0 /usr/local/kafka
# cd /usr/local/kafka/config/
# vim zookeeper.properties   #编辑zookeeper配置文件
#---------------------------------------------------------#
dataDir=/tmp/zookeeper
# the port at which the clients will connect
#客户端端口2181,也就是通过zookeeper启动kafka的时候,指定端口号
clientPort=2181
# disable the per-ip limit on the number of connections since this is a non-production config
maxClientCnxns=0
# vim server.properties   #编辑kafka配置文件
#------------------------------------------------------#
listeners=PLAINTEXT://127.0.0.1:9092

记住先启动zookeeper,再启动kafka

# ./bin/zookeeper-server-start.sh ./config/zookeeper.properties   #启动zookeeper
# ./bin/kafka-server-start.sh config/server.properties            #打开新终端启动kafka
[root@localhost ~]# netstat -tunlp | grep 9092
tcp        0      0 ::ffff:127.0.0.1:9092       :::*                        LISTEN      3092/java 

启动成功,测试一下

创建消费者

# bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic mytest --from-beginning  //消费的集群--zookeeper  localhost:2181 zookeeper端口地址  --topic mytest   监听的主题
#--from-beginning   从开头监听 
Using the ConsoleConsumer with old consumer is deprecated and will be removed in a future major release. Consider using the new consumer by passing [bootstrap-server] instead of [zookeeper].

打开新终端创建生产者

# bin/kafka-console-producer.sh --broker-list localhost:9092 --topic mytest

继续操作,输入想要输入的字符串敲击回车,观察消费者终端会发现有新消息。

OK~

posted @ 2018-01-16 14:00  温柔的风  阅读(905)  评论(0编辑  收藏  举报