Freeswitch安装及Zabbix监控

Freeswitch安装及Zabbix监控

本人是一名网工,平时搞路由器交换机防火墙为主,基本是个Linux小白,以下的安装基本参考了https://www.cnblogs.com/cn-jasonho/p/13285569.html这位博主的方法,再根据自己实际遇到的错误重新排版了一下,结合了Zabbix监控需要的模块。

如果跟我一样是Linux小白,墙裂不建议使用Centos7编译安装, 各种坑,各种没有依赖,本小白在Centos7.8上试着yum和编译安装一个礼拜都没成功,所以建议用Debian和Ubuntu,因为Freeswitch就是在Debian上开发的。

Zabbix4.4服务器我已经安装好,主要看以下几位博主的文章摸索安装:
http://www.zsythink.net/archives/447/ 写得非常详细,但版本是3.0,稍微旧了点?
https://www.cnblogs.com/smallga/articles/10514222.html (zabbix问题小结) 安装4.0以上好像要mysql8.0以上

一、添加第三方源

echo “deb http://us.archive.ubuntu.com/ubuntu/ xenial multiverse” >> /etc/apt/source.list
echo “deb-src http://us.archive.ubuntu.com/ubuntu/ xenial multiverse”>> /etc/apt/source.list
echo “deb http://us.archive.ubuntu.com/ubuntu/ xenial-updates multiverse” >> /etc/apt/source.list
echo “deb-src http://us.archive.ubuntu.com/ubuntu/ xenial-updates multiverse” >> /etc/apt/source.list
echo “deb http://cz.archive.ubuntu.com/ubuntu xenial main universe” >> /etc/apt/source.list

二、安装Video LAN程序包

apt-get update
apt-get install -y software-properties-common tzdata
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
add-apt-repository ppa:videolan/stable-daily

三、安装部分依赖包

apt-get update && apt-get install -y autoconf automake bison build-essential fail2ban gawk git-core groff groff-base erlang-dev libasound2-dev libavcodec-dev libavutil-dev libavformat-dev libav-tools libavresample-dev libswscale-dev liba52-0.7.4-dev libssl-dev libdb-dev libexpat1-dev libcurl4-openssl-dev libgdbm-dev libgnutls-dev libjpeg-dev libmp3lame-dev libncurses5 libncurses5-dev libperl-dev libogg-dev libsnmp-dev libtiff5-dev libtool libvorbis-dev libx11-dev libzrtpcpp-dev make portaudio19-dev python-dev snmp snmpd subversion unixodbc unixodbc-dev uuid-dev zlib1g-dev libsqlite3-dev libpcre3-dev libspeex-dev libspeexdsp-dev libldns-dev libedit-dev libladspa-ocaml-dev libmemcached-dev libmp4v2-dev libpq-dev libvlc-dev libv8-dev liblua5.2-dev libyaml-dev libpython-dev odbc-postgresql sendmail wget yasm libldap2-dev libcodec2-dev vim net-tools nmap

四、配置使用gawk

update-alternatives --set awk /usr/bin/gawk

五、编译安装程序依赖包

1.安装cmake
mkdir /opt/software
wget https://github.com/Kitware/CMake/releases/download/v3.17.2/cmake-3.17.2.tar.gz -P /opt/software
#cd /opt/software
#tar -zxvf cmake-3.17.2.tar.gz
cd cmake-3.7.2/
./bootstrap --prefix=/usr
make && make install (时间大概30分钟)

2.安装libks
#cd /opt/software
git clone https://github.com/signalwire/libks.git
cd /opt/software/libks
cmake .
make && make install

3.安装signalwire-c
git clone https://github.com/signalwire/signalwire-c.git /opt/software
cd /opt/software/signalwire-c
cmake .
make && make install

4.安装spandsp
git clone https://github.com/freeswitch/spandsp
cd spandsp
./bootstrap.sh
./configure
make -j
make install

5.安装sofia-sip
git clone https://github.com/freeswitch/sofia-sip
cd sofia-sip
./bootstrap.sh
./configure
make -j
make install

6.安装freeswitch编译部分依赖包
GIT_SSL_NO_VERIFY=1
git clone https://github.com/BetterVoice/freeswitch-container.git /opt/software
sh /opt/software/freeswitch-container/build/install-deps.sh

六、编制安装freeswitch 1.10

1.编译安装前,修改需要编译安装的模板
vim /opt/software/freeswitch/build/modules.conf.in
event_handlers/mod_snmp #Zabbix要监控到Freeswitch一定要编译这个模块

2.从github下载源代码
git clone https://github.com/signalwire/freeswitch.git -b v1.10 /opt/software

