概述

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联合实现出中继的负载均衡+故障转移的更多相关文章

  1. Spring cloud gateway 如何在路由时进行负载均衡

    本文为博主原创,转载请注明出处: 1.spring cloud gateway 配置路由 在网关模块的配置文件中配置路由: spring: cloud: gateway: routes: - id: ...

  2. Azure Application Gateway(一)对后端 Web App 进行负载均衡

    一,引言 今天,我们学习一个新的知识点-----Azure Application Gateway,通过Azure 应用程序网关为我么后端的服务提供负载均衡的功能.我们再文章头中大概先了解一下什么是应 ...

  3. Azure上七层负载均衡APP Gateway

    Azure的SLB和ILB是最常用的4层负载均衡工具.但有些场景是7层的负载均衡,SLB和ILB就无能为力了. Azure上已经推出了APP Gateway的服务,就是7层负载均衡的负载均衡器. 如上 ...

  4. 构建api gateway之 负载均衡

    什么是负载均衡 负载均衡,英文名称为Load Balance,其含义就是指将负载(工作任务)进行平衡.分摊到多个操作单元上进行运行 以下为几种负载均衡策略介绍 1.随机(Random) 大家很多时候说 ...

  5. Windows Azure支持七层负载均衡--Application Gateway

    一直以来Windows Azure的负载均衡(Loadbalancer)功能一直被客户诟病,无法其竞争对手(特别是国内的云厂商)匹敌. Windows Azure的负载均衡器是四层的,前期的版本不支持 ...

  6. Spring Cloud Gateway Ribbon 自定义负载均衡

    在微服务开发中,使用Spring Cloud Gateway做为服务的网关,网关后面启动N个业务服务.但是有这样一个需求,同一个用户的操作,有时候需要保证顺序性,如果使用默认负载均衡策略,同一个用户的 ...

  7. 关于Ocelot和Consul 实现GateWay(网关) 服务注册 负载均衡等方面

    Ocelot   路由  请求聚合  服务发现 认证  鉴权 限流熔断 内置负载均衡器 Consul   自动服务发现    健康检查 通过Ocelot搭建API网关   服务注册   负载均衡 1. ...

  8. API网关spring cloud gateway和负载均衡框架ribbon实战

    通常我们如果有一个服务,会部署到多台服务器上,这些微服务如果都暴露给客户,是非常难以管理的,我们系统需要有一个唯一的出口,API网关是一个服务,是系统的唯一出口.API网关封装了系统内部的微服务,为客 ...

  9. Azure Application Gateway(二)对后端 VM 进行负载均衡

    一,引言 上一节有讲到使用 Azure Application Gateway 为我们后端类型为 Web App 的 Demo 项目提供负载均衡,Azure Application Gateway 的 ...

  10. Spring cloud gateway自定义filter以及负载均衡

    自定义全局filter package com.example.demo; import java.nio.charset.StandardCharsets; import org.apache.co ...

随机推荐

  1. C++ Qt开发:使用关联容器类

    当我们谈论编程中的数据结构时,顺序容器是不可忽视的一个重要概念.顺序容器是一种能够按照元素添加的顺序来存储和检索数据的数据结构.它们提供了简单而直观的方式来组织和管理数据,为程序员提供了灵活性和性能的 ...

  2. [UOJ216][UNR#2 2A] Jakarta Skyscrapers

    印尼首都雅加达市有 $10^{18}$ 座摩天楼,它们排列成一条直线,我们从左到右依次将它们编号为 $1$ 到 $10^{18}$ .除了这 $10^{18}$ 座摩天楼外,雅加达市没有其他摩天楼. ...

  3. 【scikit-learn基础】--『预处理』之 数据缩放

    数据的预处理是数据分析,或者机器学习训练前的重要步骤.通过数据预处理,可以 提高数据质量,处理数据的缺失值.异常值和重复值等问题,增加数据的准确性和可靠性 整合不同数据,数据的来源和结构可能多种多样, ...

  4. VSCode个性化的配置

    1.下载插件 Eclipse快捷键(我以前用Eclipse习惯了,大家不需要) Premitter Vetur koroFileHeader 2.修改VSCode设置 3.粘贴下面的代码 { &quo ...

  5. The second day learning summary

    1.什么是接口测试? 接口测试是测试系统组件间接口的一种测试.接口测试主要用于外部系统与系统之间以及内部各个子系统之间的交互点,定义特定的交互点,然后通过这些交互点来,通过一些特殊的规则也就是协议,来 ...

  6. Java多线程学习(Day01)

    目录 线程简介 线程实现(重点) 线程状态 线程同步(重点) 线程通信问题 进程与线程概念 --来自百度百科的解释: 进程(Process)是计算机中的程序关于某数据集合上的一次运行活动,是系统进行资 ...

  7. 牛客刷Java记录第6天

    第一题 一个文件中的字符要写到另一个文件中,首先需要( ). A System.out.print (buffer[i]); B FileOutputStream fout = new FileOut ...

  8. 【Azure APIM】APIM 策略语句如何来设置多个Cookie值让浏览器保存

    问题描述 在APIM的 <return-response> 策略中,设置Cookie值,因为需要设置多个Cookie值,使用下面两种方式都只能保存一个Cookie值: 方式一:把多个coo ...

  9. RV1126 DSI 调试

    一.基本信息 开发板:RV1126 linux版本:4.19.111 显示屏:HX070JGI50(7寸) 显示器分别率:1024 * 600 二.MIPI协议 连接示意图(图片来源,正点资料) MI ...

  10. AnimatedList 实现动态列表

    AnimatedList实现动画  AnimatedList 和 ListView 的功能大体相似,不同的是, AnimatedList 可以在列表中插入或删除节点 时执行一个动画,在需要添加或删除列 ...