当前位置:网站首页>Pulsar的Proxy支持和SNI路由
Pulsar的Proxy支持和SNI路由
2022-07-01 02:20:00 【swadian2008】
目录
(1)为 layer-4 SNI routing 设置 ATS Proxy
(2)使用 SNI routing 配置 Pulsar-client
(2)使用 SNI routing 进行 geo-replication
代理服务器是一种中介服务器,它跨Internet将来自多个客户端的请求转发到不同的服务器。代理服务器在正向和反向代理场景中都扮演着“交通警察”的角色,并为您的系统带来了负载平衡、性能、安全性、自动扩容和缩容等好处。
Pulsar中的代理充当反向代理,并在 brokers 面前创建一个网关。Pulsar不支持 Apache Traffic Server(ATS)、HAProxy、Nginx 和 Envoy 等代理。但这些代理服务器都支持 SNI 路由(SNI routing)。SNI 路由用于将流量路由到目标,而无需终止SSL连接。第4层路由提供了更大的透明度,因为出站连接是通过检查 clent TCP 数据包中的目标地址来确定的。
Pulsar客户端(Java、C++、Python)支持SNI路由协议,因此您可以通过 proxy 连接到 brokers 。本文档将指导你如何设置 ATS 代理、启用 SNI 路由以及通过ATS代理将 Pulsar client 连接到broker 。
Pulsar 中的 ATS-SNI Routing
为了支持带有 ATS 的第4层 SNI 路由(layer-4 SNI routing),入站连接必须是TLS连接。Pulsar client 支持基于 TLS 连接的 SNI 路由协议,因此当 Pulsar client 通过 ATS 代理连接到 broker 时,Pulsar 将 ATS 用作反向代理。
Pulsar 支持 SNI 路由进行地域复制(geo-replication),因此 brokers 可以通过 ATS proxy 连接到其他集群中的 brokers。
本节介绍如何设置和使用 ATS 作为反向代理,以便 Pulsar clients 可以使用基于 TLS 连接的 SNI 路由协议通过 ATS proxy 连接到 brokers。
(1)为 layer-4 SNI routing 设置 ATS Proxy
为了支持 layer-4 SNI routing 你需要配置 records.conf and ssl_server_name.conf files.

The records.config file is located in the /usr/local/etc/trafficserver/ directory by default. 该文件列出了 ATS 使用的可配置变量。
配置 records.config files,请完成以下步骤。
- 更改 proxy 侦听的 TLS 端口(
http.server_ports),修改 proxy certs (ssl.client.cert.pathandssl.client.cert.filename) 确保 TLS 通畅(TLS tunneling)。 - 配置 tunneling to the broker 的服务端口,如果 Pulsar brokers 正在监听
4443和6651 端口,在http.connect_ports 配置中添加brokers 服务端口。
下面是一个示例。
# PROXY TLS PORT
CONFIG proxy.config.http.server_ports STRING 4443:ssl 4080
# PROXY CERTS FILE PATH
CONFIG proxy.config.ssl.client.cert.path STRING /proxy-cert.pem
# PROXY KEY FILE PATH
CONFIG proxy.config.ssl.client.cert.filename STRING /proxy-key.pem
# The range of origin server ports that can be used for tunneling via CONNECT. # Traffic Server allows tunnels only to the specified ports. Supports both wildcards (*) and ranges (e.g. 0-1023).
CONFIG proxy.config.http.connect_ports STRING 4443 6651ssl_server_name 文件用来配置处理入站和出站的 TLS 连接,配置(configuration)由入站连接提供的 SNI 值确定。该文件由一些列配置项组成,每个配置项由 SNI 值(fqdn)标识。建立入站TLS连接时,TLS 协商中的 SNI 值将与此文件中指定的项进行匹配。如果值匹配,则该项中指定的值将覆盖默认值。
下面的示例显示了来自 client 的入站 SNI 主机名的映射,以及应该重定向请求的实际 broker 服务URL。比如,如果 client 端发送 SNI header pulsar-broker1,则 proxy 将请求重定向到 pulsar-broker1:6651 service URL 来创建 TLS 隧道(tunnel )。
server_config = {
{
fqdn = 'pulsar-broker-vip',
# Forward to Pulsar broker which is listening on 6651
tunnel_route = 'pulsar-broker-vip:6651'
},
{
fqdn = 'pulsar-broker1',
# Forward to Pulsar broker-1 which is listening on 6651
tunnel_route = 'pulsar-broker1:6651'
},
{
fqdn = 'pulsar-broker2',
# Forward to Pulsar broker-2 which is listening on 6651
tunnel_route = 'pulsar-broker2:6651'
},
}
在你配置 ssl_server_name.config and records.config 文件后,ATS-proxy 服务器处理 SNI 路由并在 client 端和 broker 之间创建 TCP 隧道(TCP tunnel)。
(2)使用 SNI routing 配置 Pulsar-client
ATS SNI-routing 仅适用于TLS。你首先需要为 ATS proxy 和 brokers 启用 TLS,配置 SNI 路由协议,然后通过 ATS proxy 将 Pulsar clients 连接到 brokers 。Pulsar clients 支持 SNI 路由,可以通过连接 proxy 并将目标 broker URL发送到 SNI header。此过程由内部处理。当你使用 SNI routing protocol 创建 Pulsar client 时,你仅仅只需要初始化以下配置。
String brokerServiceUrl = “pulsar+ssl://pulsar-broker-vip:6651/”;
String proxyUrl = “pulsar+ssl://ats-proxy:443”;
ClientBuilder clientBuilder = PulsarClient.builder()
.serviceUrl(brokerServiceUrl)
.tlsTrustCertsFilePath(TLS_TRUST_CERT_FILE_PATH)
.enableTls(true) // 开启TLS
.allowTlsInsecureConnection(false)
.proxyServiceUrl(proxyUrl, ProxyProtocol.SNI) // 代理配置
.operationTimeout(1000, TimeUnit.MILLISECONDS);
Map<String, String> authParams = new HashMap();
authParams.put("tlsCertFile", TLS_CLIENT_CERT_FILE_PATH);
authParams.put("tlsKeyFile", TLS_CLIENT_KEY_FILE_PATH);
clientBuilder.authentication(AuthenticationTls.class.getName(), authParams);
PulsarClient pulsarClient = clientBuilder.build();
(2)使用 SNI routing 进行 geo-replication
你可以使用 ATS proxy 进行 geo-replication 。Pulsar brokers 可以通过使用 SNI 路由连接到 geo-replication 中的 brokers。为确保 broker 的 SNI 路由能够跨集群连接,你需要将 SNI proxy URL 配置为集群元数据(cluster metadata)。如果在集群元数据中配置了 SNI proxy URL,则可以通过 SNI 路由上的 proxy 跨集群连接到 broker 。

