CentOS 7搭建kafka集群
原创 莫问 记录栈 2022-11-16 19:49 发表于陕西 收录于合集 #centos6个 #kafka1个 #linux9个 #kafka集群1个/**
*@系统:CentOS Linux release 7.9.2009 (Core)
*@说明:jdk-11.0.12 | apache-zookeeper-3.7.1 | kafka_2.12-3.3.1
* 注意:因为有大部分操作是相同的,所以使用的是工具的批操作
*/
一、准备工作
1. 下载 jdk11
https://www.oracle.com/java/technologies/javase/jdk11-archive-downloads.html#license-lightbox
2. 下载 zookeeper
https://www.apache.org/dyn/closer.lua/zookeeper/zookeeper-3.7.1/apache-zookeeper-3.7.1-bin.tar.gz
3. 下载 kafka
https://downloads.apache.org/kafka/3.3.1/kafka_2.12-3.3.1.tgz
4. 修改主机名
# hostnamectl set-hostname kafka01
# hostnamectl set-hostname kafka02
# hostnamectl set-hostname kafka03
5. 修改 hosts
# vim /etc/hosts
==== content ====
192.168.137.129 kafka01
192.168.137.130 kafka02
192.168.137.131 kafka03
==== / ====
6. 开放防火墙端口
# 生产环境注意修改zookeeper和kafka的端口
# firewall-cmd --zone=public --add-port=2881/tcp --permanent
# firewall-cmd --zone=public --add-port=3881/tcp --permanent
# firewall-cmd --zone=public --add-port=9092/tcp --permanent
# firewall-cmd --reload
二、安装 jdk11
1. 安装
# rpm -ivh jdk-11.0.12_linux-x64_bin.rpm
2. 添加环境变量
# ls /usr/java
# vim /etc/profile
==== content ====
export JAVA_HOME=/usr/java/jdk-11.0.12
export PATH=$PATH:$JAVA_HOME/bin
==== / ====
# . /etc/profile ##source /etc/profile
3. 验证
# java -version
java version "11.0.12" 2021-07-20 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.12+8-LTS-237)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.12+8-LTS-237, mixed mode)
# cd $JAVA_HOME
# pwd
/usr/java/jdk-11.0.12
三、安装 zookeeper
1. 安装
# tar -zxf apache-zookeeper-3.7.1-bin.tar.gz -C /usr/local
# cd /usr/local/
# mv apache-zookeeper-3.7.1-bin zookeeper
2. 修改配置文件
# cd /usr/local/zookeeper/conf/
# cp zoo_sample.cfg zoo.cfg
# mkdir -p /var/zookeeper/data
# 在对应的三台机子上分别执行
# kafka01
# vim zoo.cfg
==== content ====
dataDir=/var/zookeeper/data
server.1=0.0.0.0:2881:3881
server.2=192.168.137.130:2881:3881
server.3=192.168.137.131:2881:3881
==== / ====
# echo 1 > /var/zookeeper/data/myid
# cat /var/zookeeper/data/myid
1
# kafka02
# vim zoo.cfg
==== content ====
dataDir=/var/zookeeper/data
server.1=192.168.137.129:2881:3881
server.2=0.0.0.0:2881:3881
server.3=192.168.137.131:2881:3881
==== / ====
# echo 2 > /var/zookeeper/data/myid
# cat /var/zookeeper/data/myid
2
# kafka03
# vim zoo.cfg
==== content ====
dataDir=/var/zookeeper/data
server.1=192.168.137.129:2881:3881
server.2=192.168.137.130:2881:3881
server.3=0.0.0.0:2881:3881
==== / ====
# echo 3 > /var/zookeeper/data/myid
# cat /var/zookeeper/data/myid
3
3. 添加系统服务
# cd /etc/systemd/system
# vim zookeeper.service
==== content ====
[Unit]
Description=Zookeeper Service
[Service]
Type=simple
WorkingDirectory=/usr/local/zookeeper/
PIDFile=/var/zookeeper/data/zookeeper_server.pid
SyslogIdentifier=zookeeper
ExecStart=/usr/local/zookeeper/bin/zkServer.sh start
ExecStop=/usr/local/zookeeper/bin/zkServer.sh stop
Restart=always
TimeoutSec=20
SuccessExitStatus=130 143
[Install]
WantedBy=multi-user.target
==== / ====
# systemctl daemon-reload
# systemctl enable zookeeper.service
Created symlink from /etc/systemd/system/multi-user.target.wants/zookeeper.service to /etc/systemd/system/zookeeper.service.
四、安装 kafka
1. 安装
# tar -zxf kafka_2.13-3.3.1.tgz -C /usr/local/
# mv kafka_2.13-3.3.1 kafka
2. 修改配置文件
# cd /usr/local/kafka/config
# vim server.properties
==== content ====
# kafka01
broker.id=0
# listeners=PLAINTEXT://:9092
listeners=PLAINTEXT://192.168.137.129:9092
# advertised.listeners=PLAINTEXT://your.host.name:9092
advertised.listeners=PLAINTEXT://192.168.137.129:9092
# log.dirs=/tmp/kafka-logs
log.dirs=/var/kafka/logs
# zookeeper.connect=localhost:2181
zookeeper.connect=192.168.137.129:2181,192.168.137.130:2181,192.168.137.131:2181/mykafka
----------
# kafka02
broker.id=1
# listeners=PLAINTEXT://:9092
listeners=PLAINTEXT://192.168.137.130:9092
# advertised.listeners=PLAINTEXT://your.host.name:9092
advertised.listeners=PLAINTEXT://192.168.137.130:9092
# log.dirs=/tmp/kafka-logs
log.dirs=/var/kafka/logs
# zookeeper.connect=localhost:2181
zookeeper.connect=192.168.137.129:2181,192.168.137.130:2181,192.168.137.131:2181/mykafka
----------
# kafka03
broker.id=2
# listeners=PLAINTEXT://:9092
listeners=PLAINTEXT://192.168.137.131:9092
# advertised.listeners=PLAINTEXT://your.host.name:9092
advertised.listeners=PLAINTEXT://192.168.137.131:9092
# log.dirs=/tmp/kafka-logs
log.dirs=/var/kafka/logs
# zookeeper.connect=localhost:2181
zookeeper.connect=192.168.137.129:2181,192.168.137.130:2181,192.168.137.131:2181/mykafka
==== / ====
3. 添加系统服务
# cd /etc/systemd/system
# vim kafka.service
==== content ====
[Unit]
Requires=zookeeper.service
After=zookeeper.service
[Service]
Type=simple
ExecStart=/usr/local/kafka/bin/kafka-server-start.sh /usr/local/kafka/config/server.properties
ExecStop=/usr/local/kafka/bin/kafka-server-stop.sh
Restart=Always
TimeoutSec=20
[Install]
WantedBy=multi-user.target
==== / ====
# systemctl daemon-reload
# systemctl enable kafka.service
Created symlink from /etc/systemd/system/multi-user.target.wants/kafka.service to /etc/systemd/system/kafka.service.
# init 6
4. 验证
# kafka01
# jps
8977 Jps
716 QuorumPeerMain
8623 Kafka
# kafka02
# jps
8251 Kafka
718 QuorumPeerMain
8607 Jps
# kafka03
# jps
8994 Kafka
9315 Jps
712 QuorumPeerMain
# systemctl status zookeeper.service
● zookeeper.service - Zookeeper Service
Loaded: loaded (/etc/systemd/system/zookeeper.service; enabled; vendor preset: disabled)
Active: active (running)
# systemctl status kafka.service
● kafka.service - Kafka service
Loaded: loaded (/etc/systemd/system/kafka.service; enabled; vendor preset: disabled)
Active: active (running)
-未完待续-
=推荐阅读=
=================================
=================================
记录栈 记录Linux技术、PHP技术、数据库技术、前端技术、PS技巧、IT技巧等...... 37篇原创内容 公众号收录于合集 #centos 6个 上一篇华为云HECS基于Nginx部署zabbix5.0监控下一篇CentOS 7安装部署vsftpd服务 阅读 46 记录栈 37篇原创内容 标签:service,zookeeper,192.168,kafka,Centos7,集群,usr,var From: https://www.cnblogs.com/cherishthepresent/p/17219900.html