操作系统 :CentOS 7.6_x64 FreeSWITCH版本 :1.10.9Docker版本:23.0.6FreeSWITCH这种比较复杂的系统,使用容器部署是比较方便的,今天记录下CentOS 7环境下使用docker构建FreeSWITCH编译环境及打包发布的过程。一、资源准备1、安装docker环境1)移除旧版本(可选)

yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine

2)安装依赖项

yum install -y yum-utils device-mapper-persistent-data lvm2

3)添加yum源

yum-config-manager --add-repo http://download.docker.com/linux/centos/docker-ce.repoyum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

4)查看可用docker版本

yum list docker-ce --showduplicates | sort -r

5)安装docker服务

指定版本安装(这里指定版本安装):

yum install docker-ce-cli-23.0.6 docker-ce-23.0.6  containerd.io

查看docker版本信息:

docker version

6)配置docker服务

启动docker服务: systemctl start docker配置docker服务开机启动: systemctl enable docker查看docker服务状态:systemctl status docker

2、下载FreeSWITCH源代码可从如下地址获取:https://files.freeswitch.org/releases/freeswitch/

也可通过wget获取:

wget https://files.freeswitch.org/releases/freeswitch/freeswitch-1.10.9.-release.tar.gz

3、下载FreeSWITCH依赖代码主要依赖以下代码库:libks-1.8.2 : https://github.com/signalwire/libks/archive/refs/tags/v1.8.2.tar.gzsofia-sip-1.13.14 : https://github.com/freeswitch/sofia-sip/archive/refs/tags/v1.13.14.tar.gzspandsp : https://github.com/freeswitch/spandsp.gitsignalwire-c : https://github.com/signalwire/signalwire-c/archive/refs/tags/1.3.0.tar.gz可通过wget或git获取:

wget https://github.com/signalwire/libks/archive/refs/tags/v1.8.2.tar.gzwget https://github.com/freeswitch/sofia-sip/archive/refs/tags/v1.13.14.tar.gzgit clone https://github.com/freeswitch/spandsp.gitwget https://github.com/signalwire/signalwire-c/archive/refs/tags/1.3.0.tar.gz

二、制作base包1、docker基础镜像选型这里使用Debian 11 (bullseye)作为基础镜像:

docker image pull debian:bullseye

2、在docker内编译FreeSWITCH1)启动debian容器

docker run --name debian --network host -t -d debian:bullseye 

2)复制源码到debian容器

docker cp freeswitch-1.10.9.-release.tar.gz debian:/usr/src/docker cp fs1.10.9-deps debian:/usr/src/

3)更新apt源(可选)

这里使用清华的源来加速安装:https://mirrors.tuna.tsinghua.edu.cn/help/debian/

更新apt源:

>/etc/apt/sources.listecho "deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free" >> /etc/apt/sources.listecho "deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free" >> /etc/apt/sources.listecho "deb http://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free" >> /etc/apt/sources.listecho "deb http://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free" >> /etc/apt/sources.listcat /etc/apt/sources.listapt update 

4)安装编译依赖项

apt install gcc g++ autoconf automake make cmake yasm uuid-dev libvpx-dev unixodbc-dev ncurses-dev zlib1g-dev  libjpeg-dev libtiff-dev liblua5.1-0-dev  libsqlite3-dev libsndfile-dev libavformat-dev libswscale-dev  libcurl4-openssl-dev  libpcre3-dev libspeex-dev libspeexdsp-dev libedit-dev libtool libldns-dev  libopus-dev  libpq-dev

安装libks:

tar zxvf libks-1.8.2.tar.gz cd libks-1.8.2cmake .makemake install

安装sofia-sip:

tar zxvf sofia-sip-1.13.14.tar.gzcd sofia-sip-1.13.14   ./bootstrap.sh./configuremakemake install

安装spandsp:

cd spandsp/./bootstrap.sh./configuremakemake installexport PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:${PKG_CONFIG_PATH}echo "export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:${PKG_CONFIG_PATH}" >> /etc/profileldconfig

安装signalwire-c:

tar zxvf signalwire-c-1.3.0.tar.gzcd signalwire-c-1.3.0cmake .makemake install

5)编译FreeSWITCH大致步骤:

./rebootstrap.sh && ./configure && make

具体参考 : https://www.cnblogs.com/MikeZhang/p/centos7InstallFs20221007.html6)安装及运行FreeSWITCH(可选)执行make install安装FreeSWITCH

运行FreeSWITCH:

/usr/local/freeswitch/bin/freeswitch -nonat

3、导出容器快照作为基础编译镜像1)移除FreeSWITCH源代码及依赖项

rm -rf /usr/src/freeswitch-1.10.9.-release*rm -rf /usr/src/fs1.10.9-deps/

2)导出debian容器快照

docker export -o debian_fs_builder.tar 164f8b171a95

3)给导出的容器快照添加标签

docker import debian_fs_builder.tardocker image tag 91f9e45241ed fs:base

4)导出基础编译镜像

docker image save fs:base -o fs-base.tartar zcvf fs-base.tar.gz fs-base.tar

预编译的基础镜像(fs-base.tar.gz)可从如下渠道获取:

关注微信公众号(聊聊博文,文末可扫码)后回复 20230617 获取。4、测试基础编译镜像1)导入镜像

docker load -i fs-base.tar

2)启动容器

docker run --name fs --network host -t -d fs:base /bin/bash

3)编译及运行FreeeSWITCH

仅复制FreeSWITCH源码过去即可编译及安装,演示视频可从如下渠道获取:关注微信公众号(聊聊博文,文末可扫码)后回复 2023061701 获取。三、自动构建及打包1、准备源码源码文件:freeswitch-1.10.9.-release.tar.gz2、编写DockerFile及entrypoint

完整代码可从如下渠道获取:关注微信公众号(聊聊博文,文末可扫码)后回复 20230617 获取。3、构建docker镜像自动构建脚本如下:

#! /bin/bashtar zxvf freeswitch-1.10.9.-release.tar.gzdocker build -t fs:1.0.0 .docker image save fs:1.0.0 -o fs_v1.0.0.tartar zcvf fs_v1.0.0.tar.gz fs_v1.0.0.tarrm -rf fs_v1.0.0.tar

4、发布fs镜像及启动

tar zxvf fs_v1.0.0.tar.gzdocker load -i fs_v1.0.0.tar./run.sh

使用基础编译镜像自动构建版本及运行容器的演示视频,可从如下渠道获取:

关注微信公众号(聊聊博文,文末可扫码)后回复 2023061702 获取。四、资源下载本文涉及源码和文件,可以从如下途径获取:关注微信公众号(聊聊博文,文末可扫码)后回复 20230617 获取。

微信公众号:

  • E-Mail : Mike_Zhang@live.com
  • 转载请注明出处,谢谢!