背景:frpc可以做负载均衡,防止单frpc节点宕机影响业务,但frps仍然是单点,为了解决这个问题,本文以阿里云上部署为例,防止frps存在单点情况。

配置:一个公网可访问的阿里云SLB(负载均衡,公网IP为1.1.1.1),2台1核0.5G的ECS(公网IP为2.2.2.2,3.3.3.3),4台线下机房的1核0.5G的虚拟机,业务端口为TCP 30000和35000,业务部署虚拟机两台(IP分别为10.10.10.2和10.10.10.3),云上的安全组和防火墙已经完成开放;

一、线下机房进行frpc配置

1、使用frp的负载均衡和健康检查方法,以以下配置为例::

[common]
# 服务端IP根据ECS的的IP来,分别建立2个并启动
server_addr = 2.2.2.2
server_port = 59100
token = 123456

[yl11]
type = tcp
local_ip = 10.10.10.2
local_port = 35000
remote_port = 35000
group = test
group_key = test
health_check_type = tcp
# 建立连接超时时间为 3 秒
health_check_timeout_s = 3
# 连续 3 次检查失败,此 proxy 会被摘除
health_check_max_failed = 3
# 每隔 10 秒进行一次健康检查
health_check_interval_s = 10

[yl12]
type = tcp
local_ip = 10.10.10.3
local_port = 35000
remote_port = 35000
group = test
group_key = test
health_check_type = tcp
health_check_timeout_s = 3
health_check_max_failed = 3
health_check_interval_s = 10

[y13]
type = tcp
local_ip = 10.10.10.2
local_port = 30000
remote_port = 30000
group = test1
group_key = test1
health_check_type = tcp
health_check_timeout_s = 3
health_check_max_failed = 3
health_check_interval_s = 10

[yl14]
type = tcp
local_ip = 10.10.10.3
local_port = 30000
remote_port = 30000
group = test1
group_key = test1
health_check_type = tcp
health_check_timeout_s = 3
health_check_max_failed = 3
health_check_interval_s = 10

2、以以上配置为基础,分别启动2个frpc连接2台ECS的服务端。

二、阿里云SLB设置

在SLB上,将SLB的TCP 30000和35000分别指向两台ECS的TCP 30000和35000

三、对外解析为1.1.1.1

在阿里云解析上将二级域名解析到SLB的公网IP,外界直接调用该地址就可以访问;