kafka与zookeeper的集群

基础配置

powershell 复制代码
systemctl stop firewalld && systemctl disable firewalld
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

vi /etc/hosts
ip1 node1
ip2 node2
ip3 node3

zookeeper介绍

zookeeper是一个分布式的协调服务,主要用于维护集群的元数据信息和配置信息。kafka集群依赖其存储、管理自身元数据、配置。

zookeeper在kafka中的作用

1、管理broker节点:broker的上下线、topic信息、partition信息、副本;

2、存储、管理集群的元数据信息和配置:broker的ip地址、端口、topic、partition的分配;

3、监控broker节点状态:实现fail over和load balance;

zk安装配置

powershell 复制代码
#全节点
yum install -y java-1.8.0-openjdk.x86_64 java-1.8.0-openjdk-devel.x86_64

#提前配好
vi /etc/profile
export KAFKA_HOME=/kafka_2.12-2.0.0
export ZK_HOME=/apache-zookeeper-3.7.1-bin
export KE_HOME=/efak-web-3.0.1
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.372.b07-1.el7_9.x86_64
export JRE_HOME=$JAVA_HOME/jre
export PATH=$PATH:$KAFKA_HOME/bin:$ZK_HOME/bin:$KE_HOME/bin:$JAVA_HOME/bin:$JRE_HOME/bin

tar -xvf apache-zookeeper-3.7.1-bin.tar.gz
mkdir -p /apache-zookeeper-3.7.1-bin/data
mkdir -p /apache-zookeeper-3.7.1-bin/log

cp conf/zoo_sample.cfg conf/zoo.cfg
cat zoo.cfg 
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial 
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between 
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just 
# example sakes.
dataDir=/apache-zookeeper-3.7.1-bin/data
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the 
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1

## Metrics Providers
#
# https://prometheus.io Metrics Exporter
#metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
#metricsProvider.httpPort=7000
#metricsProvider.exportJvmInfo=true
dataLogdir=/apache-zookeeper-3.7.1-bin/log
server.1=ip1:2888:3888
server.2=ip2:2888:3888
server.3=ip3:2888:3888

#节点1至3
echo "1" > /apache-zookeeper-3.7.1-bin/data/myid
echo "3" > /apache-zookeeper-3.7.1-bin/data/myid
echo "3" > /apache-zookeeper-3.7.1-bin/data/myid

#启动、停止
./zkServer.sh start
./zkServer.sh stop

kafka介绍

kafka是一个高性能、低延迟、分布式的消息传递系统,特点在于实时处理数据。其集群由多个成员节点broker组成,每个节点都可以独立处理消息传递和存储任务。

kafka安装配置

powershell 复制代码
#全节点
tar -xvf kafka_2.12-2.0.0.tgz

vi config/server.properties
log.dirs=/var/log/kafka-logs
zookeeper.connect=ip1:2181,ip2:2181,ip3:2181

#1至3节点
broker.id:0
listeners=PLAINTEXT://ip1:9092

broker.id:1

listeners=PLAINTEXT://ip2:9092

broker.id:2
listeners=PLAINTEXT://ip3:9092

#启动顺序:先启动zookeeper,后启动kafka
#关闭顺序:先关闭kafka,后关闭zookeeper (可使用kill命令直接关闭)
cd /kafka_2.12-2.0.0
kafka-server-start.sh -daemon config/server.properties &

开启JMX功能用于监控

powershell 复制代码
#全节点
vi /kafka_2.12-2.0.0/bin/kafka-server-start.sh
export JMX_PORT="9999"

可视化监控eagle

powershell 复制代码
tar -zvxf v3.0.1.tar.gz
cd kafka-eagle-bin-3.0.1 && tar -zxvf kafka-eagle-web-3.0.1-bin.tar.gz

yum install -y mariadb*

mysqladmin -uroot -p password Mdb123#

MariaDB [(none)]>create user eagle@localhost identified by 'kafka123#';
MariaDB [(none)]>select user,host from mysql.user;
MariaDB [(none)]>create database ke;
MariaDB [(none)]>exit

vi /etc/profile
export KE_HOME=/efak-web-3.0.1
export PATH=$PATH:$KAFKA_HOME/bin:$ZK_HOME/bin


vi /efak-web-3.0.1/conf/system-config.properties

cluster1.zk.list=ip1:2181,ip2:2181,ip3:2181
efak.driver=com.mysql.cj.jdbc.Driver
efak.url=jdbc:mysql://127.0.0.1:3306/ke?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull
efak.username=efak
efak.password=kafka123#

ke.sh start

集群启动

按照以上配置,首先启动zookeeper服务,确保znode节点都能够相互通信、协作,然后启动kafka服务,broker按照不同topic、partition选举为不同leader、follower,实现消息传递和存储任务的分布式协作。

相关推荐
半桶水专家28 分钟前
Kafka 性能瓶颈 → JMX 指标对照表
分布式·kafka
Jack_David5 小时前
Kafka批量消息发送
java·分布式·kafka
0xDevNull6 小时前
Apache Kafka 完全指南
分布式·kafka
人间打气筒(Ada)6 小时前
go实战案例:如何基于 Conul 给微服务添加服务注册与发现?
开发语言·微服务·zookeeper·golang·kubernetes·etcd·consul
半桶水专家8 小时前
Kafka JMX详解
分布式·kafka
y = xⁿ10 小时前
重生之我创作出了小红书:计数模块 SDS 位图分片与偏移 异步发送
后端·kafka·intellij-idea
阿里云云原生1 天前
悠悠有品:RocketMQ 稳扛核心交易,Kafka 驱动海量数据,支撑高并发游戏饰品交易平台
kafka·rocketmq
若鱼19191 天前
SpringBoot4+Kafka4 - 生产环境故障 - 消费者执行时间太长导致消息无限循环投递
java·spring·kafka
一叶飘零_sweeeet1 天前
消息队列选型终极指南:Kafka、RocketMQ、RabbitMQ 底层原理与场景化选型全解
架构·kafka·rabbitmq·rocketmq·消息队列选型
heimeiyingwang1 天前
【架构实战】消息队列 Kafka 架构分析
架构·kafka·linq