一、虚拟机搭建

1. 安装、配置 Centos

各版本记录如下:

Centos 镜像 下载地址 CentOS-8.3.2011-x86_64-minimal.iso
JDK 版本 JDK 11
Kakfa 版本 2.8.0
Zookeeper 版本 3.7.0
  1. 配置磁盘:

image.png
image.png

  1. 配置网络环境

静态地址
如果使用 NAT 模式但无法使用 DHCP 分配网络地址,则打开 Windows 服务看是否启动了和 VMWare 相关的两个服务。

  1. 关闭防火墙 ```shell systemctl status firewalld.service systemctl start firewalld.service systemctl stop firewalld.service systemctl enable firewalld.service systemctl disable firewalld.service

yum install -y lrzsz

  1. 4. 部署 JDK
  2. ```shell
  3. cd /usr
  4. mkdir java
  5. rpm -ivh jdk

2. 部署 Zookeeper

3.7.0 版本下载
XSHELL下载

  1. 修改 zoo.cfg 配置文件 ``` tickTime=2000 # 会话超时时间等于 2*tickTime

日志目录

dataDir=/var/lib/zookeeper

端口号

clientPort=2181

  1. 2. 启动 Zookeepzer
  2. ```shell
  3. bin/zkServer.sh start

3. 同一主机部署三个 Kafka 进程(单机模拟集群环境)

  1. 端口号分配 | 名称 | Broker Id | 端口号 | log 目录 | | —- | —- | —- | —- | | kafka1 | 1 | 9092 | /kafka/data/k1 | | kafka2 | 2 | 9093 | /kafka/data/k2 | | kafka3 | 3 | 9094 | /kafka/data/k3 |

  2. 修改配置文件 ```shell

    1 修改端口号

    listeners=PLAINTEXT://localhost:9094

2 修改日志目录

log.dirs=/kafka/data/k1

  1. 3. 分别启动三个节点
  2. ```shell
  3. ./bin/kafka-server-start.sh ./config/server1.properties
  1. 查看是否启动成功 ```shell jps // OUTPUT 27681 Kafka 28148 Kafka 27561 QuorumPeerMain 28553 Kafka 28985 Jps

netstat -anp |grep 9092 tcp6 0 0 :::9092 :::* LISTEN 27681/java
tcp6 0 0 127.0.0.1:33978 127.0.0.1:9092 ESTABLISHED 27681/java
tcp6 0 0 127.0.0.1:9092 127.0.0.1:33978 ESTABLISHED 27681/java

  1. 5. 创建 Topic
  2. ```shell
  3. ./bin/kafka-topics.sh --create --topic test --bootstrap-server localhost:9092
  1. 查看 Topic 描述

    1. [root@localhost kafka_2.13-2.7.0]# ./bin/kafka-topics.sh --describe --topic test --bootstrap-server localhost:9092
    2. Topic: test PartitionCount: 1 ReplicationFactor: 1 Configs: segment.bytes=1073741824
    3. Topic: test Partition: 0 Leader: 1 Replicas: 1 Isr: 1
  2. 创建三个副本的 Topic ```shell kafka-topics.sh —create —topic —partitions —replication-factor

./kafka-topics.sh —describe —topic test2 —bootstrap-server localhost:9092 // OUTPUT Topic: test2 PartitionCount: 3 ReplicationFactor: 3 Configs: segment.bytes=1073741824 Topic: test2 Partition: 0 Leader: 1 Replicas: 1,3,2 Isr: 1,3,2 Topic: test2 Partition: 1 Leader: 2 Replicas: 2,1,3 Isr: 2,1,3 Topic: test2 Partition: 2 Leader: 3 Replicas: 3,2,1 Isr: 3,2,1

  1. <a name="nBetr"></a>
  2. ## 4. 小结
  3. 以上是简单描述使用单台虚拟机安装 3 个 Kafka 进程的流程。
  4. <a name="xugWY"></a>
  5. # 二、使用 Docker 安装 Kafka 集群
  6. <a name="DhyTx"></a>
  7. ## 1. Centos 安装 Docker
  8. ```shell
  9. #1 安装 yum-utils
  10. sudo yum install -y yum-utils
  11. #2 添加源
  12. sudo yum-config-manager \
  13. --add-repo \
  14. https://download.docker.com/linux/centos/docker-ce.repo
  15. #3 Enable the nightly or test repositories
  16. sudo yum-config-manager --enable docker-ce-nightly
  17. sudo yum-config-manager --enable docker-ce-test
  18. #4 安装最新的Docker和Containerd
  19. sudo yum install -y https://download.docker.com/linux/fedora/30/x86_64/stable/Packages/containerd.io-1.2.6-3.3.fc30.x86_64.rpm
  20. sudo yum install -y docker-ce docker-ce-cli
  21. #5 启动Docker
  22. sudo systemctl start docker
  23. #6 配置Docker开机自启动
  24. sudo systemctl enable docker
  25. #7 检查Docker版本
  26. docker -v
  27. #8 安装Compose
  28. curl -L https://github.com/docker/compose/releases/download/1.25.4/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
  29. chmod +x /usr/local/bin/docker-compose
  30. yum -y install epel-release
  31. yum -y install python-pip
  32. #9 Apply executable permissions to the binary:
  33. sudo chmod +x /usr/local/bin/docker-compose

三、引用

  1. CentOS8安装Docker
  2. 使用Docker部署kafka集群