CentOS 安装并运行Kafka
1、下载Kafka
http://mirrors.hust.edu.cn/apache/kafka/2.1.1/
2、定位到/usr/local,创建kafka文件夹,进入此文件夹后解压kafka(可自行选择安装目录)
tar -xzf kafka_2.11-2.1.1.tgz
3、运行内置zookeeper
cd /usr/local/kafka/kafka_2.11-2.1.1/bin/
./zookeeper-server-start.sh ../config/zookeeper.properties &
4、配置伪分布式kafka
复制三份server.properties(自选数量),每份修改如下几个配置
# Kafka broker节点唯一标识. broker.id=0 # 端口号(伪分布式不能冲突) port=9092 # 对客户端提供的服务地址和端口号 advertised.listeners=PLAINTEXT://192.168.56.20:9092 # Kafka日志存放路径(路径自行创建) log.dirs=/home/hadoop/kafka/broker-0
# Kafka broker节点唯一标识. broker.id=1 # 端口号(伪分布式不能冲突) port=9093 # 对客户端提供的服务地址和端口号 advertised.listeners=PLAINTEXT://192.168.56.20:9093 # Kafka日志存放路径(路径自行创建) log.dirs=/home/hadoop/kafka/broker-1
# Kafka broker节点唯一标识. broker.id=2 # 端口号(伪分布式不能冲突) port=9094 # 对客户端提供的服务地址和端口号 advertised.listeners=PLAINTEXT://192.168.56.20:9094 # Kafka日志存放路径(路径自行创建) log.dirs=/home/hadoop/kafka/broker-2
5、运行Kafka
# 方式一 ./kafka-server-start.sh ../config/server0.properties & ./kafka-server-start.sh ../config/server1.properties & ./kafka-server-start.sh ../config/server2.properties & # 方式二 nohup ./kafka-server-start.sh ../config/server0.properties & nohup ./kafka-server-start.sh ../config/server1.properties & nohup ./kafka-server-start.sh ../config/server2.properties & # 方式三 ./kafka-server-start.sh -daemon ../config/server0.properties ./kafka-server-start.sh -daemon ../config/server1.properties ./kafka-server-start.sh -daemon ../config/server2.properties
6、验证
如何验证Kafka安装成功:查看topic列表即可:./kafka-topics.sh --list --zookeeper zkHost:zkPort