📜 ⬆️ ⬇️

Installing Asterisk in an OpenVZ Ubuntu 10.04.1 LTS container on a Debian GNU / Linux 5.0 host

image

Initial data:



Install and configure OpenVZ host. Features settings OpenVZ host here will not be considered.
We believe that we have it correctly configured, including NAT for guest machines and forwarding ports necessary for the server.

Downloading the template for the guest OS


cd /var/lib/vz/template/cache
wget download.openvz.org/template/precreated/contrib/ubuntu-10.04-minimal_10.04_amd64.tar.gz


Create and set up a container


sudo vzctl create 101 --ostemplate ubuntu-10.04-minimal_10.04_amd64
Created a container with ID = 101 from our template
sudo vzctl set 101 --name voip --save
set the name of the container
sudo vzctl set 101 --hostname voip.hurnet.ru --save
set the host name for the container
sudo vzctl set 101 --nameserver 8.8.8.8 --save
set the DNS for the container
sudo vzctl set 101 --description 'Asterisk VoIP server' --save
container description
sudo vzctl set 101 --ipadd 192.168.xxx.xxx --save
Set the network interface address
sudo vzctl set 101 --cpulimit 60 --save
set a limit on processor usage
sudo vzctl set 101 --diskspace 9000000:10000000 --save
9GB disk space quota (temporary excess to 10GB)
sudo vzctl set 101 --quotatime 6000 --save
time at which you can exceed the quota
sudo vzctl set 101 --privvmpages 750M:768M --save
Available memory count
sudo vzctl set 101 --vmguarpages 250M:256M --save
Guaranteed amount of memory
sudo vzctl start 101
we start
sudo vzctl enter 101
go in the container
apt-get update
apt-get upgrade

updated
sudo vzctl restart 101
(execute on the host machine, and go back to the container)
sudo apt-get install asterisk

We put asterisk


He will pull the necessary dependencies by himself. During the installation process will ask the phone
the region code (for Russia is 7), and a couple of questions about grub (not relevant, since the kernel and the loader cannot be changed from the container) There will be attempts to put it all with a bunch of errors - do not pay attention, wait patiently for the installation to finish.

We download Russian sound phrases from here http://ivrvoice.ru/downloader
We take the most recent archive. In my case, this is asterisk- sounds- rugsm- 2010-04-28. Tar. Gz
cd /usr/share/asterisk/sounds/
wget ivrvoice.ru/downloader/download/file/11
tar xvfz 11
rm 11


Getting started asterisk setup


Go to /etc/asterisk/sip.conf, find, uncomment and fix the option
language=ru
In the [general] section, uncomment the option allowguest=no
At the end of the file create a new section.
[200] ; Test user
type=friend
host=dynamic
username=200
secret=123
nat=no
canreinvite=no
context=office
callerid=”testuser″ <200>
allow=gsm
allow=ulaw
allow=alaw

With this we created one test user. the detailed syntax and description must be read in the documentation.

Then we create extensions at the end of the /etc/asterisk/extensions.conf file.
[office]
exten => 200,1, Macro(stdexten,200,SIP/200)
exten => testuser, 1, Goto(200|1)
include => demo

[macro-stdexten]
exten => s, 1, Dial (${ARG2},20,t [4] )
exten => s, 2, Goto(s-$(DIALSTATUS),1)
exten => s-NOANSWER, 1, Voicemail(u${ARG1})
exten => s-NOANSWER, 2, (Goto(default,s,1))
exten => s-BUSY, 1, Voicemail(b,${ARG1})
exten => s-BUSY, 2, (Goto(default,s,1))
exten => _s-., 1, Goto(s-NOANSWER)
exten => a, 1, VoiceMailMain(${ARG1})


Configure human integration into the asterisk system


Create a group and user from which the asterisk will work in the system:
addgroup --gid 109 asterisk
adduser --home /var/lib/asterisk --shel /bin/false --uid 104 --gid 109 --disabled-login asterisk
adduser asterisk dialout
adduser asterisk audio

It should turn out like this:
# cat /etc/group |grep asterisk
dialout:x:20:asterisk
audio:x:29:asterisk
asterisk:x:109:
# cat /etc/passwd |grep asterisk
asterisk:x:104:109:Asterisk PBX daemon,,,:/var/lib/asterisk:/bin/false


