2016-11-1
上周折腾了2天,安装升级了 FreeSWITCH 最新版本 1.6.12,把步骤记录一下以备后续查看。
1) 查看系统版本 on Debian
1$ uname -a 2Linux debian 3.16.0-4-amd64 #1 SMP Debian 3.16.36-1+deb8u1 (2016-09-03) x86_64 GNU/Linux 3 4$ lsb_release -a 5No LSB modules are available. 6Distributor ID: Debian 7Description: Debian GNU/Linux 8.6 (jessie) 8Release: 8.6 9Codename: jessie 10 11# on Debian 12$ cat /etc/debian_version 138.6 14 15# on CentOS 16cat /etc/centos-release 17CentOS release 6.6 (Final) 18 19# 查看当前主机信息 20# For systemd Debian version you may also use hostnamectl: 21hostnamectl 22
1apt-get update 2apt-get install sox 3apt-get install lsb-release 4apt-get install ngrep 5apt-get install subversion 6apt-get install lrzsz 7apt-get install python 8apt-get install python-dev 9apt-get install python-mysqldb
2) 使用 apt-get 方式进行安装,通过这种方式安装,就是下载别人已编译打包好的代码,进行安装部署,减少自己编译需要解决很多依赖包的麻烦。
【注意】
- 如果 FS 官网挂了,这种安装方式也会受到影响,部分东西仍是需要到 FS 官网上进行下载的
- 通过 apt-get 方式安装的 FS 不包括 mod_shout 模块
https://freeswitch.org/confluence/display/FREESWITCH/Debian+8+Jessie
https://freeswitch.org/confluence/display/FREESWITCH/Debian+Post-Install+Tasks
参考官方的安装文档 Installing from Debian packages
1wget -O - https://files.freeswitch.org/repo/deb/debian/freeswitch_archive_g0.pub | apt-key add - 2 3echo "deb http://files.freeswitch.org/repo/deb/freeswitch-1.6/ jessie main" > /etc/apt/sources.list.d/freeswitch.list 4 5# you may want to populate /etc/freeswitch at this point. 6# if /etc/freeswitch does not exist, the standard vanilla configuration is deployed 7 8apt-get update && apt-get install -y freeswitch-meta-all && apt-get install -y freeswitch-meta-all-dbg
通过以下命令,可以查找到和 FreeSWITCH 相关的所有 packages:
apt-cache search freeswitch
单独安装 mod_shout 模块:
1apt-cache search freeswitch-mod-shout 2 3apt-get install -y freeswitch-mod-shout && apt-get install -y freeswitch-mod-shout-dbg
3) apt-get 的安装日志,位于
tail -f /var/log/apt/history.log
4) 安装完成之后,FS 会自动启动,无论使用 /usr/bin/freeswitch -stop 或者 kill 都退出不了进程,因为它是通过 systemd 来启动的,需要使用如下命令才能正确退出 FS:
systemctl stop freeswitch.service
systemctl 其实是调用了一个脚本来启动 FS 的,可以通过以下命令找到该脚本:
1find / -name "*freeswitch.service*" 2 3# 查找结果,第一个结果其实是软链接,指向第二个结果的 4/etc/systemd/system/multi-user.target.wants/freeswitch.service 5/lib/systemd/system/freeswitch.service
FS 源码里面包含了这个脚本的:
该启动脚本配置了很多启动参数,可以对这些参数进行调整,但一般不建议直接修改这个脚本,自定义的启动参数可以另外配置在以下位置:
1;;;;; Author: Travis Cross <tc@traviscross.com> 2 3[Unit] 4Description=freeswitch 5After=syslog.target network.target local-fs.target 6 7[Service] 8; service 9Type=forking 10PIDFile=/run/freeswitch/freeswitch.pid 11Environment="DAEMON_OPTS=-nonat" 12EnvironmentFile=-/etc/default/freeswitch 13ExecStart=/usr/bin/freeswitch -u freeswitch -g freeswitch -ncwait $DAEMON_OPTS 14TimeoutSec=45s 15Restart=always 16; exec 17User=root 18Group=daemon 19LimitCORE=infinity 20LimitNOFILE=100000 21LimitNPROC=60000 22LimitSTACK=250000 23LimitRTPRIO=infinity 24LimitRTTIME=infinity 25IOSchedulingClass=realtime 26IOSchedulingPriority=2 27CPUSchedulingPolicy=rr 28CPUSchedulingPriority=89 29UMask=0007 30 31; 这里新建一个 conf 文件 32; alternatives which you can enforce by placing a unit drop-in into 33; /etc/systemd/system/freeswitch.service.d/*.conf: 34; 35; User=freeswitch 36; Group=freeswitch 37; ExecStart= 38; ExecStart=/usr/bin/freeswitch -ncwait -nonat -rp 39; 40; empty ExecStart is required to flush the list. 41; 42; if your filesystem supports extended attributes, execute 43; setcap 'cap_net_bind_service,cap_sys_nice=+ep' /usr/bin/freeswitch 44; this will also allow socket binding on low ports 45; 46; otherwise, remove the -rp option from ExecStart and 47; add these lines to give real-time priority to the process: 48; 49; PermissionsStartOnly=true 50; ExecStartPost=/bin/chrt -f -p 1 $MAINPID 51; 52; 新建完之后,需要 reload 配置文件 53; execute "systemctl daemon-reload" after editing the unit files.
5) 通过 systemctl 来启动、关闭、重启 FS:
1# 立即启动 2$ systemctl start freeswitch.service 3 4# 立即停止 5$ systemctl stop freeswitch.service 6 7# 重启 8$ systemctl restart freeswitch.service 9 10# 杀死 FS 服务进程及其所有子进程 11$ systemctl kill freeswitch.service
查看 FS 启动日志:
1# 查看某个 Unit 的日志 2$ journalctl -u freeswitch.service 3$ journalctl -u freeswitch.service --since today 4 5# 实时滚动显示某个 Unit 的最新日志 6$ journalctl -u freeswitch.service -f 7$ journalctl -u freeswitch.service -f -n 100
6) 安装完成后,执行命令确保需要的模块已经正常安装、加载:
1fs_cli > module_exists mod_curl 2fs_cli > module_exists mod_xml_curl 3fs_cli > module_exists mod_xml_rpc 4fs_cli > module_exists mod_event_socket 5fs_cli > module_exists mod_shout 6fs_cli > module_exists mod_python 7fs_cli > module_exists mod_lua 8fs_cli > module_exists mod_cdr_csv 9fs_cli > module_exists mod_tts_commandline 10fs_cli > module_exists mod_flite 11fs_cli > module_exists mod_pocketsphinx 12fs_cli > module_exists mod_opus 13fs_cli > module_exists mod_unimrcp 14fs_cli > module_exists mod_redis 15 16# 直接查看模块是否已经编译生成 17$ ll -lh /usr/lib/freeswitch/mod/
【注意】
- 通过 apt-get 方式安装 FS ,默认不安装 mod_shout 模块的,需要自己手动安装。
- 这些模块不一定全都是你所需要的,比如,我自己用了 lua 和 python,就需要 mod_lua 和 mod_python 这两模块;模块 mod_shout 是对 mp3 文件做支持的,如果需要播放 mp3 音频文件或者录音为 mp3 格式的文件,就需要该模块。
7) 使用 apt-get 方式安装 FS,安装完成后它的相关文件夹会比较分散,使用以下命令可以查找到以 freeswitch命名的文件夹:
1find / -name freeswitch -type d 2 3# 查找结果 4/run/freeswitch 5/var/log/freeswitch 6/var/lib/freeswitch 7/usr/share/doc/freeswitch 8/usr/share/perl5/auto/freeswitch 9/usr/share/freeswitch 10/usr/local/freeswitch 11/usr/lib/freeswitch 12/etc/freeswitch
8) 设置 core dump file 的文件命名规则,当 FS 崩溃的时候,会在【 根路径 】 / 下生成 core dump file
1# 查看系统变量 2sysctl kernel.core_pattern 3 4# 写入系统变量 5sysctl -w kernel.core_pattern=core.%e.%h.%p
9) 查找 fs 崩溃的时候,生成的 core file
find /home -name *core*
至此,全部安装已经完成,可以开始使用你的 FreeSWITCH 了 ^_^
1# 启动(如果服务是运行中状态,会启动失败) 2systemctl start freeswitch.service 3 4# 关闭 5systemctl stop freeswitch.service 6 7# 运行状态 8systemctl status freeswitch.service 9 10# 查看启动配置 11systemctl can freeswitch.service 12 13# 开启开机启动 14systemctl enable freeswitch.service 15 16# 取消开机启动 17systemctl disable freeswitch.service 18 19# 查看运行中的服务 20systemctl list-units --type=service 21
【参考】
https://freeswitch.org/confluence/display/FREESWITCH/Debian+8+Jessie
http://blog.jobbole.com/107760/
https://en.wikipedia.org/wiki/Core_dump
http://man7.org/linux/man-pages/man5/core.5.html
http://man.linuxde.net/sysctl/
http://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-commands.html
http://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-part-two.html