kafka单机安装
下载地址
说明
- 版本选择:3.0.0,
kafka_2.12-3.0.0.tgz
- 下载地址:https://archive.apache.org/dist/kafka/3.0.0/kafka_2.12-3.0.0.tgz
安装前准备
- 安装环境:linux,centos7
- 安装java环境,参考:linux安装java -centos安装java -linux配置java环境变量
- 安装zookeeper集群,参考:zookeeper集群安装
单机安装
-
复制下载的安装包到Linux服务器,安装包名:
kafka_2.12-3.0.0.tgz
-
进入到安装包所在路径,将安装包解压到指定目录
shelltar -zxvf kafka_2.12-3.0.0.tgz -C /opt/module/
-
重命名,将
kafka_2.12-3.0.0
重命名为kafka
shellcd /opt/module mv kafka_2.12-3.0.0/ kafka
-
修改配置文件
config/server.properties
-
broker.id
是唯一标识,如果是集群安装,集群内不能重复propertiesbroker.id=0
-
log.dirs
是kafka存储数据路径,默认路径为:/tmp/kafka-logs
,调整到kafka根目录下propertieslog.dirs=/opt/module/kafka/datas
-
zookeeper.connect
是zookeeper连接地址,调整为集群模式propertieszookeeper.connect=192.168.145.132:2181,192.168.145.133:2181,192.168.145.134:2181/kafka
连接地址后面拼接
/kafka
节点,用来存储kafka相关的信息,避免zookeeper信息混乱安装zookeeper集群,参考:zookeeper集群安装
-
listeners
默认不需要配置,有缺省配置,必要时应手动指定,下面的描述信息properties# The address the socket server listens on. It will get the value returned from # java.net.InetAddress.getCanonicalHostName() if not configured. # FORMAT: # listeners = listener_name://host_name:port # EXAMPLE: # listeners = PLAINTEXT://your.host.name:9092 #listeners=PLAINTEXT://:9092
java.net.InetAddress.getCanonicalHostName()
获取的信息可能不是我们想要的,需要手动配置propertieslisteners=PLAINTEXT://192.168.145.132:9092
-
advertised.listeners
默认不需要配置,有缺省配置,必要时应手动指定,下面的描述信息properties# Hostname and port the broker will advertise to producers and consumers. If not set, # it uses the value for "listeners" if configured. Otherwise, it will use the value # returned from java.net.InetAddress.getCanonicalHostName(). #advertised.listeners=PLAINTEXT://your.host.name:9092
-
-
配置环境变量
/etc/profile.d/my_env.sh
propertiesKAFKA_HOME=/opt/module/kafka PATH=$PATH:$KAFKA_HOME/bin export KAFKA_HOME PATH
使配置生效
shellsource /etc/profile
启动kafka服务端
-
先启动zookeeper集群,在每个服务器中,分别启动zookeeper
shellcd /opt/module/zookeeper-3.5.7/bin ./zkServer.sh start
安装zookeeper集群,参考:zookeeper集群安装
-
启动kafka
shellcd /opt/module/kafka/bin ./kafka-server-start.sh -daemon ../config/server.properties
启动kafka需要指定配置文件
-
停止kafka
shellcd /opt/module/kafka/bin ./kafka-server-stop.sh
注意:先停止kafka,再停止zookeeper