安装freeswitch最好能更改为yum为国内的源,不然下载依赖包会非常慢。

安装依赖包

 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
查看系统版本
cat /etc/centos-release

yum update -y

sudo yum install epel-release vim tcpdump net-tools.x86_64 -y

sudo yum install gcc-c++ sqlite-devel zlib-devel libcurl-devel pcre-devel speex-devel ldns-devel libedit-devel openssl-devel git -y

yum install yasm nasm opus-devel -y

yum groupinstall perl* -y

yum install python -y

yum install bzip2 -y

yum install -y libshout-devel lame-devel libmpg123-devel

yum install bc -y

yum install curl -y

yum install expect telnet -y

yum install -y unixODBC unixODBC-devel mysql-connector-odbc

yum install -y yum-plugin-ovl centos-release-scl rpmdevtools yum-utils git wget vim devtoolset-7-gcc* devtoolset-7 libtiff-devel cmake3 libatomic unixODBC unixODBC-devel.x86_64 postgresql-libs postgresql-devel libpqxx-devel

# 执行上面好像就异常了

yum install -y gcc-c++ autoconf automake libtool ncurses-devel zlib-devel libjpeg-devel openssl-devel e2fsprogs-devel sqlite-devel libcurl-devel pcre-devel speex-devel ldns-devel libedit-devel libxml2-devel libyuv-devel libvpx-devel libvpx2* libdb4* libidn-devel unbound-devel libuuid-devel lua-devel libsndfile-devel yasm-devel

[!NOTE] 注意: curl#6 - “Could not resolve host: mirrorlist.centos.org; Name or service not known”

vim /etc/yum.repos.d/CentOS-Base.repo

增加下面内容: [centos-sclo-rh] name=CentOS-7 - SCLo rh baseurl=http://vault.centos.org/centos/7/sclo/$basearch/rh/ gpgcheck=1 enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo [centos-sclo-sclo] name=CentOS-6.10 - SCLo sclo baseurl=http://vault.centos.org/centos/7/sclo/$basearch/sclo/ gpgcheck=1 enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

拉取freeswitch源码

1
2
3
4
mkdir -p /data/freeswitch
cd /data/freeswitch
git clone --branch v1.10.12 https://github.com/signalwire/freeswitch.git
#https://github.com/signalwire/freeswitch/archive/refs/tags/v1.10.12.tar.gz

编译安装sofia-sip模块

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
git clone https://github.com/freeswitch/sofia-sip

cd sofia-sip

./bootstrap.sh -j

./configure

make

make install

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

ldconfig

编译安装spandsp模块

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
cd /data/freeswitch

git clone https://github.com/freeswitch/spandsp.git

cd spandsp

./bootstrap.sh -j

./configure

make

make install

ldconfig

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH

编译安装freeswitch

1
2
3
4
5
6
7
8
9
./bootstrap.sh -j

./configure --enable-portable-binary --prefix=/usr/local/freeswitch --with-gnu-ld --with-python --with-openssl --enable-core-odbc-support --enable-zrtp

#./configure    --enable-shared --enable-libx264 --enable-gpl

make

make install

编译中可能出现错误

  1. checking for libks2 >= 2.0.0… checking for libks >= 1.8.2… configure: error: You need to either install libks2 or libks or disable mod_verto in modules.conf
# modules.conf需要在freeswit安装源目录中执行./bootstrap.sh -j,才会生成
vim ./modules.conf
# 找到endpoints/mod_verto,注释掉
  1. checking for libks2 >= 2.0.0… checking for libks >= 1.8.2… configure: error: You need to either install libks2 or libks or disable mod_signalwire in 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
# 两个方法,安装signalwire或直接注释这个applications/mod_signalwire模块
# 安装signwire需要安装cmake,和libks
# 上面已经安装cmake3可以直接使用
wget https://cmake.org/files/v3.13/cmake-3.13.3.tar.gz
tar -zxvf cmake-3.13.3.tar.gz
cd cmake-3.13.3 
 ./bootstrap
 make
 make install

# 安装libks,要注意最新版本是libks2,如果需要libks,安装-bv1.8.3
git clone  https://github.com/signalwire/libks.git
cmake3 .
make
make install

git clone https://github.com/signalwire/signalwire-c.git
cmake3 .
make
make install

# 映射生效
vi ~/.bashrc
# 增加下面的的内容
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/local/lib64/pkgconfig:${PKG_CONFIG_PATH}

# 执行下面命令
source ~/.bashrc

# 解决这些错误后,再从新执行安装freeswitch的命令
  1. You must install libavformat-dev and libswscale-dev to build mod_av. Stop
 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
