这篇文章记录一下
在 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

#!/bin/bash

# 遇到错误停止执行
set -e

# --- 核心版本定义 ---
FS_VERSION="v1.10.12"

# 安装路径
INSTALL_PATH="/usr/local/freeswitch"

echo "==============================================================="
echo "开始安装 FreeSWITCH $FS_VERSION"
echo "依赖库:libks Sofia-SIP , SpanDSP,signalwire-c"
echo "==============================================================="

# 1. 安装 Debian 11 基础编译环境
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-deps
mkdir -p /usr/src/freeswitch-deps
cd /usr/src/freeswitch-deps
git 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 libks
cmake . -DCMAKE_INSTALL_PREFIX=/usr -DWITH_LIBBACKTRACE=1
make -j$(nproc)
make install
cd ..

ldconfig

# 2. 编译安装 Sofia-SIP
echo ">>> 正在编译 Sofia-SIP..."
cd sofia-sip
./bootstrap.sh
./configure --prefix=/usr
make -j$(nproc)
make install
cd ..

# 3. 编译安装 SpanDSP (fs 分支)
echo ">>> 正在编译 SpanDSP ..."
cd spandsp
./bootstrap.sh
./configure --prefix=/usr
make -j$(nproc)
make install
cd ..

echo ">>> 正在编译 signalwire-c ..."
cd signalwire-c
PKG_CONFIG_PATH=/usr/lib/pkgconfig:/usr/local/lib/pkgconfig \
cmake . -DCMAKE_INSTALL_PREFIX=/usr
make install
cd ..

# 更新动态链接库缓存
ldconfig

# 4. 下载并配置 FreeSWITCH 1.10.12
echo ">>> 正在下载 FreeSWITCH $FS_VERSION..."
cd /usr/src
# 如果目录已存在则删除,确保干净构建
rm -rf freeswitch
git clone --branch $FS_VERSION https://github.com/signalwire/freeswitch.git
cd freeswitch

# 初始化构建文件
./bootstrap.sh -j

# 确保开启 mod_sofia (SIP 核心) 和 mod_spandsp
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

# 开启 mariadb 模块以支持 MariaDB / Mysql 连接(可选,默认已支持 PostgreSQL)
sed -i 's/#databases\/mod_mariadb/databases\/mod_mariadb/' modules.conf

# 6. 执行配置、编译与安装
echo ">>> 开始执行 Configure..."
./configure --prefix=$INSTALL_PATH --enable-core-pgsql-support

echo ">>> 开始编译 (请耐心等待)..."
make -j$(nproc)
make install

# 7. 安装声音文件
echo ">>> 安装声音文件..."
make cd-sounds-install
make cd-moh-install

# 8. 权限设置与符号链接
ln -sf $INSTALL_PATH/bin/fs_cli /usr/bin/fs_cli
ln -sf $INSTALL_PATH/bin/freeswitch /usr/bin/freeswitch

if ! 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
<!-- 找到default_password这一行,修改为以下内容-->
<X-PRE-PROCESS cmd="set" data="default_password=myfs213"/>

<!-- 找到 bind_server_ip 这一行,修改为以下内容 -->
<X-PRE-PROCESS cmd="set" data="bind_server_ip=$${domain}"/>

<!-- 找到 external_rtp_ip 这一行,修改为以下内容 -->
<X-PRE-PROCESS cmd="set" data="external_rtp_ip=$${domain}"/>

<!-- 找到 external_sip_ip 这一行,修改为以下内容 -->
<X-PRE-PROCESS cmd="set" data="external_sip_ip=$${domain}"/>

禁用不用的模块 (SignalWire/Verto)

打开该文件:
nano /usr/local/freeswitch/conf/autoload_configs/modules.conf.xml

找到以下几行并加上注释(或者直接删除):

1
2
3
4
5
<!-- 找到这一行,加上注释 -->
<!-- <load module="mod_verto"/> -->

<!-- 找到这一行,加上注释 -->
<!-- <load module="mod_signalwire"/> -->

确认 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.xmlexternal.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 或者不带 -nc
freeswitch -nc

# 进入fs_cli查看状态
fs_cli

# 查看状态
sofia status

# 重启内部 SIP 配置文件
sofia profile internal restart

# 查看 internal SIP 配置文件状态
sofia status profile internal

# 查看外部 SIP 配置文件状态
sofia status profile external

# 查看 5060 端口监听状态
ss -lntup | grep 5060

在控制台中执行常用检查命令

进入 fs_cli 后(看到 freeswitch@debian> 提示符),输入以下命令:

  • 检查版本信息:确认是否为 1.10.12 以及编译时间。

    1
    version
  • 检查运行状态:查看运行时间、会话数等。

    1
    status
  • **验证 SIP 模块 (mod_sofia)**:检查 SIP 端口(5060/5080)是否已开启。

    1
    sofia status
  • 验证 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 中输入:
    1
    shutdown
    或者在 Linux 命令行执行:
    1
    killall freeswitch

备份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 -e

INSTALL_PATH="/usr/local/freeswitch"
cd /usr/src/freeswitch

echo ">>> 正在重新配置模块..."
# 这里你可以根据需要增减 sed 命令来开启新模块,或者手动编辑 modules.conf 文件
# 例如开启 mariadb:
# sed -i 's/#databases\/mod_mariadb/databases\/mod_mariadb/' modules.conf

./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
-- 数据库配置信息 (与你 XML 中的一致)
local dsn = "mariadb://Server=192.168.2.246;Database=freeswitch;Uid=root;Pwd=mysql"

-- 1. 尝试连接
local dbh = freeswitch.Dbh(dsn)

if dbh:connected() then
freeswitch.consoleLog("info", "--- [DB Test] 连接成功! ---\n")

-- 2. 执行一个简单的查询测试
-- 修改这一行
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)

-- 3. 释放连接
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
-- 数据库配置信息 (与你 XML 中的一致)
local dsn = "pgsql://hostaddr=192.168.2.246 dbname=freeswitch user=postgres password='postgres'"

-- 1. 尝试连接
local dbh = freeswitch.Dbh(dsn)

if dbh:connected() then
freeswitch.consoleLog("info", "--- [DB Test] 连接成功! ---\n")

-- 2. 执行一个简单的查询测试
-- 修改这一行
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)

-- 3. 释放连接
dbh:release()
freeswitch.consoleLog("info", "--- [DB Test] 连接已正常关闭 ---\n")
else
freeswitch.consoleLog("err", "--- [DB Test] 连接失败!请检查 DSN 配置、IP 权限或防火墙 ---\n")
end