Asterisk realtime centos 7
yum install epel-release
Install dependencies
yum install unixODBC-devel
yum install unixODBC
yum install python-devel
yum install python-pip
yum install MySQL-python
yum install mysql-connector-odbc
yum install unixODBC unixODBC-devel libtool-ltdl libtool-ltdl-devel
Install LAMP
https://hostadvice.com/how-to/how-to-install-lamp-stack-on-centos-7/
Install Asterisk
sed -i 's/\(^SELINUX=\).*/\SELINUX=disabled/' /etc/sysconfig/selinux
sed -i 's/\(^SELINUX=\).*/\SELINUX=disabled/' /etc/selinux/config
reboot
MAKE SURE SELINUX IS DISABLED running the next command
sestatus
sed -i 's/\(^SELINUX=\).*/\SELINUX=disabled/' /etc/sysconfig/selinux
sed -i 's/\(^SELINUX=\).*/\SELINUX=disabled/' /etc/selinux/config
reboot
MAKE SURE SELINUX IS DISABLED running the next command
sestatus
yum -y update
yum -y groupinstall core base "Development Tools"
yum install -y make wget openssl-devel ncurses-devel newt-devel libxml2-devel kernel-devel gcc gcc-c++ sqlite-devel
cd /usr/src/
wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-16-current.tar.gz
tar zxvf asterisk*
cd /usr/src/asterisk*
contrib/scripts/install_prereq install
./configure --libdir=/usr/lib64 --with-pjproject-bundled --with-jansson-bundled && make menuselect && make && make install
make samples
make config
ldconfig
service asterisk start
asterisk -rvvvvvvvvvvvvv
Install Realtime
Install Realtime
Create the DB
# mysqladmin -u root -p 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
/etc/odbc.ini | |
[asterisk-mysql] | |
Description = MySQL connection to 'asterisk' database | |
Driver = MySQL | |
Database = asterisk | |
Server = localhost | |
UserName = root | |
Password = 7891 | |
Port = 3306 | |
Socket = /var/lib/mysql/mysql.sock | |
/etc/odbcinst.ini | |
# Example driver definitions | |
# Driver from the postgresql-odbc package | |
# Setup from the unixODBC package | |
[PostgreSQL] | |
Description = ODBC for PostgreSQL | |
Driver = /usr/lib/psqlodbc.so | |
Setup = /usr/lib/libodbcpsqlS.so | |
Driver64 = /usr/lib64/psqlodbc.so | |
Setup64 = /usr/lib64/libodbcpsqlS.so | |
FileUsage = 1 | |
# Driver from the mysql-connector-odbc package | |
# Setup from the unixODBC package | |
[MySQL] | |
Description = ODBC for MySQL | |
Driver = /usr/lib/libmyodbc5.so | |
Setup = /usr/lib/libodbcmyS.so | |
Driver64 = /usr/lib64/libmyodbc5.so | |
Setup64 = /usr/lib64/libodbcmyS.so | |
FileUsage = 1 | |
/etc/asterisk/res_odbc.conf | |
[asterisk-mysql] | |
enabled => yes | |
dsn => asterisk-mysql | |
username => root | |
password => 7891 | |
pre-connect => yes | |
/etc/asterisk/cdr_adaptive_odbc.conf | |
[asterisk-mysql] | |
connection=asterisk-mysql | |
table=cdr | |
alias start => calldate | |
---------------------------- | |
Load on asterisk | |
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 Connecting PJSIP Sorcery to the Realtime Database
nano /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 Realtime Configuration
/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
insert into ps_aors (id, max_contacts) values (103, 1); insert into ps_auths (id, auth_type, password, username) values (103, 'userpass', 103, 103); insert into ps_endpoints (id, transport, aors, auth, context, disallow, allow, direct_media) values (103, 'transport-udp', '103', '103', 'testing', 'all', 'g722', 'no'); |
https://gist.github.com/ambiorixg12/79805c7d25c7ca7d6a1cc0c009002b6d
https://gist.github.com/ambiorixg12/0811ced4784d8a7e13c0567b940da993
https://wiki.asterisk.org/wiki/display/AST/Setting+up+PJSIP+Realtime
----------------------------php code----
php /home/ambiorix/insert_device.php 2222
<?php
$link = mysqli_connect("localhost", "root", "mypass", "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);
?>
No hay comentarios:
Publicar un comentario