首页 > 系统相关 >Linux 下 kafka 集群部署

Linux 下 kafka 集群部署

时间:2024-07-09 13:57:03浏览次数:28  
标签:log -- server #################### 集群 Linux kafka 1.1

本文将以三台服务器为例,介绍在 linux 系统下kafka的部署方式。

1. zookeeper下载

下载地址:Apache Kafka

选择需要的介质下载,这里以 kafka_2.11-1.1.1.tgz 为例

2.环境准备

   部署kafka需要先部署JDK 以及zookeeper ,JDK部署可以参考Linux下JDK 安装-CSDN博客 

zookeeper 部署可以参考 Linux 下 zookeeper 集群部署-CSDN博客

3.kafka部署

注:以下操作三台机器均需要修改

3.1 修改系统配置文件

(1)编辑 hosts 文件

         vi /etc/hosts

        添加如下内容

         ip(第一台机器)   kafka1

         ip(第二台机器)   kafka2

         ip(第三台机器)   kafka3

(2)编辑ulimit

         vi /etc/security/limits.d/20-nproc.conf

        添加如下内容

       * soft nofile 655350

       * hard nofile 655350

(3)编辑系统参数

        vi /etc/sysctl.conf

        添加如下内容

        vm.max_map_count=655350

       保存后执行命令生效

        sysctl -p

3.2 开放端口

kafka 默认需要开通节点 9092 端口

(1)查看防火墙状态

        systemctl status firewalld

(2)开放端口

       firewall-cmd --zone=public --add-port=9092/tcp --permanent  

(3)防火墙重新加载配置

       firewall-cmd --reload  

(4) 查看防火墙所有开放的端口

       firewall-cmd --zone=public --list-ports

3.3 安装 kafka

(1) 解压

       上传kafka介质( kafka_2.11-1.1.1.tgz)到 /opt 目录

       解压到当前目录下

       tar zxfv  kafka_2.11-1.1.1.tgz

(2) 配置 jvm.option

         touch /opt/kafka_2.11-1.1.1/bin/kafka-run-class.sh

         vi  /opt/kafka_2.11-1.1.1/bin/kafka-run-class.sh

         添加如下内容

export KAFKA_HEAP_OPTS="-Xmx4g -Xms4g -XX:MetaspaceSize=96m -XX:+UseG1GC -XX:MaxGCPauseMillis=20 -XX:InitiatingHeapOccupancyPercent=35 -XX:G1HeapRegionSize=16M -XX:MinMetaspaceFreeRatio=50 -XX:MaxMetaspaceFreeRatio=80"
export JMX_PORT=9988

(3) 修改 server.properties 配置文件

         vi  /opt/kafka_2.11-1.1.1/config/server.properties

         注:broker.id及listeners 修改为对应节点ID和地址,zookeeper.connect改为zk 地址

#################### Server Basics ####################

# The id of the broker. This must be set to a unique integer for each broker.
# 修改为节点ID
broker.id=1  

#################### Socket Server Settings ####################

# The address the socket server listens on. It will get the value returned from 
# java.net.InetAddress.getCanonicalHostName() if not configured.
#   FORMAT:
#     listeners = listener_name://host_name:port
#   EXAMPLE:
#     listeners = PLAINTEXT://your.host.name:9092
listeners=PLAINTEXT://kafka1:9092

# Hostname and port the broker will advertise to producers and consumers. If not set, 
# it uses the value for "listeners" if configured.  Otherwise, it will use the value
# returned from java.net.InetAddress.getCanonicalHostName().
#advertised.listeners=PLAINTEXT://your.host.name:9092

# Maps listener names to security protocols, the default is for them to be the same. See the config documentation for more details
#listener.security.protocol.map=PLAINTEXT:PLAINTEXT,SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_SSL

# The number of threads that the server uses for receiving requests from the network and sending responses to the network
num.network.threads=3

# The number of threads that the server uses for processing requests, which may include disk I/O
num.io.threads=8

# The send buffer (SO_SNDBUF) used by the socket server
socket.send.buffer.bytes=102400

# The receive buffer (SO_RCVBUF) used by the socket server
socket.receive.buffer.bytes=102400

# The maximum size of a request that the socket server will accept (protection against OOM)
socket.request.max.bytes=104857600


#################### Log Basics ####################

# A comma separated list of directories under which to store log files
log.dirs=/data/kafka

# The default number of log partitions per topic. More partitions allow greater
# parallelism for consumption, but this will also result in more files across
# the brokers.
num.partitions=1

