Soporte & Consultoria

Soporte Remoto y Consultoria skype : ambiorixg12.
Nota no se brinda ningun tipo de consulta o soporte fuera del blog de forma gratuita

domingo, 18 de junio de 2023

Asterisk Rocky Linux 9 Realtime

 1- Update system

 dnf  update


2- Insall epel repo


dnf install epel-release


3-  Install unixODBC-devl


dnf --enablerepo=crb install unixODBC-devel


dnf  install unixODBC


4- Install Python devel


dnf install python-devel


5 Install Python pip


dnf install python-pip


6- Install Python-Mysql and  mysql-connector-odbc


dnf --enablerepo=epel-testing install python3-mysqlclient



7- Install  this packages

dnf  install unixODBC unixODBC-devel libtool-ltdl libtool-ltdl-devel


if     libtool-ltdl-devel  doesnt  get install run this



dnf --enablerepo=resilientstorage install libtool-ltdl-devel





8 Install core development packages


dnf groupinstall -y --allowerasing core base "Development Tools"


9 Install these  dev packages


dnf install -y make wget openssl-devel ncurses-devel newt-devel libxml2-devel kernel-devel gcc gcc-c++ sqlite-devel


dnf install -y initscripts svn chkconfig


10 Install Asterisk

cd /usr/src/


  1.  wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-20-current.tar.gz


  1. tar zxvf asterisk*


  1. rm *.gz


  1. cd asterisk-20*


  1.  contrib/scripts/install_prereq install


  1. ./configure --libdir=/usr/lib64 --with-pjproject-bundled --with-jansson-bundled && make menuselect && make && make install

  2.    make samples

  3.    make config

  4.    ldconfig

  5.     /etc/init.d/asterisk start

  6.    asterisk -rvvvvvvvv



11)  Create a MySQL password  and Asterisk realtime DB

sudo dnf install mariadb-server


sudo systemctl start mariadb


sudo systemctl status mariadb


sudo systemctl enable mariadb


mysqladmin -u root -p password 'asterisk'




  1. mysqladmin -u root password 'asterisk'



  1. mysqladmin -u root -pasterisk create asterisk




First, install Alembic:
# pip install alembic
Then, move to the Asterisk source directory containing the Alembic scripts:
# cd contrib/ast-db-manage/
Next, edit the config.ini.sample file and change the sqlalchemy.url option, e.g.
sqlalchemy.url = mysql://root:password@localhost/asterisk
such that the URL matches the username and password required to access your database.
Then rename the config.ini.sample file to config.ini
# cp config.ini.sample config.ini
Finally, use Alembic to setup the database tables:
# alembic -c config.ini upgrade head
You'll see something similar to:
# alembic -c config.ini upgrade head
INFO  [alembic.migration] Context impl MySQLImpl.
INFO  [alembic.migration] Will assume non-transactional DDL.
INFO  [alembic.migration] Running upgrade None -> 4da0c5f79a9c, Create tables
INFO  [alembic.migration] Running upgrade 4da0c5f79a9c -> 43956d550a44, Add tables for pjsip
#
You can then connect to MySQL to see that the tables were created:
# mysql -u root -p -D asterisk

mysql> show tables;
+--------------------+
| Tables_in_asterisk |
+--------------------+
| alembic_version    |
| iaxfriends         |
| meetme             |
| musiconhold        |
| ps_aors            |
| ps_auths           |
| ps_contacts        |
| ps_domain_aliases  |
| ps_endpoint_id_ips |
| ps_endpoints       |
| sippeers           |
| voicemail          |
+--------------------+
12 rows in set (0.00 sec)
mysql> quit


12) Install  alembic


 pip install alembic

 

 alembic --version





13) Install connector


  dnf install mariadb-connector-c


    dnf install mariadb-connector-odbc



14 ) Install PHP


dnf install php


dnf install php-mysqlnd




Configuration files.

/etc/odbc.ini

[asterisk]
Description           = MySQL connection to 'asterisk' database
Driver                = MariaDB
Database              = asterisk
Server                = localhost
UserName              = root
Password              = asterisk
Port                  = 3306
Socket                = /var/lib/mysql/mysql.sock


/etc/odbcinst.ini
# Driver from the mariadb-connector-odbc package
# Setup from the unixODBC package
[MariaDB]
Description     = ODBC for MariaDB
Driver          = /usr/lib/libmaodbc.so
Driver64        = /usr/lib64/libmaodbc.so
FileUsage = 1

