kafka安装教程

检查java8 没有就安装

java -version

安装jdk1.8

yum -y install java-1.8.0-openjdk

下载kafka (网速很慢)

wget https://dlcdn.apache.org/kafka/3.5.0/kafka_2.13-3.5.0.tgz

解压缩

tar -xzf kafka_2.13-3.5.0.tgz
cd kafka_2.13-3.5.0

后台启动ZooKeeper服务(这里使用kafka里自带的zookeeper启动服务,也可以自己下载安装zookeeper) 默认端口2181

bin/zookeeper-server-start.sh   -daemon config/zookeeper.properties

*集群https://ken.io/note/zookeeper-cluster-deploy-guide

server.1=192.168.88.11:2888:3888
server.2=192.168.88.12:2888:3888
server.3=192.168.88.13:2888:3888

kafka配置文件,改完再启动Kafka 默认端口 9092

*集群 https://www.cnblogs.com/kentalk/p/kafka-cluster-deploy-guide.html

进入配置文件夹

cd  /kafka_2.13-3.5.0/config

编辑server.properties

vim server.properties

• broker.id:唯一标识ID
• listeners=PLAINTEXT://localhost:9092:kafka服务监听地址和端口
• log.dirs:日志存储目录
• zookeeper.connect:指定zookeeper服务地址

在内网部署及访问kafka时,只需要配置listeners参数即可

listeners=PLAINTEXT://192.168.110.129:9092

1外网环境_在内网部署kafka服务,并且生产者或者消费者在外网环境时,需要添加额外的配置

listener.security.protocol.map=INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT
listeners=INTERNAL://192.168.110.129:9092,EXTERNAL://192.168.110.129:9093
advertised.listeners=INTERNAL://192.168.110.129:9092,EXTERNAL://<公网ip>:<端口>
inter.broker.listener.name=INTERNAL

2外网环境_此时zookeeper中的配置如下

{"listener_security_protocol_map":{"INTERNAL":"PLAINTEXT","EXTERNAL":"PLAINTEXT"},"endpoints":["INTERNAL://192.168.110.129:9092","EXTERNAL://<公网ip>:<端口>"],"jmx_port":-1,"host":"192.168.110.129","timestamp":"1578999811569","port":9092,"version":4}
stamp":"1578999811569","port":9092,"version":4}
cZxid = 0x500285971
ctime = Tue Jan 14 19:03:31 CST 2020
mZxid = 0x500285971
mtime = Tue Jan 14 19:03:31 CST 2020
pZxid = 0x500285971
cversion = 0
dataVersion = 0
aclVersion = 0+
ephemeralOwner = 0x30095ee6b3e3e58
dataLength = 236
numChildren = 0

启动Kafka

bin/kafka-server-start.sh  -daemon  config/server.properties

//后台运行
bin/kafka-server-start.sh  -daemon  config/server.properties

常用命令

bin/kafka-server-stop.sh

bin/kafka-topics.sh --create --topic test --bootstrap-server localhost:9092

bin/kafka-console-producer.sh --topic test --bootstrap-server localhost:9092

bin/kafka-console-consumer.sh --topic test --from-beginning --bootstrap-server localhost:9092

img

可视化工具 https://www.kafkatool.com/download.html

——————————————————————自行安装zookeeper————————————————————

下载zookeeper (网速很慢)

wget https://dlcdn.apache.org/zookeeper/zookeeper-3.8.2/apache-zookeeper-3.8.2-bin.tar.gz
下载网址 https://zookeeper.apache.org/releases.html

解压

tar -zxvf zookeeper-3.4.12.tar.gz

创建数据和日志存放目录

cd /www/zookeeper/
mkdir data
mkdir log

把conf下的zoo_sample.cfg备份一份,然后重命名为zoo.cfg

cd conf/
cp zoo_sample.cfg zoo.cfg

配置zookeeper,编辑zoo.cfg文件

vim zoo.cfg
重新配置dataDir和dataLogDir的存储路径,就刚刚创建的目录

最后,启动 Zookeeper 服务 , 进入Zookeeper的bin目录

cd zookeeper/zookeeper-3.4.12/bin

启动Zookeeper

./zkServer.sh start

查询Zookeeper状态

./zkServer.sh status

关闭Zookeeper状态

./zkServer.sh stop

posted @ 2023-11-18 12:05  誓鼎  阅读(99)  评论(0编辑  收藏  举报