kafka安装
安装zookeeper
下载 zookeeper-3.4.13.tar.gz
安装
tar -zxvf zookeeper-3.4.13.tar.gz mv zookeeper-3.4.13 /usr/local/zookeeper mkdir -p /var/lib/zookeeper cd /usr/local/zookeeper/conf cp zoo_sample.cfg zoo.cfg vim zoo.cfg sudo vim zoo.cfg sudo /usr/local/zookeeper/bin/zkServer.sh start
验证
$telnet localhost 2181 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. srvr Zookeeper version: 3.4.13-2d71af4dbe22557fda74f9a9b4309b15a7487f03, built on 06/29/2018 04:05 GMT Latency min/avg/max: 0/0/0 Received: 1 Sent: 0 Connections: 1 Outstanding: 0 Zxid: 0x0 Mode: standalone Node count: 4 Connection closed by foreign host.
安装Kafka Broker
安装
tar -zxvf kafka_2.12-2.1.1.tgz sudo mv kafka_2.12-2.1.1 /usr/local/kafka mkdir /tmp/kafka-logs /usr/local/kafka/bin/kafka-server-start.sh -daemon /usr/local/kafka/config/server.properties
测试
发消息
$/usr/local/kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test >hello word >
收消息
$/usr/local/kafka/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning Test Message 1 Test Message 2 u 123 abc hello word
配置说明
位置:kafka/config/server.properties里面的参数
broker.id:每个broker都有一个唯一的标识符,默认值是0,在整个Kafka集群里是唯一的。值可以任意选定,为了便于维护可以配置为机器名
zookeeper.connect:用于配置保存broker元数据的Zookeeper地址,格式:hostname:port/path(如localhost:2181),多个用逗号隔开
logs.dirs: Kafka把所有的消息都保存在磁盘上,存放这些认知片段的目录通过logs.dir指定,它是用逗号隔开的本地文件系统路径(默认配置是/tmp/kafka-logs)