debian11 中 freeswitch 编译安装(更新2026-05-04)
这篇文章记录一下 在 Debian 11 中编译安装 FreeSWITCH 1.10.12 的过程。 以及一些额外的配置说明
前提环境: Linux debian11 5.10.0-39-amd64 #1 SMP Debian 5.10.251-1 (2026-03-09) x86_64 GNU/Linux
设置代理
1 2 3 export http_proxy="http://192.168.2.246:7897" export https_proxy="http://192.168.2.246:7897" export no_proxy="localhost,127.0.0.1,192.168.2.234"
新建freeswitch_install.sh文件,写入以下内容
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 set -eFS_VERSION="v1.10.12" INSTALL_PATH="/usr/local/freeswitch" echo "===============================================================" echo "开始安装 FreeSWITCH $FS_VERSION " echo "依赖库:libks Sofia-SIP , SpanDSP,signalwire-c" echo "===============================================================" apt-get update apt-get install -y \ autoconf \ automake \ bison \ build-essential \ cmake \ erlang-dev \ git \ libavformat-dev \ libavresample-dev \ libcurl4-openssl-dev \ libdb-dev \ libedit-dev \ libexpat1-dev \ libflac-dev \ libgdbm-dev \ libldns-dev \ liblua5.2-dev \ libmariadb-dev \ libmp3lame-dev \ libmpg123-dev \ libncurses5-dev \ libogg-dev \ libopus-dev \ libpcre3-dev \ libpq-dev \ libshout3-dev \ libsndfile1-dev \ libspeex-dev \ libspeexdsp-dev \ libsqlite3-dev \ libssl-dev \ libswscale-dev \ libtiff5-dev \ libtool \ libtool-bin \ libtpl-dev \ libvorbis-dev \ nasm \ pkg-config \ python3-dev \ unixodbc-dev \ uuid-dev \ wget \ zlib1g-dev rm -rf /usr/src/freeswitch-depsmkdir -p /usr/src/freeswitch-depscd /usr/src/freeswitch-depsgit clone --branch v2.0.10 https://github.com/signalwire/libks.git git clone --branch v1.13.17 https://github.com/freeswitch/sofia-sip.git git clone --branch fs https://github.com/freeswitch/spandsp.git git clone --branch v2.0.5 https://github.com/signalwire/signalwire-c.git echo ">>> 正在编译 libks 依赖库..." cd libkscmake . -DCMAKE_INSTALL_PREFIX=/usr -DWITH_LIBBACKTRACE=1 make -j$(nproc ) make install cd ..ldconfig echo ">>> 正在编译 Sofia-SIP..." cd sofia-sip./bootstrap.sh ./configure --prefix=/usr make -j$(nproc ) make install cd ..echo ">>> 正在编译 SpanDSP ..." cd spandsp./bootstrap.sh ./configure --prefix=/usr make -j$(nproc ) make install cd ..echo ">>> 正在编译 signalwire-c ..." cd signalwire-cPKG_CONFIG_PATH=/usr/lib/pkgconfig:/usr/local/lib/pkgconfig \ cmake . -DCMAKE_INSTALL_PREFIX=/usr make install cd ..ldconfig echo ">>> 正在下载 FreeSWITCH $FS_VERSION ..." cd /usr/srcrm -rf freeswitch git clone --branch $FS_VERSION https://github.com/signalwire/freeswitch.git cd freeswitch./bootstrap.sh -j sed -i 's/#endpoints\/mod_sofia/endpoints\/mod_sofia/' modules.conf sed -i 's/#applications\/mod_spandsp/applications\/mod_spandsp/' modules.conf sed -i 's/#applications\/mod_av/applications\/mod_av/' modules.conf sed -i 's/#formats\/mod_shout/formats\/mod_shout/' modules.conf sed -i 's/#databases\/mod_mariadb/databases\/mod_mariadb/' modules.conf echo ">>> 开始执行 Configure..." ./configure --prefix=$INSTALL_PATH --enable-core-pgsql-support echo ">>> 开始编译 (请耐心等待)..." make -j$(nproc ) make install echo ">>> 安装声音文件..." make cd-sounds-install make cd-moh-install ln -sf $INSTALL_PATH /bin/fs_cli /usr/bin/fs_cliln -sf $INSTALL_PATH /bin/freeswitch /usr/bin/freeswitchif ! getent group freeswitch > /dev/null; then groupadd freeswitch; fi if ! getent passwd freeswitch > /dev/null; then useradd -r -g freeswitch -d $INSTALL_PATH -s /bin/false freeswitch; fi chown -R freeswitch:freeswitch $INSTALL_PATH chmod -R ug+rw $INSTALL_PATH echo "===============================================================" echo "FreeSWITCH $FS_VERSION 安装成功!" echo "您可以执行 'freeswitch -nc' 启动程序,'fs_cli' 进入控制台。" echo "==============================================================="
执行 1 2 chmod +x freeswitch_install.sh./freeswitch_install.sh
配置文件路径 你的所有配置文件都位于:
1 /usr/local/freeswitch/etc/freeswitch
启动前调整 细节调整 打开该文件:nano /usr/local/freeswitch/etc/freeswitch/vars.xml
找到以下行并修改 :
1 2 3 4 5 6 7 8 9 10 11 <X-PRE-PROCESS cmd ="set" data ="default_password=myfs213" /> <X-PRE-PROCESS cmd ="set" data ="bind_server_ip=$${domain}" /> <X-PRE-PROCESS cmd ="set" data ="external_rtp_ip=$${domain}" /> <X-PRE-PROCESS cmd ="set" data ="external_sip_ip=$${domain}" />
禁用不用的模块 (SignalWire/Verto) 打开该文件:nano /usr/local/freeswitch/conf/autoload_configs/modules.conf.xml
找到以下几行并加上注释 (或者直接删除):
确认 mod_sofia 已启用
确保这一行是没有 注释的(你发给我的内容里已经是开启的了):
1 <load module ="mod_sofia" />
配置数据库连接 /usr/local/freeswitch/etc/freeswitch/autoload_configs/switch.conf.xml
在 <settings> 标签内添加以下行:
postgresql 数据库连接字符串:
1 2 <param name ="core-db-dsn" value ="pgsql://hostaddr=192.168.2.246 dbname=freeswitch user=postgres password='postgres' options='-c client_min_messages=NOTICE'" />
/usr/local/freeswitch/etc/freeswitch/sip_profiles/internal.xml 和 external.xml
在 <settings> 标签内添加以下行:
postgresql 数据库连接字符串:
1 <param name ="odbc-dsn" value ="pgsql://hostaddr=192.168.2.246 dbname=freeswitch user=postgres password='postgres'" />
可选操作:如果你使用了 mod_fifo 或者其他需要数据库连接的模块,也可以在对应的配置文件中添加相同的数据库连接字符串,例如:
/usr/local/freeswitch/etc/freeswitch/autoload_configs/fifo.conf.xml
在 <settings> 标签内添加以下行:
1 2 3 4 5 <param name ="odbc-dsn" value ="pgsql://hostaddr=192.168.2.246 dbname=freeswitch user=postgres password='postgres'" /> 可选操作:如果你使用了 mod_db 或者其他需要数据库连接的模块,
/usr/local/freeswitch/etc/freeswitch/autoload_configs/db.conf.xml
在 <settings> 标签内添加以下行:
1 <param name ="odbc-dsn" value ="pgsql://hostaddr=192.168.2.246 dbname=freeswitch user=postgres password='postgres'" />
说明
这会让 FreeSWITCH 使用 PostgreSQL 数据库来存储核心数据和 SIP 相关数据。
确保你的 PostgreSQL 数据库已经创建了 freeswitch 用户和 freeswitch 数据库,并且允许从 FreeSWITCH 服务器的 IP地址连接。
启动 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 freeswitch -nc fs_cli sofia status sofia profile internal restart sofia status profile internal sofia status profile external ss -lntup | grep 5060
在控制台中执行常用检查命令 进入 fs_cli 后(看到 freeswitch@debian> 提示符),输入以下命令:
检查版本信息 :确认是否为 1.10.12 以及编译时间。
检查运行状态 :查看运行时间、会话数等。
**验证 SIP 模块 (mod_sofia)**:检查 SIP 端口(5060/5080)是否已开启。
验证 SpanDSP 模块 :确认我们之前解决的 mod_spandsp 是否加载成功。
1 module_exists mod_spandsp
退出控制台 : 输入 /exit 或按 Ctrl+D(这不会关闭 FreeSWITCH 服务,只是断开控制台连接)。
查看日志文件 如果需要调试或查看启动详情,可以查看日志:
1 tail -f -n 500 /usr/local/freeswitch/var/log/freeswitch/freeswitch.log
管理服务 (停止/重启) 因为你是通过 -nc (no console) 手动启动的,管理方式如下:
停止 FreeSWITCH : 在 fs_cli 中输入:
或者在 Linux 命令行执行:
备份freeswitch配置 1 2 cp -r /usr/local/freeswitch/etc/freeswitch /usr/local/freeswitch/etc/freeswitch.bak_$(date +%F)
仅编译脚本 新建 fs_rebuild.sh 文件,内容如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 #!/bin/bash set -eINSTALL_PATH="/usr/local/freeswitch" cd /usr/src/freeswitchecho ">>> 正在重新配置模块..." ./bootstrap.sh -j ./configure --prefix=$INSTALL_PATH --enable-core-pgsql-support echo ">>> 正在编译并更新二进制文件 (不会触碰您的 XML 配置)..." make -j$(nproc ) make install echo ">>> 更新完成。请在 fs_cli 中执行 'reloadxml' 并重启对应模块。"
执行:
1 2 chmod +x fs_rebuild.sh./fs_rebuild.sh
lua 脚本测试数据库连接 你可以创建一个简单的 Lua 脚本来测试数据库连接是否成功:
在 /usr/local/freeswitch/share/freeswitch/scripts/ 目录下创建 test_mysql.lua 文件,内容如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 local dsn = "mariadb://Server=192.168.2.246;Database=freeswitch;Uid=root;Pwd=mysql" local dbh = freeswitch.Dbh(dsn)if dbh:connected() then freeswitch.consoleLog("info" , "--- [DB Test] 连接成功! ---\n" ) local sql = "SELECT NOW() as `ts_now`" dbh:query(sql, function (row) freeswitch.consoleLog("info" , string .format ("--- [DB Test] 数据库当前时间: %s ---\n" , row.ts_now)) end ) dbh:release() freeswitch.consoleLog("info" , "--- [DB Test] 连接已正常关闭 ---\n" ) else freeswitch.consoleLog("err" , "--- [DB Test] 连接失败!请检查 DSN 配置、IP 权限或防火墙 ---\n" ) end
test_pgsql.lua 文件内容如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 local dsn = "pgsql://hostaddr=192.168.2.246 dbname=freeswitch user=postgres password='postgres'" local dbh = freeswitch.Dbh(dsn)if dbh:connected() then freeswitch.consoleLog("info" , "--- [DB Test] 连接成功! ---\n" ) local sql = "SELECT NOW() as ts_now" dbh:query(sql, function (row) freeswitch.consoleLog("info" , string .format ("--- [DB Test] 数据库当前时间: %s ---\n" , row.ts_now)) end ) dbh:release() freeswitch.consoleLog("info" , "--- [DB Test] 连接已正常关闭 ---\n" ) else freeswitch.consoleLog("err" , "--- [DB Test] 连接失败!请检查 DSN 配置、IP 权限或防火墙 ---\n" ) end