前言
Linux 上部署 FreeSWITCH 是一件比较麻烦的事情,用 Docker 部署相对方便且更容易运维。下面详述官方项目部署步骤。
容器公开以下端口:
- 5060/tcp 5060/udp 5080/tcp 5080/udp作为SIP信令端口。
- 5066/tcp 7443/tcp作为WebSocket信令端口。
- 8021/tcp作为事件套接字端口。
- 64535-65535/udp作为媒体端口。
部署步骤
一、克隆git
- 执行命令
git clone https://github.com/BetterVoice/freeswitch-container.git
- 得到一个名为 freeswitch-container 的文件夹
# Jenkins. FROM ubuntu:16.04 MAINTAINER Thomas Quintana <thomas@bettervoice.com> # Enable the Ubuntu multiverse repository. RUN echo "deb http://us.archive.ubuntu.com/ubuntu/ trusty multiverse" >> /etc/apt/source.list RUN echo "deb-src http://us.archive.ubuntu.com/ubuntu/ trusty multiverse">> /etc/apt/source.list RUN echo "deb http://us.archive.ubuntu.com/ubuntu/ trusty-updates multiverse" >> /etc/apt/source.list RUN echo "deb-src http://us.archive.ubuntu.com/ubuntu/ trusty-updates multiverse" >> /etc/apt/source.list # Enable videolan stable repository. RUN apt-get update && apt-get install -y software-properties-common RUN add-apt-repository ppa:videolan/stable-daily # Install Dependencies. # missing in 16.04 libmyodbc RUN 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-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 unixodbc wget yasm libldap2-dev # Use Gawk. RUN update-alternatives --set awk /usr/bin/gawk # Install source code dependencies. ADD build/install-deps.sh /root/install-deps.sh WORKDIR /root RUN chmod +x install-deps.sh RUN ./install-deps.sh RUN rm install-deps.sh # Configure Fail2ban ADD conf/freeswitch.conf /etc/fail2ban/filter.d/freeswitch.conf ADD conf/freeswitch-dos.conf /etc/fail2ban/filter.d/freeswitch-dos.conf ADD conf/jail.local /etc/fail2ban/jail.local RUN touch /var/log/auth.log # Download FreeSWITCH. WORKDIR /usr/src ENV GIT_SSL_NO_VERIFY=1 #RUN git clone https://freeswitch.org/stash/scm/fs/freeswitch.git -b v1.6 RUN git clone https://github.com/signalwire/freeswitch.git -b v1.6 # Bootstrap the build. WORKDIR freeswitch RUN ./bootstrap.sh # Enable the desired modules. ADD build/modules.conf /usr/src/freeswitch/modules.conf # Build FreeSWITCH. RUN ./configure --enable-core-pgsql-support RUN make RUN make install RUN make uhd-sounds-install RUN make uhd-moh-install # RUN make samples # Post install configuration. ADD sysv/init /etc/init.d/freeswitch RUN chmod +x /etc/init.d/freeswitch RUN update-rc.d -f freeswitch defaults ADD sysv/default /etc/default/freeswitch ADD build/bashrc /root/.bashrc ADD conf/fs_sync /bin/fs_sync # Add the freeswitch user. RUN adduser --gecos "FreeSWITCH Voice Platform" --no-create-home --disabled-login --disabled-password --system --ingroup daemon --home /usr/local/freeswitch freeswitch RUN chown -R freeswitch:daemon /usr/local/freeswitch # Add confile file ADD build/lib/* /usr/lib/ RUN ln /usr/lib/x86_64-linux-gnu/libpcre32.so.3.13.2 /usr/lib/libpcre.so.1 RUN ln /usr/lib/x86_64-linux-gnu/libedit.so.2.0.53 /usr/lib/libedit.so.0 RUN ln /usr/lib/libssl.so.1.0.0 /usr/lib/libssl.so.10 RUN ln /usr/lib/libcrypto.so.1.0.0 /usr/lib/libcrypto.so.10 ADD build/token.txt /usr/local/freeswitch/bin/ ADD build/robot.conf /usr/local/freeswitch/bin/ ADD build/alitoken_time.cfg /usr/local/freeswitch/bin/ ADD build/alitoken /usr/local/freeswitch/bin/ ADD build/mod_vmd.so /usr/local/freeswitch/mod/ ADD conf/* /usr/local/freeswitch/conf/ RUN chmod +x /usr/local/freeswitch/bin/alitoken # Create the log file. RUN touch /usr/local/freeswitch/log/freeswitch.log RUN chown freeswitch:daemon /usr/local/freeswitch/log/freeswitch.log # Open the container up to the world. EXPOSE 5060/tcp 5060/udp 5080/tcp 5080/udp EXPOSE 5066/tcp 7443/tcp EXPOSE 8021/tcp EXPOSE 64535-65535/udp # Start the container. CMD service snmpd start && service freeswitch start && tail -f /usr/local/freeswitch/log/freeswitch.log
二、执行构建命令
执行完构建命令后,会得到一个 docker 镜像
docker build -t freeswitch .
三、创建容器
端口需要映射,但是由于docker中的一个问题,映射 -p 60535-65535:60535-65535/udp 这样的大端口范围会占用大量内存。用 --userland proxy=false 启动 docker 可以部分解决这个问题,但启动仍然很慢。
解决方法:手动添加iptables规则
# 注意需要修改路径
CID=$(sudo docker run --name freeswitch -p 5060:5060/tcp -p 5060:5060/udp -p 5080:5080/tcp -p 5080:5080/udp -p 8021:8021/tcp -p 7443:7443/tcp -p 60535-65535:60535-65535/udp -v /home/ubuntu/freeswitch/conf:/usr/local/freeswitch/conf bettervoice/freeswitch-container:1.6.6)
# 手动添加iptables规则
CIP=$(sudo docker inspect --format='{{.NetworkSettings.IPAddress}}' $CID)
sudo iptables -A DOCKER -t nat -p udp -m udp ! -i docker0 --dport 60535:65535 -j DNAT --to-destination $CIP:60535-65535
sudo iptables -A DOCKER -p udp -m udp -d $CIP/32 ! -i docker0 -o docker0 --dport 60535:65535 -j ACCEPT
sudo iptables -A POSTROUTING -t nat -p udp -m udp -s $CIP/32 -d $CIP/32 --dport 60535:65535 -j MASQUERADE
四、复制相关文件
sudo cp sysv/systemd/docker.freeswitch.service /lib/systemd/system/
sudo systemctl daemon-reload
sudo cp sysv/docker.freeswitch.py /usr/local/bin/
五、开启、关闭服务
# Enable the service
sudo systemctl enable docker.freeswitch
# Start the service
sudo systemctl start docker.freeswitch
# Stop the service
sudo systemctl stop docker.freeswitch
注
确保在 autoload_configs/switch.conf.xml 中正确设置了 rtp 启动端口和 rtp 结束端口。此外,还需要为每个可从公共 ip 地址访问的配置文件设置 ext rtp ip和ext sip ip。有关更多说明,请参阅freeswitch文档。
容器操作
容器中提供了以下模块,可以在运行时通过提供一个modules.conf.xml文件来加载,该文件中未注释所需的模块名称。
应用(Applications)
mod_avmd
: Detects voicemail beeps using a generalized approach.mod_blacklist
: Blacklist module.mod_callcenter
: Call queuing application that can be used for call center needs.mod_cidlookup
: Provides a means (database, url) to lookup the callerid name from a number.mod_commands
: A mass plethora of API interface commands.mod_conference
: Conference room module.mod_curl
: Allows scripts to make HTTP requests as receive responses as plain text or JSON.mod_db
: Database key/value store functionality, group dialing, and limit backend.mod_directory
: Dial by Name directory.mod_distributor
: Simple round-robin style distributions.mod_dptools
: Dialplan Tools: provides a number of apps and utilities for the dialplan.mod_easyroute
: A simple DID routing engine that uses a database lookup to determine how to route an incoming call.mod_enum
: Route PSTN numbers over internet according to ENUM servers, such as e164.orgmod_esf
: Holds the multi cast paging application for SIP.mod_esl
: Allows to generate remote ESL commands.mod_expr
: Brian Allen Vanderburg's expression evaluation library.mod_fifo
: FIFO module.mod_fsk
: FSK (Frequency-Shift Keying) data transfermod_fsv
: FreeSWITCH Video application (Recording and playback)mod_hash
: Hashtable key/value store functionality and limit backendmod_httapi
: HT-TAPI Hypertext Telephony API (Twilio FreeSWITCH style)mod_http_cache
: HTTP GET with caching.mod_ladspa
: use Auto-tune on your call.mod_lcr
: Implements LCR (Least Cost Routing)mod_memcache
: API that integrates with memcached (a distributed key/value object store)mod_mongo
: http://www.mongodb.org/mod_mp4
: MP4 File Format support for video apps.mod_nibblebill
: Billing module ("nibbles" at credit/cash amounts during calls)mod_oreka
: Module for Media Recording with Orekamod_rad_auth
: use RADIUS for authenticationmod_redis
: supplies a limit back-end that uses Redis.mod_rss
: Reads RSS feeds via a TTS engine.mod_sms
: Apps for chat messagesmod_snapshot
: Records a sliding window of audio and can take snapshots to disk.mod_snom
: Controlling softkeys on Snom phones (button function, led state, label etc.)mod_spandsp
: Spandsp tone and DTMF detectors. A combination of mod_fax and mod_voipcodecs and mod_t38gateway.mod_spy
: User spy module.mod_stress
: Module for detecting voice stress.mod_tone_detect
: Tone detection module.mod_translate
: Format numbers into a specified format.mod_valet_parking
: Allows calls to be parked and picked up easily.mod_vmd
: Voicemail beep detection module.mod_voicemail
: Full-featured voicemail module.mod_voicemail_ivr
: VoiceMail IVR Interface.mod_xml_odbc
: Allows user directory to be accessed from a database in realtime.
语音识别/文本到语音(Speech Recognition / Text-to-Speech)
mod_flite
- Free open source Text to Speech.mod_pocketsphinx
- Free open source Speech Recognition.mod_tts_commandline
- Run a command line and play the outputted file.mod_unimrcp
- Module for an open MRCP implementation
编解码器(Codecs)
mod_amr
: GSM-AMR (Adaptive Multi-Rate) codec.mod_amrwb
: GSM-AMRWB (ARM Wide Band) codec.mod_bv
: BroadVoice16 and BroadVoice32 audio codecs (Broadcom codecs).mod_celt
: CELT ultra-low delay audio codec.mod_codec2
: FreeSWITCH CODEC2 Module.mod_dahdi_codec
- DAHDI Codecs (G729A 8.0kbit, G723.1 5.3kbit).mod_g723_1
: G.723.1 codec.mod_g729
: G.729 codec.mod_h26x
: H26X signed linear codec.mod_ilbc
: ILBC codec.mod_isac
: Internet Speech Audio Codec open sourced by Google, used in WebRTCmod_mp4v
: MPEG4 video codecmod_opus
: The OPUS ultra-low delay audio codec (http://opus-codec.org/)mod_siren
: G.722.1 (Siren7) and G.722.1 Annex C (Siren14) Polycom codecs.mod_speex
: Speex codec.mod_theora
: Theora video codecmod_voipcodecs
: VoIP Codecs (G.711, G.722, G.726, GSM-FR, IMA_ADPCM, LPC10)mod_vp8
: VP8 video codec
呼叫(Dialplan)
mod_dialplan_asterisk
: Allows you to create dialplans the old-fashioned way.mod_dialplan_directory
: Allows you to obtain a dialplan from a directory resourcemod_dialplan_xml
: Allows you to program dialplans in XML format.mod_yaml
: Allows you to program dialplans in YAML format.
名录(Directories)
mod_ldap
: LDAP module made to obtain dialplans, user accounts, etc.
端点(Endpoints)
mod_alsa
: Sound card endpoint.mod_dingaling
: Jabber/Google Talk integration module; note XMPP access to Google Voice ended 2014.05.15mod_loopback
: Loopback endpoint module - A loopback channel driver to make an outbound call as an inbound call.mod_portaudio
: Voice through a local soundcard.mod_rtmp
: "Real time media protocol" endpoint for FreeSWITCH.mod_skinny
: SCCP modulemod_skypopen
: Skype compatible module.mod_sofia
: SIP module.
事件句柄(Event Handlers)
mod_cdr_csv
: CSV call detail record handler.mod_cdr_mongodb
: MongoDB CDR modulemod_cdr_pg_csv
: Asterisk Compatible CDR Module with PostgreSQL interfacemod_cdr_sqlite
: SQLite CDR Modulemod_erlang_event
: Module to send/receive events/commands in Erlang's binary format.mod_event_multicast
: Broadcasts events to netmask.mod_event_socket
: Sends events via a single socket.mod_event_zmq
: http://www.zeromq.org/mod_json_cdr
: JSON CDR Module to files or curlmod_radius_cdr
: RADIUS CDR Module.mod_rayo
: 3PCC over XMPP - http://rayo.org/xepmod_snmp
: SNMP AgentX modulemod_xml_cdr
- XML-based call detail record handler.
文件格式(File Formats)
mod_local_stream
: Multiple channels connected to same looped file stream.mod_native_file
: File interface for codec specific file formats.mod_portaudio_stream
: Stream from an external audio source for Music on Holdmod_shell_stream
: Stream audio from an arbitrary shell command. Read audio from a database, from a soundcard, etc.mod_shout
: MP3 files and shoutcast streams.mod_sndfile
: Multi-format file format transcoder (WAV, etc)mod_ssml
: Speech Synthesis Markup Language parsermod_tone_stream
: Tone Generation Stream.mod_vlc
: Stream audio from VLC media player using libvlc.
语言(Languages)
mod_lua
- Lua support.mod_perl
- Perl support.mod_python
- Python Support.mod_v8
- Google V8 JavaScript (ECMAScript) engine.
日志(Loggers)
mod_console
- Console logger.mod_logfile
- File logger.mod_syslog
- Syslog logger.
特定语言(Language-Specific)
mod_say_de
- German language text-to-speech enginemod_say_en
- English language text-to-speech enginemod_say_es
- Spanish language text-to-speech enginemod_say_fa
- Persian language text-to-speech enginemod_say_fr
- French language text-to-speech enginemod_say_he
- Hebrew language text-to-speech enginemod_say_hr
- Croatian language text-to-speech enginemod_say_hu
- Hungarian language text-to-speech enginemod_say_it
- Italian language text-to-speech enginemod_say_ja
- Japanese language text-to-speech enginemod_say_nl
- Dutch language text-to-speech enginemod_say_pl
- Polish language text-to-speech enginemod_say_pt
- Portuguese language text-to-speech enginemod_say_ru
- Russian language text-to-speech enginemod_say_th
- Thai language text-to-speech enginemod_say_zh
- Chinese, Mandarin, Cantonese language text-to-speech engine
外部 API
mod_xml_curl
- XML Gateway Code. Configure FreeSWITCH™ from a web server on boot and on the fly.mod_xml_ldap
- LDAP XML Gateway.mod_xml_radius
- RADIUS authentication gateway.mod_xml_rpc
- XML Remote Procedure Calls. Issue commands from your web application.mod_xml_scgi
- Simple Common Gateway Interface.
参考:https://hub.docker.com/r/bettervoice/freeswitch-container
来源:oschina
链接:https://my.oschina.net/u/4415385/blog/4269054