基础配置
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,实现消息传递和存储任务的分布式协作。