# The number of threads per data directory to be used for log recovery at startup and flushing at shutdown.
# This value is recommended to be increased for installations with data dirs located in RAID array.
num.recovery.threads.per.data.dir=1

#################### Internal Topic Settings  ####################
# The replication factor for the group metadata internal topics "__consumer_offsets" and "__transaction_state"
# For anything other than development testing, a value greater than 1 is recommended for to ensure availability such as 3.
offsets.topic.replication.factor=3
transaction.state.log.replication.factor=3
transaction.state.log.min.isr=2

#################### Log Flush Policy ####################

# Messages are immediately written to the filesystem but by default we only fsync() to sync
# the OS cache lazily. The following configurations control the flush of data to disk.
# There are a few important trade-offs here:
#    1. Durability: Unflushed data may be lost if you are not using replication.
#    2. Latency: Very large flush intervals may lead to latency spikes when the flush does occur as there will be a lot of data to flush.
#    3. Throughput: The flush is generally the most expensive operation, and a small flush interval may lead to excessive seeks.
# The settings below allow one to configure the flush policy to flush data after a period of time or
# every N messages (or both). This can be done globally and overridden on a per-topic basis.

# The number of messages to accept before forcing a flush of data to disk
#log.flush.interval.messages=10000

# The maximum amount of time a message can sit in a log before we force a flush
#log.flush.interval.ms=1000

#################### Log Retention Policy ####################

# The following configurations control the disposal of log segments. The policy can
# be set to delete segments after a period of time, or after a given size has accumulated.
# A segment will be deleted whenever *either* of these criteria are met. Deletion always happens
# from the end of the log.

# The minimum age of a log file to be eligible for deletion due to age
log.retention.hours=168

# A size-based retention policy for logs. Segments are pruned from the log unless the remaining
# segments drop below log.retention.bytes. Functions independently of log.retention.hours.
#log.retention.bytes=1073741824

# The maximum size of a log segment file. When this size is reached a new log segment will be created.
log.segment.bytes=1073741824

# The interval at which log segments are checked to see if they can be deleted according
# to the retention policies
log.retention.check.interval.ms=300000

#################### Zookeeper ####################

# 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=zk1:2181,zk2:2181,zk3:2181

# Timeout in ms for connecting to zookeeper
zookeeper.connection.timeout.ms=6000


#################### Group Coordinator Settings ####################

# The following configuration specifies the time, in milliseconds, that the GroupCoordinator will delay the initial consumer rebalance.
# The rebalance will be further delayed by the value of group.initial.rebalance.delay.ms as new members join the group, up to a maximum of max.poll.interval.ms.
# The default value for this is 3 seconds.
# We override this to 0 here as it makes for a better out-of-the-box experience for development and testing.
# However, in production environments the default value of 3 seconds is more suitable as this will help to avoid unnecessary, and potentially expensive, rebalances during application startup.
group.initial.rebalance.delay.ms=0

(4)创建数据目录

        mkdir -p /data/kafka

(5)启动

/opt/kafka_2.11-1.1.1/bin/kafka-server-start.sh -daemon /opt/kafka_2.11-1.1.1/config/server.properties
3.4 验证

(1) 创建topic

/opt/kafka_2.11-1.1.1/bin/kafka-topics.sh --create --zookeeper zk1 --replication-factor 2 --partitions 1 --topic hello

(2) 连接producer

/opt/kafka_2.11-1.1.1/bin/kafka-console-producer.sh --broker-list kafka1:9092 --topic hello

(3) 连接consumer

/opt/kafka_2.11-1.1.1/bin/kafka-console-consumer.sh --bootstrap-server kafka2:9092 --topic hello --from-beginning

/opt/kafka_2.11-1.1.1/bin/kafka-console-consumer.sh --bootstrap-server kafka3:9092 --topic hello --from-beginning

(3) 测试

          在producer的shell中输入字符如:test

          consumer中会显示test

4. 设置服务开机自启动

注:以下操作三台机器均需要修改

(1)关闭kafka

        /opt/kafka_2.11-1.1.1/bin/kafka-server-stop.sh

(2)创建启动服务文件

      touch /etc/systemd/system/kafka.service

      vi /etc/systemd/system/kafka.service

 3)编写启动脚本

[Unit]
Description=kafka.service
After=network.target remote-fs.target

[Service]
User=root
Type=forking
ExecStart=/usr/bin/bash /opt/kafka_2.11-1.1.1/bin/kafka-server-start.sh -daemon /opt/kafka_2.11-1.1.1/config/server.properties
ExecStop=/usr/bin/bash /opt/kafka_2.11-1.1.1/bin/kafka-server-stop.sh
ExecReload=$ExecStop;$ExecStart
LimitCORE=infinity
LimitNOFILE=204800
LimitNPROC=204800

