下载freeswitch包

1
https://freeswitch.org/confluence/display/FREESWITCH/FreeSWITCH+1.10.x+Release+notes

找到最新安装包for centos

安装依赖

1
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

安装cmake

1
2
3
4
5
6
7
8
yum remove cmake #卸载yum安装的版本,若无安装则忽略
cd /usr/local/src
wget https://cmake.org/files/v3.14/cmake-3.14.0.tar.gz
tar vzxf cmake-3.14.0.tar.gz
cd cmake-3.14.0
./configure
make
make install

安装libks

1
2
3
4
5
6
7
cd /usr/local/src
yum install libatomic
git clone https://github.com/signalwire/libks.git
cd libks
cmake .
make
make install

安装signalwire-c

1
2
3
4
5
6
7
cd /usr/local/src
git clone https://github.com/signalwire/signalwire-c.git
cd signalwire-c/
cmake .
make
make install
ln -sf /usr/local/lib64/pkgconfig/signalwire_client.pc /usr/lib64/pkgconfig/signalwire_client.pc

编译x264

1
2
3
4
git clone http://git.videolan.org/git/x264.git
./configure –disable-asm
make
make install

编译安装mod_av

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
wget http://download1.rpmfusion.org/free/el/updates/7/x86_64/x/x264-libs-0.148-24.20170521gitaaa9aa8.el7.x86_64.rpm
wget http://download1.rpmfusion.org/free/el/updates/7/x86_64/x/x264-devel-0.148-24.20170521gitaaa9aa8.el7.x86_64.rpm
rpm -hiv x264-libs-0.148-24.20170521gitaaa9aa8.el7.x86_64.rpm
rpm -hiv x264-devel-0.148-24.20170521gitaaa9aa8.el7.x86_64.rpm
cd /usr/local/src
git clone https://gitee.com/nwaycn/libav.git
cd libav
./configure --enable-pic --enable-shared --enable-libx264 --enable-gpl --extra-libs="-ldl"
make
make install

cp /usr/local/lib/pkgconfig/libavcodec.pc /usr/lib64/pkgconfig/
cp /usr/local/lib/pkgconfig/libavdevice.pc /usr/lib64/pkgconfig/
cp /usr/local/lib/pkgconfig/libavfilter.pc /usr/lib64/pkgconfig/
cp /usr/local/lib/pkgconfig/libavformat.pc /usr/lib64/pkgconfig/
cp /usr/local/lib/pkgconfig/libavresample.pc /usr/lib64/pkgconfig/
cp /usr/local/lib/pkgconfig/libavutil.pc /usr/lib64/pkgconfig/
cp /usr/local/lib/pkgconfig/libswscale.pc /usr/lib64/pkgconfig/
ldconfig #动态链接库管理命令,其目的为了让动态链接库为系统所共享

安装spandsp

1
2
3
4
5
6
7
cd /usr/local/src/freeswitch-1.10.5.-release
git clone https://github.com/freeswitch/spandsp.git
cd spandsp
./configure
make
make install
ldconfig

安装sofia-sip

1
2
3
4
5
6
7
8
cd /usr/local/src/freeswitch-1.10.5.-release
git clone https://github.com/freeswitch/sofia-sip.git
cd sofia-sip
./bootstrap.sh -j
./configure
make
make install
ldconfig

设置包路径

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

安装编译环境

1
yum install -y http://files.freeswitch.org/freeswitch-release-1-6.noarch.rpm epel-release

编译Freeswitch

1
2
3
4
5
6
7
cd /usr/local/src/
tar vzxf freeswitch-1.10.5.-release.tar.gz
cd freeswitch-1.10.5.-release
./configure --disable-signalwire
# 如果在configure报错,再重新设置下包路径
make
make install

You must install libopus-dev to build mod_opus. Stop.报错

找到codecs目录,直接删除codec_opus子目录。编译成功

配置freeswitch任何路径启动

1
2
ln -sf /usr/local/freeswitch/bin/freeswitch /usr/local/bin/
ln -sf /usr/local/freeswitch/bin/fs_cli /usr/local/bin/

