1. 安装jdk8;
2. kafka安装包下载:https://www.apache.org/dyn/closer.cgi?path=/kafka/2.1.0/kafka_2.12-2.1.0.tgz
3. 解压,并配置环境变量:
1) vim /etc/profile
2) export KAFKA_HOMNE=/root/work/kafka_2.12-2.1.0
export PATH=$PATH:$KAFKA_HOME/bin
3)source /etc/profile
4. 编辑server.properties:
#外部访问必须开启这个配置,192.168.2.234这个是安装kafka的服务器的地址
listeners=PLAINTEXT://192.168.2.234:9092
#kafka日志
log.dirs=/john/kafka/kafka_2.11-2.0.0/kafka-logs
#zk
zookeeper.connect=192.168.2.234:2181
host.name=192.168.2.234
5. 启动:
1)启动zk,
nohup zookeeper-server-start.sh /john/kafka/kafka_2.11-2.0.0/config/zookeeper.properties &
2)启动kafka broker:
nohup kafka-server-start.sh /john/kafka/kafka_2.11-2.0.0/config/server.properties &
3)生产者:broker-list不要使用localhost,而是使用ip,否则会报错(broker may not be available)
kafka-console-producer.sh --topic mytopic --broker-list 192.168.2.234:9092
3)消费者:bootstrap-server不要使用localhost,而是使用ip,否则会报错(broker may not be available)
kafka-console-consumer.sh --topic mytopic --bootstrap-server 192.168.2.234:9092