~sergio

ARTIGOS

Instalación de Asterisk 18 en Debian 11 ou Debian 10

11-07-2022

Escollemos compilalo xa que a versión do Asterisk que ten Debian no repo do Debian é a 16.

Paso 1: Actualizar o sistema

apt update
apt full-upgrade -y
reboot -f
            

Paso 2: Instalar dependencias

Xa que se vai compilar o Asterisk fai falta instalar as dependencias para poder facelo:

apt -y install build-essential git curl wget \
    libnewt-dev libssl-dev libncurses5-dev subversion \
    libsqlite3-dev libjansson-dev libxml2-dev |
    uuid-dev default-libmysqlclient-dev
            

Verificar que exiten GCC e CMAKE no sistema:

make --version
GNU Make 4.3
[...]

gcc --version
gcc (GCC) 12.1.0
[...]
            

Paso 3: Baixar o tarball do Asterisk 18 LTS

cd /usr/src/
curl -O http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-18-current.tar.gz
            

Descomprimilo:

tar xvf asterisk-18-current.tar.gz
cd asterisk-18*/
            

Baixar a biblioteca de decodificación mp3 ó directorio de código:

./contrib/scripts/get_mp3_source.sh
A    addons/mp3
A    addons/mp3/MPGLIB_README
A    addons/mp3/common.c
A    addons/mp3/huffman.h
A    addons/mp3/tabinit.c
A    addons/mp3/Makefile
A    addons/mp3/README
A    addons/mp3/decode_i386.c
A    addons/mp3/dct64_i386.c
A    addons/mp3/MPGLIB_TODO
A    addons/mp3/mpg123.h
A    addons/mp3/layer3.c
A    addons/mp3/mpglib.h
A    addons/mp3/decode_ntom.c
A    addons/mp3/interface.c
Exported revision 202.
            

Confirmar que están instaladas todas as dependencias executando o script *install_prereq*:

./contrib/scripts/install_prereq install
            

Este é o mensaxe de salida de si está todo correcto:

[...]
Setting up odbcinst (2.3.6-0.1+b1) ...
Setting up odbcinst1debian2:amd64 (2.3.6-0.1+b1) ...
Setting up unixodbc-dev:amd64 (2.3.6-0.1+b1) ...
Processing triggers for initramfs-tools (0.140) ...
update-initramfs: Generating /boot/initrd.img-5.10.0-8-amd64
Processing triggers for libglib2.0-0:amd64 (2.66.8-1) ...
No schema files found: doing nothing.
Processing triggers for libc-bin (2.31-13) ...
Processing triggers for man-db (2.9.4-2) ...
Setting up libgmime-3.0-dev:amd64 (3.2.7-1) ...

#############################################
## install completed successfully
#############################################
            

Paso 4: Compilar e instalar Asterisk 18 en Debian 11 / Debian 10

Despóis de instalar tódalas dependencias xa se pode iniciar a compilación e instalación.

Executa o script *configure* para satisfacer as dependencias de compilación:

./configure
[...]
configure: creating ./config.status
config.status: creating makeopts
config.status: creating autoconfig.h
configure: Menuselect build configuration successfully completed

               .$$$$$$$$$$$$$$$=..
            .$7$7..          .7$$7:.
          .$$:.                 ,$7.7
        .$7.     7$$$$           .$$77
     ..$$.       $$$$$            .$$$7
    ..7$   .?.   $$$$$   .?.       7$$$.
   $.$.   .$$$7. $$$$7 .7$$$.      .$$$.
 .777.   .$$$$$$77$$$77$$$$$7.      $$$,
 $$$~      .7$$$$$$$$$$$$$7.       .$$$.
.$$7          .7$$$$$$$7:          ?$$$.
$$$          ?7$$$$$$$$$$I        .$$$7
$$$       .7$$$$$$$$$$$$$$$$      :$$$.
$$$       $$$$$$7$$$$$$$$$$$$    .$$$.
$$$        $$$   7$$$7  .$$$    .$$$.
$$$$             $$$$7         .$$$.
7$$$7            7$$$$        7$$$
 $$$$$                        $$$
  $$$$7.                       $$  (TM)
   $$$$$$$.           .7$$$$$$  $$
     $$$$$$$$$$$$7$$$$$$$$$.$$$$$$
       $$$$$$$$$$$$$$$$.

configure: Package configured for:
configure: OS type  : linux-gnu
configure: Host CPU : x86_64
configure: build-cpu:vendor:os: x86_64 : pc : linux-gnu :
configure: host-cpu:vendor:os: x86_64 : pc : linux-gnu :
            

Personaliza a instalación do Asterisk usando o menú de opciós:

make menuselect
            

Usando as flechas do teclado para navegar polos menus e a tecla *Enter* para aceptar a selección.

Por exemplo: selecciona *Add-ons* e baixando ata *format_mp3* acepta para dar soporte as locuciós en mp3.

