💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# :-: kafka集群搭建 **一、前提条件** 1、部署Kafka集群搭建需要服务器至少3台,奇数台 2、Kafka的安装需要java环境,jdk1.8 3、Kafka安装包版本:kafka\_2.12-2.7.0.tgz 4、假设3台服务器分别为:kafka1、kafka2、kafka3 **二、Zookeeper集群搭建** 直接使用kafka自带的zookeeper建立zk集群 1、将安装包kafka\_2.12-2.7.0.tgz上传到//usr/local/kafka目录下 2、解压:tar -zxvf kafka\_2.12-2.7.0.tgz 改名为kafka01 3、进入目录:cd /usr/local/kafka/kafka01 4、创建zookeeper目录:mkdir /usr/local/kafka/kafka01/zk\_datas 5、进入目录:cd /usr/local/kafka/kafka01/config 6、修改zookeeper.properties文件: ![](https://img.kancloud.cn/92/75/9275f7cec676fc83e09c09aeeb63b81d_1141x570.png) ``` dataDir=/usr/local/kafka/kafka01/zk_datas clientPort=2181 maxClientCnxns=0 admin.enableServer=false ``` 同样配置另外2台kafka \*\*clientPort 为2182 2183 \*\* **dataDir=/usr/local/kafka/kafka02/zk\_datas dataDir=/usr/local/kafka/kafka03/zk\_datas** ***** **执行启动** /usr/local/kafka/kafka01/bin/zookeeper-server-start.sh /usr/local/kafka/kafka01/config/zookeeper.properties >/dev/null 2>&1 & /usr/local/kafka/kafka02/bin/zookeeper-server-start.sh /usr/local/kafka/kafka02/config/zookeeper.properties >/dev/null 2>&1 & ***** **三、Kafka集群搭建** 1、进入目录:cd /usr/local/kafka/kafka01 2、创建kafka日志数据目录:mkdir /usr/local/kafka/kafka01/logs 3、进入目录:cd /usr/local/kafka/kafka01/config 4、修改server.properties配置文件: ``` broker.id=0 listeners=PLAINTEXT://:9091 advertised.host.name=180.163.89.77 advertised.listeners=PLAINTEXT://180.163.89.77:9091 log.dirs=/usr/local/kafka/kafka01/logs zookeeper.connect=localhost:2181,localhost:2182 #开启 删除 topic 功能 delete.topic.enable=true #绑定节点的名称,值为当前节点 host.name=node01 ``` ![](https://img.kancloud.cn/f9/0c/f90c9a254d80cd6cfae7996152a4cb1f_1456x856.png)\*\*\*\* ***** **5、 启动kafka集群:** /usr/local/kafka/kafka01/bin/kafka-server-start.sh /usr/local/kafka/kafka01/config/server.properties 2>&1 & /usr/local/kafka/kafka02/bin/kafka-server-start.sh /usr/local/kafka/kafka02/config/server.properties 2>&1 & ***** kafka默认是自动创建topic,当你尝试发送到topic或订阅topic时,会自动创建topic ~~~ //创建topic bin/kafka-topics.sh --create --zookeeper 192.168.121.205:2181 --replication-factor 1 --partitions 1 --topic mykafka //查看topic bin/kafka-topics.sh --list --zookeeper 192.168.121.205:2181 //创建生产者 bin/kafka-console-producer.sh --broker-list 192.168.121.205:9092 --topic mykafka //创建消费者 bin/kafka-console-consumer.sh --zookeeper 192.168.121.205:2181 --topic mykafka --from-beginning ~~~ ***** **6、kafkaUI-1.2.3.jar** ![](https://img.kancloud.cn/79/3b/793b9535f620c50e4abdd327aa8de404_1404x816.png) ![](https://img.kancloud.cn/f5/d0/f5d0cafb87ed8530787724456b26616b_1369x611.png)