freeswitch 后台启动

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 后台启动命令
freeswitch -nc -rp

# 进入命令
fs_cli

# 退出命令
/exit
/bye
等等...

# fs_cli报错
fs_cli.c:1673 main() Error Connecting [] 
# 解决方法
vim /usr/local/freeswitch/conf/autoload_configs/event_socket.conf.xml
<param name="listen-ip" value="::"/> 改为 <param name="listen-ip" value="0.0.0.0"/>

设置fs支持ssl

宝塔面板设置域名及nginx设置

设置nginx的ssl

配置fs

  • 打开conf/vars.conf 设置支持ssl的配置

    1
    2
    3
    <X-PRE-PROCESS cmd="set" data="internal_ssl_enable=true"/> 
    <X-PRE-PROCESS cmd="set" data="external_auth_calls=true"/>
    <X-PRE-PROCESS cmd="set" data="external_ssl_enable=true"/>
  • 打开conf/sip_profiles/internal.xml 查看ws和wss端口是否已打开

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<!-- for sip over websocket support -->
<param name="ws-binding" value=":5066"/>

<!-- for sip over secure websocket support -->
<!-- You need wss.pem in $${certs_dir} for wss or one will be created for you -->
<param name="wss-binding" value=":7443"/>


# 在底部增加:
<param name="apply-candidate-acl" value="121.37.189.177"/>
<param name="apply-candidate-acl" value="rfc1918.auto"/>
<param name="apply-candidate-acl" value="localnet.auto"/>
<param name="apply-candidate-acl" value="lan"/>
<param name="apply-candidate-acl" value="wan"/>
  • 打开conf/autoload_configs/acl_conf.xml并配置
1
2
<list name="localnet.auto" default="allow">
</list>
  • 配置fs证书为宝塔设置的证书
1
2
3
4
5
6
7
cd /usr/local/freeswitch/certs
# 备份fs的原有证书
mv wss.pem wss.pem.bak

touch wss.pem
cat /etc/xxx/live/xxx.com/fullchain.pem > wss.pem
cat /etc/xxx/live/uxxx.com/privkey.pem > wss.pem

配置网关

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
# 新建文件 /usr/local/freeswitch/conf/dialplan/default/00_gw1.xml

<include>
<extension name="call_out3">
<condition field="destination_number" expression="^10(.*)$">
<action application="set" data="effective_caller_id_name=200200001"/>
<action application="set" data="effective_caller_id_number=200200001"/>
<!--<action application="bridge" data="sofia/gateway/gw3/$1"/>-->
<action application="bridge" data="sofia/gateway/gw3/cs1$1"/>
</condition>
</extension>

</include>

# 新建文件 /usr/local/freeswitch/conf/sip_profiles/external/gw1.xml

<include>
<gateway name="gw3">
<param name="realm" value="121.196.168.81:62019"/>
<param name="proxy" value="121.196.168.81:62019"/>
<param name="username" value=""/>
<param name="password" value=""/>
<param name="register" value="false"/>
<param name="caller-id-in-from" value="true"/>
</gateway>
</include>

重启fs服务

1
sofia profile external rescan reloadxml

拨号测试

1
2
3
originate {effective_caller_id_numer=200200001}sofia/internal/xxx15180347840@x.x.x.x:5060 &bridge(user/1001)

# xxx 为呼叫前缀

originate {effective_caller_id_numer=846374233}sofia/internal/18757131514@112.74.104.148:7060 &bridge(user/1000)

originate {auto_answer=true,effective_caller_id_numer=846374233}sofia/external/18757131514@112.74.104.148:7060 &bridge({instant_ringback=true,effective_caller_id_numer=846374233}sofia/external/15058371889@112.74.104.148:7060)

查看已注册的坐席

bgapi originate {ringback=/usr/local/freeswitch/sounds/229.wav,ignore_early_media=true,effective_caller_id_numer=846374233}sofia/gateway/gw2/18757131514 ‘&lua(call.lua 360 15058371889 846374233)

平安车险 小蒋
4558.00
200万+座位险41万/坐