前言
freswitch在centos7下编译总体上还是步骤比较复杂的。
忠告
千万别使用 CentOS 部署 FreeSWITCH !!!
以下大部分都是笔者用 CentOS7 自编译踩得坑。
建议直接 Debian 安装官方编译好的包!!!可以少踩很多坑(严重怀疑官方歧视 CentOS)。
一、环境
centos 7.9
freeswitch 1.10.9
安装依赖
yum install gcc gcc-c++ 注意gcc需要4.8.5不能太高
yum install -y wget zlib-devel libjpeg-devel freetype-devel
官方插件
yum install -y epel-release
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 rpm-build libX11-devel libyuv-devel
安装高版本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
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
安装yasm
#安装
wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
tar -xvf yasm-1.3.0.tar.gz
cd yasm-1.3.0
./configure
make && make install
cd ..
首先安装nasm
wget https://www.nasm.us/pub/nasm/releasebuilds/2.14/nasm-2.14.tar.gz
tar -zxvf nasm-2.14.tar.gz
cd nasm-2.14
./configure
make
make install
二、下载源码
freeswitch下载地址: https://github.com/signalwire/freeswitch.git
另外有两个比较重新的库需要手动安装,分别是spandsp和sofia-sip
下载命令:
cd /data
git clone -b v1.10.9 https://github.com/signalwire/freeswitch
cd /data/freeswitch
git clone https://github.com/freeswitch/spandsp.git
git clone https://github.com/freeswitch/sofia-sip.git
三、编译
.安装 epel扩展和文件传输工具lrzsz
yum install -y epel-release lrzsz
.安装yasm
yum -y install yasm
- 编译必需库
首先,要先编译spandsp和sofia-sip, 否则freeswitch在configure阶段会报错。
#编译spandsp
cd /data/freeswitch/spandsp
./bootstrap.sh
./configure
make
make install
#编译sofia-sip
cd /data/freeswitch/sofia-sip
./bootstrap.sh
./configure
make
make install
添加库的路径到系统
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:${PKG_CONFIG_PATH}
ldconfig
修改module.conf
下面则是安装freeswitch, 由于freeswitch支持动态编译和动态加载,一些不需要的模块可以不编译,如:mod_signalwire、mod_av,修改方法: 找到module.conf文件,找到mod_signalwire和mod_av注释掉,修改如下:
#applications/mod_signalwire
#applications/mod_av
- 编译freeswitch
有了前两步的准备,编译freeswitch基本就不会遇到问题了,命令如下:
cd /data/freeswitch
./bootstrap.sh
./configure --enable-portable-binary --prefix=/usr/local/freeswitch --with-gnu-ld --with-python --with-openssl --enable-core-odbc-support --enable-zrtp
make
make install
编译完成后,会出现下面信息:
****************************** REPORT ******************************
UniMRCP version............... : 1.2.0
APR version................... : 1.2.8
APR-util version.............. : 1.2.8
Sofia-SIP version............. : 1.13.15
Compiler...................... : gcc
Compiler flags................ : -g -O2 -pthread
Preprocessor definitions...... : -D_REENTRANT -D_GNU_SOURCE
Linker flags.................. : -L/home1/irteam/freeswitch/libs/apr-util/xml/expat/lib
UniMRCP client lib............ : yes
Sample UniMRCP client app..... : yes
Sample UMC C++ client app..... : yes
Misc ASR client lib and app... : yes
UniMRCP server lib............ : yes
UniMRCP server app............ : yes
Demo synthesizer plugin....... : yes
Demo recognizer plugin........ : yes
Demo verifier plugin.......... : yes
Recorder plugin............... : yes
Installation layout........... : classic
Installation directory........ : /usr/local/freeswitch
********************************************************************
-------------------------- FreeSWITCH configuration --------------------------
Locations:
prefix: /usr/local/freeswitch
exec_prefix: /usr/local/freeswitch
bindir: ${exec_prefix}/bin
confdir: /usr/local/freeswitch/conf
libdir: ${exec_prefix}/lib
datadir: /usr/local/freeswitch
localstatedir: /usr/local/freeswitch
includedir: /usr/local/freeswitch/include/freeswitch
certsdir: /usr/local/freeswitch/certs
dbdir: /usr/local/freeswitch/db
grammardir: /usr/local/freeswitch/grammar
htdocsdir: /usr/local/freeswitch/htdocs
fontsdir: /usr/local/freeswitch/fonts
logfiledir: /usr/local/freeswitch/log
modulesdir: /usr/local/freeswitch/mod
pkgconfigdir: ${exec_prefix}/lib/pkgconfig
recordingsdir: /usr/local/freeswitch/recordings
imagesdir: /usr/local/freeswitch/images
runtimedir: /usr/local/freeswitch/run
scriptdir: /usr/local/freeswitch/scripts
soundsdir: /usr/local/freeswitch/sounds
storagedir: /usr/local/freeswitch/storage
cachedir: /usr/local/freeswitch/cache
四 ./configure编译问题解决
执行./configure,做相关编译前的环境检查,错误处理如下:
4.1 安装pcre
checking for libpcre >= 7.8... Package libpcre was not found in the pkg-config search path. Perhaps you should add the directory containing `libpcre.pc' to the PKG_CONFIG_PATH environment variable No package 'libpcre' found
configure: error: Library requirements (libpcre >= 7.8) not met; consider adjusting the PKG_CONFIG_PATH environment variable if your libraries are in a nonstandard prefix so pkg-config can find them.
少包,执行:
yum install pcre
yum install pcre-devel解决
4.2 安装speex
checking for speex >= 1.2rc1 speexdsp >= 1.2rc1... Package speex was not found in the pkg-config search path. Perhaps you should add the directory containing speex.pc' to the PKG_CONFIG_PATH environment variable No package 'speex' found Package speexdsp was not found in the pkg-config search path. Perhaps you should add the directory containing
speexdsp.pc' to the PKG_CONFIG_PATH environment variable No package 'speexdsp' found
configure: error: Library requirements (speex >= 1.2rc1 speexdsp >= 1.2rc1) not met; consider adjusting the PKG_CONFIG_PATH environment variable if your libraries are in a nonstandard prefix so pkg-config can find them.
执行:
yum install speex
yum install speex-devel
4.3 屏蔽libldns
checking for libldns >= 1.6.6... checking for ldns_str2rdf_a in -lldns... no
configure: error: You need to either install libldns-dev or disable mod_enum in modules.conf
vi modules.conf
#applications/mod_enum
4.4 安装libedit-dev
configure: error: You need to either install libedit-dev (>= 2.11) or configure with --disable-core-libedit-support
yum install libedit-devel
4.5、安装sounds声音文件
make sounds-install
make moh-install
4.6、注释掉mod_av
making all mod_av
make[4]: Entering directory /freeswitch/src/mod/applications/mod_av' Makefile:1442: *** You must install libavformat-dev and libswscale-dev to build mod_av. Stop. make[4]: Leaving directory
/freeswitch/src/mod/applications/mod_av'
vi modules.conf
#applications/mod_av
或者安装
wget https://libav.org/releases/libav-12.3.tar.gz
libav 12.3 - Download, Browsing & More | Fossies Archive
tar -xf libav-12.3.tar.gz
cd libav-12.3
./configure --enable-pic --enable-shared --enable-libx264 --enable-gpl --extra-libs="-ldl"
make
make install
注意,版本必须是12.3的版本,不然报错
avformat.c: In function 'no_video_decode_packets':
avformat.c:2464:59: error: 'AVStream {aka struct AVStream}' has no member named 'codecpar'; did you mean 'codec'?
switch_packetizer_feed_extradata(context->packetizer, st->codecpar->extradata, st->codecpar->extradata_size);
这是你的libav版本不对,你要用12.3的版本,之后的版本去掉了codec的指针,用了新的接口,对应mod_av不兼容。要么修改mod_av的源码把对应函数换成最新的,要么使用12.3的版本
但是,视频会议报错:
2023-07-06 14:14:34.648698 99.87% [NOTICE] avcodec.c:1432 codec: id=28 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
2023-07-06 14:14:34.648698 99.87% [DEBUG] conference_video.c:3381 Setting up video write codec H264 at slot 0 group none
2023-07-06 14:14:34.648698 99.87% [WARNING] switch_event.c:2975 no subscribers for conference-liveArray.chengdu-@10.10.10.10 , src/switch_event.c
2023-07-06 14:14:34.668703 99.87% [INFO] avcodec.c:1491 initializing encoder 1920x1080
2023-07-06 14:14:34.668703 99.87% [DEBUG] avcodec.c:1230 NVENC HW CODEC NOT PRESENT
2023-07-06 14:14:34.668703 99.87% [ERR] avcodec.c:1240 Cannot find encoder id: 28
2023-07-06 14:14:34.708702 99.87% [INFO] avcodec.c:1491 initializing encoder 1920x1080
2023-07-06 14:14:34.708702 99.87% [DEBUG] avcodec.c:1230 NVENC HW CODEC NOT PRESENT
另外,尝试安装ffmpeg-devel
直接用 Debian 系统安装 FreeSWITCH ,不需要自己苦逼的编译安装
mod_av 需要 libavformat-dev,但 CentOS 没有,通过第三方 yum 库安装 ffmpeg-devel 包实现(yum 的 FreeSWITCH 版本里面是没有 mod_av、mod_b64、mod_png 的,所以上面的安装也就没有):
rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm
yum install -y ffmpeg-devel
成功解决报错问题(Cannot find encoder id: 28)。
#########################
libav库
libav库的编译安装是可选的。
如果需要fs的mod_av模块,就要首先编译安装libav库。
使用ffmpeg库无法正常编译安装mod_av,过程较蛋疼。
编译安装libav库,要首先安装libx264库,否则mod_av库的编译还是会报错。
#编译安装libx264
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/
#编译安装libav
wget -c http://files.freeswitch.org/downloads/libs/libav-12.tar.bz2
tar -jxvf libav-12.tar.bz2
cd libav
./configure --enable-pic --enable-shared --enable-libx264 --enable-gpl --extra-libs="-ldl" --extra-cflags=-I/usr/include --extra-ldflags=-L/usr/lib64
make
sudo make install
sudo cp /usr/local/lib/pkgconfig/libavcodec.pc /usr/local/lib/pkgconfig/libavdevice.pc /usr/local/lib/pkgconfig/libavfilter.pc /usr/local/lib/pkgconfig/libavformat.pc /usr/local/lib/pkgconfig/libavresample.pc /usr/local/lib/pkgconfig/libavutil.pc /usr/local/lib/pkgconfig/libswscale.pc /usr/lib64/pkgconfig/
sudo ldconfig
4.7、注释掉mod_lua
make[4]: Entering directory `//freeswitch/src/mod/languages/mod_lua'
CXX mod_lua_la-mod_lua.lo
mod_lua.cpp:37:17: fatal error: lua.h: No such file or directory
#include "lua.h"
#languages/mod_lua
4.8、安装opus-devel
错误提示:You must install libopus-dev to build mod_opus
yum -y install opus-devel
如果还是报这个错误,在 Makefile 就注释这两行,暂时直接屏蔽,待确认(已放弃):
大概是在第 896、897 行
vim freeswitch/src/mod/codecs/mod_opus/Makefile
#install: error
#all: error
##########################################
这里单独说一下opus的安装,安装fs的时候可能会报错:“You must install libopus-dev to build mod_opus”,
解决方法:是手动安装opus-devel和opus,
RPM resource opus-devel
https://centos.pkgs.org/7/centos-x86_64/opus-1.0.2-6.el7.x86_64.rpm.html
例如我是通过rpm安装的:先下载opus-devel和opus的rpm包,然后执行:
rpm -ivh opus-devel-1.1.1-2.el7.x86_64.rpm
rpm -ivh opus-1.1.1-2.el7.x86_64.rpm。
安装完opus和opus-devel后,重新./configure并执行make clean,否则可能会有问题,这一点在这里有讲到。 很有可能在手动安装opus的时候系统会提示已安装过opus发生冲突,这时候执行yum remove opus卸载掉原来的opus即可。 关于opus这个模块,网上很多文章给出解决方案是修改Makefile文件绕过这个模块,但是本人并不推荐,因为fs的一些功能是依赖opus的(例如webrtc)。
默认安装 mod_opus,该插件安装失败的解决方案
问题,查询configure.consolelog.txt,可以发现项目依赖opus 1.1版本
#查看系统支持的opus版本:
yum list opus #可见系统只支持 1.0.2-6.el7
#因此先卸载
yum remove -y opus
#重新安装 1.1版本
#先下载 opus 1.1
wget http://pkgrepo.linuxtech.net/el6/release/x86_64/libopus-1.1-1.el6.x86_64.rpm
#安装
rpm -Uvh libopus-1.1-1.el6.x86_64.rpm
#再下载opus-devel 1.1
wget http://pkgrepo.linuxtech.net/el6/release/x86_64/libopus-devel-1.1-1.el6.x86_64.rpm
#安装
rpm -Uvh libopus-devel-1.1-1.el6.x86_64.rpm
#重新执行
./configure --prefix=/usr/local/freeswitch_1_6_20 --disable-multilib --with-lib-subdir=/usr/lib64 > configure.consolelog.txt #配置编译环境.
checking for opus >= 1.1... yes #依赖检查通过
#重新 make 即可成功
4.9、安装 libks
# libks
git clone https://github.com/signalwire/libks.git
cd libks
/usr/local/bin/cmake .
make
sudo make install
4.10、安装signalwire-c
Makefile:947: *** You must install signalwire-client-c to build mod_signalwire. Stop.
cd /usr/local/src/freeswitch
git clone https://github.com/signalwire/signalwire-c.git
cd signalwire-c
cmake .
make
sudo make install
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/local/lib64/pkgconfig:${PKG_CONFIG_PATH}
sudo ldconfig
ln -sf /usr/local/lib64/pkgconfig/signalwire_client.pc /usr/lib64/pkgconfig/signalwire_client.pc
或者
# signalwire
git clone https://github.com/signalwire/signalwire-c.git
cd signalwire-c
/usr/local/bin/cmake .
make
sudo make install
cp /usr/local/lib/pkgconfig/*.pc /usr/lib/pkgconfig/
cp -f /usr/local/lib/* /usr/lib64/
4.11、其他
- 报错让你安装libmpg123-dev,只需yum install mpg123-devel;
- 报错让你安装libmp3lame-dev,只需yum install lame-devel;
- 报错说缺少libshout3-dev,只需yum install libshout-devel等
关于声音文件安装。如果服务器能连外网,就很方便了,在源代码目录中执行:
make sounds-install
make moh-install
如果你的服务器不能连外网的话,可能还要手动下载声音文件并解压,然后放在/usr/local/freeswitch/sounds路径下。本人下载的是这两个(建议下载默认的8Khz语音文件):
GitHub - freeswitch/freeswitch-sounds
五、验证
freeswitch安装完成之后,下一步就是启动freeswitch并验证可用性了。
首先
- 启动freeswitch
cd /usr/local/freeswitch/bin
./freeswitch -nonat
参考
【FreeSwitch开发实践】centos7下编译安装freeswitch及常见编译问题的解决_checking for spandsp >= 3.0... configure: error: n_一马途追的博客-CSDN博客
https://www.cnblogs.com/qiuzhendezhen/p/16829294.html
FreeSwitch安装部署 | 不知道叫啥博客
- 实战1:FreeSwitch的安装 - 简书
FreeSwitch安装部署 | 不知道叫啥博客
centos7.9编译安装freeswitch1.6.20-张良人技术博客
版权归原作者 zzhongcy 所有, 如有侵权,请联系我们删除。