在这个例子中,一个 Pulsar 集群被部署到两个独立的区域 us-west 和 us-east,两个区域都配置了ATS proxy,每个区域的 brokers 都支持 ATS proxy。我们在两个集群中都配置了集群元数据,所以在任何一个集群中的 brokers 都能使用 SNI routing 并且通过 ATS proxy 连接到另一个集群的 brokers。
(a) Configure the cluster metadata for us-east with us-east broker service URL and us-east ATS proxy URL with SNI proxy-protocol. // 配置集群元数据
./pulsar-admin clusters update \
--broker-url-secure pulsar+ssl://east-broker-vip:6651 \
--url http://east-broker-vip:8080 \
--proxy-protocol SNI \
--proxy-url pulsar+ssl://east-ats-proxy:443
(b) Configure the cluster metadata for us-west with us-west broker service URL and us-west ATS proxy URL with SNI proxy-protocol.
./pulsar-admin clusters update \
--broker-url-secure pulsar+ssl://west-broker-vip:6651 \
--url http://west-broker-vip:8080 \
--proxy-protocol SNI \
--proxy-url pulsar+ssl://west-ats-proxy:443
边栏推荐
- SWT/ANR问题--ANR/JE引发SWT
- CentOS installs multiple versions of PHP and switches
- Objects and object variables
- Live shopping mall source code, realize left-right linkage of commodity classification pages
- What are the applications of SMS in enterprises?
- 十大券商有哪些?另外想问,现在在线开户安全么?
- The latest CSDN salary increase technology stack in 2022 overview of APP automated testing
- 静态域与静态方法
- Short message sending solution in medical his industry
- SWT/ANR问题--AMS/WMS
猜你喜欢

Batch import of Excel data in applet

Analysis on user behavior loss of data exploration e-commerce platform

如何在智汀中实现智能锁与灯、智能窗帘电机场景联动?

How does the property send a text message to the owner?

VirtualBox installation enhancements

House change for agricultural products? "Disguised" house purchase subsidy!

小程序云开发之--微信公众号文章采集篇

机器学习10-信念贝叶斯分类器

@The difference between configurationproperties and @value

How to realize the scene linkage of intelligent lock, lamp and intelligent curtain motor in zhiting?
随机推荐
Pytoch -- foundation refers to the north_ II. What high school students can understand [back propagation and gradient descent]
go导入自建包
(翻译)实时内联验证更容易让用户犯错的原因
Find the length of the common part of two line segments
QT web development - VIDEO - Notes
機器學習10-信念貝葉斯分類器
Calculate special bonus
(translation) reasons why real-time inline verification is easier for users to make mistakes
Video tutorial | Chang'an chain launched a series of video tutorial collections (Introduction)
What is the difference between port number and process number?
halcon变量窗口的图像变量不显示,重启软件和电脑都没用
7-2 punch in reward DP for puzzle a
LabVIEW计算相机图像传感器分辨率以及镜头焦距
Leetcode 面试题 17.10. 主要元素
十大劵商如何开户?还有,在线开户安全么?
SWT/ANR问题--Deadlock
SWT / anr problem - binder stuck
How do I open an account on my mobile phone? Also, is it safe to open an account online?
CorelDRAW 2022 Chinese Simplified 64 bit direct download
What are the preferential activities for stock account opening? In addition, is it safe to open a mobile account?