We set the necessary file permissions
chown -R asterisk. /etc/asterisk
chown -R asterisk. /var/{lib,log,spool}/asterisk
chown -R asterisk. /usr/share/asterisk/
mkdir /var/run/asterisk
chown -R asterisk. /var/run/asterisk/


Create a startup script:
nano /etc/init.d/asterisk with the following content:
')
#! / bin / sh
#
# asterisk start the asterisk PBX
# © Mark Purcell <msp@debian.org>
# © Tzafrir Cohen <tzafrir.cohen@xorcom.com>
# © Faidon Liambotis <paravoid@debian.org>

# This package is free software; you can redistribute it and / or modify
# it under the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Based on:
#
# skeleton example file to build /etc/init.d/ scripts.
# This file should be used to construct scripts for /etc/init.d.
#
# Written by Miquel van Smoorenburg <miquels@cistron.nl>.
# Modified for Debian GNU / Linux
# by Ian Murdock <imurdock@gnu.ai.mit.edu>.
#
# Version: @ (#) skeleton 1.9 26-Feb-2001 miquels@cistron.nl
#

### BEGIN INIT INFO
# Provides: asterisk
# Required-Start: $ local_fs zaptel
# Required-Stop: $ local_fs
# Should-start:
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Asterisk PBX
# Description: Controls the Asterisk PBX
### END INIT INFO

PATH = / usr / local / sbin: / usr / local / bin: / sbin: / bin: / usr / sbin: / usr / bin
NAME = asterisk
USER = $ NAME
GROUP = $ USER
DAEMON = / usr / sbin / $ NAME
DESC = "Asterisk PBX"
PIDFILE = "/var/run/asterisk/asterisk.pid"
ASTSAFE_PIDFILE = "/var/run/asterisk/asterisk_safe.pid"
PIDFILE_DIR = ` dirname $ PIDFILE`
UMASK = 007 # by default
# MAXFILES = 1024 # (the system default)

# by default: use real-time priority
PARAMS = ""
CHDIR_PARM = ""
AST_REALTIME = "yes"
RUNASTERISK = "yes"
AST_DUMPCORE = "no"
AST_DUMPCORE_DIR = "/ var / spool / asterisk" # only used if AST_DUMPCORE! = No
# core_pattern. See: http://lxr.linux.no/source/Documentation/sysctl/kernel.txt
# CORE_PATTERN =
if [ -r / etc / default / $ NAME ] ; then . / etc / default / $ NAME ; fi

if [ " $ RUNASTERISK " ! = "yes" ] ; then
echo "Asterisk not yet configured. Edit / etc / default / asterisk first."
exit 0
fi

if [ " $ AST_REALTIME " ! = "no" ]
then
PARAMS = " $ PARAMS -p"
fi

if [ " $ AST_DUMPCORE " ! = "no" ]
then
PARAMS = " $ PARAMS -g"
if [ " $ CORE_PATTERN " ! = '' ]
then
echo " $ CORE_PATTERN " > / proc / sys / kernel / core_pattern
fi
if [ -d " $ AST_DUMPCORE_DIR " ]
then
CHDIR_PARM = "--chdir $ AST_DUMPCORE_DIR "
fi
fi

if [ "x $ USER " = "x" ]
then
echo "Error: empty USER name"
exit 1
fi
if [ ` id -u " $ USER " ` = 0 ]
then
echo "Starting as root not supported."
exit 1
fi
PARAMS = " $ PARAMS -U $ USER "

if [ "x $ AST_DEBUG_PARAMS " = x ]
then
AST_DEBUG_PARAMS = -cvvvvvddddd
fi
if [ " $ RUNASTSAFE " = "yes" ] ; then
# The value of WRAPPER_DAEMON in can be set in / etc / default / asterisk
WRAPPER_DAEMON = $ {WRAPPER_DAEMON: - / usr / sbin / safe_asterisk}
REALDAEMON = " $ WRAPPER_DAEMON "
else
REALDAEMON = " $ DAEMON "
fi

test -x $ DAEMON || exit 0

