Installer un nouveau serveur SIP Asterisk
Oussama Hammami, 2010-05-12
Switzernet
0- Préparation de l’installation
0.1- Création d’utilisateur sona
0.3- modifier mot de passe root
2- Installation du serveur MySQL
3- Installation d’un contrôleur de démarrage pour Debian
4- Installation et Configuration exim4 (serveur de messagerie électronique):
8.1- Contrôle de l’ajout des codecs
8.2- Vérifier la création de la liste des clients
8.3- Vérifier le lancement des scripts perl
8.4- Vérification de la création de la base de données Asterisk
Utiliser la commande adduser sona pour crée un nouveau utilisateur :
ks34189:~# adduser sona
Adding user `sona' ...
Adding new group `sona' (1000) ...
Adding new user `sona' (1000) with group `sona' ...
Creating home directory `/home/sona' ...
Copying files from `/etc/skel' ...
Enter new UNIX password: password0
Retype new UNIX password: password0
passwd: password updated successfully
Changing the user information for sona
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] y
ks34189:~#
Pour des raisons de sécurité, on supprime l’accès SSH en root. Avant de le faire, s’assurer que le login sona fonctionne bien. Lancer un nouveau SSH sur le serveur en utilisant sona comme login. Une fois logué, passer en root avec la commande su -. Si ça fonctionne, continuer. Sinon, il faudra chercher le problème (la prochaine étape nous couperait l’accès au serveur).
Editer le fichier /etc/ssh/sshd_config
ns300880# vi /etc/ssh/sshd_config
Remplacer :
#PermitRootLogin yes
Ou (dépend de la version de SSH / configuration initiale de l’hébergeur) :
PermitRootLogin yes
Par :
PermitRootLogin no
Redémarrer sshd :
ns300880# /etc/init.d/ssh restart
ns300880# exit
Après le redémarrage de sshd (/etc/rc.d/sshd restart) ou du serveur (reboot), on doit se loguer avec l’utilisateur sona, puis on passe en root avec la commande su -.
Le login en root ne doit plus fonctionner, mais tout de même demander un mot de passe qui sera refusé même si correct. Vérifier en essayant de se loguer par ssh avec l’utilisateur root.
Taper la commande passwd root a fin de modifier le mot de passe
ks34189:~# passwd root
Enter new UNIX password: password0
Retype new UNIX password: password0
passwd: password updated successfully
ks34189:~# hostname
ks34189.kimsufi.com
ks34189:~# hostname astrad3.switzernet.com
Ainsi, sur un système basé sur Debian, nous pouvons aussi éditer le fichier /etc/hostname et remplacez le nom du système, puis exécutez
ks34189:~# vi /etc/hostname
astrad3.switzernet.com
ks34189:~# /etc/init.d/hostname.sh
ks34189:~# hostname
astrad3.switzernet.com
Asterisk est un PCBX : un serveur de communications téléphoniques qui utilise le protocole SIP. Autrement dit : un serveur VOIP
Ce document décrit l’installation d’Asterisk et sa configuration et la mis en place des scripts qui assure la communication via RADIUS avec notre serveur de facturation PortaBilling.
La plate-forme que nous choisissons est Debian Linux 5.0, la version stable d'Asterisk dans Debian est pour le moment 1.4.21.2:
Astrad3:~# aptitude update
Astrad3:~# aptitude show asterisk
Package: asterisk
State: not installed
Version: 1:1.4.21.2~dfsg-3
Priority: optional
Section: comm.
Si la version utilisée n'est plus disponible par le gestionnaire d'aptitude, une copie de tous les paquets utilisés dans ce document se trouve dans ce dossier d'installation [091208].
On lance installation d’Asterisk
astrad:~# aptitude install asterisk
Le programme d'installation va créer le dossier de configuration d'Asterisk (/etc/asterisk) avec des fichiers de configuration par défaut. Pour démarrer à partir d'une configuration vierge, nous nous déplaçons tous ces fichiers dans un dossier séparé:
astrad# cd /etc/asterisk
astrad:/etc/asterisk# mkdir default-confs
astrad:/etc/asterisk# mv *.conf default-confs/
astrad:/etc/asterisk# mv asterisk.adsi extensions.ael manager.d telcordia-1.adsi default-confs/
astrad:/etc/asterisk# ls
default-confs
Le client RADIUS de PortaOne peut être trouvé sur la page suivante, avec la configuration et les instructions d'installation: http://www.voip-info.org/tiki-index.php?page=PortaOne+Radius+auth. Les prochaines étapes de ce document décrit les étapes que nous avons suivies
Tout d'abord, les dépendances Perl (modules) doit être installées. Ici, nous utilisons CPAN:
astrad:~# perl -MCPAN -e shell;
CPAN is the world-wide archive of perl resources. It consists of about
300 sites that all replicate the same contents around the globe. Many
countries have at least one CPAN site already. The resources found on
CPAN are easily accessible with the CPAN.pm module. If you want to use
CPAN.pm, lots of things have to be configured. Fortunately, most of
them can be determined automatically. If you prefer the automatic
configuration, answer 'yes' below.
If you prefer to enter a dialog instead, you can answer 'no' to this
question and I'll let you configure in small steps one thing after the
other. (Note: you can revisit this dialog anytime later by typing 'o
conf init' at the cpan prompt.)
Would you like me to configure as much as possible automatically? [yes] yes
. . .
cpan shell -- CPAN exploration and modules installation (v1.9205)
ReadLine support available (maybe install Bundle::CPAN or Bundle::CPANxxl?)
cpan[1]> install YAML
cpan[2]> install Config::IniFiles
cpan[3]> install Crypt::CBC
cpan[4]> install Crypt::DES
cpan[5]> install Authen::Radius # (leave all RADIUS config empty when prompted)
cpan[6]> install Crypt::Rijndael
cpan[7]> install Digest::MD5
cpan[8]> install Asterisk::Manager
cpan[9]> install Asterisk::AGI
cpan[10]> install List::Util
cpan[11]> install Sys::Syslog
cpan[12]> install Date::Manip
cpan[13]> exit
il faut aussi installer une autre dépendance manuellement car elle n’est pas encore disponible dans CPAN
astrad:~# cd /root/
astrad:~# mkdir astrad-src
astrad:~# cd astrad-src
astrad:~# wget http://asterisk.gnuinter.net/files/asterisk-perl-1.01.tar.gz
astrad:~# tar xzf asterisk-perl-1.01.tar.gz
astrad:~# cd asterisk-perl-1.01
astrad:~/asterisk-perl-1.01# perl Makefile.PL
Checking if your kit is complete...
Looks good
Writing Makefile for asterisk-perl
astrad:~/asterisk-perl-1.01# make all
cp lib/Asterisk/Manager.pm blib/lib/Asterisk/Manager.pm
cp lib/Asterisk/Voicemail.pm blib/lib/Asterisk/Voicemail.pm
cp lib/Asterisk/Outgoing.pm blib/lib/Asterisk/Outgoing.pm
cp lib/Asterisk/QCall.pm blib/lib/Asterisk/QCall.pm
cp lib/Asterisk.pm blib/lib/Asterisk.pm
cp lib/Asterisk/AGI.pm blib/lib/Asterisk/AGI.pm
Manifying blib/man3/Asterisk::Voicemail.3pm
Manifying blib/man3/Asterisk::Manager.3pm
Manifying blib/man3/Asterisk::Outgoing.3pm
Manifying blib/man3/Asterisk::AGI.3pm
astrad:~/asterisk-perl-1.01# make install
Installing /usr/local/share/perl/5.10.0/Asterisk.pm
Installing /usr/local/share/perl/5.10.0/Asterisk/Manager.pm
Installing /usr/local/share/perl/5.10.0/Asterisk/Voicemail.pm
Installing /usr/local/share/perl/5.10.0/Asterisk/Outgoing.pm
Installing /usr/local/share/perl/5.10.0/Asterisk/QCall.pm
Installing /usr/local/share/perl/5.10.0/Asterisk/AGI.pm
Installing /usr/local/man/man3/Asterisk::Voicemail.3pm
Installing /usr/local/man/man3/Asterisk::Manager.3pm
Installing /usr/local/man/man3/Asterisk::Outgoing.3pm
Installing /usr/local/man/man3/Asterisk::AGI.3pm
Writing /usr/local/lib/perl/5.10.0/auto/asterisk-perl/.packlist
Appending installation info to /usr/local/lib/perl/5.10.0/perllocal.pod
Nous installons aussi des dépendances supplémentaires et des services publics à l'aide d'aptitude:
astrad# aptitude install libdbi-perl
astrad# aptitude install libdbd-mysql-perl
astrad# aptitude install ntp
astrad# aptitude install ngrep
astrad# apt-get install mysql-server
|
Entrer le mot de passe de l'utilisateur MySQL root password1
|
Pour des raisons de sécurité, le paquet MySQL disponible dans Debian est installé pour ne pas écouter sur le réseau, le port 3306 est fermé.
Pour que MySQL écoute sur le réseau, il faut, dans le fichier /etc/mysql/my.cnf, supprimer (ou commenter) la ligne skip-networking puis redémarrer MySQL.
astrad# vi /etc/mysql/my.cnf
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address = 127.0.0.1 (commenter cette ligne en ajoutant #)
astrad# /etc/init.d/mysql restart
Utilisez la commande GRANT pour configurer le compte username2 avec le mot de passe de password2 :
astrad3:~/astrad-src/asterisk-perl-1.01# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 33
Server version: 5.0.51a-24+lenny3 (Debian)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>GRANT ALL ON *.* to 'username2'@'%' IDENTIFIED BY 'password2';
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
astrad3:~/astrad-src/asterisk-perl-1.01# /etc/init.d/mysql restart
Tester la connexion MySQL distante depuis un autre serveur
mysql -h astrad3.switzernet.com -uusername2 -ppassword2
astrad3:~/astrad-src/asterisk-perl-1.01# apt-get install rcconf
aptitude install exim4 exim4-config
dpkg-reconfigure exim4-config
- Sélectionner Internet site;…
- Taper ‘Hostname’ du serveur Asterisk
Envoyer un email à votre boite mail pour tester la configuration
astrad# echo "test" | mailx -s testBody your.name@switzernet.com
Pour configurer Asterisk en commence par créer un répertoire de travaille et télécharger notre modèle de configuration
astrad# mkdir /root/src-asterisk
astrad# cd /root/src-asterisk
astrad: /root/src-asterisk# wget http://switzernet.com/public/100518-src-asterisk-debian/asterisk.tar.gz
astrad: /root/src-asterisk# tar xzf asterisk.tar.gz
astrad: /root/src-asterisk# ls
100105-asterisk-list agi-bin asterisk asterisk.tar.gz crontab init.d install.sh myasterisk mysql
Insérer le mot de passe et le nom d’utilisateur http dans le fichier 100105-asterisk-list/Liste-Asterisk.pl
astrad: /root/src-asterisk# vi 100105-asterisk-list/Liste-Asterisk.pl
. . .
use Crypt::Rijndael;
$http_user="username";
$http_passwd="password";
sub md5sum{
my $file = shift;
my $di
. . .
Ajouter l’IP de serveur Asterisk dans le fichier de configuration asterisk/asterisk.conf
astrad: /root/src-asterisk# vi asterisk/asterisk.conf
. . .
[options]
systemname => your.ip.adress
;systemname => aaaasss
Éditer le fichier de configuration de connexion MySQL avec Billing asterisk/billing.conf
astrad: /root/src-asterisk# vi asterisk/billing.conf
;
; Billing Configuration
;
[general]
DB_NAME=porta-sip
DB_HOST=Master.ip.adress
DB_USER=username
DB_PASS=password
Éditer le fichier de configuration asterisk/extensions.conf
astrad: /root/src-asterisk# vi asterisk/extensions.conf
[globals]
RADIUS_Server=Master.ip.adress
RADIUS_Secret=password
RADIUS_Auth_Port=1812
RAIUS_Acct_Port=1813
Acct_Update_Timeout=60
NAS_IP_Address=your.ip.adress
. . .
Ajouter l’adresse IP de serveur Asterisk dans le fichier asterisk/manager.conf
astrad: /root/src-asterisk# vi asterisk/manager.conf
. . .
[general]
enabled = yes
port = 5038
bindaddr = 127.0.0.1,your.ip.adress
secret=test
Éditer le script perl init.d/clean-register.pl à fin d’ajouter les paramètres de connexion MySQL
astrad: /root/src-asterisk# vi init.d/clean-register.pl
. . .
my $dbh;
my $LOCAL_HOST="your.ip.adress";
my $DB_NAME="porta-sip";
my $DB_HOST="Master.ip.adress";
my $DB_USER="username";
my $DB_PASS="password";
. . .
Ajouter dans le script perl myasterisk/ast-resend-lost.pl les paramètres de connexion MySQL et RADIUS
astrad: /root/src-asterisk# vi myasterisk/ast-resend-lost.pl
. . .
sub mysql_connect {
my $DB_NAME="asterisk";
my $DB_HOST="localhost";
my $DB_USER="root";
my $DB_PASS="password";
. . .
sub send_packet {
my $id=shift;
my $request;
my $DB_NAME="asterisk";
my $DB_HOST="localhost";
my $DB_USER="root";
my $DB_PASS="password";
my $RADIUS_Server='Master.adress.ip';
my $RADIUS_Secret='password';
. . .
Création du répertoire du fichier sip.log
astrad: /root/src-asterisk# mkdir /var/sipenv-your.ip.adress
Lancer le fichier install.sh
astrad: /root/src-asterisk# chmod +x install.sh
astrad: /root/src-asterisk# ./install.sh
Taper le mot de passe root de MySQL déjà crée dans l’installation du serveur MySQL : password1
Sélectionner clean-register.pl et appuyer sur espace pour valider
Ajouter dans ce fichier /etc/rsyslog.conf
astrad:~# vi /etc/rsyslog.conf
...
#
# First some standard log files. Log by facility.
#
auth,authpriv.* /var/log/auth.log
*.*;auth,authpriv.none -/var/log/syslog
#cron.* /var/log/cron.log
daemon.* -/var/log/daemon.log
kern.* -/var/log/kern.log
lpr.* -/var/log/lpr.log
mail.* -/var/log/mail.log
user.* -/var/log/user.log
local0.* -/var/log/asterisk.log
...
astrad:~# /etc/init.d/rsyslog restart
astrad:~# aptitude install munin-node snmp snmpd
Édition des paramètres de configuration de client munin
astrad:~# vi /etc/munin/munin-node.conf
. . .
# A list of addresses that are allowed to connect. This must be a
# regular expression, due to brain damage in Net::Server, which
# doesn't understand CIDR-style network notation. You may repeat
# the allow line as many times as you'd like
allow ^127\.0\.0\.1$
allow ^213\.186\.60\.219$
# Which address to bind to;
host *
. . .
Édition des paramètres de configuration SNMP
astrad:~# vi /etc/snmp/snmpd.conf
. . .
# sec.name source community
com2sec readonly default astrad
#com2sec paranoid default public
#com2sec readonly default public
#com2sec readwrite default private
. . .
astrad:~# vi /etc/default/snmpd
. . .
# snmpd options (use syslog, close stdin/out/err).
SNMPDOPTS='-Lsd -Lf /dev/null -u snmp -I -smux -p /var/run/snmpd.pid'
#SNMPDOPTS='-Lsd -Lf /dev/null -u snmp -I -smux -p /var/run/snmpd.pid 127.0.0.1'
. . .
Pour valider les changements redémarrer le service SNMP et munin
astrad:~# /etc/init.d/munin-node restart
astrad:~# /etc/init.d/snmpd restart
En allant dans l’interface de commande (CLI) d’Asterisk, on peut voir les codecs installés.
astrad3:~/src-asterisk# asterisk -r
Asterisk 1.4.21.2~dfsg-3+lenny1, Copyright (C) 1999 - 2008 Digium, Inc. and others.
Created by Mark Spencer <markster@digium.com>
Asterisk comes with ABSOLUTELY NO WARRANTY; type 'core show warranty' for details.
This is free software, with components licensed under the GNU General Public
License version 2 and other licenses; you are welcome to redistribute it under
certain conditions. Type 'core show license' for details.
=========================================================================
This package has been modified for the Debian GNU/Linux distribution
Please report all bugs to http://bugs.debian.org/asterisk
=========================================================================
Connected to Asterisk 1.4.21.2~dfsg-3+lenny1 currently running on astrad3 (pid = 12758)
astrad3*CLI> show translation
Translation times between formats (in milliseconds) for one second of data
Source Format (Rows) Destination Format (Columns)
g723 gsm ulaw alaw g726aal2 adpcm slin lpc10 g729 speex ilbc g726 g722
g723 - 3 2 2 2 2 1 3 9 10 - 2 -
gsm 11 - 2 2 2 2 1 3 9 10 - 2 -
ulaw 11 3 - 1 2 2 1 3 9 10 - 2 -
alaw 11 3 1 - 2 2 1 3 9 10 - 2 -
g726aal2 11 3 2 2 - 2 1 3 9 10 - 1 -
adpcm 11 3 2 2 2 - 1 3 9 10 - 2 -
slin 10 2 1 1 1 1 - 2 8 9 - 1 -
lpc10 13 5 4 4 4 4 3 - 11 12 - 4 -
g729 12 4 3 3 3 3 2 4 - 11 - 3 -
speex 11 3 2 2 2 2 1 3 9 - - 2 -
ilbc - - - - - - - - - - - - -
g726 11 3 2 2 1 2 1 3 9 10 - - -
g722 - - - - - - - - - - - - -
The 'show translation' command is deprecated and will be removed in a future release. Please use 'core show translation' instead.
astrad3*CLI> quit
astrad3:~/src-asterisk#
Ces fichiers doivent être crée automatiquement après 5 minute du lancement de script install.sh
astrad3:~/src-asterisk# ls -l /etc/asterisk/
total 536
-rw-r----- 1 asterisk asterisk 311 May 20 20:15 asterisk.conf
-rw-r----- 1 asterisk asterisk 107 May 20 20:15 billing.conf
-rw-r--r-- 1 asterisk asterisk 90 May 20 20:15 cdr.conf
-rw-r--r-- 1 asterisk asterisk 734 May 20 20:15 cdr_custom.conf
-rw-r--r-- 1 asterisk asterisk 502 May 20 20:20 db-customer-ip.conf
-rw-r--r-- 1 asterisk asterisk 508 May 20 20:20 db-deny-node.conf
-rw-r--r-- 1 asterisk asterisk 488670 May 20 20:20 db-friends.conf
-rw-r--r-- 1 asterisk asterisk 1800 May 20 20:20 db-peers.conf
drwxr-xr-x 3 root root 4096 May 20 19:17 default-confs
-rw-r--r-- 1 asterisk asterisk 3691 May 20 20:15 extensions.conf
-rw-r--r-- 1 asterisk asterisk 61 May 20 20:15 logger.conf
-rw-r----- 1 asterisk asterisk 403 May 20 20:15 manager.conf
-rw-r----- 1 asterisk asterisk 2062 May 20 20:15 modules.conf
-rw-r----- 1 asterisk asterisk 642 May 20 20:15 sip.conf
On doit toujours voir ces 4 scripts qui tournent avec le processus d’Asterisk
astrad3:~/src-asterisk# ps aux | grep ast
asterisk 3750 6.0 3.6 539264 73336 ? Ssl 20:15 0:33 /usr/sbin/asterisk -p -U asterisk
asterisk 6414 0.0 0.5 54664 10212 ? S 20:20 0:00 /usr/bin/perl /root/myasterisk/ast-rad-acc.pl
asterisk 6418 0.0 0.4 51136 8180 ? S 20:20 0:00 /usr/bin/perl /root/myasterisk/ast-reg-switz.pl
asterisk 6422 0.1 0.8 73016 17444 ? S 20:20 0:00 /usr/bin/perl /root/myasterisk/ast-resend-lost.pl
root 6425 0.0 0.1 31248 3000 ? S 20:20 0:00 /usr/bin/perl /root/myasterisk/ast-ngrep.pl
root 6625 0.0 0.0 3876 616 pts/0 S+ 20:24 0:00 grep ast
Avec la commande show databases on doit voir la base de données asterisk
astrad3:~/src-asterisk# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 37
Server version: 5.0.51a-24+lenny3 (Debian)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| asterisk |
| mysql |
+--------------------+
3 rows in set (0.00 sec)
mysql> quit
Bye
Configurer votre téléphone IP avec hostname au lieu de sipX.youroute.net et vous pouvez faire un appel vers une destination payante votre Mobile par exemple.
Ensuite aller à https://www.intarnetinc.com/trace_call.html
Et normalement on doit voir que l’appel est correctement facturé.
http://switzernet.com/public/100518-src-asterisk-debian/
http://switzernet.com/public/100510-cacti-monitoring/
http://dev.mysql.com/doc/refman/5.0/fr/
http://www.commentcamarche.net/contents/mysql/mysqlimport.php3
http://doc.ubuntu-fr.org/services
http://plfnicolarius.free.fr/tutoriel_logiciel_linux_controler_le_demarrage_de_debian_et_ubuntu.php
http://dev.petitchevalroux.net/linux/configuration-exim4-avec-gmail-linux.19.html
http://switzernet.com/company/091208-asterisk-radius/
http://switzernet.com/company/100125-conf-astrad2/
http://switzernet.com/company/091229-asterisk-codecs/
http://switzernet.com/company/090324-portasip-ovh-clone/
http://switzernet.com/company/091229-asterisk-codecs/