3.安装引导
cd /opt/software/freeswitch
./bootstrap.sh
./configure --prefix=/opt/freeswitch --with-gnu-ld --with-python --with-erlang --with-openssl --enable-portable-binary --enable-core-odbc-support --enable-zrtp
make && make install
make uhd-sounds-install //标准提示音
make uhd-moh-install //标准通话音乐

我在安装引导的时候出现的错误:

checking for spandsp >= 3.0… configure: error: no usable spandsp; please install spandsp3 devel package or equivalent
[email protected]:/opt/software/freeswitch#
[email protected]:/opt/software/freeswitch# sudo apt-get install libtiff4-dev
Reading package lists… Done
Building dependency tree
Reading state information… Done
Package libtiff4-dev is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
However the following packages replace it:
libtiff5-dev:i386 libtiff5-dev
E: Package ‘libtiff4-dev’ has no installation candidate
通过这位博主的方法解决的:https://blog.****.net/pku1254/article/details/108367312

七、添加SIP 48000Hz音频程序

wget https://files.freeswitch.org/releases/sounds/freeswitch-sounds-en-us-callie-48000-1.0.52.tar.gz
wget https://files.freeswitch.org/releases/sounds/freeswitch-sounds-music-48000-1.0.52.tar.gz
tar -zxvf freeswitch-sounds-en-us-callie-48000-1.0.52.tar.gz
tar -zxvf freeswitch-sounds-music-48000-1.0.52.tar.gz
cd /opt/software
cp -r en/us/callie/ascii/48000 /opt/freeswitch/share/freeswitch/sounds/en/us/callie/ascii/
cp -r en/us/callie/base256/48000 /opt/freeswitch/share/freeswitch/sounds/en/us/callie/base256/
cp -r en/us/callie/conference/48000 /opt/freeswitch/share/freeswitch/sounds/en/us/callie/conference/
cp -r en/us/callie/currency/48000 /opt/freeswitch/share/freeswitch/sounds/en/us/callie/currency/
cp -r en/us/callie/digits/48000 /opt/freeswitch/share/freeswitch/sounds/en/us/callie/digits/
cp -r en/us/callie/directory/48000 /opt/freeswitch/share/freeswitch/sounds/en/us/callie/directory/
cp -r en/us/callie/ivr/48000 /opt/freeswitch/share/freeswitch/sounds/en/us/callie/ivr/
cp -r en/us/callie/misc/48000 /opt/freeswitch/share/freeswitch/sounds/en/us/callie/misc/
cp -r en/us/callie/phonetic-ascii/48000 /opt/freeswitch/share/freeswitch/sounds/en/us/callie/phonetic-ascii/
cp -r en/us/callie/time/48000 /opt/freeswitch/share/freeswitch/sounds/en/us/callie/time/
cp -r en/us/callie/voicemail/48000 /opt/freeswitch/share/freeswitch/sounds/en/us/callie/voicemail/
cp -r en/us/callie/zrtp/48000 /opt/freeswitch/share/freeswitch/sounds/en/us/callie/zrtp/
cp -r music/48000 /opt/freeswitch/share/freeswitch/sounds/music/

八、添加启动

ln -s /opt/freeswitch/bin/freeswitch /usr/bin/
ln -s /opt/freeswitch/bin/fs_cli /usr/bin/

九、禁用freeswitch IPv6功能

mv /opt/freeswitch/etc/freeswitch/sip_profiles/external-ipv6.xml /opt/freeswitch/etc/freeswitch/sip_profiles/external-ipv6.xml-bak
mv /opt/freeswitch/etc/freeswitch/sip_profiles/internal-ipv6.xml /opt/freeswitch/etc/freeswitch/sip_profiles/internal-ipv6.xml-bak

十、修改listen的IP

vi /opt/freeswitch/etc/freeswitch/autoload_configs/event_socket.conf.xml

改为

十一、修改RTP语音通话UDP端口范围

vim /opt/freeswitch/etc/freeswitch/autoload_configs/switch.conf.xml
定义随机打开端口范围31768~32768

注:如修改完启动freeswitch时只能启动8081/8082/8021端口,shutdonw后删除/opt/freeswitch/var/log/freeswitch/目录下的root权限文件和目录重启即可。

十二、启动freeswitch

/usr/bin/freeswitch -nc -nonat
#netstat -lntup (需要20-30s启动,随后才能看到进程和端口)
tcp 0 0 0.0.0.0:8021 0.0.0.0:* LISTEN 28569/freeswitch
tcp 0 0 192.168.0.102:5080 0.0.0.0:* LISTEN 30917/freeswitch
tcp 0 0 192.168.0.102:5060 0.0.0.0:* LISTEN 30917/freeswitch
tcp 0 0 192.168.0.102:5066 0.0.0.0:* LISTEN 30917/freeswitch
tcp 0 0 192.168.0.102:8081 0.0.0.0:* LISTEN 30917/freeswitch
tcp 0 0 192.168.0.102:8082 0.0.0.0:* LISTEN 30917/freeswitch
tcp 0 0 192.168.0.102:7443 0.0.0.0:* LISTEN 30917/freeswitch
udp 0 0 192.168.0.102:5060 0.0.0.0:* 30917/freeswitch
udp 0 0 192.168.0.102:5080 0.0.0.0:* 30917/freeswitch
udp 0 0 0.0.0.0:1337 0.0.0.0:* 30917/freeswitch
#fs_cli //使用客户端连接程序连接freeswitch

