Kafka集群安装和配置

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Kafka集群安装和配置相关的知识,希望对你有一定的参考价值。

(一)、环境介绍
1、服务器的相关设置:
1、kafka1:172.20.67.52
2、kafka2:172.20.67.56
3、kafka3:172.20.67.57

2、zookeeper所需的三个端口
1、2181
2、2888
3、3888
三个端口的作用:
2181:对客户端提供服务
2888:集群内机器通讯使用(Leader监听此端口)
3888:选举leader使用

3、kafka 所需的端口
9092:kafka所需的端口

(二)、kafka集群的安装配置
(1)、kafka1172.20.67.52的安装及相关配置

1、去官网下载相应的版本(https://kafka.apache.org/downloads )。我已下载好直接使用kafka_2.11-0.11.0.3版本

2、解压并放到相应的目录

    [[email protected] opt]# tar xf kafka_2.11-0.11.0.3.tgz
    [[email protected] opt]# mv kafka_2.11-0.11.0.3  /usr/local/kafka

3、zookeeper的相关配置

[[email protected] kafka]# vim /usr/local/kafka/config/zookeeper.properties
dataDir=/data/zookeeper
clientPort=2181
maxClientCnxns=0
tickTime=2000
initLimit=20
syncLimit=10
server.1=172.20.67.52:2888:3888
server.2=172.20.67.56:2888:3888
server.3=172.20.67.57:2888:3888

4、kafka的相关配置

[[email protected] kafka]# vim /usr/local/kafka/config/server.properties 
broker.id=1
host.name=172.20.67.52
listeners=PLAINTEXT://172.20.67.52:9092
log.dirs=/data/kafka-logs
log.retention.check.interval.ms=300000
log.retention.hours=1
log.segment.bytes=1073741824
num.io.threads=4
default.replication.factor=2
num.network.threads=3
num.partitions=30
num.recovery.threads.per.data.dir=1
port=9092
socket.receive.buffer.bytes=102400
socket.request.max.bytes=104857600
socket.send.buffer.bytes=102400
zookeeper.connect=172.20.67.52:2181,172.20.67.56:2181,172.20.67.57:2181
zookeeper.connection.timeout.ms=10000
fetch.message.max.bytes=52428700
replica.fetch.max.bytes=52428700

5、启动时加入到/etc/rc.local

[[email protected] config]# vim /etc/rc.local
cd /var/tmp;nohup /usr/local/kafka/bin/zookeeper-server-start.sh /usr/local/kafka/config/zookeeper.properties &
cd /tmp;nohup /usr/local/kafka/bin/kafka-server-start.sh /usr/local/kafka/config/server.properties &
touch /var/lock/subsys/local

6、依次创建zookeeper的数据目录/data/zookeeper和文件/data/zookeeper/myid,此时我们需要对应的Zookeeper服务器上在dataDir的目录下面新建myid文件,同时把对应的1、2、3写进去。

[[email protected] config]# mkdir -p /data/zookeeper
[[email protected] config]# vim /data/zookeeper/myid
1

7、依次启动集群的kafka1、kafka2、kafka3 的zookeeper


[[email protected] config]# /usr/local/kafka/bin/zookeeper-server-start.sh    /usr/local/kafka/config/zookeeper.properties  &

8、然后在依次启动集群的kafka1、kafka2、kafka3 的kafka服务

[[email protected] config]# cd /tmp;nohup /usr/local/kafka/bin/kafka-server-start.sh /usr/local/kafka/config/server.properties &

9、最后依次按照2、3、4、5、6、7、8的步骤依次在kafka2(172.20.67.56)和kafka3(172.20.67.57)依次安装配置zookeeper和kafka的配置文件和启动。

[[email protected] opt]# jps
31234 Jps
30298 QuorumPeerMain
30573 Kafka

10、查看集群所启动的端口

kafka1
[[email protected] ~]# netstat -lntp|grep java
tcp6       0      0 172.20.67.52:3888       :::*                    LISTEN      20184/java          
tcp6       0      0 127.0.0.1:9600          :::*                    LISTEN      20143/java          
tcp6       0      0 172.20.67.52:9092       :::*                    LISTEN      20649/java          
tcp6       0      0 :::35300                :::*                    LISTEN      20649/java          
tcp6       0      0 :::2181                 :::*                    LISTEN      20184/java          
tcp6       0      0 :::46471                :::*                    LISTEN      20184/java 

kafka2
[[email protected] ~]# netstat -lntp|grep java
tcp6       0      0 172.20.67.56:3888       :::*                    LISTEN      30298/java          
tcp6       0      0 :::33395                :::*                    LISTEN      30298/java          
tcp6       0      0 :::43031                :::*                    LISTEN      30573/java          
tcp6       0      0 172.20.67.56:9092       :::*                    LISTEN      30573/java          
tcp6       0      0 :::2181                 :::*                    LISTEN      30298/java  

kafka3
[[email protected] ~]# netstat -lntp|grep java
tcp6       0      0 172.20.67.57:3888       :::*                    LISTEN      26313/java          
tcp6       0      0 :::44194                :::*                    LISTEN      26313/java          
tcp6       0      0 172.20.67.57:9092       :::*                    LISTEN      26883/java          
tcp6       0      0 :::2181                 :::*                    LISTEN      26313/java          
tcp6       0      0 172.20.67.57:2888       :::*                    LISTEN      26313/java          
tcp6       0      0 :::36041                :::*                    LISTEN      26883/java  

以上是关于Kafka集群安装和配置的主要内容,如果未能解决你的问题,请参考以下文章

Kafka安装和集群的相关配置

kafka集群配置和使用

KafkaZK和Kafka集群的安装和配置

kafka单点集群配置

ELK之七------Zookeeper和Kafka安装与配置

KafKa集群安装配置