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

最全FreeSwitch CentOS通用编译部署教程


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

cat /proc/version 或者 uname -a命令查看
Linux version 3.10.0-1160.90.1.el7.x86_64 ([email protected]) (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不必单独拉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时没有报依赖的错误,但是报了spandsp相关内容编译的错误:

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中的内容导致的编译错误,去GitHub上查看提交记录,刚好是23年6月底提交的,离我编译就几天的时间,真是倒霉蛋哦,这时候就考虑回退spandsp的代码到之前的版本,然后重新编译就可以编译成功了
具体步骤:

//先切到对应目录下删除相关内容
cd /usr/local/src/freeswitch
rm -rf spandsp
//重新拉取代码
git clone https://github.com/freeswitch/spandsp.git
//git log或者gitlab上查看对应commit id并切换
git checkout -b finecode20230705 0d2e6ac65e0e8f53d652665a743015a88bf048d4
//按照之前的步骤重新编译安装

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/*.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信令内部端口

修改语音流端口,freeswitch默认rtp语音端口范围如下:




9.防火墙配置

1、在var.xml中修改
这里没有使用stun功能,而是直接把公网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

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这个文件里的拨号规则(正则表达式):










主要是改下正则表达式,允许所有数字。另外,默认还有一个N秒不接认为超时的配置,默认是30秒,如果有需要调整的,也可以一并修改。
调整/usr/local/freeswitch/conf/dialplan/public.xml


   
   
       
   

批量生成用户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.参考:

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

你可能感兴趣的:(Freeswitch,SIP,freeswitch,sip,centos,linux)