Kafka-Listener配置参数、配置公网访问以及可能出现的问题

核心参数

listeners

Listener List - Comma-separated list of URIs we will listen on and the listener names. If the listener name is not a security protocol, listener.security.protocol.map must also be set. Specify hostname as 0.0.0.0 to bind to all interfaces. Leave hostname empty to bind to default interface. Examples of legal listener lists: PLAINTEXT://myhost:9092,SSL://:9091 CLIENT://0.0.0.0:9092,REPLICATION://localhost:9093

简要说明
配置需要监听的URI

参数格式

  • 使用逗号分隔的URI列表
  • 协议名称://主机名:端口、listener名称://主机名:端口
  • 不同主机名可以绑定相同端口

附加说明

  • 如果列表中存在使用相同协议的listener,必须要在listener.security.protocol.map中定义不同的名称
  • 可以使用0.0.0.0的ip绑定所有网卡
advertised.listeners

Listeners to publish to ZooKeeper for clients to use, if different than the listeners config property. In IaaS environments, this may need to be different from the interface to which the broker binds. If this is not set, the value for listeners will be used. Unlike listeners it is not valid to advertise the 0.0.0.0 meta-address.
简要说明
该参数是将listener发布到Zk中,供client使用

参数格式

  • 参数值必须为listeners中定义的某个listener 或者 对应name的listener在listeners中的定义使用了0.0.0.0作为host,在advertised.listeners中可以指定某个网卡ip
  • 不能使用host为0.0.0.0的listener
listener.security.protocol.map

Map between listener names and security protocols. This must be defined for the same security protocol to be usable in more than one port or IP. For example, internal and external traffic can be separated even if SSL is required for both. Concretely, the user could define listeners with names INTERNAL and EXTERNAL and this property as: INTERNAL:SSL,EXTERNAL:SSL. As shown, key and value are separated by a colon and map entries are separated by commas. Each listener name should only appear once in the map. Different security (SSL and SASL) settings can be configured for each listener by adding a normalised prefix (the listener name is lowercased) to the config name. For example, to set a different keystore for the INTERNAL listener, a config with name listener.name.internal.ssl.keystore.location would be set. If the config for the listener name is not set, the config will fallback to the generic config (i.e. ssl.keystore.location)

简单说明
该参数用于listener name与安全协议之间进行映射。

参数格式
键值是通过冒号进行分隔的,键值对之间通过逗号进行分隔。协议的合法取值为:PLAINTEXT, SSL, SASL_PLAINTEXT, SASL_SSL

附加说明

  • 安全参数的配置通过添加前缀进行设置,比如配置LISTENER_A的ssl.keystore.location的参数:listener.name.listener_a.ssl.keystore.location,listener name需要转成小写。
inter.broker.listener.name

Name of listener used for communication between brokers. If this is unset, the listener name is defined by security.inter.broker.protocol. It is an error to set this and security.inter.broker.protocol properties at the same time

简单说明
该参数是用来设置broker之间进行通信时采用的listener名称
参数格式
listener name
附加说明
如果该参数没有设置,则采用security.inter.broker.protocol配置。同时设置inter.broker.listener.name和security.inter.broker.protocol会出现错误。listener必须要在advertised.listeners中进行配置,否则会出现inter.broker.listener.name must be a listener name defined in advertised.listeners. The valid options based on currently configured listeners are A,B的错误。

配置外网访问

配置实例
listeners=PRIVATE://0.0.0.0:9092,PUBLIC://0.0.0.0:9093
advertised.listeners=PRIVATE://192.168.16.4:9092,PUBLIC://180.77.248.246:9093
listener.security.protocol.map=PRIVATE:PLAINTEXT,PUBLIC:PLAINTEXT
inter.broker.listener.name=PRIVATE
可能会出现的问题
listener_name不能相同

