概述

本文介绍如何在 CentOS 7 上通过源码编译安装 FreeSWITCH。

系统要求: CentOS 7.x


📦 安装依赖

基础依赖

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
# 更新系统
sudo yum update -y

# 安装 EPEL 源
sudo yum install -y epel-release

# 安装开发工具
sudo yum groupinstall -y "Development Tools"

# 安装基础依赖
sudo yum install -y \
git cmake3 gcc-c++ libuv-devel \
wget autoconf automake libtool \
libuuid-devel zlib-devel \
libjpeg-devel ncurses-devel \
openssl-devel libcurl-devel \
pcre-devel speex-devel \
ldns-devel libedit-devel \
sqlite-devel libsndfile-devel \
opus-devel libogg-devel \
libvorbis-devel libshout-devel \
libmpg123-devel lame-devel \
lua-devel yasm

# 安装 opus
sudo yum install -y opus opus-devel

安装 FFmpeg 依赖

1
2
3
4
5
6
7
8
9
10
11
# 安装 RPM Fusion 源(用于 FFmpeg)
sudo yum install -y \
https://download1.rpmfusion.org/free/el/rpmfusion-free-release-7.noarch.rpm

# 安装 FFmpeg 及开发库
sudo yum install -y \
ffmpeg ffmpeg-devel \
libavcodec-devel \
libavformat-devel \
libavutil-devel \
libswscale-devel

额外依赖

如果编译过程中提示缺少其他依赖,按需安装:

📚 安装第三方库

安装 libsrtp 库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 创建工作目录

sudo mkdir -p src
cd src

# 下载并编译 libsrtp
wget https://github.com/cisco/libsrtp/archive/v2.3.0.tar.gz
tar -xzvf v2.3.0.tar.gz
cd libsrtp-2.3.0
./configure --prefix=/usr --enable-openssl
make shared_library
sudo make install

# 更新共享库缓存
sudo ldconfig

安装 Sofia-SIP 库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 返回工作目录
cd src

# 下载并编译 Sofia-SIP
wget https://github.com/freeswitch/sofia-sip/archive/v1.13.7.tar.gz
tar -xzvf v1.13.7.tar.gz
cd sofia-sip-1.13.7
./bootstrap.sh
./configure
make
sudo make install

# 更新共享库缓存
sudo ldconfig

安装 SpanDSP 库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 返回工作目录
cd src

# 下载并编译 SpanDSP
wget https://github.com/freeswitch/spandsp/archive/refs/heads/master.zip
unzip master.zip
cd spandsp-master
./bootstrap.sh
./configure
make
sudo make install

# 更新共享库缓存
sudo ldconfig

安装 libks 库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 返回工作目录
cd src

# 克隆并编译 libks
git clone https://github.com/signalwire/libks.git
cd libks
cmake3 .
make
sudo make install

# 创建 pkgconfig 链接
sudo ln -sf /usr/local/lib64/pkgconfig/signalwire_client2.pc \
/usr/local/lib64/pkgconfig/signalwire_client.pc

# 设置环境变量
export PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig:$PKG_CONFIG_PATH

# 验证安装
pkg-config --modversion signalwire_client

# 更新共享库缓存
sudo ldconfig

🔧 编译和安装 FreeSWITCH

克隆源码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

#创建工作文件夹
cd ~/src
mkdir -p ~/src
cd ~/src/

#方法一,通过rpm安装
echo "USER" > /etc/yum/vars/fsausername
echo "PASS" > /etc/yum/vars/fsapassword
yum install -y https://$(< /etc/yum/vars/fsausername):$(< /etc/yum/vars/fsapassword)@fsa.freeswitch.com/repo/yum-stack/fsa/centos-release/signalwire-stack-release-repo-0-1.noarch.rpm epel-release
yum install -y freeswitch-config-vanilla freeswitch-lang-* freeswitch-sounds-*


# 克隆 FreeSWITCH 源码
sudo git clone https://github.com/signalwire/freeswitch.git
cd freeswitch
git tag -l
git checkout v1.10.11

配置编译选项

1
2
3
4
5
6
7
# 配置编译选项
./configure \
--prefix=/usr/local/freeswitch \
--with-openssl \
--with-pgsql \
--enable-core-modules \
--enable-modules="mod_sofia mod_dialplan_xml mod_commands mod_event_socket"

编译安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 编译(耗时较长,耐心等待)
make

# 安装
sudo make install

# 安装音频文件
sudo make sounds-install
# 或者 sudo make cd-sounds-install
sudo make moh-install
#或者 sudo make cd-moh-install

# 安装示例配置文件
sudo make samples

缺少依赖问题处理

如果安装过程中出现缺少依赖等错误:

1
2
3
4
5
6
7
8
9
10
11
12
13
# 查看错误日志
tail -f /usr/local/freeswitch/log/freeswitch.log

#使用yum install 安装依赖之后,记得 输出sudo ldconfig 更新共享库缓存
sudo ldconfig

# 安装缺失的依赖后,清理并重新编译
make clean
./configure --enable-core-modules \
--enable-modules="mod_sofia mod_dialplan_xml mod_commands mod_event_socket"

make
sudo make install

🔗 创建符号链接(可选)

1
2
3
4
5
# 创建 FreeSWITCH 软链接
sudo ln -sf /usr/local/freeswitch/bin/freeswitch /usr/bin/freeswitch

# 创建 fs_cli 软链接
sudo ln -sf /usr/local/freeswitch/bin/fs_cli /usr/bin/fs_cli

🚀 启动 FreeSWITCH 服务

创建运行用户

1
2
3
4
5
# 创建 freeswitch 用户
sudo useradd -r -d /usr/local/freeswitch -s /sbin/nologin freeswitch

