记录一下2021年采用asterisk18配置pjsip分机和webrtc音视频的教程,测试采用浏览器WebRTC呼叫软电话sip分机,WebRTC接听之间的拨号和内部SIP分机和浏览器WebRTC分机之间实现互拨通话。
测试环境:
操作系统: CentOS-8.3
软交换: asterisk-18.5
分机: jsSip网页demo、eyeBeam、MicroSIP
浏览器; 谷歌、火狐浏览器
直接上步骤
1) centos8.3下载地址:
中科大开源镜像:
https://mirrors.ustc.edu.cn/centos/8.3.2011/isos/x86_64/CentOS-8.3.2011-x86_64-minimal.iso
2) Asterisk我使用的是2021年6月最新版本 asterisk-18.5,下载地址如下:
http://downloads.asterisk.org/pub/telephony/asterisk/
3) 安装centos8.3
3.1 启动centos安装程序,选择第1项菜单"Install CentOS Linux 8",如下图
3.2 进入安装选项设置,主要注意以下几点:
1)选择English
2)选择亚洲/上海时区
3)关闭 KDUMP (不关闭也没事,我个人喜欢关闭,反正也看不懂dump消息)
4)选择安装介质(硬盘)
5)设置root密码
6)配置网络,设置网卡IP地址
所有操作步骤如下图:
3.3 上述设置好后,等待安装结束后,点击Reboot System重启系统后就装好了,如下图。
4)安装前准备好必要的软件
使用root账号ssh登录centos8系统,运行命令设置系统,安装一些必须的软件,以便于编译asterisk18
4.1 关闭selinux和防火墙,命令如下:
setenforce 0
sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
systemctl stop firewalld.service
systemctl disable firewalld.service
4.2 多做一步:修改时区为中国标准,并同步时间。因为绝对会有人安装的时候选择了默认的美国时区。
echo 'LANG="en_US.UTF-8"' > /etc/locale.conf
source /etc/locale.conf
unlink /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
同步阿里云的时间
yum -y install chrony
#修改 /etc/chrony.conf 加入阿里云的ntp地址,具体可以百度搜索
#参考这篇教程: https://blog.csdn.net/baozi_xiaoge/article/details/103823996
systemctl enable chronyd.service
systemctl restart chronyd.service
/usr/bin/chronyc sources
4.3 修改centos8默认镜像源为中科大镜像,并启用额外的PowerTools镜像源,加快软件包下载进度。参考中科大开源镜像网站修改源《CentOS 源使用帮助》的方法。
sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^#baseurl=http://mirror.centos.org/$contentdir|baseurl=https://mirrors.ustc.edu.cn/centos|g' \
-i.bak \
/etc/yum.repos.d/CentOS-Linux-AppStream.repo \
/etc/yum.repos.d/CentOS-Linux-BaseOS.repo \
/etc/yum.repos.d/CentOS-Linux-Extras.repo \
/etc/yum.repos.d/CentOS-Linux-PowerTools.repo \
/etc/yum.repos.d/CentOS-Linux-Plus.repo
yum -y install dnf-plugins-core
sed -i 's/^enabled=.*/enabled=1/' /etc/yum.repos.d/CentOS-Linux-PowerTools.repo
sed -i 's/^enabled=.*/enabled=1/' /etc/yum.repos.d/CentOS-Linux-Plus.repo
dnf config-manager --set-enabled powertools
dnf config-manager --set-enabled plus
#dnf repolist
4.4 安装epel软件源和一些实用工具包
可以下载到本地后上传到centos8,也可以在线安装,epel下载地址: https://mirrors.ustc.edu.cn/epel/epel-release-latest-8.noarch.rpm
rpm -ivh epel-release-latest-8.noarch.rpm
yum makecache
yum -y install lsof tree net-tools screen
4.5 安装编译asterisk18所需相关依赖包,下面几条yum命令搜集于网络并整理,可能有重复软件包,yum会自动跳过已经安装的,直接复制到bash执行就行,不用理会。
yum -y install bison ncurses ncurses-devel zlib zlib-devel openssl openssl-devel gnutls-devel gcc gcc-c++ mysql-devel libxml2-devel sqlite-devel make autoconf libtool* patch perl flex
yum -y install hiredis hiredis-devel redis
systemctl enable redis.service
yum -y install libpri libpri-devel libcurl libcurl-devel
yum -y install uuid libuuid-devel jansson jansson-devel
yum -y install gsm gsm-devel sox libogg libogg-devel spandsp spandsp-devel speex speex-devel libvorbis libvorbis-devel libsrtp libsrtp-devel speexdsp speexdsp-devel
yum install -y gcc gcc-c++ bison mysql-devel mysql-server make ncurses-devel sox libxml2-devel libtiff-devel audiofile-devel gtk2-devel git kernel-devel crontabs cronie cronie-anacron wget vim uuid-devel libtool sqlite-devel unixODBC unixODBC-devel bzip2 patch libedit-devel
yum -y install opus opus-devel xmlstarlet opusfile opusfile-devel libedit-devel
yum -y install util-linux
#mysql
yum -y install mysql mysql-server mysql-devel mysql-common mysql-libs
systemctl enable mysqld.service
4.6 启用以前老版本centos6的 /etc/rc.local 开机自启动功能,如果我们需要让asterisk自动启动,可以在这里加入asterisk开机执行的命令,这样就不用自己编写systemd的启动脚本了。
参考此处教程: https://blog.csdn.net/weixin_39611930/article/details/111324569
chmod +x /etc/rc.d/rc.local
echo -e '\n[Install]\nWantedBy=multi-user.target' >> /usr/lib/systemd/system/rc-local.service
systemctl daemon-reload
systemctl enable rc-local
至此,centos8的编译asterisk环境准备完毕,下面把asterisk18源码传到asterisk,进行编译。
【补充】由于后面编译asterisk选择mp3模块,需要svn在线下载mp3源码,所以此处补充安装svn,也安装wget和screen两个好用的软件。
yum -y install subversion wget screen
5)编译asterisk18
5.1 将下载好的asterisk18上传到centos8,并解压,操作命令记录如下。
[root@centos83 ~]# ls
asterisk-18-current.tar.gz
[root@centos83 ~]#
[root@centos83 ~]# tar zxf asterisk-18-current.tar.gz
[root@centos83 ~]#
[root@centos83 ~]# cd asterisk-18.5.0/
[root@centos83 asterisk-18.5.0]#
5.2 asterisk编译安装需要在线下载pjproject的tar.gz包,由于总所周知的原因,在我们的centos8机器上可能无法实时下载,造成编译失败。于是我采用一些技术,预先下载了pjproject的tar.gz包并传到了centos8机器。备注:之前安装踩过这个坑,所以此处作为事后诸葛亮,提前做一下说明。下载地址请参考如下两个链接:
https://wiki.asterisk.org/wiki/display/AST/PJSIP-pjproject
https://www.pjsip.org/
pjproject的tar.gz包文件放在: /tmp/pjproject-2.10.tar.bz2
[root@centos83 asterisk-18.5.0]# ls /tmp/pjproject-2.10.tar.bz2
/tmp/pjproject-2.10.tar.bz2
[root@centos83 asterisk-18.5.0]#
5.3 采用如下命令开始编译,编译完成后asterisk将安装到 /opt/asterisk/目录。
./configure LDFLAGS="-L/lib64 -L/usr/lib64 -L/usr/local/lib64 -L/lib -L/usr/lib -L/usr/local/lib -L/usr/lib64/mysql" \
--prefix=/opt/asterisk \
--with-libcurl=/usr \
--with-mysqlclient \
--with-opus \
--with-opusfile=/usr \
--with-sqlite3=/usr \
--with-ogg=/usr \
--with-oss=/usr \
--with-vorbis=/usr \
--with-srtp=/usr \
--with-ssl=/usr \
--with-libxml2 \
--with-jansson=/usr \
--with-pjproject=/tmp/pjproject-2.10.tar.bz2
一些主要开关说明:
--with-mysqlclient : 编译支持拨号规则的MYSQL app,以及通话记录采用mysql存储
--with-opus : webrtc标准要求实现opus语音编码,建议编译的时候加上
--with-srtp : 如果webrtc需要加密通话,需要srtp
--with-pjproject : pjsip协议栈支持
执行过程如下:
[root@centos83 asterisk-18.5.0]#
[root@centos83 asterisk-18.5.0]# ./configure LDFLAGS="-L/lib64 -L/usr/lib64 -L/usr/local/lib64 -L/lib -L/usr/lib -L/usr/local/lib -L/usr/lib64/mysql" \
> --prefix=/opt/asterisk \
> --with-libcurl=/usr \
> --with-mysqlclient \
> --with-opus \
> --with-opusfile=/usr \
> --with-sqlite3=/usr \
> --with-ogg=/usr \
> --with-oss=/usr \
> --with-vorbis=/usr \
> --with-srtp=/usr \
> --with-ssl=/usr \
> --with-libxml2 \
> --with-jansson=/usr \
> --with-pjproject=/tmp/pjproject-2.10.tar.bz2
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
......
checking for GTK2... yes
configure: creating ./config.status
config.status: creating makeopts
config.status: creating autoconfig.h
configure: Menuselect build configuration successfully completed
configure: build-cpu:vendor:os: x86_64 : pc : linux-gnu :
configure: host-cpu:vendor:os: x86_64 : pc : linux-gnu :
[root@centos83 asterisk-18.5.0]#
[root@centos83 asterisk-18.5.0]#
5.4 执行 make menuselect 命令,选择安装模块,如下:
[root@centos83 asterisk-18.5.0]# make menuselect
CC="cc" CXX="g++" LD="" AR="" RANLIB="" CFLAGS="" LDFLAGS="" make -C menuselect CONFIGURE_SILENT="--silent" cmenuselect
make[1]: Entering directory '/root/asterisk-18.5.0/menuselect'
gcc -g -D_GNU_SOURCE -Wall -DHAVE_NCURSES -I/usr/include/libxml2 -c -o menuselect.o menuselect.c
gcc -g -D_GNU_SOURCE -Wall -DHAVE_NCURSES -c -o strcompat.o strcompat.c
gcc -g -D_GNU_SOURCE -Wall -DHAVE_NCURSES -c -o menuselect_curses.o menuselect_curses.c
gcc -o cmenuselect menuselect.o strcompat.o menuselect_curses.o -lncurses -ltinfo -lxml2 -lz -llzma -lm -ldl
make[1]: Leaving directory '/root/asterisk-18.5.0/menuselect'
CC="cc" CXX="g++" LD="" AR="" RANLIB="" CFLAGS="" LDFLAGS="" make -C menuselect CONFIGURE_SILENT="--silent" nmenuselect
make[1]: Entering directory '/root/asterisk-18.5.0/menuselect'
make[1]: Nothing to be done for 'nmenuselect'.
make[1]: Leaving directory '/root/asterisk-18.5.0/menuselect'
CC="cc" CXX="g++" LD="" AR="" RANLIB="" CFLAGS="" LDFLAGS="" make -C menuselect CONFIGURE_SILENT="--silent" gmenuselect
make[1]: Entering directory '/root/asterisk-18.5.0/menuselect'
gcc -g -D_GNU_SOURCE -Wall -DHAVE_NCURSES -I/usr/include/gtk-2.0 -I/usr/lib64/gtk-2.0/include -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/fribidi -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/uuid -I/usr/include/harfbuzz -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/atk-1.0 -pthread -c -o menuselect_gtk.o menuselect_gtk.c
gcc -o gmenuselect menuselect.o strcompat.o menuselect_gtk.o -lgtk-x11-2.0 -lgdk-x11-2.0 -lpangocairo-1.0 -latk-1.0 -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lpangoft2-1.0 -lpango-1.0 -lgobject-2.0 -lglib-2.0 -lfontconfig -lfreetype -lxml2 -lz -llzma -lm -ldl
make[1]: Leaving directory '/root/asterisk-18.5.0/menuselect'
make[1]: Entering directory '/root/asterisk-18.5.0'
Generating input for menuselect ...
add-ons: 里面我们选择mp3和mysql相关的,如下:
Call Detail Recording: 只选择如下几项
Channel Drivers: 里面务必去掉 chan_sip 老的sip协议栈,因为它过时了,已经停止维护了,我们需要采用功能更加强大的pjsip。按照如下方式选择即可。
Codec Translators: 要勾选 codec_opus,如下图:
Resource Modules: 勾选 res_chan_stats 和 res_endpoint_stats,如下图:
Utilities: 把可选的工具都勾上,如下图。
其余的项目保持默认,按's'按键,保持选择模块,下面开始make编译。
5.5 执行 make 开始编译,请耐心等待15分钟。
[root@centos83 asterisk-18.5.0]# make
[CC] astcanary.c -> astcanary.o
[LD] astcanary.o -> astcanary
[CC] astdb2sqlite3.c -> astdb2sqlite3.o
[CC] hash/hash.c -> hash/hash.o
[CC] hash/hash_bigkey.c -> hash/hash_bigkey.o
......
**************************************************************
*** ***
*** ---> IMPORTANT INFORMATION ABOUT format_mp3 <--- ***
*** ***
*** format_mp3 has been selected to be installed, but the ***
*** MP3 decoder library has not yet been downloaded into ***
*** the source tree. To do so, please run the following ***
*** command: ***
*** ***
*** $ contrib/scripts/get_mp3_source.sh ***
*** ***
**************************************************************
[CC] app_mysql.c -> app_mysql.o
[LD] app_mysql.o -> app_mysql.so
[CC] cdr_mysql.c -> cdr_mysql.o
[LD] cdr_mysql.o -> cdr_mysql.so
[CC] res_config_mysql.c -> res_config_mysql.o
[LD] res_config_mysql.o -> res_config_mysql.so
Building Documentation For: third-party channels pbx apps codecs formats cdr cel bridges funcs tests main res addons
+--------- Asterisk Build Complete ---------+
+ Asterisk has successfully been built, and +
+ can be installed by running: +
+ +
+ make install +
+-------------------------------------------+
[root@centos83 asterisk-18.5.0]#
上面提示mp3源码下载失败,众所周知的原因,可以预先下载mp3。由于本次测试我们用不到mp3功能,此处先不管。
5.6 执行 make install 安装二进制等文件,在执行make samples 或者 make basic-pbx 安装配置文件,如下:
[root@centos83 asterisk-18.5.0]#
[root@centos83 asterisk-18.5.0]# make install
**************************************************************
*** ***
*** ---> IMPORTANT INFORMATION ABOUT format_mp3 <--- ***
*** ***
*** format_mp3 has been selected to be installed, but the ***
*** MP3 decoder library has not yet been downloaded into ***
*** the source tree. To do so, please run the following ***
*** command: ***
*** ***
*** $ contrib/scripts/get_mp3_source.sh ***
*** ***
**************************************************************
Installing modules from channels...
Installing modules from pbx...
Installing modules from apps...
Installing modules from codecs...
Installing modules from formats...
Installing modules from cdr...
Installing modules from cel...
Installing modules from bridges...
Installing modules from funcs...
Installing modules from tests...
Installing modules from main...
[root@centos83 asterisk-18.5.0]# make basic-pbx
Installing basic-pbx config files...
Installing file configs/basic-pbx/asterisk.conf
Installing file configs/basic-pbx/cdr.conf
Installing file configs/basic-pbx/cdr_custom.conf
Installing file configs/basic-pbx/confbridge.conf
Installing file configs/basic-pbx/extensions.conf
Installing file configs/basic-pbx/indications.conf
Installing file configs/basic-pbx/logger.conf
Installing file configs/basic-pbx/modules.conf
Installing file configs/basic-pbx/musiconhold.conf
Installing file configs/basic-pbx/pjsip.conf
Installing file configs/basic-pbx/pjsip_notify.conf
Installing file configs/basic-pbx/queues.conf
Installing file configs/basic-pbx/README
Installing file configs/basic-pbx/voicemail.conf
Updating asterisk.conf
[root@centos83 asterisk-18.5.0]#
6)采用如下命令( /opt/asterisk/sbin/asterisk )启动asterisk ,并用asterisk -r 进入控制台,可以看到系统默认配置了几个pjsip分机,如下。
[root@centos83 ~]# /opt/asterisk/sbin/asterisk
[root@centos83 ~]#
[root@centos83 ~]# /opt/asterisk/sbin/asterisk -r
Asterisk 18.5.0, Copyright (C) 1999 - 2021, Sangoma Technologies Corporation and others.
Created by Mark Spencer <markster@digium.com>
Asterisk comes with ABSOLUTELY NO WARRANTY; type 'core show warranty' for details.
This is free software, with components licensed under the GNU General Public
License version 2 and other licenses; you are welcome to redistribute it under
certain conditions. Type 'core show license' for details.
=========================================================================
Connected to Asterisk 18.5.0 currently running on centos83 (pid = 88260)
centos83*CLI>
centos83*CLI> pj
pjproject pjsip
centos83*CLI> pjsip list endpoints
Endpoint: <Endpoint/CID.....................................> <State.....> <Channels.>
==========================================================================================
Endpoint: 1101/1101 Unavailable 0 of 1
Endpoint: 1102/1102 Unavailable 0 of 1
Endpoint: 1103/1103 Unavailable 0 of 1
Endpoint: 1104/1104 Unavailable 0 of 1
Endpoint: 1105/1105 Unavailable 0 of 1
Endpoint: 1106/1106 Unavailable 0 of 1
Endpoint: 1107/1107 Unavailable 0 of 1
Endpoint: 1108/1108 Unavailable 0 of 1
Endpoint: 1109/1109 Unavailable 0 of 1
Endpoint: 1110/1110 Unavailable 0 of 1
Endpoint: 1111/1111 Unavailable 0 of 1
Endpoint: 1112/1112 Unavailable 0 of 1
Endpoint: 1113/1113 Unavailable 0 of 1
Endpoint: 1114/1114 Unavailable 0 of 1
Endpoint: 1115/1115 Unavailable 0 of 1
Endpoint: dcs-endpoint Not in use 0 of inf
Objects found: 16
centos83*CLI>
至此asterisk18的安装全部完成,由于篇幅有限,后续webrtc相关配置留在以后再发。如果上述安装遇到问题,请联系我微信 acmepbx ,QQ 3448691033 , 一起交流学习进步。