最全FreeSwitch 1.10.9 Linux通用编译部署教程

FreeSwitch 通用编译部署教程


FreeSwitch的版本历程

2006年-第一个版本
2008年-1.0凤凰版
2012年-Freeswitch 1.2
2014年-FreeSwitch 1.4 WebRTC
2015年-FreeSwitch 1.6 视频通话和视频会议
2017年-FreeSwitch 1.8
2019年-FreeSwitch 1.10
2020年-FreeSwitch 1.10.3
2023年-FreeSwitch 1.10.9

此安装教程自测freeswitch1.10.2与freeswitch1.10.9版本能正常安装,freeswitch1.10.7/freeswitch1.10.8安装情况应该与freeswitch1.10.9相同

1.基础环境

操作系统:
阿里云ECS CentOS Linux release 7.9 (Ubuntu等Linux系统安装一些问题见文末,可参照前面的步骤,基本上大同小异)

cat /proc/version 或者 uname -a命令查看
Linux version 3.10.0-1160.90.1.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) )

2.安装方式

使用源码编译安装

可使用git拉取代码编译安装,也可以使用WinSCP等工具上传源码tar包到服务器再编译安装

3.安装基础依赖

yum install -y git alsa-lib-devel autoconf automake bison broadvoice-devel bzip2 curl-devel libdb4-devel e2fsprogs-devel erlang flite-devel g722_1-devel gcc-c++ gdbm-devel gnutls-devel ilbc2-devel ldns-devel libcodec2-devel libcurl-devel libedit-devel libidn-devel libjpeg-devel libmemcached-devel libogg-devel libsilk-devel libsndfile-devel libtheora-devel libtiff-devel libtool libuuid-devel libvorbis-devel libxml2-devel lua-devel lzo-devel mongo-c-driver-devel ncurses-devel net-snmp-devel openssl-devel opus-devel pcre-devel perl perl-ExtUtils-Embed pkgconfig portaudio-devel postgresql-devel python-devel python-devel soundtouch-devel speex-devel sqlite-devel unbound-devel unixODBC-devel wget which yasm zlib-devel libshout-devel libmpg123-devel lame-devel

4.下载cmake并进行编译安装

wget https://github.com/Kitware/CMake/releases/download/v3.23.0/cmake-3.23.0.tar.gz
tar -zvxf cmake-3.23.0.tar.gz
cd cmake-3.23.0
./bootstrap
make
make install

#链接
sudo ln -sf /usr/local/bin/cmake /usr/bin/cmake
sudo ln -sf /usr/local/bin/cpack /usr/bin/cpack
sudo ln -sf /usr/local/bin/ctest /usr/bin/ctest

5.需要手动安装所需的依赖

autoconf-2.71及以上版本
下载链接:http://mirrors.kernel.org/gnu/autoconf/

cd /usr/local/src
tar xzvf autoconf-2.71.tar.gz
cd autoconf-2.71
./configure  //做相关编译前的环境检查
make
make install

opus-1.3.1及以上版本

yum remove opus
cd /usr/local/src
wget https://archive.mozilla.org/pub/opus/opus-1.3.1.tar.gz
tar xzvf opus-1.3.1.tar.gz
cd opus-1.3.1
./configure  //做相关编译前的环境检查
make
make install
cp /usr/lib/pkgconfig/opus.* /usr/lib64/pkgconfig/

如果没安装opus编译时会报错
You must install libopus-dev to build mod_opus. Stop.
如果手动安装后还是不行参照如下方式进行安装:

cd /etc/yum.repos.d/
touch linuxtech.repo
vi  linuxtech.repo

//linuxtech.repo中添加如下内容:
//按i或者insert键进入编辑模式,按Esc键退出编辑模式,输入:wq!保存退出。

[linuxtech]
name=LinuxTECH
baseurl=http://pkgrepo.linuxtech.net/el6/release/
enabled=1
gpgcheck=1
gpgkey=http://pkgrepo.linuxtech.net/el6/release/RPM-GPG-KEY-LinuxTECH.NET

//最后安装opus:
yum install libopus-devel

6.下载源代码

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.
//如果安装freeswitch1.10.2等版本可以不用拉spandsp和sofia-sip的代码,直接在官网链接下载tar包导入服务器即可解压编译

cd /usr/local/src
git clone -b v1.10.9 https://github.com/signalwire/freeswitch

cd /usr/local/src/freeswitch
git clone https://github.com/freeswitch/spandsp.git
git clone https://github.com/freeswitch/sofia-sip.git
//编译spandsp
cd /usr/local/src/freeswitch/spandsp
./bootstrap.sh
./configure
make
make install
//编译sofia-sip
cd /usr/local/src/freeswitch/sofia-sip
./bootstrap.sh
./configure
make
make install
//添加库的路径到系统
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:${PKG_CONFIG_PATH} 
ldconfig

编译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  
//编译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
make install

如果编译时还是提示spandsp之类的未安装,返回对应文件夹make install一下spandsp并:

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:${PKG_CONFIG_PATH} 
ldconfig

再回去make clean一下,随后配置./configure,然后再重新尝试make

7.编译freeswitch1.10.9问题处理

