distributor和gateway联合实现出中继的负载均衡+故障转移

概述
freeswitch是一款简单好用的VOIP开源软交换平台。
在之前的文章,我们介绍过distributor模块实现多线路分发的配置方法,但是当线路发生故障时,distributor并不会自动跳过故障线路实现故障转移。
本节中,我们利用gateway的option检测配置,实现中继线路的故障转移。
环境
centos:CentOS release 7.0 (Final)或以上版本
freeswitch:v1.10.7
GCC:4.8.5
APP接口
distributor的接口格式中,可以追加排除列表“<exception1> <exceptionN>”,distributor在选线的时候会跳过排除列表中的线路。
distributor <list name>[ <exception1> <exceptionN>]
sofia接口检测external下所有的gateway状态,并返回“DOWN”状态的gateway列表。
sofia profile external gwlist down
配置&测试
配置conf/sip_profile/external/gw-138-5080.xml,设置网关参数,gw-138-5090.xml和gw-138-15090.xml设置方法一样。
<include>
<gateway name="gw-138-5080">
<param name="username" value="not-used"/>
<param name="realm" value="10.55.55.138:5080"/>
<param name="password" value="not-used"/>
<param name="register" value="false"/>
<!--send an options ping every x seconds, failure will unregister and/or mark it down-->
<param name="ping" value="20"/>
<param name="ping-min" value="3"/>
<param name="ping-max" value="6"/>
<param name="ping-user-agent" value="proxy"/>
</gateway>
</include>
配置文件conf/autoload_configs/distributor.conf.xml,设置distributor列表。
<configuration name="distributor.conf" description="Distributor Configuration">
<lists>
<list name="test-gw" total-weight="3">
<node name="gw-138-5080" weight="1"/>
<node name="gw-138-5090" weight="1"/>
<node name="gw-138-15090" weight="1"/>
</list>
</lists>
</configuration>
修改配置文件conf/dialplan/test.xml,设置拨号计划,仅仅使用distributor接口。
<extension name="test" continue="false">
<condition field="destination_number" expression="^(\d+)$">
<action application="bridge" data="{sip_invite_call_id=${sip_call_id}}sofia/gateway/${distributor(test-gw)}/$1"/>
</condition>
</extension>
刷新distributor配置数据。
reloadxml
distributor_ctl reload
发起呼叫10011->1002,三次的测试日志如下,可以看到"gw-138-15090"网关有故障但是仍然会被选到。
2022-12-14 11:15:36.478543 [INFO] mod_dialplan_xml.c:637 Processing 10011 <10011>->1002 in context public
...
Dialplan: sofia/external/10011@10.55.55.138 Action bridge({sip_invite_call_id=${sip_call_id}}sofia/gateway/${distributor(test-gw)}/1002)
...
EXECUTE sofia/external/10011@10.55.55.138 bridge({sip_invite_call_id=6b70dbfd-f600-123b-7d99-000c29a63969}sofia/gateway/gw-138-5080/1002)
...
EXECUTE sofia/external/10011@10.55.55.138 bridge({sip_invite_call_id=42ddfe80-f602-123b-7d99-000c29a63969}sofia/gateway/gw-138-5090/1002)
...
EXECUTE sofia/external/10011@10.55.55.138 bridge({sip_invite_call_id=498bf45b-f602-123b-7d99-000c29a63969}sofia/gateway/gw-138-15090/1002)
2022-12-14 11:28:58.618511 [ERR] mod_sofia.c:4511 Gateway 'gw-138-15090' is down!
distributor和gateway联合使用实现出中继线路的负载均衡+故障转移。
修改配置文件conf/dialplan/test.xml,使用distributor和sofia接口。
<extension name="test" continue="false">
<condition field="destination_number" expression="^(\d+)$">
<action application="bridge" data="{sip_invite_call_id=${sip_call_id}}sofia/gateway/${distributor(test-gw ${sofia(profile external gwlist down)})}/$1"/>
</condition>
</extension>
刷新dialplan拨号计划。
reloadxml
发起呼叫10011->1002,三次的测试日志如下,"gw-138-15090"网关不再会被选中。
2022-12-14 13:54:08.495843 [INFO] mod_dialplan_xml.c:637 Processing 10011 <10011>->1002 in context public
...
2022-12-14 13:54:16.435860 [WARNING] sofia.c:6098 Ping failed gw-138-15090 with code 503 - count 3/0/6, state DOWN
...
Dialplan: sofia/external/10011@10.55.55.138 Action bridge({sip_invite_call_id=${sip_call_id}}sofia/gateway/${distributor(test-gw ${sofia(profile external gwlist down)})}/1002)
...
EXECUTE sofia/external/10011@10.55.55.138 bridge({sip_invite_call_id=910ce208-f616-123b-7d99-000c29a63969}sofia/gateway/gw-138-5080/1002)
...
EXECUTE sofia/external/10011@10.55.55.138 bridge({sip_invite_call_id=96142b51-f616-123b-7d99-000c29a63969}sofia/gateway/gw-138-5090/1002)
...
EXECUTE sofia/external/10011@10.55.55.138 bridge({sip_invite_call_id=9a7872ed-f616-123b-7d99-000c29a63969}sofia/gateway/gw-138-5080/1002)
...
总结
freeswitch有非常多好用的功能,每个功能设计简单,能力单一,但是我们可以把不同的功能组合在一起,实现各种复杂的需求。
最好的设计就是功能模块的高内聚,低耦合,职责单一,同时又可以灵活组合。
空空如常
求真得真
distributor和gateway联合实现出中继的负载均衡+故障转移的更多相关文章
- Spring cloud gateway 如何在路由时进行负载均衡
本文为博主原创,转载请注明出处: 1.spring cloud gateway 配置路由 在网关模块的配置文件中配置路由: spring: cloud: gateway: routes: - id: ...
- Azure Application Gateway(一)对后端 Web App 进行负载均衡
一,引言 今天,我们学习一个新的知识点-----Azure Application Gateway,通过Azure 应用程序网关为我么后端的服务提供负载均衡的功能.我们再文章头中大概先了解一下什么是应 ...
- Azure上七层负载均衡APP Gateway
Azure的SLB和ILB是最常用的4层负载均衡工具.但有些场景是7层的负载均衡,SLB和ILB就无能为力了. Azure上已经推出了APP Gateway的服务,就是7层负载均衡的负载均衡器. 如上 ...
- 构建api gateway之 负载均衡
什么是负载均衡 负载均衡,英文名称为Load Balance,其含义就是指将负载(工作任务)进行平衡.分摊到多个操作单元上进行运行 以下为几种负载均衡策略介绍 1.随机(Random) 大家很多时候说 ...
- Windows Azure支持七层负载均衡--Application Gateway
一直以来Windows Azure的负载均衡(Loadbalancer)功能一直被客户诟病,无法其竞争对手(特别是国内的云厂商)匹敌. Windows Azure的负载均衡器是四层的,前期的版本不支持 ...
- Spring Cloud Gateway Ribbon 自定义负载均衡
在微服务开发中,使用Spring Cloud Gateway做为服务的网关,网关后面启动N个业务服务.但是有这样一个需求,同一个用户的操作,有时候需要保证顺序性,如果使用默认负载均衡策略,同一个用户的 ...
- 关于Ocelot和Consul 实现GateWay(网关) 服务注册 负载均衡等方面
Ocelot 路由 请求聚合 服务发现 认证 鉴权 限流熔断 内置负载均衡器 Consul 自动服务发现 健康检查 通过Ocelot搭建API网关 服务注册 负载均衡 1. ...
- API网关spring cloud gateway和负载均衡框架ribbon实战
通常我们如果有一个服务,会部署到多台服务器上,这些微服务如果都暴露给客户,是非常难以管理的,我们系统需要有一个唯一的出口,API网关是一个服务,是系统的唯一出口.API网关封装了系统内部的微服务,为客 ...
- Azure Application Gateway(二)对后端 VM 进行负载均衡
一,引言 上一节有讲到使用 Azure Application Gateway 为我们后端类型为 Web App 的 Demo 项目提供负载均衡,Azure Application Gateway 的 ...
- Spring cloud gateway自定义filter以及负载均衡
自定义全局filter package com.example.demo; import java.nio.charset.StandardCharsets; import org.apache.co ...
随机推荐
- [ARC156D] Xor Sum 5
Problem Statement You are given a sequence of $N$ non-negative integers $A=(A_1,A_2,\dots,A_N)$ and ...
- 用JS实现简单的屏幕录像机
本文将介绍如何用JS实现简单的屏幕录像机. 一.录制准备 创建一个按钮 <button id="recording-toggle">Start recording< ...
- requests.exceptions.ProxyError问题解决方法
出现这个问题是因为你系统上在使用代理,然后你的代理又是规则匹配的. https://stackoverflow.com/questions/36906985/switch-off-proxy-in-r ...
- 华企盾DSC防泄密软件造成VS启动报目录错误
解决方法:找到安装路径下的Privateregistry.bin文件解密即可
- ElasticSearch之cat aliases API
执行aliases命令,如下: curl -X GET "https://localhost:9200/_cat/aliases?pretty&v=true" --cace ...
- 网安区过年-Log4j2
Log4j2-2021 漏洞原理 Apache Log4j 2 是Java语言的日志处理套件,使用极为广泛.在其2.0到2.14.1版本中存在一处JNDI注入漏洞,攻击者在可以控制日志内容的情况下,通 ...
- 如何用.net制作一个简易爬虫抓取华为应用市场数据
公司最近要做一款手机,手机需要制作一个应用市场.那么问题来了,自己制作应用市场,数据从哪来呢?作为一个创业型公司.搜集数据变成为了难题. 于是突然想到能不能通过程序去抓取别人应用市场的数据-- 那么我 ...
- 【OpenVINO】 使用 OpenVINO CSharp API 部署 PaddleOCR 项目介绍
前言: 在之前的项目中,我们已经使用 OpenVINOTM CSharp API 部署 PaddleOCR 全系列模型,但随着PaddleOCRv4版本发布以及OpenVINO CSharp AP ...
- Spring源码学习笔记4——BeanFactoryPostProcessor执行
一丶BeanFactoryPostProcessor是什么 Spring留给我们的一个扩展接口,在BeanDefinition加载注册完之后,并执行一些前置操作(笔记3)之后会反射生产所有的BeanF ...
- 亿级日活业务稳如磐石,华为云CodeArts PerfTest发布
摘要:近日,华为云性能测试服务CodeArts PerfTest全新上线,提供低门槛.低成本的一站式云化性能测试解决方案. 本文分享自华为云社区<亿级日活业务稳如磐石,华为云CodeArts P ...