前言
Linux 上部署 FreeSWITCH 是一件比較麻煩的事情,用 Docker 部署相對方便且更容易運維。下面詳述官方項目部署步驟。python
容器公開如下端口:linux
- 5060/tcp 5060/udp 5080/tcp 5080/udp做爲SIP信令端口。
- 5066/tcp 7443/tcp做爲WebSocket信令端口。
- 8021/tcp做爲事件套接字端口。
- 64535-65535/udp做爲媒體端口。
部署步驟
1、克隆gitgit
- 執行命令
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
2、執行構建命令github
執行完構建命令後,會獲得一個 docker 鏡像web
docker build -t freeswitch .
3、建立容器redis
端口須要映射,可是因爲docker中的一個問題,映射 -p 60535-65535:60535-65535/udp 這樣的大端口範圍會佔用大量內存。用 --userland proxy=false 啓動 docker 能夠部分解決這個問題,但啓動仍然很慢。sql
解決方法:手動添加iptables規則mongodb
# 注意須要修改路徑 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
4、複製相關文件docker
sudo cp sysv/systemd/docker.freeswitch.service /lib/systemd/system/ sudo systemctl daemon-reload sudo cp sysv/docker.freeswitch.py /usr/local/bin/
5、開啓、關閉服務shell
# 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