Build FreeSWITCH
这里主要介绍三种安装方法
- Docker安装
- 源码安装
- 官网依赖安装
第一节 Docker 安装 FreeSwitch
1、Authentication required
最新FreeSwitch需要PAT才可以安装依赖。
SignalWire Personal Access Tokens (PAT)s are required to access FreeSWITCH install packages. HOWTO Create a SignalWire Personal Access Token
2、阿里源
由于使用debian默认的源是国外的,下载比较久,创建sources.list
文件
cat >> sources.list <<-'EOF'
deb http://mirrors.aliyun.com/debian/ bullseye main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ bullseye main non-free contrib
deb http://mirrors.aliyun.com/debian-security/ bullseye-security main
deb-src http://mirrors.aliyun.com/debian-security/ bullseye-security main
deb http://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib
deb http://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib
EOF
3、创建Dockerfile
这里我已经创建了账号,使用的时候请替换TOKEN
FROM debian:11.1
# 安装编译freeswitch,所需要依赖环境
ENV TOKEN=pat_CKj8GjohjcGkU3JEMsuAzfri
ADD ./sources.list /etc/apt/sources.list
RUN apt-get clean && apt-get update && apt-get install -yq gnupg2 wget lsb-release vim sngrep
RUN wget --http-user=andy --http-password=$TOKEN -O /usr/share/keyrings/signalwire-freeswitch-repo.gpg https://freeswitch.signalwire.com/repo/deb/debian-release/signalwire-freeswitch-repo.gpg
RUN echo "machine freeswitch.signalwire.com login andy password $TOKEN" > /etc/apt/auth.conf
RUN echo "deb [signed-by=/usr/share/keyrings/signalwire-freeswitch-repo.gpg] https://freeswitch.signalwire.com/repo/deb/debian-release/ `lsb_release -sc` main" > /etc/apt/sources.list.d/freeswitch.list
RUN echo "deb-src [signed-by=/usr/share/keyrings/signalwire-freeswitch-repo.gpg] https://freeswitch.signalwire.com/repo/deb/debian-release/ `lsb_release -sc` main" >> /etc/apt/sources.list.d/freeswitch.list
RUN apt-get update -y && apt-get build-dep freeswitch -y
# 需要把下载freeswitch-1.10.7.tar.gz,解压到Dockerfile文件同级目录下,添加到docker镜像里
#RUN wget https://files.freeswitch.org/releases/freeswitch/freeswitch-1.10.7.-release.tar.gz && tar -xzvf freeswitch-1.10.7.-release.tar.gz
ADD ./freeswitch-1.10.7.-release.tar.gz /opt/
# 自定义安装freeswitch模块
COPY ./modules.conf /opt/freeswitch-1.10.7.-release/modules.conf
RUN cd /opt/freeswitch-1.10.7.-release && ./configure && make -j && make all install
# RUN cd /opt/freeswitch-1.10.7.-release && ./configure && make -j && make all install && make cd-sounds-install cd-moh-install
#配置环境路径
#ENV PATH "/usr/local/freeswitch/bin:$PATH"
#修改配置信息
# ADD ./vars.xml /usr/local/freeswitch/conf/vars.xml #修改密码、端口、IP等
# ADD ./switch.conf.xml /usr/local/freeswitch/conf/autoload_configs/switch.conf.xml #端口
# ADD ./event_socket.conf.xml /usr/local/freeswitch/conf/autoload_configs/event_socket.conf.xml #esl链接密码
# 添加启动文件
ADD ./start.sh /start.sh
RUN chmod +x /start.sh
SHELL ["/bin/bash"]
HEALTHCHECK --interval=15s --timeout=5s \
CMD /usr/local/freeswitch/bin/fs_cli -x status | grep -q ^UP || exit 1
CMD ["/start.sh"]
start.sh脚本
#!/bin/bash
set -e
exec /usr/local/freeswitch/bin/freeswitch
目录结构如下
4、创建阿里云容器个人账号
阿里云官网容器镜像服务
5、创建Makefile
SHELL = /bin/bash
VERSION = 1.0.1
all:
echo Hi
setup:
if [[ ! -f .env ]]; then \
cp env.example .env; \
fi
run:
docker-compose up -d
start:
docker-compose up
bash:
docker exec -it xswitch bash
cli:
docker exec -it xswitch fs_cli
logs:
docker logs -f --tail=100 xswitch
stop:
docker stop xswitch
pull:
docker pull registry.cn-hangzhou.aliyuncs.com/andy_wg/freeswitch:${VERSION}
.PHONY conf:
docker cp xswitch:/usr/local/freeswitch/conf .
eject: conf
echo conf copied to local dir, please edit docker-compose.yml to use it
get-sounds:
wget -O sounds.zip https://xswitch.cn/download/sounds.zip
unzip sounds.zip
echo "edit docker-compose.yml to use it"
build:
docker build -t xswitch .
push:
docker tag xswitch registry.cn-hangzhou.aliyuncs.com/andy_wg/freeswitch:${VERSION}
docker push registry.cn-hangzhou.aliyuncs.com/andy_wg/freeswitch:${VERSION}
login:
docker login --username=浪浪舒服 registry.cn-hangzhou.aliyuncs.com
get-ip:
curl myip.ipip.net
6、生成镜像并上传阿里云
make build
make push
7、运行
宿主机目录:/data/freeswitch/conf,需要提前准备freeswitch的conf的配置。
docker run -it --network host --name freeswitch -v /data/freeswitch/conf:/usr/local/freeswitch/conf -d freeswitch-1.10.7
8、安装CJSON
安装完FreeSwitch后,当启动lua调用json的时候会报错,这时需要安装下面的库
https://github.com/Kong/kong-cjson/archive/2.1.0.tar.gz
9、参考
- https://github.com/signalwire/freeswitch/tree/master/docker
- https://www.jianshu.com/p/f9f142709f32
- 小樱桃 https://github.com/rts-cn/xswitch
- 开源项目 softswitch-gateway(软交换网关) ;项目地址:https://github.com/Atoms-Cat/softswitch-gateway
第二节 源码安装
1、前提
安装方式可分为Docker安装和源码安装,推荐使用Docker安装
由于FreeSWITCH核心开发者大部分都使用Debian,在Debian上安装FreeSWITCH的方法见FreeSwitch官网
2、获取源码
3、安装
安装FreeSWITCH前需要安装一些依赖。在不同的平台上,依赖不同的包,如:
- Debian/Ubuntu:
apt-get -y install build-essential subversion automake autoconf wget libtool libncurses5-dev
- CentOS:
yum install -y git gcc-c++ yasm autoconf automake libtool wget python 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 opus-devel libvpx-devel libvpx2* libdb4* libidn-devel unbound-devel libuuid-devel lua-devel libsndfile-devel libtiff-devel
FreeSWITCH最新的源代码将Sofia-SIP和SpanDSP移出了FreeSWITCH代码仓库,分离到了独立的仓库中,在安装FreeSWITCH之前需要单独安装:
https://github.com/freeswitch/sofia-sip
https://github.com/freeswitch/spandsp
最新的mod\_verto模块也需要libks,源代码可以从以下地址获取:
https://github.com/signalwire/libks
重点:
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
获取FreeSwich源码
git clone https://github.com/signalwire/freeswitch.git
编译安装:
./bootstrap.sh # 初始化源码环境和工具
./configure # 配置,如果将FreeSWITCH装到特定位置,可以使用 --prefix 指定
make # 编译
make install # 安装
创建软链接
ln -sf /usr/local/freeswitch/bin/freeswitch /usr/bin/
ln -sf /usr/local/freeswitch/bin/fs_cli /usr/bin/
4、参考链接
- https://freeswitch.org/confluence/display/FREESWITCH/Installation
- https://github.com/signalwire/freeswitch
- https://freeswitch.org/confluence/display/FREESWITCH/Debian
- https://mp.weixin.qq.com/s/neH4XsMEH-pteOxn6bnY3A
第三节 官网依赖安装
1、环境
操作系统:Centos7.4 FreeSwitch:1.10.7
2、提前
SpanDSP and sofia-sip
Sofia-sip and SpanDSP dependencies have been removed from the FreeSWITCH™ tree since v1.10.4 Release (05 August 2020).
You can find source files of Sofia-sip here: https://github.com/freeswitch/sofia-sip
SpanDSP sources are here: https://github.com/freeswitch/spandsp
Packages for Sofia-sip and SpandDSP are available for all supported platforms from our packaging repos.
You might have to visit each directory, run ./bootstrap.sh then ./configure then make install
3、源码安装
echo "signalwire" > /etc/yum/vars/signalwireusername
echo "pat_CKj8GjohjcGkU3JEMsuAzfri" > /etc/yum/vars/signalwiretoken
yum install -y https://$(< /etc/yum/vars/signalwireusername):$(< /etc/yum/vars/signalwiretoken)@freeswitch.signalwire.com/repo/yum/centos-release/freeswitch-release-repo-0-1.noarch.rpm epel-release
yum-builddep -y freeswitch
yum install -y yum-plugin-ovl centos-release-scl rpmdevtools yum-utils git
yum install -y devtoolset-4-gcc*
scl enable devtoolset-4 'bash'
cd /usr/local/src
git clone -b v1.10 https://github.com/signalwire/freeswitch.git freeswitch
cd /usr/local/src/freeswitch
./bootstrap.sh -j
./configure --enable-portable-binary \
--prefix=/usr --localstatedir=/var --sysconfdir=/etc \
--with-gnu-ld --with-python --with-erlang --with-openssl \
--enable-core-odbc-support --enable-zrtp
make
make -j install
make -j cd-sounds-install
make -j cd-moh-install