程序员

Kafka集群搭建(kafka2.5+eagle)

2020-06-20  本文已影响0人  冬天里的懒喵

1.环境准备

1.1 硬件环境

为了安装kafka最近环境,向运维申请了3台测试虚拟机,后续很多学习过程都将在此3台服务器上进行,内存为8G,虚拟磁盘 500G. IP如下:

IP                      HOST
192.168.162.201          m162p201
192.168.162.202          m162p202
192.168.162.203          m162p203

操作系统版本如下:

[root@m162p201 software]# lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID: CentOS
Description:    CentOS Linux release 7.7.1908 (Core)
Release:        7.7.1908
Codename:       Core

1.2软件环境

下载1.8版本的jdk和kafka2.5 以及
jdk
https://download.oracle.com/otn/java/jdk/8u251-b08/3d5a2bb8f8d4428bbe94aed7ec7ae784/jdk-8u251-linux-x64.tar.gz
kafka
https://kafka.apache.org/downloads#2.5.0
scalca版本选择了2.12 在apache的下载链接上下载
https://www.apache.org/dyn/closer.cgi?path=/kafka/2.5.0/kafka_2.12-2.5.0.tgz
kafka-eagle
http://download.kafka-eagle.org/
将上述文件都上传到上述三台服务器的/opt/software目录

cd  /opt/software
ls 
jdk-8u251-linux-x64.tar.gz   kafka_2.12-2.5.0.tgz   kafka-eagle-bin-1.4.8.tar.gz  
apache-zookeeper-3.5.6-bin.tar.gz 

1.3 jdk安装

jdk为基础软件,通常情况下不使用系统自带的jdk,一般还是通过自行解压之后,在需要使用的用户中配置环境变量即可.

mkdir /opt/jdk
cd /opt/jdk
tar -zxvf /opt/software/jdk-8u251-linux-x64.tar.gz

1.4 zookeeper安装

安装过程参见 https://www.jianshu.com/p/0e813f6a6049
此处就不赘述详细流程,在每台服务器都新建一个zookeeper用户,之后配置环境变量和各服务器的zk参数即可。

useradd -d  /opt/zookeeper  zookeeper 

在l /etc/security/limit.conf中增加如下内容:

zookeeper  soft nproc 16384
zookeeper  hard nproc 16384
zookeeper  soft nofile 65535
zookeeper  hard nofile 65536

切换到zookeeper用户 su - zookeeper
建立软链接,便于以后切换版本:

 ln -s /opt/zookeeper/zookeeper-3.4.10 /opt/zookeeper/zookeeper

环境变量 .bash_profile文件配置如下:

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
JAVA_HOME=/opt/jdk1.8.0_251
CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar
PATH=$JAVA_HOME/bin:$PATH
export PATH

alias acdconf='cd /opt/zookeeper/apache-zookeeper/conf/'

之后配置好zookeeper启动
zookeeper配置:

# 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=/opt/zookeeper/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
server.1=192.168.162.201:2888:3888
server.2=192.168.162.202:2888:3888
server.3=192.168.162.203:2888:3888

之后建立data目录:

mkdir /opt/zookeeper/data
echo 1 > /opt/zookeeper/data/myid

同样在另外两台服务器将myid配置为 2和3.
启动zookeeper

/opt/zookeeper/zookeeper/bin/zkServer.sh start

2 安装kafka和eagel

2.1安装kafka

useradd -d  /opt/kafka kafka  

在l /etc/security/limit.conf中增加如下内容:

kafka soft nproc 16384
kafka hard nproc 16384
kafka soft nofile 65535
kafka hard nofile 65536

切换到kafka 用户 su - kafka
建立软链接,便于以后切换版本:

tar -zxvf /opt/soft/kafka_2.12-2.5.0.tar.gz
 ln -s /opt/kafka/kafka_2.12-2.5.0 /opt/kafka/apache-kafka 

环境变量 .bash_profile文件配置如下:

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
JAVA_HOME=/opt/jdk1.8.0_251
CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar
PATH=$JAVA_HOME/bin:$PATH
export PATH

alias acdconf='cd /opt/kafka/apache-kafka/conf/'

配置/opt/kafka/apache-kafka/config/server.properties
需要修改的参数如下:

broker.id=1
listeners=PLAINTEXT://192.168.162.201:9092
log.dirs=/opt/kafka/kafka-logs
zookeeper.connect=192.168.162.201:2181,192.168.162.202:2181,192.168.162.203:2181

另外两台服务器配置的birker.id 分别为2和3,其他配置参数只需要修改IP
m162p202

broker.id=2
listeners=PLAINTEXT://192.168.162.202:9092
log.dirs=/opt/kafka/kafka-logs
zookeeper.connect=192.168.162.201:2181,192.168.162.202:2181,192.168.162.203:2181

m162p203

broker.id=3
listeners=PLAINTEXT://192.168.162.203:9092
log.dirs=/opt/kafka/kafka-logs
zookeeper.connect=192.168.162.201:2181,192.168.162.202:2181,192.168.162.203:2181

之后启动kafka