if [ ! -d " $ PIDFILE_DIR " ] ; then
mkdir " $ PIDFILE_DIR "
chown $ USER : $ GROUP " $ PIDFILE_DIR "
fi

set -e

if [ " $ UMASK " ! = '' ]
then
umask $ UMASK
fi

# allow changing the per-process open files limit:
if [ " $ MAXFILES " ! = '' ]
then
ulimit -n $ MAXFILES
fi

status ( ) {
plist = ` ps ax | awk "{if (\ \ $ 5 == \" $ DAEMON \ " ) print \ \ $ 1}" `
if [ " $ plist " = "" ] ; then
echo " $ DESC is stopped"
return 1
else
echo " $ DESC is running: $ plist "
return 0
fi
}

asterisk_rx ( ) {
if ! status > / dev / null; then return 0 ; fi

# if $ HOME is set, asterisk -rx writes a .asterisk_history there
(
unset HOME

$ DAEMON -rx "$ 1"
)
}

case "$ 1" in
debug )
# we add to skip
# accidentally. Once may cause
# confusing results. I also want to maintain the user's choice
# of -p
echo "Debugging $ DESC :"
$ DAEMON $ PARAMS $ AST_DEBUG_PARAMS
exit 0
;;
start )
if status > / dev / null; then
echo " $ DESC is already running. Use restart."
exit 0
fi
echo -n "Starting $ DESC :"
if [ " $ RUNASTSAFE " ! = "yes" ] ; then
# TODO: asterisk
# was killed? status should check for wrapper
# "safe mode"
if status > / dev / null; then
echo " $ DESC is already running. Use restart."
exit 0
fi
start-stop-daemon - start - group $ GROUP - pidfile " $ PIDFILE " \
$ CHDIR_PARM \
--exec $ REALDAEMON - $ PARAMS
else
start-stop-daemon - start - group $ GROUP \
--background --make-pidfile \
$ CHDIR_PARM --pidfile " $ ASTSAFE_PIDFILE " \
--exec $ REALDAEMON - $ PARAMS
fi


echo " $ NAME ."
;;
stop )
echo -n "Stopping $ DESC : $ NAME "
# Try gracefully.
# this may hang in some cases. Specifically, when the asterisk
# processes is stopped. No bother to worry about cleanup:
asterisk dies.
( asterisk_rx 'stop now' > / dev / null 2 > & 1 & ) &
if [ " $ RUNASTSAFE " = "yes" ] ; then
start-stop-daemon --stop --quiet --oknodo \
--pidfile $ ASTSAFE_PIDFILE
rm -f $ ASTSAFE_PIDFILE
fi
# just making sure it's really really dead.
# KILL is asterisk -r in the background
start-stop-daemon --stop --quiet --oknodo --retry = 0/2 / TERM / 2 / KILL / 5 --exec $ DAEMON
echo "."
;;
reload )
echo "Reloading $ DESC configuration files."
asterisk_rx 'module reload'
;;
logger-reload )
asterisk_rx 'logger reload'
;;
extensions-reload | dialplan-reload )
echo "Reloading $ DESC configuration files."
asterisk_rx 'dialplan reload'
;;
restart-convenient )
asterisk_rx 'restart when convenient'
;;
restart | force-reload )
$ 0 stop
$ 0 start
;;
status )
status
exit $?
;;
zaptel-fix )
echo "Unloading and reloading loading Asterisk and Zaptel:"
$ 0 stop
/ etc / init.d / zaptel unload
# load modules from / etc / modules. This will break if you count on
# discover / hotplug
/ etc / init.d / module-init-tools
/ etc / init.d / zaptel start
$ 0 start
;;
* )
N = / etc / init.d / $ NAME
echo "Usage: $ N {start | stop | restart | reload | status | debug | logger-reload | extensions-reload | restart-convenient | force-reload}" > & 2
exit 1
;;
esac

exit 0


We give him the right rights
chmod 755 /etc/init.d/asterisk

We start at the start:
update-rc.d asterisk defaults 90 10

We reload the container to make sure that everything starts by itself:
sudo vzctl restart 101

Make sure that everything works by connecting to a VoIP client:
192.168.xxx.xxx
: 200
: 123


Making a test call, for example, to number 500

We are happy.

Source: https://habr.com/ru/post/107571/


All Articles