安装好前面的依赖后,编译freeswitch1.10.9时应该没有报依赖的错误(如果有请检查是否有漏掉的步骤,或者百度解决,再次编译前记得make clean后重新./configure),但是报了spandsp相关内容编译的错误error: ‘V18_MODE_5BIT_4545’ undeclared:

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.

freeswitch安装完成后,为了让freeswitch在任何一个目录都可以运行,我们可以配置软连接:

ln -sf /usr/local/freeswitch/bin/freeswitch /usr/local/bin/
ln -sf /usr/local/freeswitch/bin/fs_cli /usr/local/bin/
//freeswitch默认安装路径/usr/local/freeswitch

8.常见配置文件说明

文件说明
vars.xml一些常用变量
dialplan/default.xml缺省的拨号计划
directory/default/*.xmlSIP用户,每用户一个文件
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备份)
修改默认端口
<X-PRE-PROCESS cmd="set" data="internal_sip_port=5060"/>
5060默认为freswitch 的sip信令内部端口

9.防火墙配置

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这个变量即可。

2、配置阿里云的防火墙及操作系统防火墙。具体参考:
https://developer.signalwire.com/freeswitch/FreeSWITCH-Explained/Networking/Firewall_1048908/

注:
阿里云点击:实例->安全组->配置规则,即可开始配置防火墙规则
另外,如果云服务器还安装了宝塔这里的工具,也需要在宝塔面板中对防火墙进行设置才能让freeswitch正常工作

防火墙配置完成后应该就可以了,使用设备注册上服务器拨打下回音电话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中

10.账号密码配置/添加新用户

修改默认密码:vars.xml
<X-PRE-PROCESS cmd="set" data="default_password=1234"/>

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="^(10[01][0-9])$">   -->
<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目录下

11.freeswitch后台基础操作指令

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 显示版本信息

12.相关tar包下载

如果网络不好拉不下来GitHub上的代码,可以下载下面的tar包编译试一下:(0积分,绝不给CSDN打一点工)包含:autoconf-2.71、cmake-3.23.0、opus-1.3.1、sofia-sip、spandsp、freeswitch-1.10.2.-release、freeswitch-1.10.9.-release
链接:
https://download.csdn.net/download/qq_36369267/88003573

13.VoIP客户端工具推荐:

推荐portsip-uc和linphone,Android和Windows均有安装包,portsip在IOS上应该也是有客户端的,可自行搜索下载使用

14.Ubuntu问题:

步骤与CentOS基本一致,具体步骤参考一下下面这篇博文:
https://blog.csdn.net/qq_40170041/article/details/123996904

编译部署可能遇到的问题:

#报错1
configure: error: no usable libodbc; please install unixodbc devel package or equivalent
#处理
sudo apt-get install unixodbc
或./configure时不带参数(unixodbc安装后没用时采用此方式)
#报错2:
src/switch_apr.c:81:23: fatal error: uuid/uuid.h: No such file or directory
#处理
sudo apt-get install uuid-dev

15.参考:

References:
https://www.cnblogs.com/kn-zheng/p/17388340.html
https://blog.51cto.com/lion3875/599416
http://www.360doc.com/content/15/0401/19/15077656_459884519.shtml

  • 9
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 13
    评论
部署 FreeSWITCH,你需要按照以下步骤进行操作: 1. 安装依赖: - 在 Ubuntu 上,可以使用以下命令安装所需的依赖: ``` sudo apt-get update sudo apt-get install -y autoconf automake libtool wget python-dev build-essential zlib1g-dev libjpeg-dev libncurses5-dev libssl-dev libsqlite3-dev libcurl4-openssl-dev libpcre3-dev libspeex-dev libspeexdsp-dev libldns-dev libedit-dev yasm ``` 2. 下载 FreeSWITCH 源码: - 使用以下命令从官方网站下载最新的 FreeSWITCH 源码包: ``` wget https://files.freeswitch.org/freeswitch-releases/freeswitch-1.10.5.tar.gz tar xzf freeswitch-1.10.5.tar.gz ``` 3. 编译和安装 FreeSWITCH: - 进入解压后的源码目录: ``` cd freeswitch-1.10.5 ``` - 运行以下命令进行配置和编译: ``` ./bootstrap.sh -j ./configure --prefix=/usr/local/freeswitch make && make install ``` 4. 设置系统服务: - 创建一个 systemd 服务单元文件 `/etc/systemd/system/freeswitch.service`,并将以下内容写入文件中: ``` [Unit] Description=FreeSWITCH After=network.target [Service] Type=forking User=freeswitch Group=freeswitch ExecStart=/usr/local/freeswitch/bin/freeswitch -ncwait -nonat -u freeswitch -g freeswitch PIDFile=/usr/local/freeswitch/run/freeswitch.pid [Install] WantedBy=default.target ``` - 运行以下命令启动 FreeSWITCH 服务: ``` systemctl daemon-reload systemctl enable freeswitch systemctl start freeswitch ``` 5. 验证安装: - 运行以下命令检查 FreeSWITCH 是否正在运行: ``` systemctl status freeswitch ``` - 如果一切正常,你应该能够看到 FreeSWITCH 运行的状态信息。 这些步骤应该能够帮助你成功部署 FreeSWITCH。如果你遇到任何问题,请查看 FreeSWITCH 官方文档或在社区寻求帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Ryan爱吃糖

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值