Activa ou desactiva os módulos que necesites, coa configuración por defecto funcionará perfectamente.

Garda e sal para actualizar a configuración.

Para compilar o Asterisk 18 LTS no Debian 11 ou Debian 10 executa:

make
            

O proceso de compilación debería rematar en breves, depende da potencia da máquina:

[...]
   [LD] res_pjsip_publish_asterisk.o -> res_pjsip_publish_asterisk.so
   [CC] res_calendar_exchange.c -> res_calendar_exchange.o
   [LD] res_calendar_exchange.o -> res_calendar_exchange.so
   [CC] res_pjsip_registrar.c -> res_pjsip_registrar.o
   [LD] res_pjsip_registrar.o -> res_pjsip_registrar.so
Building Documentation For: third-party channels pbx apps codecs formats cdr cel bridges funcs tests main res addons
 +--------- Asterisk Build Complete ---------+
 + Asterisk has successfully been built, and +
 + can be installed by running:              +
 +                                           +
 +                make install               +
 +-------------------------------------------+
            

O último paso é instalar o Asterisk executando o comando _make install_:

make install
            

Paso 5: Configurar o Asterisk 18 LTS despóis da instalación

Despóis de instalar o Asterisk, podes instalar a documentación:

make progdocs
            

Instala as configuraciós por defecto e os exemplos:

make samples
make config
ldconfig
            

Instala o códec g729:

wget http://asterisk.hosting.lv/bin/codec_g729-ast180-gcc4-glibc-x86_64-core2.so
mv codec_g729-ast180-gcc4-glibc-x86_64-core2.so /usr/lib/asterisk/modules/codec_g729.so
            

Máis adiante, unha vez arranque o asterisk podes comprobar si está ben instalado co comando:

asterisk -rx "core show translation recalc 10"
            

Instala as locuciós en español:

wget https://www.sinologic.net/proyectos/voces/asterisk-es_ES-alaw.tar.gz
wget https://www.sinologic.net/proyectos/voces/asterisk-es_ES-ulaw.tar.gz
wget https://www.sinologic.net/proyectos/voces/asterisk-es_ES-g729.tar.gz
wget https://www.sinologic.net/proyectos/voces/asterisk-es_ES-gsm.tar.gz
ls asterisk-es_ES-*.tar.gz | xargs -n1 tar -C / -xvzf
            
Crea o usuario Asterisk

Crea un usuario e grupo aparte para executar os servicios asterisk e asigna os permisos correctos:

groupadd asterisk
useradd -r -d /var/lib/asterisk -g asterisk asterisk
usermod -aG audio,dialout asterisk
chown -R asterisk.asterisk /etc/asterisk
chown -R asterisk.asterisk /var/{lib,log,spool}/asterisk
chown -R asterisk.asterisk /usr/lib/asterisk
            

Confirma o id do usuario asterisk:

id asterisk
uid=997(asterisk) gid=1001(asterisk) groups=1001(asterisk),20(dialout),29(audio)
            

Establece o usuario e grupo co que vai executarse o servicio asterisk:

vim /etc/default/asterisk
AST_USER="asterisk"
AST_GROUP="asterisk"
            

O arquivo de configuración por defecto que usa o asterisk é */etc/asterisk/asterisk.conf*.

Podes abrilo e ver si fai falta aplicar algún cambio.

vim /etc/asterisk/asterisk.conf
runuser = asterisk              ; The user to run as.
rungroup = asterisk             ; The group to run as.
            

Reinicia o servicio asterisk despóis de facer os cambios:

/etc/init.d/asterisk restart
            

ou

systemctl restart asterisk
            

Ahora podes conectar ó CLI do Asterisk para comprobar que se está executando:

asterisk -rvv
Asterisk 18.11.1, Copyright (C) 1999 - 2021, Sangoma Technologies Corporation and others.
Created by Mark Spencer 
[...]
Connected to Asterisk 18.11.1 currently running on debian-bullseye-01 (pid = 48369)
debian-bullseye-01*CLI>
            

Executa algún comando de asterisk para comprobar a funcionalidade:

debian-bullseye-01*CLI> core show  uptime
System uptime: 16 minutes, 29 seconds
Last reload: 16 minutes, 29 seconds

debian-bullseye-01*CLI> core show  sysinfo

System Statistics
-----------------
  System Uptime:             18 hours
  Total RAM:                 2030244 KiB
  Free RAM:                  160672 KiB
  Buffer RAM:                58964 KiB
  Total Swap Space:          0 KiB
  Free Swap Space:           0 KiB

  Number of Processes:       172

debian-bullseye-01*CLI> exit
Asterisk cleanly ending (0).
Executing last minute cleanups
            

Ahora tes instalado e configurado o Asterisk 18 LTS en unha máquina con Debian 11 ou Debian 10.

Podes consultar a documentación oficial, moito máis detallada, na Páxina oficial.