借鉴官网教程:http://kafka.apache.org/082/documentation.html#quickstart
安装kafka
1.安装
tips:
tar在linux上是常用的打包、压缩、加压缩工具,他的参数很多,折里仅仅列举常用的压缩与解压缩参数
参数:
-c :create 建立压缩档案的参数;
-x : 解压缩压缩档案的参数;
-z : 是否需要用gzip压缩;
-v: 压缩的过程中显示档案;
-f: 置顶文档名,在f后面立即接文件名,不能再加参数
wget "http://mirror.cc.columbia.edu/pub/software/apache/kafka/0.11.0.2/kafka_2.12-0.11.0.2.tgz"
mkdir kafka
tar -xvzf kafka_2.12-0.11.0.2.tgz
2.启动
(1)start the server
先启动zookeeper server
bin/zookeeper-server-start.sh config/zookeeper.properties
再启动kafka server
bin/kafka-server-start.sh config/server.properties
(2)create topic
bin/kafka-topics.sh --create --zookeeper 192.168.1.244:8780 --replication-factor 1 --partitions 1 --topic test_1
(3)send messages
生产者生产数据
其中broker的端口为9092
(4)start a consumer
消费者消费数据:
(5)setting up a multi-broker cluster
cp config/server.properties config/server-1.properties
cp config/server.properties config/server-2.properties
cp config/server.properties config/server-3.properties
然后,改一下3个配置
config/server-1.properties: broker.id=1 port=9093 log.dir=/home/luo/qzd/kafka-logs-1 config/server-2.properties: broker.id=2 port=9094 log.dir=/home/luo/qzd/kafka-logs-2
config/server-3.properties: broker.id=3 port=9095 log.dir=/home/luo/qzd/kafka-logs-3
循环上面的步骤