2016-11-1
上周折腾了2天,安装升级了 FreeSWITCH 最新版本 1.6.12,把步骤记录一下以备后续查看。
1) 查看系统版本 on Debian
$ uname -a Linux debian 3.16.0-4-amd64 #1 SMP Debian 3.16.36-1+deb8u1 (2016-09-03) x86_64 GNU/Linux $ lsb_release -a No LSB modules are available. Distributor ID: Debian Description: Debian GNU/Linux 8.6 (jessie) Release: 8.6 Codename: jessie # on Debian $ cat /etc/debian_version 8.6 # on CentOS cat /etc/centos-release CentOS release 6.6 (Final) # 查看当前主机信息 # For systemd Debian version you may also use hostnamectl: hostnamectl
apt-get update apt-get install sox apt-get install lsb-release apt-get install ngrep apt-get install subversion apt-get install lrzsz apt-get install python apt-get install python-dev apt-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
wget -O - https://files.freeswitch.org/repo/deb/debian/freeswitch_archive_g0.pub | apt-key add - echo "deb http://files.freeswitch.org/repo/deb/freeswitch-1.6/ jessie main" > /etc/apt/sources.list.d/freeswitch.list # you may want to populate /etc/freeswitch at this point. # if /etc/freeswitch does not exist, the standard vanilla configuration is deployed apt-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 模块:
apt-cache search freeswitch-mod-shout apt-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 的,可以通过以下命令找到该脚本:
find / -name "*freeswitch.service*" # 查找结果,第一个结果其实是软链接,指向第二个结果的 /etc/systemd/system/multi-user.target.wants/freeswitch.service /lib/systemd/system/freeswitch.service
FS 源码里面包含了这个脚本的:
该启动脚本配置了很多启动参数,可以对这些参数进行调整,但一般不建议直接修改这个脚本,自定义的启动参数可以另外配置在以下位置:
;;;;; Author: Travis Cross <tc@traviscross.com> [Unit] Description=freeswitch After=syslog.target network.target local-fs.target [Service] ; service Type=forking PIDFile=/run/freeswitch/freeswitch.pid Environment="DAEMON_OPTS=-nonat" EnvironmentFile=-/etc/default/freeswitch ExecStart=/usr/bin/freeswitch -u freeswitch -g freeswitch -ncwait $DAEMON_OPTS TimeoutSec=45s Restart=always ; exec User=root Group=daemon LimitCORE=infinity LimitNOFILE=100000 LimitNPROC=60000 LimitSTACK=250000 LimitRTPRIO=infinity LimitRTTIME=infinity IOSchedulingClass=realtime IOSchedulingPriority=2 CPUSchedulingPolicy=rr CPUSchedulingPriority=89 UMask=0007 ; 这里新建一个 conf 文件 ; alternatives which you can enforce by placing a unit drop-in into ; /etc/systemd/system/freeswitch.service.d/*.conf: ; ; User=freeswitch ; Group=freeswitch ; ExecStart= ; ExecStart=/usr/bin/freeswitch -ncwait -nonat -rp ; ; empty ExecStart is required to flush the list. ; ; if your filesystem supports extended attributes, execute ; setcap 'cap_net_bind_service,cap_sys_nice=+ep' /usr/bin/freeswitch ; this will also allow socket binding on low ports ; ; otherwise, remove the -rp option from ExecStart and ; add these lines to give real-time priority to the process: ; ; PermissionsStartOnly=true ; ExecStartPost=/bin/chrt -f -p 1 $MAINPID ; ; 新建完之后,需要 reload 配置文件 ; execute "systemctl daemon-reload" after editing the unit files.
5) 通过 systemctl 来启动、关闭、重启 FS:
# 立即启动 $ systemctl start freeswitch.service # 立即停止 $ systemctl stop freeswitch.service # 重启 $ systemctl restart freeswitch.service # 杀死 FS 服务进程及其所有子进程 $ systemctl kill freeswitch.service
查看 FS 启动日志:
# 查看某个 Unit 的日志 $ journalctl -u freeswitch.service $ journalctl -u freeswitch.service --since today # 实时滚动显示某个 Unit 的最新日志 $ journalctl -u freeswitch.service -f $ journalctl -u freeswitch.service -f -n 100
6) 安装完成后,执行命令确保需要的模块已经正常安装、加载:
fs_cli > module_exists mod_curl fs_cli > module_exists mod_xml_curl fs_cli > module_exists mod_xml_rpc fs_cli > module_exists mod_event_socket fs_cli > module_exists mod_shout fs_cli > module_exists mod_python fs_cli > module_exists mod_lua fs_cli > module_exists mod_cdr_csv fs_cli > module_exists mod_tts_commandline fs_cli > module_exists mod_flite fs_cli > module_exists mod_pocketsphinx fs_cli > module_exists mod_opus fs_cli > module_exists mod_unimrcp fs_cli > module_exists mod_redis # 直接查看模块是否已经编译生成 $ 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命名的文件夹:
find / -name freeswitch -type d # 查找结果 /run/freeswitch /var/log/freeswitch /var/lib/freeswitch /usr/share/doc/freeswitch /usr/share/perl5/auto/freeswitch /usr/share/freeswitch /usr/local/freeswitch /usr/lib/freeswitch /etc/freeswitch
8) 设置 core dump file 的文件命名规则,当 FS 崩溃的时候,会在【 根路径 】 / 下生成 core dump file
# 查看系统变量 sysctl kernel.core_pattern # 写入系统变量 sysctl -w kernel.core_pattern=core.%e.%h.%p
9) 查找 fs 崩溃的时候,生成的 core file
find /home -name *core*
至此,全部安装已经完成,可以开始使用你的 FreeSWITCH 了 ^_^
# 启动(如果服务是运行中状态,会启动失败) systemctl start freeswitch.service # 关闭 systemctl stop freeswitch.service # 运行状态 systemctl status freeswitch.service # 查看启动配置 systemctl can freeswitch.service # 开启开机启动 systemctl enable freeswitch.service # 取消开机启动 systemctl disable freeswitch.service # 查看运行中的服务 systemctl list-units --type=service
【参考】
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