• 01 kafka 集群搭建


    前言

    // 今年的第一个目标应该就是这样了吧 

    呵呵 最近有一系列环境搭建的相关需求

    记录一下

    kafka 三个节点 : 192.168.110.150, 192.168.110.151, 192.168.110.152

    150 为 master, 151 为 slave01, 152 为 slave02 

    三台机器都做了 trusted shell  

    kafka 单节点 docker 搭建

    创建 docker-compose.yml 如下, 然后 docker-compose up -d 启动 kafka 即可使用

    1. version: '3.2'
    2. services:
    3. zookeeper:
    4. image: wurstmeister/zookeeper
    5. container_name: zookeeper
    6. ports:
    7. - "2181:2181"
    8. restart: always
    9. kafka:
    10. image: wurstmeister/kafka:2.12-2.3.0
    11. ports:
    12. - "9092:9092"
    13. container_name: kafka
    14. environment:
    15. - KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181
    16. - KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://${IP}:9092
    17. - KAFKA_LISTENERS=PLAINTEXT://:9092
    18. - KAFKA_ADVERTISED_HOST_NAME=192.168.235.250
    19. volumes:
    20. - /var/run/docker.sock:/var/run/docker.sock
    21. restart: always

    kafka 集群搭建

    kafka 三个节点 : 192.168.110.150, 192.168.110.151, 192.168.110.152

    zookeeper 单节点 : 192.168.110.250

    1. 基础环境准备 

    192.168.110.250 上面安装 zookeeper 

    1. root@ubuntu:~/HelloDocker/zookeeper# docker ps
    2. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    3. 7e2781f9a2aa zookeeper "/docker-entrypoint.…" 7 months ago Up About an hour 2888/tcp, 0.0.0.0:2181->2181/tcp, 3888/tcp, 0.0.0.0:18080->8080/tcp zk

    192.168.110.150, 192.168.110.151, 192.168.110.152 上面安装 jdk, 上传 kafka 的安装包 

    安装包来自于 Apache Kafka

    1. root@ubuntu:/usr/local/ProgramFiles# ll
    2. total 69916
    3. drwxr-xr-x 3 root root 4096 May 13 19:48 ./
    4. drwxr-xr-x 11 root root 4096 Jan 5 05:53 ../
    5. drwxr-xr-x 8 10143 10143 4096 Apr 7 2021 jdk1.8.0_291/
    6. -rw-r--r-- 1 root root 71578705 May 13 19:48 kafka_2.12-2.8.1.tgz
    7. root@ubuntu:/usr/local/ProgramFiles# java -version
    8. java version "1.8.0_291"
    9. Java(TM) SE Runtime Environment (build 1.8.0_291-b10)
    10. Java HotSpot(TM) 64-Bit Server VM (build 25.291-b10, mixed mode)

    2. kafka 配置调整 

    分别进入 master, slave01, slave02 机器 

    进入 kafka 目录, 调整 config/server.properties 

    1. # The id of the broker. This must be set to a unique integer for each broker.
    2. broker.id=0
    3. # The address the socket server listens on. It will get the value returned from
    4. # java.net.InetAddress.getCanonicalHostName() if not configured.
    5. # FORMAT:
    6. # listeners = listener_name://host_name:port
    7. # EXAMPLE:
    8. # listeners = PLAINTEXT://your.host.name:9092
    9. listeners=PLAINTEXT://192.168.110.150:9092
    10. # Zookeeper connection string (see zookeeper docs for details).
    11. # This is a comma separated host:port pairs, each corresponding to a zk
    12. # server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002".
    13. # You can also append an optional chroot string to the urls to specify the
    14. # root directory for all kafka znodes.
    15. zookeeper.connect=192.168.110.250:2181

    1. broker.id=1
    2. listeners=PLAINTEXT://192.168.110.151:9092
    3. zookeeper.connect=192.168.110.250:2181

    1. broker.id=2
    2. listeners=PLAINTEXT://192.168.110.152:9092
    3. zookeeper.connect=192.168.110.250:2181

    3. 启动 kafka 集群

    进入 master, slave01, slave02 分别启动 kafka-server 

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

    测试集群

    基于 kafka 脚本的测试

    1. root@master:/usr/local/ProgramFiles/kafka_2.12-2.8.1# ./bin/kafka-topics.sh --create --zookeeper 192.168.110.250:2181 --topic test --partitions 3 --replication-factor 1
    2. Created topic test.
    3. root@master:/usr/local/ProgramFiles/kafka_2.12-2.8.1# ./bin/kafka-console-producer.sh --broker-list 192.168.110.150:9092,192.168.110.151:9092,192.168.110.152:9092 --topic test
    4. >{}^[[Dsdfsdfsdf
    5. >HelloWoerld
    6. >root@master:/usr/local/ProgramFiles/kafka_2.12-2.8.1# ./bin/kafka-console-consumer.sh --bootstrap-server 192.168.110.150:9092,192.168.110.151:9092,192.168.110.152:9092 --topic test --from-beginning
    7. HelloWoerld
    8. {sdfsdfsdf

    检查 zookeeper 的元数据信息 

    基于 offset expolorer 的测试

  • 相关阅读:
    plsql连接oracle数据库
    Win11勒索软件防护怎么打开?Win11安全中心勒索软件防护如何设置
    FPGA学习之状态机
    实现一个简单的 ctrl+ f 搜索
    四、业务数据解析
    围剿小程序
    嵌入式学习笔记(39)蜂鸣器和PWM定时器编程实践
    linux cpu物理信息查看
    在线文档生成:Swagger
    Windows 11 如何同步文件到OneDrive ?
  • 原文地址:https://blog.csdn.net/u011039332/article/details/124765069