Hello, dear habravchane.
For several months now I've been picking on the great product FreeSWITCH. It never ceases to amaze me with its functionality, reliability and performance (even in those areas where you don’t expect it to).
One of my experiments, which soon, most likely, will go into production, concerned the amazing, from my point of view, mod_sofia recover function. The recover function allows FreeSWITCH (FS) to recover calls after crashing, or, if FS is running in a high-available cluster, pick up calls on the second node! ATTENTION! without interruptions in calls to subscribers, both in the case of RTP proxying, and without it.
')
This is implemented quite simply, thanks to the use of an external DBMS and mod_sofia settings, which are responsible for the SIP stack. Those. mod_sofia stores all the information about current calls in the external database, and when the second node of the cluster is more beautiful, it is possible to read these settings and pick up the calls.
So, we will need:
- Free switch
- Separately installed DBMS (in my case mysql)
- unixODBC
- the dependencies that FS will require (described on the wiki )
- heartbeat
I will not dwell on the process of installing FS and cutting out unnecessary modules from it; all experiments will be placed on the default configuration. At the end just add some gateway to make external calls.
We will assume that everything that we need is established, let's proceed to the most interesting! Tinkering configs.
Setting the default FS is already completely ringing and for tests we will be more than enough.
On the database server we execute:
#mysqladmin -u dba_user -p create fs_cnf
This will create a database in which FS will store its settings.
Our clarister will consist of 2 working nodes and a database server.
Address of the first node 172.16.100.200
Address of the second node 172.16.100.201
General address 172.16.100.205
Address DB server 172.16.100.210
All actions below are performed on both FreeSWITCH nodes.In the /etc/odbc.ini file we enter the connection parameters to the database server
[fsw-cnf] Description = MySQL ODBC Database TraceFIle = stderr Driver = MySQL SERVER = 172.16.100.210 USER = fs-usr PASSWORD = super_secure_password OPTION = 67108864 DATABASE = fs_cnf
We want FS to work on a shared IP, for this file freeswitch_base_dir / conf / vars.xml
you need to enter the line:
<X-PRE-PROCESS cmd="set" data="local_ip_v4=172.16.100.205"/>
In order for recover to work, you need to enable call tracking in sip profiles. What profiles are beautifully described
here . Go to freeswitch_base_dir / conf / sip_profiles / and add the line (internal, external) to the settings of both profiles:
<param name="track-calls" value="true"/>
Also in both profiles we specify the parameters for connecting to the database server.
<param name="odbc-dsn" value="fsw-cnf:fs-usr:super_secure_password"/>
Go to the file freeswitch_base_dir / conf / autoload_configs / switch.conf.xml and add the line or uncomment and edit:
<param name="core-db-dsn" value="fsw-cnf:fs-usr:super_secure_password"/>
This is for the core FS settings.
When you start FS itself will create the necessary tables for work.
Next, configure heartbeat:
vim /etc/ha.d/authkeys
auth 1 1 sha1 mega_super_secure_key
chmod 600 /etc/ha.d/authkeys
vim /etc/ha.d/ha.cf
# logfacility local0 # keepalive 100ms deadtime 2 warntime 1 initdead 120 # udpport 694 bcast eth0 # node fs1 fs2 # ? auto_failback on
vim /etc/ha.d/haresources (on the second node you need to change the hostname (fs1 to fs2))
fs1 IPaddr2::172.16.100.205/255.255.255.0/eth0 freeswitch::fsrecover
freeswitch :: fsrecover - the init.d section of the script that will raise our profiles to us, we will add it in the next step
In /etc/init.d/freeswitch between restart and reload add
fsrecover) $FS_HOME/bin/fs_cli -x "sofia profile internal start" $FS_HOME/bin/fs_cli -x "sofia profile external start" /bin/sleep 1 $FS_HOME/bin/fs_cli -x "sofia recover" ;;
Now when one of the nodes crashes the second will raise the total IP and restart the FS profiles, then execute the cherished command and pick up the calls.
To check the outgoing call, we need to edit the dialplan and add a gateway.
In my example, I will use voip.ms with a ten-digit number. Go to freeswitch_base_dir / conf / sip_profiles / external / and create a file with the following content:
<include> <gateway name="voipms"> <param name="username" value="your_username" /> <param name="password" value="your_password" /> <param name="proxy" value="montreal|houston|newyork|etc.voip.ms" /> <param name="realm" value="voip.ms" /> <param name="register" value="true" /> <param name="sip_cid_type" value="rpd" /> </gateway> </include>
Add to freeswitch_base_dir / conf / dialplan / default.xml (change the regular expression and caller-id parameters)
<extension name="Outbound 10 Digits"> <condition field="destination_number" expression="^(\d{10})$"> <action application="set" data="effective_caller_id_number=8001231234"/> <action application="set" data="effective_caller_id_name=800 Number"/> <action application="bridge" data="sofia/gateway/voipms/$1"/> </condition> </extension>
Start the demons:
chkconfig heartbeat on service heartbeat start chkconfig freeswitch on service freeswitch start
The start-up friswitch script will launch it on both nodes, but on an inactive node, profiles will not rise, since no ip on which they run.
For tests, we take any extenson from freeswitch_base_dir / conf / directory / default, registering:
Proxy: 172.16.100.205
username: 1000
password: 1234 (This is default_password, it must be changed in vars.xml)
We dial any number, in the process of conversation we put one of the nodes and voila! Heartbeat detects that the second node is lying, picks up the common IP, runs the script, thereby launching inactive profiles. Interruption of the media stream is only 2-3 seconds, i.e. the time it takes for a heartbit to intercept resources + 1 second in freeswitch: fsrecover
Everything. Thank you for your attention, I hope the article will be useful to someone. Suggestions and suggestions are more than welcome. The plans are to write about a bunch of mod_xml_curl, mod_lcr and something else.
P.S. As they say: "do not kick much, the first article."
Literature:
wiki.freeswitch.org