[Install]
WantedBy=multi-user.target

(4)关闭和启动服务

       启动

       systemctl start kafka.service

       停止

       systemctl stop kafka.service

       重启

       systemctl restart kafka.service

(5)设置服务是否开机启动

      添加系统服务

      systemctl enable kafka.service

      删除系统服务

      systemctl disable kafka.service

(6)重启机器

       reboot

       查看kafka是否开机自启动。

标签:log,--,server,####################,集群,Linux,kafka,1.1
From: https://blog.csdn.net/qq_59998784/article/details/140094323

相关文章

  • Pyodps2节点连接linux服务器(paramiko 检查文件是否存在)
    在maxcomputer加入paramiko相关资源包1#!/usr/bin/python2#-*-coding:UTF-8-*-34##@resource_reference{"six.zip"}5##@resource_reference{"PyNaCl-1.4.0.zip"}6##@resource_reference{"paramiko-2.7.2.zip"}7##@resource_r......
  • Linux常用命令-curl
    CURL是一个强大的命令行工具,用于在终端中与网络资源进行交互,支持多种协议和定制选项,非常适合开发者和系统管理员进行网络调试和数据传输操作。基本用法发送GET请求:curlhttp://example.com向http://example.com发送一个简单的GET请求,并输出响应内容到标准输出。保......
  • haproxy搭建Web集群
    一.案例概述    haproxy是目前比较流行的一种群集调度工具,同类工具中lvs性能更好,但搭建相对复杂;nginx的upstream模块支持群集功能,但是对群集节点健康检测功能不强,高并发性能没有Haproxy好;Haproxy的官方网站是http://www.haproxy.org/。    常见的Web群集调度......
  • linux 常用和不那么常用命令记录02 磁盘占用
    常用的磁盘相关命令du有的时候我们想要查询一个文件所占用的磁盘空间大小,可以使用du命令来查看命令配置参数du[options][filesordirectories]-h:以人类可读的格式显示输出(例如KB、MB、GB)。-s:显示总计空间,而不显示每个子目录的具体大小。-c:显示所有文件......
  • 零基础学习linux
    ##1.回顾总结指令: > 切换: su xxx /su-xxx   >> 显示当前路径: pwd  >> 显示目录内容: ll /ls >> 清屏:clear >> 目录切换: cd  >> uname-a  ==> all >> 重启关机: reboot>> 返回上一级: cd ../......
  • linux 上安装FTP : vsftpd (含常见问题:读取目录列表失败,的处理)
    服务器上有时候需要安装ftp以便调试或给不懂使用服务器命令的同学更新文件 1、安装vsftpdyumupdateyuminstallvsftpd2、编辑配置文件确保以下配置的值和下面一致anonymous_enable=NOlocal_enable=YESwrite_enable=YESchroot_local_user=YES这些配置......
  • 【Linux】:程序替换
     朋友们、伙计们,我们又见面了,本期来给大家解读一下有关Linux程序替换的相关知识点,如果看完之后对你有一定的启发,那么请留下你的三连,祝大家心想事成!C语言专栏:C语言:从入门到精通数据结构专栏:数据结构个 人 主 页 :stackY、C++专栏  :C++Linux专 栏 :L......
  • Linux 设置环境变量
    1.Linux设置环境变量1.1.export命令1.2.直接使用export命令设置环境变量1.3.修改配置文件设置环境变量1.Linux设置环境变量1.1.export命令export命令用于设置或显示环境变量。用法:export[-fn][name[=value]...]或export-p选项:-f: refertos......
  • Linux环境中应急响应与排查溯源思路总结
    0前言在应急响应和溯源时,经常会遇见Linux系统环境,然后小编经常只记得思路忘记部分命令,下面是小编对Linux环境下应急响应和排查的思路总结。本文来源无问社区(wwlib.cn)更多详细内容可前往观看http://www.wwlib.cn/index.php/artread/artid/2729.html1目录文件分析1.1系统用......
  • 应用程序会不会导致linux内核崩溃?
    应用程序有可能导致Linux内核崩溃,但这种情况并不是绝对的,它取决于多种因素。应用程序或Linux内核本身都可能存在bug。当应用程序的某部分逻辑与内核的某部分逻辑发生冲突时,有可能导致内核崩溃。例如,应用程序可能尝试访问非法的内存地址,或者触发内核中的某个未修复的错误。这......