Multiple Asterisk instances for multiple ips in same machine

we have a dedicated server and want to run a 2nd instance of asterisk mapped to another ip to run a ip-pbx for my brothers office. ideally also with it’s own freepbx frontend too. is this possible and what is the best way to do it ? must i use xen or is it possible just configuring asterisk to do this ?

martin

Hi

The only way I have done it was a secont install in a different directory structure, and it did work OK

But that was too long ago and I have no notes on doing it

Ian

We are also using multiple Asterisk 1.4 instances on the same server, with just one installation, here is a quick howto:

  1. copy all the files of the Asterisk configuration directory (/etc/asterisk) in the a new directory for the new Asterisk instance, /etc/asterisk/;
  2. modify the file asterisk.conf you find in the /etc/asterisk/ directory
    from
[directories]
astetcdir => /etc/asterisk
astmoddir => /usr/lib/asterisk/modules
astvarlibdir => /var/lib/asterisk
astdatadir => /var/lib/asterisk
astagidir => /var/lib/asterisk/agi-bin
astspooldir => /var/spool/asterisk
astrundir => /var/run
astlogdir => /var/log/asterisk

to

[directories]
astetcdir => /etc/asterisk/<instance>
astmoddir => /usr/lib/asterisk/modules
astvarlibdir => /var/lib/asterisk/<instance>
astdatadir => /var/lib/asterisk/<instance>
astagidir => /var/lib/asterisk/<instance>/agi-bin
astspooldir => /var/spool/asterisk/<instance>/
astrundir => /var/run/<instance>
astlogdir => /var/log/asterisk/<instance>
  1. copy all the contents of the /var/lib/asterisk directory in the new directory /var/lib/asterisk;
  2. Check h323.conf, http.conf, iax.conf, manager.conf, mgcp.conf, sip.conf and skinny.conf and be sure that the Asterisk instance listen to a different ip or port respect to the other instances;
  3. If the ip used is the same use different rtp ports per instance (rtp.conf);
  4. copy all the contents of the /var/spool/asterisk directory in the new directory /var/spool/asterisk;
  5. copy all the contents of the /var/log/asterisk directory in the new directory /var/log/asterisk;
  6. create the directory /var/run/<instance
  7. when you start Asterisk tell it where is the configuration file asterisk.conf with the -C parameter;
  8. modifify the init script to pass the right parameters to Asterisk when starting it and to look for control files in the right subdirectories.

This is an extract from my docs, hope it helps you start.

Cheers.

Marco Bruni
www.marcobruni.net

Seems very strange, can not start the second instance.

Copied directories, changed RTP port range, SIP port (the IP address is the same for both Asterisks).
But still can not start the 2nd instance.

Show the process:

vn ~ # ps aux | grep asteris root 8709 0.0 0.0 108164 764 pts/2 S 07:48 0:00 /bin/sh /usr/sbin/safe_asterisk -U asterisk -G asterisk asterisk 8712 0.6 0.4 2743012 32516 pts/2 Sl 07:48 0:09 /usr/sbin/asterisk -f -U asterisk -G asterisk -vvvg -c

Trying to start one more:

vn ~ # /usr/sbin/asterisk -f -U asterisk -G asterisk -C /etc/asterisk_2/asterisk.conf Privilege escalation protection disabled! See https://wiki.asterisk.org/wiki/x/1gKfAQ for more details. Asterisk already running on /var/run/asterisk/asterisk.ctl. Use 'asterisk -r' to connect.

Trying to connect to the second Asterisk:

But this connects me to the first (and only running) Asterisk.

Some time ago I started several instances on FreeBSD. Now it CentOS 6.6.
I also tried to kill ‘safe_asterisk’ first and then start the 2nd instance.
And also tried killing ‘safe_asterisk’, then aserisk itself. Then starting Asterisk manually, not with init scripts (not with ‘service asterisk start’). Then starting the 2nd one with ‘-C /etc/asterisk_2/asteris.conf’.

But in all cases I get a message that Asterisk is already running.

You didn’t specify an alternative directory for the .ctl file. You will need alternative directories for at least the run directory and the ASTDB one, and I’d advise do so for the log directories.

Hello David55, I configured it in asterisk.conf for the 2nd instance:

vn ~ # more /etc/asterisk_2/asterisk.conf 
[directories](!)
astetcdir => /etc/asterisk_2
astmoddir => /usr/lib64/asterisk/modules
astvarlibdir => /var/lib/asterisk_2
astdbdir => /var/lib/asterisk_2
astkeydir => /var/lib/asterisk_2
astdatadir => /var/lib/asterisk_2
astagidir => /var/lib/asterisk_2/agi-bin
astspooldir => /var/spool/asterisk_2
astrundir => /var/run/asterisk_2
astlogdir => /var/log/asterisk_2
astsbindir => /usr/sbin

And of course created the directory.

There is, or at least used to be, a comment in the generated asterisk.conf saying you must remove the (!) for the directories section to be effective.

Thak you David. That was the clue.
But the default asterisk.conf does not have such a comment (at least in Asterisk on CentOS, from repository).

Couldn’t you just run each Asterisk in its own chroot?

http://en.wikipedia.org/wiki/Chroot