# 设置目录权限
sudo chown -R freeswitch:freeswitch /usr/local/freeswitch

创建 systemd 服务文件

1
2
# 创建服务文件
sudo vim /etc/systemd/system/freeswitch.service

添加以下内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[Unit]
Description=FreeSWITCH
After=network.target network-online.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/usr/local/freeswitch/run/freeswitch.pid
User=freeswitch
Group=freeswitch
ExecStart=/usr/local/freeswitch/bin/freeswitch -nc -nonat -hp
ExecReload=/bin/kill -HUP $MAINPID
TimeoutSec=300
Restart=always
LimitNOFILE=200000

[Install]
WantedBy=multi-user.target

启动服务

1
2
3
4
5
6
7
8
9
10
11
# 重载 systemd 配置
sudo systemctl daemon-reload

# 启动 FreeSWITCH
sudo systemctl start freeswitch

# 设置开机自启
sudo systemctl enable freeswitch

# 查看服务状态
sudo systemctl status freeswitch

手动启动(调试用)

1
2
3
4
5
6
7
8
9
10
11
# 前台运行(调试模式)
/usr/local/freeswitch/bin/freeswitch -c

# 后台运行
/usr/local/freeswitch/bin/freeswitch -nc

# 停止
/usr/local/freeswitch/bin/freeswitch -stop

# 进入 CLI
/usr/local/freeswitch/bin/fs_cli

✅ 验证安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 检查版本
freeswitch -version

# 进入 CLI
fs_cli

# 在 CLI 中查看状态
status

# 查看已加载模块
module_exists mod_sofia

# 退出 CLI
/exit

⚙️ modules.conf 加载的模块列表

配置文件位置

/usr/local/freeswitch/conf/autoload_configs/modules.conf

默认加载的模块

模块 类型 说明
mod_sofia endpoints SIP 协议栈
mod_skinny endpoints Skinny 协议
mod_event_socket event_handlers 事件 Socket
mod_cdr_sqlite event_handlers CDR SQLite
mod_local_stream formats 本地流媒体
mod_native_file formats 原生文件格式
mod_sndfile formats 音频文件格式
mod_tone_stream formats 音调流
mod_lua languages Lua 脚本支持
mod_console loggers 控制台日志
mod_logfile loggers 文件日志
mod_syslog loggers 系统日志
mod_say_zh say 中文语音报时
mod_xml_cdr xml_int XML CDR
mod_xml_rpc xml_int XML RPC
mod_xml_scgi xml_int XML SCGI

完整 modules.conf 配置

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
# Applications
#applications/mod_blacklist

# Endpoints
#endpoints/mod_rtmp
endpoints/mod_skinny
endpoints/mod_sofia
#endpoints/mod_verto

# Event Handlers
#event_handlers/mod_amqp
#event_handlers/mod_cdr_csv
#event_handlers/mod_cdr_mongodb
#event_handlers/mod_cdr_pg_csv
event_handlers/mod_cdr_sqlite
#event_handlers/mod_erlang_event
#event_handlers/mod_event_multicast
event_handlers/mod_event_socket
#event_handlers/mod_fail2ban
#event_handlers/mod_format_cdr
#event_handlers/mod_json_cdr
#event_handlers/mod_radius_cdr
#event_handlers/mod_odbc_cdr
#event_handlers/mod_kazoo
#event_handlers/mod_rayo
#event_handlers/mod_smpp
#event_handlers/mod_snmp
#event_handlers/mod_event_zmq

# Formats
#formats/mod_imagick
formats/mod_local_stream
formats/mod_native_file
#formats/mod_png
#formats/mod_portaudio_stream
#formats/mod_shell_stream
#formats/mod_shout
formats/mod_sndfile
#formats/mod_ssml
formats/mod_tone_stream
#formats/mod_vlc
#formats/mod_opusfile

# Languages
#languages/mod_basic
#languages/mod_java
languages/mod_lua
#languages/mod_managed
#languages/mod_perl
#languages/mod_python
#languages/mod_python3
#languages/mod_v8
#languages/mod_yaml

# Loggers
loggers/mod_console
#loggers/mod_graylog2
loggers/mod_logfile
loggers/mod_syslog
#loggers/mod_raven

# Say
#say/mod_say_de
#say/mod_say_en
#say/mod_say_es
#say/mod_say_es_ar
#say/mod_say_fa
#say/mod_say_fr
#say/mod_say_he
#say/mod_say_hr
#say/mod_say_hu
#say/mod_say_it
#say/mod_say_ja
#say/mod_say_nl
#say/mod_say_pl
#say/mod_say_pt
#say/mod_say_ru
#say/mod_say_sv
#say/mod_say_th
say/mod_say_zh

# Timers
#timers/mod_posix_timer
#timers/mod_timerfd

# XML Interfaces
xml_int/mod_xml_cdr
#xml_int/mod_xml_curl
#xml_int/mod_xml_ldap
#xml_int/mod_xml_radius
xml_int/mod_xml_rpc
xml_int/mod_xml_scgi

# Third-party modules
#mod_freetdm|https://github.com/freeswitch/freetdm.git -b master

## Experimental Modules (don't cry if they're broken)
#../../contrib/mod/xml_int/mod_xml_odbc

启用/禁用模块

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 编辑模块配置
vim /usr/local/freeswitch/conf/autoload_configs/modules.conf

# 启用模块:删除行首的 # 号
# mod_sofia
mod_sofia

# 禁用模块:在行首添加 # 号
mod_event_socket
# mod_event_socket

# 重新加载配置
fs_cli -x "reloadxml"

# 加载新模块
fs_cli -x "load mod_模块名"

🔗 相关文档


© 2018–2026 小周周 · 使用 Stellar 构建

站内搜索

没有找到内容!