1) In this article I would like to explain how we can create multi-server Asterisk set-up with Kamailio help. Before we can proceed you will need to set-up 2 separate Asterisk servers - asterisk1 & asterisk2, server running MySQL DB, you need to configure SIP Realtime on both Asterisk servers so it will use same MySQL DB(please use separate sipregs table for each server, in my set-up I named them sipregs_asterisk1 & sipregs_asterisk2) and you will need to install Kamailio with default configuration. Additionally we will use func_odbc on Asterisk, but it should be already compiled, if you set up your Asterisk with SIP realtime using ODBC.
2) For Asterisk SIP realtime I recommend following manual , I skipped voicemail* tables. Use your common sense and follow only asterisk related steps.
3) First what we need to create view
sipregs_all what will have data from our both sipregs tables:
It is not recommended to share
sipregs table between servers, each server should have it own table.
4) Make sure that in
sip.conf you have following options switched on:
5) Now we need to decide how we will name our Asterisk boxes. I named them
6) Now we need to set-up systemname, use names from previous point. You can change systemname in
asterisk.conf like this:
7) Now we can set-up trunks on both Asterisk servers. In
sip.conf of asterisk1 I have following entry, you need same entry on asterisk2,
just change ip-address and trunk name accordingly.
8) This is my dialplan, please put it on both servers. Following
dialplan check with
func_odbc where currently called extension registered and if it is not on same server as caller then it sends call to
trunk with name from field
regserver, what should be systemname. If we do not find extension we just hangup a call, off cause we can hangup
with specific error like “404 Not Found”, but this is homework for you. ;)
9) Additionally you need to configure odbc function in
func_odbc.conf. It checks on what server currently user is
located and sort result based on
regseconds field, cause there might be several entries, if extension didn’t unregistered
properly from one server and then registered on other one.
10) Now you need to add users to
11) Please add users to
12) On this point you should be ready with Asterisk part. To test it - register with 2 SIP clients with each on separate Asterisk server and you should be able to call one extension from other.
13) Now you need to install Kamailio. It is very easy to do I think even simpler then Asterisk. I recommend following manual .
14) This is my Kamailio config .
15) This is my content of
16) Now you should be able to register on Kamailio ip-address and calls should work even if 2 extensions are registered on separate servers. When one servers dies, extension will be able to make call through second server, but it will not be able to receive call until it re-registers, so I recommend to put 60 seconds re-registration timeout on all extensions.
17) This is very simple and easy cluster set-up of Asterisk, off cause there are dozens other options, what include register server on Kamailio side, using DUNDi and etc. You can even skip Kamailio and use DNS based fail-over, just make sure that your SIP clients support DNS SRV records.
18) In following set-up single point of failure is Kamailio and MySQL DB. For MySQL you can use some-kind cluster(Galera, Percona), there is dozens manuals online. For Kamailio you can have some-kind fail-over set-up too. I hope this article was help-full and I really do not intended to answer all question, but I just wanted to provide simple manual for cluster set-up from where you can start to build up your set-up.