2

FreeSWITCH容器化问题之rtp端口占用

 9 months ago
source link: https://www.cnblogs.com/MikeZhang/p/fsRtpPort20230924.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

操作系统 :CentOS 7.6_x64、debian 11 (bullseye,docker)

FreeSWITCH版本 :1.10.9

Docker版本:23.0.6

FreeSWITCH容器化带来部署便利的同时,也会遇到一些问题,比如今天要讨论的RTP端口占用问题(FreeSWITCH申请宿主机已占用的端口)。

我将从以下三个方面进行展开:

1)从源码层面分析FreeSWITCH的端口分配及检查逻辑;

2)描述开启RTP端口占用检测的方法;

3)演示RTP端口占用检测效果;

FreeSWITCH容器化参考我之前的文章:

https://www.cnblogs.com/MikeZhang/p/dockerPackFs20230617.html

https://www.cnblogs.com/MikeZhang/p/dockerFS20230716.html

一、端口分配及检查逻辑

文件:switch_core_port_allocator.c

1、  端口查找的主循环

如果系统认为还有端口可分配,则一直重试,没有退出循环的逻辑,存在导致fs宕机的风险。

300959-20230924104729160-1045039389.png

 2、端口检查逻辑  

端口检查通过bind函数实现,尝试bind,成功后,关闭socket,释放端口。 

存在以下两个问题: 

1)  效率不高; 

2)  bind后会执行释放操作,rtp使用时仍然会存在失败的风险;

300959-20230924104752491-540359403.png

二、启RTP端口占用检测的方法

FreeSWITCH默认不开启rtp端口检测占用,端口分配了就直接使用。可通过如下配置开启rtp端口检查。

文件 :autoload_configs/switch.conf.xml

<param name="rtp-port-usage-robustness" value="true"/>

三、RTP端口占用检测效果演示

1、调整端口范围

文件:autoload_configs/switch.conf.xml

<param name="rtp-start-port" value="$${force_rtp_start_port}"/>
<param name="rtp-end-port" value="$${force_rtp_end_port}"/>

示例如下:

300959-20230924112700860-304352391.png

2、容器外占用端口

安装netcat:

yum install netcat

占用端口:

nc -l -u 20002

3、呼叫测试

3.1、开启后可实现端口占用检查,如果占用了则重新分配

测试效果如下:

300959-20230924104954561-1950629682.png

 3.2、如果rtp端口范围比较小,会出现一直尝试分配端口的情况,可能会导致fs宕机

 测试效果如下:

300959-20230924105008552-2098940872.png
 
300959-20230924105015488-1037552408.png

好,就这么多了,希望对你有帮助。 


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK