PBX 是 Private Branch Exchange 的缩写。它是在组织内部使用的专用电话系统,并根据特定组织的需求进行定制。组织中的 PBX 用户可以在内部进行内部通信,也可以与外界进行外部通信。VoIP(IP 语音)、ISDN(综合业务数字网络)或模拟等渠道促进了外部通信。
使用 PBX 电话系统的优点是,您可以获得比物理线路更多的电话、用户之间的免费通话以及呼叫队列、数字接线员、呼叫转移、语音邮件和呼叫录音等大量功能。PBX 电话系统的一些示例包括 FreeSwitch、3cx、Elastix、FreePBX 和 Asterisk。
在本指南中,我们将了解如何在 Ubuntu 20.04/18.04 上安装 FreeSwitch PBX
FreeSwitch 是一个免费的开源通信平台。它支持实时通信、视频以及 IP 语音和WebRTC。它可以在 Windows、MacOS、Linux 和 FreeBSD 上运行。它用于构建具有聊天和屏幕共享的网络会议、IVR、会话边界控制器、批发最低成本路由等功能的 PBX 系统。
freeswitch1.10.7/freeswitch1.10.8安装情况应该与freeswitch1.10.9相同
sudo apt-get install libavformat-dev
sudo apt-get install libswscale-dev
sudo apt-get install libpq-dev
在 Ubuntu 20.04/18.04 上安装 FreeSwitch PBX
首先更新你的系统包
sudo apt -y update
sudo apt -y upgrade
接下来,安装在 Ubuntu 20.04/18.04 上运行 FreeSwitch PBX 所需的依赖项
sudo apt install -y git subversion build-essential autoconf automake libtool g++ pkg-config
libtiff-dev libncurses5 libncurses5-dev make libjpeg-dev libtool libtool-bin
libsqlite3-dev libpcre3-dev libspeexdsp-dev libldns-dev libedit-dev
yasm uuid uuid-dev liblua5.2-dev libopus-dev cmake
以下软件包是可选的,但我们可以安装它们。
sudo apt install -y libcurl4-nss-dev libcurl4-openssl-dev libexpat1-dev
libgnutls28-dev libtiff5-dev libx11-dev unixodbc-dev libssl-dev python-dev
zlib1g-dev libasound2-dev libogg-dev libvorbis-dev libperl-dev libgdbm-dev libdb-dev uuid-dev libsndfile1-dev
下载源代码
freeswitch1.10.4及之后的版本freeswitch官方将spandsp 和 sofia-sip单拎出来了,需要单独拉代码编译,如果是编译1.10.4之前的freeswitch(如freeswitch1.10.2版本)不必单独拉spandsp和sofia-sip的代码,直接编译freeswitch即可
重大改动历史:
https://developer.signalwire.com/freeswitch/FreeSWITCH-Explained/Release-Notes/FreeSWITCH
-1.10.x-Release-notes_25460878/
//可直接在上述链接中下载freeswitch的tar包
1.8 -> 1.10.0: pgqsql moved out from FreeSWITCH core to its own module, mod_pgsql .
See 1.10.0 (Release date: 05 August 2019) at the bottom.
1.10.3 -> 1.10.4: SpanDSP and sofia-sip have been removed.
See 1.10.4 (Release date: 05 Aug 2020) below.
1.10.6 -> 1.10.7: Default behaviour change: to not skip announcement type apps on recovery,
not hangup call on SRTP errors, 1000 maximum receiving requests per second, auth-messages
and auth-subscriptions are enabled by default now, freeswitch.log log line prefix modified:
will affect fail2ban log line matching until similarly modified in fail2ban
(https://github.com/fail2ban/fail2ban/issues/3143).
See 1.10.7 (Release date: 24 Oct 2021) below.
安装spandsp、sofia-sip、libks和signalwire
// 安装spandsp
# git clone https://github.com/freeswitch/spandsp.git
# cd spandsp
# ./bootstrap.sh -j
# ./configure
# make
# sudo make install
# ldconfig
// 安装sofia-sip
no usable sofia-sip; please install sofia-sip-ua devel package or equivalent
# git clone https://github.com/freeswitch/sofia-sip.git
#cd sofia-sip
# ./bootstrap.sh -j
# ./configure
# make
# make install0
# ldconfig
sudo apt install -y cmake
cd /usr/src
sudo git clone https://github.com/signalwire/libks.git
cd libks
sudo cmake .
sudo make
sudo make install
cd /usr/src
git clone https://github.com/signalwire/signalwire-c.git
cd signalwire-c
sudo cmake .
sudo make
sudo make install
编译freeswitch前将不必要的模块编译禁用掉,如果不禁用则需要安装对应的依赖,否则会报错
cd /usr/local/src/freeswitch
vim module.conf
//将mod_signalwire和mod_av内容注释掉
#applications/mod_signalwire
#applications/mod_av
//mod_verto不禁用可能会编译报错You need to either install libks or disable mod_verto in modules.conf
#endpoints/mod_verto
接下来,使用 wget从 freeswitch发布页面 获取最新的 FreeSwitch 版本:
cd /usr/src
sudo wget https://files.freeswitch.org/freeswitch-releases/freeswitch-1.10.3.-release.zip
sudo apt -y install unzip
sudo unzip freeswitch-1.10.3.-release.zip
cd freeswitch-1.10.3.-release/
请注意 ,如果您尚未安装 unzip,请通过运行 apt -y install unzip安装它
sudo apt -y install unzip
现在运行标准安装过程
//编译freeswitch
cd /usr/local/src/freeswitch
./bootstrap.sh //如果是GitHub拉的代码有这一步,如果是下载tar包解压的没有这一步
./configure --enable-portable-binary --prefix=/usr/local/freeswitch
--with-gnu-ld --with-python --with-openssl
--enable-core-odbc-support --enable-zrtp
make
如果在编译过程中遇到错误,您可以注释掉任何引发错误的模块或安装缺少的依赖项。就我而言,我最初注释掉了 languages/mod_lua 和 applications/mod_signalwire ,但您可以根据收到的错误注释更多内容。之后重新启动编译,如下所示:
sudo ./configure && sudo make clean && sudo make
如果编译成功, 接下来,安装 freeswitch:
sudo make install
现在编译声音
sudo make all cd-sounds-install cd-moh-install
创建 simlink 以轻松使用服务。
sudo ln -s /usr/local/freeswitch/bin/freeswitch /usr/bin/
sudo ln -s /usr/local/freeswitch/bin/fs_cli /usr/bin
添加具有较低权限的新组和用户来运行 FreeSWITCH 服务。
cd /usr/local
sudo groupadd freeswitch
sudo adduser --disabled-password --quiet --system
--home /usr/local/freeswitch --gecos "FreeSWITCH Voice Platform" --ingroup freeswitch freeswitch
sudo chown -R freeswitch:freeswitch /usr/local/freeswitch/
sudo chmod -R ug=rwX,o= /usr/local/freeswitch/
sudo chmod -R u=rwx,g=rx /usr/local/freeswitch/bin/
我们需要将 FreeSwitch 添加为 systemd 单元文件。使用您喜欢的编辑器打开新文件 /etc/systemd/system/freeswitch.service并 粘贴以下内容:
sudo vim /etc/systemd/system/freeswitch.service
粘贴以下内容
[Unit]
Description=freeswitch
Wants=network-online.target
Requires=syslog.socket network.target local-fs.target
After=syslog.socket network.target network-online.target local-fs.target
[Service]
Type=forking
Environment="DAEMON_OPTS=-nonat"
EnvironmentFile=-/etc/default/freeswitch
ExecStartPre=/bin/chown -R freeswitch:freeswitch /usr/local/freeswitch
ExecStart=/usr/bin/freeswitch -u freeswitch -g freeswitch -ncwait $DAEMON_OPTS
TimeoutSec=45s
Restart=always
RestartSec=90
StartLimitInterval=0
StartLimitBurst=6
User=root
Group=daemon
LimitCORE=infinity
LimitNOFILE=100000
LimitNPROC=60000
LimitSTACK=250000
LimitRTPRIO=infinity
LimitRTTIME=infinity
IOSchedulingClass=realtime
IOSchedulingPriority=2
CPUSchedulingPolicy=rr
CPUSchedulingPriority=89
UMask=0007
NoNewPrivileges=false
[Install]
WantedBy=multi-user.target
启动 FreeSwitch 服务并在启动时启用它
sudo chmod ugo+x freeswitch.service
sudo systemctl start freeswitch.service
sudo systemctl enable freeswitch.service
现在检查 FreeSWITCH 服务的状态
sudo systemctl status freeswitch.service
如果 freeswitch 已正确安装并运行,输出应如下所示
现在您可以使用客户端连接到 FreeSWITCH,如下所示
# fs_cli -r
一般是软件或库找不到,有三种解决方法
安装过程中遇到的问题及解决方法
sudo apt install autoconf
sudo apt install libtool-bin
# git clone https://github.com/freeswitch/spandsp.git
# cd spandsp
# ./bootstrap.sh -j
# ./configure
# make
# make install
# ldconfig
# git clone https://github.com/freeswitch/sofia-sip.git
#cd sofia-sip
# ./bootstrap.sh -j
# ./configure
# make
# make install
# ldconfig
fatal error: openssl/ssl.h: No such file or directory
解决方法: sudo apt install libssl-dev
Package sqlite3 was not found
解决方法:
sudo apt install libsqlite3-dev
sudo apt install sqlite3
libcurl was not found
解决方法: sudo apt install libcurl4-nss-dev
Package libpcre was not found
解决方法: sudo apt install libpcre3-dev
Package speex was not found
sudo apt install libspeexdsp-dev
You need to either install libldns-dev or disable mod_enum in modules.conf
解决方法: sudo apt install libldns-dev
You need to either install libks or disable mod_verto in modules.conf
方法一:下载安装 https://github.com/signalwire/libks.git
方法二:1 禁用 mod_verto1
sudo vim modules.conf
#endpoints/mod_verto
error: You need to either install libedit-dev
解决方法: sudo apt install libedit-dev
缺少yasm
解决方法: sudo apt install yasm
You need to either install signalwire-client-c
方法一:下载编译安装: https://github.com/signalwire/signalwire-c.git
方法二: 注释掉modules.conf中的signalwire模块
编译错误
./include/apr_general.h:33:14: error: ‘__DARWIN_NSIG’ undeclared here (not in a function) 33 | #define NSIG __DARWIN_NSIG
注: 没找到原因,发现没有代码使用该定,直接将该行定义注释掉
接口过期编译错误
错误1:
In file included from src/switch_apr.c:79:
/usr/include/openssl/md5.h:49:27: note: declared here
49 | OSSL_DEPRECATEDIN_3_0 int MD5_Init(MD5_CTX *c);
| ^~~~~~~~
src/switch_apr.c:1177:9: warning: ‘MD5_Update’ is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
1177 | MD5_Update(&md5_context, input, inputLen);
解决方法:关闭接口过期警告
sudo vim Makefile
CFLAGS = -g -O2 -Wno-error=deprecated-declarations
错误2:
skinny_protocol.c:685:65: error: array subscript ‘skinny_message_t {aka struct skinny_message}[0]’ is partly outside array bounds of ‘unsigned char[292]’ [-Werror=array-bounds]
CFLAGS = -g -O2 -Wno-error=deprecated-declarations -Wno-error=array-bounds
解决方法:关闭相应告警
sudo vim Makefile
CFLAGS = -g -O2 -Wno-error=array-bounds
Makefile:1481: *** You must install libavformat-dev and libswscale-dev to build mod_av. Stop.
sudo apt install libavformat-dev
sudo apt install libswscale-dev
注: 如果编译时还提示找不到,需要重新执行sudo ./configure
缺少libtiff
configure: error: "Cannot build without libtiff (does your system require a libtiff-devel package?)"
解决方法:sudo apt install libtiff-dev
缺少uuid
src/switch_apr.c:81:10: fatal error: uuid/uuid.h: No such file or directory
解决方法:sudo apt install uuid
如果依旧找不到,查看 一下uuid.h文件的位置, 在笔者环境中,如下
$ ls /usr/include/linux/uuid.h
/usr/include/linux/uuid.h
可以看出uuid.h在linux目录下,只要相应的创建/usr/lnclude/uuid目录,并将linux/uuid.h拷贝过去可以了
/usr/bin/ld: ./.libs/libfreeswitch.so: undefined reference to `uuid_parse'
/usr/bin/ld: ./.libs/libfreeswitch.so: undefined reference to `uuid_unparse_lower'
/usr/bin/ld: ./.libs/libfreeswitch.so: undefined reference to `uuid_generate'
解决方法:sudo apt install uuid-dev
making all mod_spandsp
make[4]: Entering directory `/usr/local/src/freeswitch-1.10.9.-release/src/mod/applications/mod_spandsp'
CC mod_spandsp_la-mod_spandsp.lo
CC mod_spandsp_la-udptl.lo
CC mod_spandsp_la-mod_spandsp_fax.lo
CC mod_spandsp_la-mod_spandsp_dsp.lo
mod_spandsp_dsp.c: In function ‘get_v18_mode’:
mod_spandsp_dsp.c:159:10: error: ‘V18_MODE_5BIT_4545’ undeclared (first use in this function)
int r = V18_MODE_5BIT_4545;
^
mod_spandsp_dsp.c:159:10: note: each undeclared identifier is reported only once for each function it appears in
mod_spandsp_dsp.c:165:8: error: ‘V18_MODE_5BIT_50’ undeclared (first use in this function)
r = V18_MODE_5BIT_50;
^
mod_spandsp_dsp.c: In function ‘spandsp_tdd_send_session’:
mod_spandsp_dsp.c:216:2: error: too few arguments to function ‘v18_init’
tdd_state = v18_init(NULL, TRUE, get_v18_mode(session), V18_AUTOMODING_GLOBAL, put_text_msg, NULL);
^
In file included from /usr/local/include/spandsp.h:111:0,
from mod_spandsp.h:50,
from mod_spandsp_dsp.c:36:
/usr/local/include/spandsp/v18.h:138:29: note: declared here
SPAN_DECLARE(v18_state_t *) v18_init(v18_state_t *s,
^
mod_spandsp_dsp.c: In function ‘spandsp_tdd_encode_session’:
mod_spandsp_dsp.c:263:2: error: too few arguments to function ‘v18_init’
pvt->tdd_state = v18_init(NULL, TRUE, get_v18_mode(session), V18_AUTOMODING_GLOBAL, put_text_msg, NULL);
^
In file included from /usr/local/include/spandsp.h:111:0,
from mod_spandsp.h:50,
from mod_spandsp_dsp.c:36:
/usr/local/include/spandsp/v18.h:138:29: note: declared here
SPAN_DECLARE(v18_state_t *) v18_init(v18_state_t *s,
^
mod_spandsp_dsp.c: In function ‘spandsp_tdd_decode_session’:
mod_spandsp_dsp.c:341:2: error: too few arguments to function ‘v18_init’
pvt->tdd_state = v18_init(NULL, FALSE, get_v18_mode(session), V18_AUTOMODING_GLOBAL, put_text_msg, pvt);
^
In file included from /usr/local/include/spandsp.h:111:0,
from mod_spandsp.h:50,
from mod_spandsp_dsp.c:36:
/usr/local/include/spandsp/v18.h:138:29: note: declared here
SPAN_DECLARE(v18_state_t *) v18_init(v18_state_t *s,
^
make[4]: *** [mod_spandsp_la-mod_spandsp_dsp.lo] Error 1
make[4]: Leaving directory `/usr/local/src/freeswitch-1.10.9.-release/src/mod/applications/mod_spandsp'
make[3]: *** [mod_spandsp-all] Error 1
make[3]: Leaving directory `/usr/local/src/freeswitch-1.10.9.-release/src/mod'
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/usr/local/src/freeswitch-1.10.9.-release/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/usr/local/src/freeswitch-1.10.9.-release'
make: *** [all] Error 2
[root@maomaosPC freeswitch-1.10.9.-release]#
将源代码放到Source Insight工程中搜索相关关键词检查发现是spandsp中的内容导致的编译错误,freeswitch相关部分的代码和spandsp模块代码不匹配,去GitHub上查看提交记录,刚好是23年6月底提交的,离我编译就隔了几天的时间,真是个倒霉蛋哦。言归正传,这时候考虑回退spandsp的代码到之前代码匹配的版本,然后重新编译就可以编译成功。
具体步骤:
//先切到对应目录下删除相关内容
cd /usr/local/src/freeswitch
rm -rf spandsp
//重新拉取代码
git clone https://github.com/freeswitch/spandsp.git
//spandsp目录下执行git log或者gitlab上查看对应commit id并切换
git checkout -b finecode20230705 0d2e6ac65e0e8f53d652665a743015a88bf048d4
//按照之前的步骤重新编译安装
//在Github上反馈了这个问题后, 维护人员2023/07/19回复:
mod_spandsp uses the defines you change, e.g. V18_MODE_5BIT_4545 from v18.h,
so it is broken now as it hasn't been updated. It needs to be updated with new defines.
文件 | 说明 |
---|---|
vars.xml | 一些常用变量 |
dialplan/default.xml | 缺省的拨号计划 |
directory/default/*.xml | SIP用户,每用户一个文件 |
sip_profiles/internal.xml | 一个SIP |
sip_profiles/externa.xml | 另一个SIP-UA,用作外部连接,端口5080 |
autoload_configs/modules.conf.xml | 配置当FreeSWITCH启动时自动装载哪些模块 |
cd /usr/local/freeswitch/conf
#(freeswitch1.10.9在/usr/local/freeswitch/etc/freeswitch目录下)
#找到vars.xml修改:(可以copy一份存为vars.xml.bak备份)
#修改默认端口
#
#5060默认为freswitch 的sip信令内部端口
1、在var.xml中修改
<!--X-PRE-PROCESS cmd="stun-set" data="external_rtp_ip=stun:stun.freeswitch.org"/-->
这里没有使用stun功能,而是直接把公网ip填在这里
<X-PRE-PROCESS cmd="stun-set" data="external_rtp_ip="阿里云分配的公网ip"/>
(freeswitch1.10.9好像如果是默认的端口不用配置这个也能正常使用,修改xml文件后无法访问需要设置stun再reloadxml)
在var.xml中修改了之后,就无需在conf/sip_profiles/internal.xml 和 external.xml中修改了,
网上有很多例子都是直接在这两个文件改其实不用,var中改好了之后,这两个文件直接引用external_rtp_ip这个变量即可。
防火墙配置完成后应该就可以了,使用设备注册上服务器拨打下回音电话9196试试能不能听到回音。
FreeSwitch常用默认号码:
号码 | 说明 |
---|---|
9664 | 保持音乐 |
9191 | 注册CluCon |
9192 | 调用info在log中显示Channel信息 |
9195 | echo, 回音测试,延迟5秒 |
9196 | echo,回音测试 |
9197 | milliwatte extention, 铃音生成 |
9198 | TGML铃音生成示例 |
9180 | 铃音测试,使用远端生成的回铃音 |
9181 | 铃音测试,产生英式铃音 |
9182 | 铃音测试,使用音乐当铃音,彩铃 |
9183 | 先应答,然后发送英式铃音 |
9184 | 先应答,然后发送音乐铃音 |
9178 | 收传真 |
9179 | 发传真 |
5000 | IVR实例 |
4000 | 听取主意信箱 |
33xx | 电话会议,48Hz(其中xx为00~99,下同) |
32xx | 电话会议,32Hz(其中xx为00~99,下同) |
31xx | 电话会议,16Hz(其中xx为00~99,下同) |
30xx | 电话会议,8Hz(其中xx为00~99,下同) |
2000-2002 | 呼叫组 |
1000-1019 | 默认分机号码(默认密码1234) |
FreeSwitch默认号码大部分是拨号计划的名称,具体定义在conf/diaplan/default.xml中
修改默认密码:vars.xml
freeswitch批量添加用户
参考:https://blog.51cto.com/u_15049794/3833216
(freeswitch1.10.9在/usr/local/freeswitch/etc/freeswitch目录下寻找)
在/usr/local/freeswitch/conf/directory/default
下有1000.xml~1019.xml
这20个默认用户的配置文件
创建用户的xml后,要加载这些新用户的xml,需要修改/usr/local/freeswitch/conf/dialplan/default.xml这个文件里的拨号规则(正则表达式):
<extension name="Local_Extension">
<condition field="destination_number" expression="^([0-9]\d+)$">
<action application="set" data="call_timeout=120"/>
condition>
extension>
主要是改下正则表达式,允许所有数字。另外,默认还有一个N秒不接认为超时的配置,默认是30秒,如果有需要调整的,也可以一并修改。
调整/usr/local/freeswitch/conf/dialplan/public.xml
<extension name="public_extensions">
<condition field="destination_number" expression="^([0-9]\d+)$">
<action application="transfer" data="$1 XML default"/>
condition>
extension>
批量生成用户xml文件:
import org.apache.commons.lang3.StringUtils;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class CreateFreeswitchUser {
public static void main(String[] args) throws IOException {
String template = "D:\\soft\\FreeSWITCH\\conf\\directory\\default\\";
String templateContent = read(template + "1000.xml");
//创建99个用户
for (int i = 1; i < 100; i++) {
String newUser = "1" + StringUtils.leftPad(i + "", 3, '0');
String newContent = templateContent.replaceAll("1000", newUser);
String newFileName = template + newUser + ".xml";
write(newFileName, newContent);
System.out.println(newFileName + " done!");
}
}
static String read(String fileName) throws IOException {
File f = new File(fileName);
if (!f.exists()) {
return null;
}
FileInputStream fs = new FileInputStream(f);
String result = null;
byte[] b = new byte[fs.available()];
fs.read(b);
fs.close();
result = new String(b);
return result;
}
static void write(String fileName, String fileContent) throws IOException {
File f = new File(fileName);
if (f.exists()) {
f.delete();
}
FileOutputStream fs = new FileOutputStream(f);
fs.write(fileContent.getBytes());
fs.flush();
fs.close();
}
}
然后将生成的用户文件拷贝到/usr/local/freeswitch/conf/directory/default
目录下
ps -ef | grep freeswithch 查看进程号
netstat -an | grep 5060 查询FreeSWITCH 监听在哪个IP地址上(默认5060端口的情况下)
whereis freeswitch 查看freeswitch安装路径
freeswitch -help可查看帮助信息
freeswitch 启动并前台运行
freeswitch -nc 启动并后台运行
freeswitch -stop 停止
fs_cli 进入freeswitch控制台后:
show registrations 查看注册用户情况
sofia status profile internal reg 显示在线注册用户信息
status 查看freeswitch的运行状态
/exit 或 /quit 或 /bye 退出fs_cli
shutdown 关闭freeswitch
reloadxml 重新加载xml配置
console loglevel 7 开启控制台日志级别, 0-7, 数字越大日志越多
version 显示版本信息
推荐portsip-uc和linphone,Android和Windows均有安装包,portsip在IOS上应该也是有客户端的,可自行搜索下载使用
1、官网下载ffmpeg4.1。
2、进入ffmpeg4.1根目录执行
`./configure --enable-shared --enable-gpl --enable-libx264 --enable-libspeex`
3、执行make和make install。如果出现类似
make: Warning: File ffbuild/config.mak' has modification time 8011 s in the future
的警告执行
find . -type f | xargs -n 5 touch。
4、执行ldconfig加载。
5、执行ffmpeg -codecs如果能返回编码,表示编译成功。
备注:先要安装`libx264。`
如果无法执行有可能是路径错误,尝试设置环境变量LD_LIBRARY_PATH={安装路径},
查找安装路径的方法:`find / -name ffmpeg`。