这个是因为我使用了PLAINTEXT作为多个listener的名称,但是当使用协议名称作为listener名称时,只能使用一次,因为本身listener名称是不能重复。一般情况下,我们还是自己在listener.security.protocol.map中进行listener name和协议的映射。

inter.broker.listener.name must be a listener name defined in advertised.listeners. The valid options based on currently configured listeners are PRIVATE,PUBLIC

这是因为我使用了自定义的listener name定义的listener,一般来说默认inter.broker.listener.name为PLAINTEXT,如果我们在listener列表中没有定义名称为PLAINTEXT的listener,就会抛出该异常。

advertised.listeners listener names must be equal to or a subset of the ones defined in listeners

该问题是我误解了listener host的意义导致的,我一开始的理解是,该host是用于过滤客户机的ip地址,只有用于定义listener的客户机ip才能进行连接,有点白名单的意思,listeners是内网ip白名单,advertised.listeners是外网ip白名单,这个理解当然是错误的。我们在定义时,必须遵照规则:

参数值必须为listeners中定义的某个listener 或者 对应name的listener在listeners中的定义使用了0.0.0.0作为host,在advertised.listeners中可以指定某个网卡ip

参考来源:
1、https://www.codercto.com/a/68756.html
2、http://kafka.apache.org/documentation/#configuration

### 内外网的概念及其配置 #### 一、内外网的基本概念 公网地址(Public IP)是指可以直接连接到互联网上的唯一标识符,用于全球范围内的设备通信。私网地址(Private IP),也称为局域网地址,则是在特定范围内有效,通常仅限于企业内部或家庭网络中的设备间通信[^2]。 两者的主要区别在于使用范围和分配方式上有所不同: - **公网地址**由国际标准化组织统一规划并分配给各个国家和地区运营商管理; - **私网地址**则无需向外界申请注册即可自由设定,在RFC1918文档中有明确规定哪些区间属于保留专用用途而不参与广义互联通讯协议栈运作之中。 #### 二、Kafka 的内外网访问配置 对于 Kafka 而言,其 `listeners` 参数决定了服务会绑定在哪张网卡之上进行消息收发操作。如果希望支持来自不同区域客户端请求接入,则需合理设置该参数值来满足实际需求场景下的灵活性要求: 当 Kafka 宿主机具备真实物理意义上的外部接口时,可以通过指定 EXTERNAL 类型 listener 使用对应的真实外网 IP 地址完成相关部署工作;反之如果没有实体硬件层面的支持而是依靠 NAT 技术实现虚拟转换而来的话,则应该坚持采用本地回环或者内联网段作为主要联系方式之一以保障整体架构稳定性的同时也能充分利用已有资源条件达成目标效果[^1]。 具体示例如下所示: ```properties # 配置文件片段 listeners=INTERNAL://192.168.0.213:9092,EXTERNAL://<public-ip>:9093 advertised.listeners=INTERNAL://192.168.0.213:9092,EXTERNAL://<public-ip>:9093 listener.security.protocol.map=INTERNAL:PLAINTEXT,EXTERNAL:SSL ``` 上述例子展示了如何定义多个监听器以便分别处理来自内部与外部用户的连接请求,并且还可以根据不同安全等级的需求选用适合的安全传输机制加以保护数据交换过程中的隐私性和完整性[^3]。 #### 三、Windows 平台下同时访问内外网的方法 为了使 Windows 主机能顺利地在同一时间既能够正常浏览网页又能稳定运行公司内部业务系统等功能模块之间相互独立却又彼此关联密切的关系链路当中去,可通过增加一条持久化静态路由规则的方式解决可能存在的冲突问题: 执行命令如下: ```cmd route add -p <external-network> mask 255.255.255.0 <gateway> ``` 这里 `<external-network>` 应替换为目标子网段前缀部分数值形式表达出来; 同样地也需要填写好通往那里所经过的第一个跳转节点位置信息即默认网关地址[`^4`]。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

木子的木木

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值