/etc/asterisk/res_odbc.conf
[asterisk]
enabled => yes
dsn => asterisk
username => admin
password => asterisk
pre-connect => yes


/etc/asterisk/cdr_adaptive_odbc.conf

[asterisk]
connection=asterisk
table=cdr
alias start => calldate




module reload res_odbc.so

Check connection

asterisk_realtime*CLI> odbc show all

ODBC DSN Settings
-----------------

  Name:   asterisk
  DSN:    asterisk
    Number of active connections: 1 (out of 1)
    Logging: Disabled




/etc/asterisk/sorcery.conf
[res_pjsip] ; Realtime PJSIP configuration wizard
endpoint=realtime,ps_endpoints
auth=realtime,ps_auths
aor=realtime,ps_aors
domain_alias=realtime,ps_domain_aliases
contact=realtime,ps_contacts

[res_pjsip_endpoint_identifier_ip]
identify=realtime,ps_endpoint_id_ips

[res_pjsip_outbound_registration]
registration=realtime,ps_registrations




/etc/asterisk/extconfig.conf
ps_endpoints => odbc,asterisk
ps_auths => odbc,asterisk
ps_aors => odbc,asterisk
ps_domain_aliases => odbc,asterisk
ps_endpoint_id_ips => odbc,asterisk
ps_contacts => odbc,asterisk
ps_registrations = odbc,asterisk


etc/asterisk/modules.conf
preload => res_odbc.so
preload => res_config_odbc.so
noload => chan_sip.so 


/etc/asterisk/pjsip.conf
[transport-udp]
type=transport
protocol=udp
bind=0.0.0.0

RESTART the asterisk service after add the transport


core restart now



----------------------------php code----
php /home/ambiorix/insert_device.php 2222

<?php
$link = mysqli_connect("localhost", "root", "asterisk", "asterisk");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$sip_device ="$argv[1]";

$query1 = "INSERT INTO `ps_aors` (`id`, `max_contacts`) VALUES ($sip_device, 1)";
if (mysqli_query($link, $query1)) {
    printf("Query 1 executed successfully.\n");
} else {
    printf("Error executing query 1: %s\n", mysqli_error($link));
}

$query2 = "INSERT INTO `ps_auths` (`id`, `auth_type`, `password`, `username`) VALUES ($sip_device, 'userpass', $sip_device, $sip_device)";
if (mysqli_query($link, $query2)) {
    printf("Query 2 executed successfully.\n");
} else {
    printf("Error executing query 2: %s\n", mysqli_error($link));
}

$query3 = "INSERT INTO `ps_endpoints` (`id`, `transport`, `aors`, `auth`, `context`, `disallow`, `allow`, `direct_media`) 
VALUES ($sip_device, 'transport-udp', '$sip_device', '$sip_device', 'testing', 'all', 'g722', 'no')";
if (mysqli_query($link, $query3)) {
    printf("Query 3 executed successfully.\n");
} else {
    printf("Error executing query 3: %s\n", mysqli_error($link));
}

/* close connection */
mysqli_close($link);
?>


Source


https://centos.pkgs.org/9-stream/centos-crb-x86_64/unixODBC-devel-2.3.9-4.el9.x86_64.rpm.html


https://rockylinux.pkgs.org/8/rockylinux-appstream-x86_64/unixODBC-devel-2.3.7-1.el8.i686.rpm.html


https://rockylinux.pkgs.org/8/rockylinux-appstream-x86_64/libtool-ltdl-devel-2.4.6-25.el8.x86_64.rpm.html


https://centos.pkgs.org/9-stream/centos-resilientstorage-x86_64/libtool-ltdl-devel-2.4.6-44.el9.i686.rpm.html









https://rockylinux.pkgs.org/9/rockylinux-appstream-x86_64/compat-openssl11-1.1.1k-4.el9_0.i686.rpm.html


https://rockylinux.pkgs.org/9/rockylinux-appstream-aarch64/mariadb-connector-c-3.2.6-1.el9_0.aarch64.rpm.html



https://rockylinux.pkgs.org/9/rockylinux-appstream-aarch64/mariadb-connector-odbc-3.1.12-3.el9.aarch64.rpm.html