安装到这里基本Freeswitch就安装完了, 可以进行默认配置的测试,但出现30秒就自动挂断,是因为没有配置外网IP,因为是内部测试环境用,所以我们要注释掉
vim /opt/freeswitch/etc/freeswitch/sip_profiles/internal.xml
参考这位博主的办法 https://blog.****.net/FlyLikeButterfly/article/details/100581609
Freeswitch安装及Zabbix监控

十三、进入freeswitch load mod_snmp

以下进入SNMP和zabbix-agent的配置
fs_cli
load mod_snmp

如果没有这个模块,证明你编译安装前没有选好模块, 参考第六步
修改自动加载
vim /opt/freeswitch/etc/freeswitch/autoload_configs/modules.conf.xml

改为

十四、安装net-snmp和snmp

apt-get install net-snmp* -y
apt-get install snmp* -y

vim /etc/snmp/snmpd.conf
修改SNMP agent IP为本机IP
#Listen for connections from the local system only
agentAddress udp:0.0.0.0:161

允许查看OID的范围和SNMP RO字符和读取来源网段
ACCESS CONTROL
#ystem + hrSystem groups only
view all included .1
view systemonly included .1.3.6.1.2.1.1
view systemonly included .1.3.6.1.2.1.25.1
# Full access from the local host
#rocommunity public localhost
# Default access to basic system info
rocommunity mycom localhost
rocommunity mycom 10.200.3.167 #Zabbix服务器的IP
service snmpd restart

重启后可以读以下OID
[email protected]:~# snmpwalk -v2c -c mycom 127.0.0.1 .1.3.6.1.4.1.27880
iso.3.6.1.4.1.27880.1.1.1.0 = Hex-STRING: 48 BF 0B FF 28 7F 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 21 02 5F
iso.3.6.1.4.1.27880.1.1.2.0 = STRING: “c4b21661-7485-4b56-806d-ead22b1f49b7”
iso.3.6.1.4.1.27880.1.2.1.0 = Timeticks: (367216) 1:01:12.16
iso.3.6.1.4.1.27880.1.2.2.0 = Counter32: 0
iso.3.6.1.4.1.27880.1.2.3.0 = Gauge32: 0
iso.3.6.1.4.1.27880.1.2.4.0 = Gauge32: 1000
iso.3.6.1.4.1.27880.1.2.5.0 = Gauge32: 0
iso.3.6.1.4.1.27880.1.2.6.0 = Gauge32: 0
iso.3.6.1.4.1.27880.1.2.7.0 = Gauge32: 30
iso.3.6.1.4.1.27880.1.2.8.0 = Gauge32: 0
iso.3.6.1.4.1.27880.1.2.9.0 = Gauge32: 0
iso.3.6.1.4.1.27880.1.2.10.0 = Gauge32: 0
iso.3.6.1.4.1.27880.1.2.11.0 = Gauge32: 0

十五、安装zabbix-agent及配置

指定更新源,注意zabbix-agent和Zabbix服务器的版本要匹配,不然可能收集不到数据
https://www.zabbix.com/documentation/4.0/zh/manual/installation/install_from_packages/debian_ubuntu (14.04 和18.04需要修改命令,详情请看URL)
# wget https://repo.zabbix.com/zabbix/4.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_4.0-2+xenial_all.deb
#dpkg -i zabbix-release_4.0-2+xenial_all.deb
#apt update
运行以下命令以安装 Zabbix agent :
#apt install zabbix-agent
配置zabbix-agent
vim /etc/zabbix/zabbix_agentd.conf
Server=10.200.3.167
ListenPort=10050
ServerActive=10.200.3.167
Hostname=freeswitch

Freeswitch的监控模板导入

下载模板
https://share.zabbix.com/atc/freeswitch
Freeswitch安装及Zabbix监控

监控Freeswitch的效果

Freeswitch安装及Zabbix监控

相关参考链接

[1]https://blog.****.net/pku1254/article/details/108367312
[2]https://share.zabbix.com/atc/freeswitch
[3]https://www.iteye.com/blog/fs20041242-889041
[4]https://hitfyd.gitee.io/2017/11/27/%E5%9C%A8Ubuntu%E4%B8%8A%E7%BC%96%E8%AF%91%E5%AE%89%E8%A3%85FreeSWITCH/