# mod_av安装花了很多时间,如果不需要这个模块,可以到modules注释掉
# 安装了这个依然失败,放弃这个(不要安装)
git clone https://freeswitch.org/stash/scm/sd/libav.git
cd libav
./configure             #CFLAGS="-fPIC" ./configure --enable-pic --enable-shared
make                    # make CXXFLAGS="-fPIC"
make install

# 从网上找到方法直接安装ffmpeg 3.4,注意ffmpeg的版本
# 安装依赖
yum -y install makeautomake bzip2 unzip patch subversion libjpeg-devel
# 安装依赖库
git clone https://github.com/cisco/openh264
make && make install
git clone https://code.videolan.org/videolan/x264
make && make install


wget -c http://files.freeswitch.org/downloads/libs/libx264.tar.bz2
tar -jxvf libx264.tar.bz2
cd libx264
./configure --enable-static --enable-shared --prefix=/usr
make
sudo make install
sudo cp /usr/lib/pkgconfig/x264.pc /usr/lib64/pkgconfig/
sudo cp /usr/lib/libx264.so /usr/lib64/
sudo cp /usr/lib/libx264.a /usr/lib64/

# 每次编译失败后,需要make uninstall,之后在make clean
git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg 
cd ffmpeg 
git checkout n3.4
./configure --enable-shared --disable-static --enable-libopenh264 --enable-libx264 --enable-gpl --enable-nonfree --enable-encoder=libx264 --enable-encoder=libx264rgb --enable-encoder=bmp --enable-encoder=png
make
make install
  1. You must install libopus-dev to build mod_opus. Stop
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
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
  1. mod_spandsp编译异常,如下错误
 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
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:114: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:114: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:114: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 `/data/freeswitch/freeswitch/src/mod/applications/mod_spandsp'
make[3]: *** [mod_spandsp-all] Error 1
make[3]: Leaving directory `/data/freeswitch/freeswitch/src/mod'
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/data/freeswitch/freeswitch/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/data/freeswitch/freeswitch'
make: *** [all] Error 2

# freeswitch v1.10.12版本最新的spandsp也不适合
git clone https://github.com/freeswitch/spandsp.git 
# spandsp目录下执行git log或者gitlab上查看对应commit id并切换 
git checkout -b finecode20230705 0d2e6ac65e0e8f53d652665a743015a88bf048d4
./bootstrap.sh 
./configure 
make 
make install

建立软链接

1
2
3
4
5
6
7
sudo ln -sf /usr/local/freeswitch/bin/freeswitch /usr/local/bin/
sudo ln -sf /usr/local/freeswitch/bin/fs_cli /usr/local/bin/

# 也可以设置开机启动
cp -r /usr/local/freeswitch/bin/freeswitch /etc/rc.d/init.d
echo -e "/etc/init.d/freeswitch -nonat -nc" >> /etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local

测试运行

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# 后台启动freeswitch服务 
freeswitch -nc -rp 
freeswitch -nonat -nc -rp //不检查路由穿透行,加上此参数后会启动很快 
freeswitch -stop  //停止
fs_cli 
# freeswitch -help 
             -help -- 显示本帮助信息 
             -version -- 显示版本信息 
             -rp -- 开启高优先级(实时)设置 
             -nosql -- 不使用SQL,show channels 类的命令将不能显示结果 
             -nonat -- 如果路由器支持uPnP或NAT-PMP,则FreeSWITCH可以自动解决NAT穿越问题。如果路由器不支持,则该选项可以使启动更快 
             -stop -- 关闭 FreeSWITCH,它会在run目录中查找 PID文件 
             -nc -- 启动到后台模式,没有控制台

sngrep抓包工具

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# sngrep 抓包工具
# 安装依赖 可能存在问题:configure: error:  You need to have libpcap installed to compile sngrep
yum install libpcap-devel

# https://github.com/irontec/sngrep/releases 查看相应版本
wget https://github.com/irontec/sngrep/releases/download/v1.8.2/sngrep-1.8.2.tar.gz
tar -xzvf sngrep-1.8.2.tar.gz
cd sngrep-1.8.2
./bootstrap.sh
./configure
make
make install

# 运行
sngrep

终端链接工具

Linephone,包括window,android,ios(需要国外账号)

可能存在问题

  1. 32秒挂掉这个问题没有出现,不知道是不是这台机器没有开防火墙的原因呢,有待考究。
  2. openssl的版本会影响会编译的,最好能还原到最原始的版本:OpenSSL 1.0.2k-fips 26 Jan 2017(第一次安装就因为这个版本花了大量时间)

总结

以上安装教程,参考网上很多教程整理,很感谢他们分享。

  1. centos 7无需token编译安装freeswitch 1.10.11 ——筑梦之路
  2. docker 基于Debian镜像安装FreeSwitch1.10.7
  3. 最全FreeSwitch 1.10.9 Linux通用编译部署教程