kafka-0.10.2.2集群搭建
程序员文章站
2022-06-14 10:53:45
...
1.部署规划:
服务器ip | tcp链接端口 |
---|---|
192.168.1.111 | 9092 |
192.168.1.112 | 9092 |
192.168.1.113 | 9092 |
2.前提条件:
- 各服务器开放端口(9092),或防火墙关闭。
- 各服务器添加主机名,能互相ping通:
192.168.1.111 linux1
192.168.1.112 linux2
192.168.1.113 linux3
3.安装kafka:
3.1 新建kafka用户:
三台机器都执行此操作:
[[email protected] install_files]# useradd kafka
[[email protected] install_files]# passwd kafka
Changing password for user kafka.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
3.2 解压缩安装包:
[[email protected] install_files]$ cd /home/kafka/
[[email protected] ~]$ ll
total 0
[[email protected] ~]$ tar -xzvf /home/install_files/kafka_2.12-0.10.2.2.tgz
[[email protected] ~]$ ll
total 4
drwxr-xr-x. 7 kafka kafka 4096 Sep 20 20:14 kafka_2.12-0.10.2.2
3.3 修改配置文件:
[[email protected] ~]$ cd kafka_2.12-0.10.2.2/config/
[[email protected] config]$ ll
total 60
-rw-r--r--. 1 kafka kafka 906 Jun 22 2018 connect-console-sink.properties
-rw-r--r--. 1 kafka kafka 909 Jun 22 2018 connect-console-source.properties
-rw-r--r--. 1 kafka kafka 2760 Jun 22 2018 connect-distributed.properties
-rw-r--r--. 1 kafka kafka 883 Jun 22 2018 connect-file-sink.properties
-rw-r--r--. 1 kafka kafka 881 Jun 22 2018 connect-file-source.properties
-rw-r--r--. 1 kafka kafka 1074 Jun 22 2018 connect-log4j.properties
-rw-r--r--. 1 kafka kafka 2061 Jun 22 2018 connect-standalone.properties
-rw-r--r--. 1 kafka kafka 1199 Jun 22 2018 consumer.properties
-rw-r--r--. 1 kafka kafka 4369 Jun 22 2018 log4j.properties
-rw-r--r--. 1 kafka kafka 1900 Jun 22 2018 producer.properties
-rw-r--r--. 1 kafka kafka 5694 Sep 21 01:20 server.properties
-rw-r--r--. 1 kafka kafka 1032 Jun 22 2018 tools-log4j.properties
-rw-r--r--. 1 kafka kafka 1023 Jun 22 2018 zookeeper.properties
[[email protected] config]$ vim server.properties
修改如下位置:
# A comma seperated list of directories under which to store log files
# kafaka日志文件的位置
log.dirs=/home/kafka/kafka_2.12-0.10.2.2/logs
# Zookeeper connection string (see zookeeper docs for details).
# This is a comma separated host:port pairs, each corresponding to a zk
# server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002".
# You can also append an optional chroot string to the urls to specify the
# root directory for all kafka znodes.
# zookeeper集群的地址
zookeeper.connect=192.168.1.111:2181,192.168.1.112:2181,192.168.1.113:2181
3.4 启动测试:
[[email protected] ~]$ cd /home/kafka/kafka_2.12-0.10.2.2/bin
[[email protected] bin]$ ./kafka-server-start.sh ../config/server.properties
...启动日志输出
以上操作为前台启动,新打开会话窗口,检查端口占用:
[[email protected] ~]$ lsof -i:9092
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 3149 kafka 158u IPv6 45885 0t0 TCP *:XmlIpcRegSvc (LISTEN)
java 3149 kafka 159u IPv6 45886 0t0 TCP linux1:XmlIpcRegSvc->linux2:51497 (ESTABLISHED)
java 3149 kafka 166u IPv6 45892 0t0 TCP linux1:34521->linux2:XmlIpcRegSvc (ESTABLISHED)
java 3149 kafka 167u IPv6 45893 0t0 TCP linux1:53346->linux3:XmlIpcRegSvc (ESTABLISHED)
说明已经启动成功。
切换为后台启动:
[[email protected] ~]$ cd /home/kafka/kafka_2.12-0.10.2.2/bin
[[email protected] bin]$ nohup ./kafka-server-start.sh ../config/server.properties &
3.5 集群环境配置
3.5.1 拷贝kafka环境到其他服务器:
将111的kafka安装环境分别拷贝到112、113服务器。
[[email protected] ~]$ scp -r kafka_2.12-0.10.2.2 [email protected]:/home/kafka/
[email protected]'s password:
...
3.5.2 修改集群配置:
在三台服务器分别执行以下操作:
[[email protected] kafka_2.12-0.10.2.2]$ cd /home/kafka/kafka_2.12-0.10.2.2/config
[[email protected] config]$ vim server.properties
修改如下位置:
# The id of the broker. This must be set to a unique integer for each broker.
# 这里设置broker的id,不能重复,111、112、113分别设置为:0、1、2
broker.id=0
然后分别启动112、113的kafka服务。
3.6 管控台插件kafka-manager安装使用:
安装过程也较为复杂,参照另一篇博客: https://blog.csdn.net/u012374672/article/details/101197023
上一篇: Drawable
下一篇: 《kafka权威指南》之基本配置和调优