下载
安装zookeeper
[root@kafkad ~]# wget http://mirrors.hust.edu.cn/apache/zookeeper/zookeeper-3.4.10/zookeeper-3.4.10.tar.gz [root@kafkad opt]# tar -zxvf zookeeper-3.4.10.tar.gz [root@kafkad opt]# cd zookeeper-3.4.10/conf
将zoo_sample.cfg复制一份改为zoo.cfg
[root@kafkad conf]# cp zoo_sample.cfg zoo.cfg [root@kafkad conf]# vim zoo.cfg # The number of milliseconds of each tick tickTime=2000 # The number of ticks that the initial # synchronization phase can take initLimit=10 # The number of ticks that can pass between # sending a request and getting an acknowledgement syncLimit=5 # the directory where the snapshot is stored. # do not use /tmp for storage, /tmp here is just # example sakes. dataDir=/tmp/zookeeper dataLogDir=/var/log/kafka/zk # the port at which the clients will connect clientPort=2181 server.1=[192.168.1.165]:2888:3888 # the maximum number of client connections. # increase this if you need to handle more clients #maxClientCnxns=60 # # Be sure to read the maintenance section of the # administrator guide before turning on autopurge. # # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance # # The number of snapshots to retain in dataDir #autopurge.snapRetainCount=3 # Purge task interval in hours # Set to "0" to disable auto purge feature #autopurge.purgeInterval=1
进入bin目录,启动,重启,停止,查看状态命令如下
[root@kafkad zookeeper-3.4.10]# cd bin/ [root@kafkad bin]# pwd /opt/zookeeper-3.4.10/bin [root@kafkad bin]# ./zkServer.sh start ZooKeeper JMX enabled by default Using config: /opt/zookeeper-3.4.10/bin/../conf/zoo.cfg Starting zookeeper ... STARTED
安装kafka
[root@kafkad bin]# cd /opt/ [root@kafkad opt]# wget http://mirrors.hust.edu.cn/apache/kafka/1.1.0/kafka_2.11-1.1.0.tgz [root@kafkad opt]# tar -zxvf kafka_2.11-1.1.0.tgz [root@kafkad opt]# cd kafka_2.11-1.1.0/config [root@kafkad config]# vim server.properties listeners=PLAINTEXT://192.168.1.165:9092 zookeeper.connect=192.168.1.165:2181
启动
[root@kafkad ~]# /opt/kafka_2.11-1.1.0/bin/kafka-server-start.sh -daemon /opt/kafka_2.11-1.1.0/config/server.properties
测试
创建一个名叫test的topic
[root@kafkad bin]# ./kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test Created topic "test".
查看所有的topic
[root@kafkad bin]# ./kafka-topics.sh --list --zookeeper localhost:2181 test
发送消息
[root@kafkad kafka_2.11-1.1.0]# bin/kafka-console-producer.sh --broker-list 192.168.1.165:9092 --topic test1 >q >q >w >d >ew >ddd
查看消费
[root@kafkad ~]# cd /opt/kafka_2.11-1.1.0 [root@kafkad kafka_2.11-1.1.0]# bin/kafka-console-consumer.sh --bootstrap-server 192.168.1.165:9092 --topic test1 --from-beginning q q w d ew ddd bbs.centoscn.vip
参考地址:https://rorschachchan.github.io/2019/01/16/%E6%90%AD%E5%BB%BAKakfa2-11%E4%B8%BAELK%E6%9C%8D%E5%8A%A1/
继续阅读
- 我的QQ
- QQ扫一扫
-
- 我的头条
- 头条扫一扫
-
评论