cd /opt/kafka/apache-kafka
bin/kafka-server-start.sh -daemon config/server.properties

2.2安装eagle

eagle安装在kafka用户下,因此不用重新创建目录。此外eagle只需要在一个节点安装即可。
切换到kafka用户:

tar -zxvf kafka-eagle-bin-1.4.8.tar.gz  

建立软链接,便于后续切换版本

ln -s /opt/kafka/kafka-eagle-web-1.4.8  /opt/kafka/kafka-eagle

在环境变量中增加eagle的相关内容:

KE_HOME=/opt/kafka/kafka-eagle
export KE_HOME

修改配置文件:
vim /opt/kafka/kafka-eagle/conf/system-config.properties

######################################
# multi zookeeper & kafka cluster list
######################################
kafka.eagle.zk.cluster.alias=cluster1
cluster1.zk.list=192.168.162.201:2181,192.168.162.202:2181,192.168.162.203:2181

######################################
# broker size online list
######################################
cluster1.kafka.eagle.broker.size=20

######################################
# zk client thread limit
######################################
kafka.zk.limit.size=25

######################################
# kafka eagle webui port
######################################
kafka.eagle.webui.port=8048

######################################
# kafka offset storage
######################################
cluster1.kafka.eagle.offset.storage=kafka
cluster2.kafka.eagle.offset.storage=zk

######################################
# kafka metrics, 15 days by default
######################################
kafka.eagle.metrics.charts=false
kafka.eagle.metrics.retain=15


######################################
# kafka sql topic records max
######################################
kafka.eagle.sql.topic.records.max=5000
kafka.eagle.sql.fix.error=false

######################################
# delete kafka topic token
######################################
kafka.eagle.topic.token=keadmin

######################################
# kafka sasl authenticate
######################################
cluster1.kafka.eagle.sasl.enable=false
cluster1.kafka.eagle.sasl.protocol=SASL_PLAINTEXT
cluster1.kafka.eagle.sasl.mechanism=SCRAM-SHA-256
cluster1.kafka.eagle.sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required username="kafka" password="kafka-eagle";
cluster1.kafka.eagle.sasl.client.id=
cluster1.kafka.eagle.sasl.cgroup.enable=false
cluster1.kafka.eagle.sasl.cgroup.topics=

cluster2.kafka.eagle.sasl.enable=false
cluster2.kafka.eagle.sasl.protocol=SASL_PLAINTEXT
cluster2.kafka.eagle.sasl.mechanism=PLAIN
cluster2.kafka.eagle.sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="kafka" password="kafka-eagle";
cluster2.kafka.eagle.sasl.client.id=
cluster2.kafka.eagle.sasl.cgroup.enable=false
cluster2.kafka.eagle.sasl.cgroup.topics=

######################################
# kafka ssl authenticate
######################################
cluster3.kafka.eagle.ssl.enable=false
cluster3.kafka.eagle.ssl.protocol=SSL
cluster3.kafka.eagle.ssl.truststore.location=
cluster3.kafka.eagle.ssl.truststore.password=
cluster3.kafka.eagle.ssl.keystore.location=
cluster3.kafka.eagle.ssl.keystore.password=
cluster3.kafka.eagle.ssl.key.password=
cluster3.kafka.eagle.ssl.cgroup.enable=false
cluster3.kafka.eagle.ssl.cgroup.topics=

######################################
# kafka sqlite jdbc driver address
######################################
kafka.eagle.driver=org.sqlite.JDBC
kafka.eagle.url=jdbc:sqlite:/opt/kafka/kafka-eagle/db/ke.db
kafka.eagle.username=admin
kafka.eagle.password=123456

######################################
# kafka mysql jdbc driver address
######################################
#kafka.eagle.driver=com.mysql.jdbc.Driver
#kafka.eagle.url=jdbc:mysql://127.0.0.1:3306/ke?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull
#kafka.eagle.username=root
#kafka.eagle.password=123456

由于服务器上没有安装mysql因此,用sqlite即可
kafka.eagle.username=admin
kafka.eagle.password=123456
则指定了eagle登陆的用户名和密码。
监听8048端口。此外,为了eagle采集更多的kafka运行信息,需要开启kafka的jmx服务,修改每个节点kafka的启动脚本
vim /opt/kafka/apache-kafka/bin/kafka-server-start.sh
增加30行内容

 28 if [ "x$KAFKA_HEAP_OPTS" = "x" ]; then
 29     export KAFKA_HEAP_OPTS="-Xmx1G -Xms1G"
 30     export JMX_PORT="7788"
 31 fi

之后重启即可。注意每个节点都需要修改。
现在启动eagle
cd /opt/kafka/kafka-eagle/bin
执行 ke.sh 即可
初次启动,需要初始化数据库,比较慢,耐心等待即可。
eagel界面访问:
http://192.168.162.201:8048/ke/account/signin?/ke/

image.png image.png image.png

eagle的各项监控指标都比较齐全,对kafka的架构比较了解之后,很方便就能看懂。因此不再做过多介绍。

上一篇下一篇

猜你喜欢

热点阅读