Установка Asterisk (перевод)

Материал из darklurker wiki
Перейти к: навигация, поиск

Подготовка системы

Отключим SELinux (если не понимаете что это такое)

sed -i s/SELINUX=enforcing/SELINUX=disabled/g /etc/selinux/config

Установим зависимости:

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install -y kernel-devel kernel-headers
yum install -y e2fsprogs-devel  keyutils-libs-devel krb5-devel libogg \
libselinux-devel libsepol-devel libxml2-devel libtiff-devel gmp php-pear \
php php-gd php-mysql php-pdo php-mbstring ncurses-devel \
mysql-connector-odbc unixODBC unixODBC-devel \
audiofile-devel libogg-devel openssl-devel zlib-devel  \
perl-DateManip sox git wget net-tools psmisc
yum install -y gcc gcc-c++ make gnutls-devel \
libxml2-devel ncurses-devel subversion doxygen \
texinfo curl-devel net-snmp-devel neon-devel  \
uuid-devel libuuid-devel sqlite-devel sqlite \
speex-devel gsm-devel libtool libtool-ltdl libtool-ltdl-devel \
libsrtp libsrtp-devel xmlstarlet

Обновим систему:

yum update -y

Перезагрузимся:

reboot now

Если не установлена MariaDB, то устанавливаем:

yum -y install mariadb-server mariadb mariadb-devel

Запустим MariaBD и добавим в автозапуск:

systemctl start mariadb.service
systemctl enable mariadb.service

Если это первая установка, то запустим первое конфигурирование MariaDB:

mysql_secure_installation

Установка Asterisk

cd /usr/src
wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-15-current.tar.gz
tar zxvf asterisk-15-current.tar.gz
cd asterisk*
contrib/scripts/get_mp3_source.sh
contrib/scripts/install_prereq install
./configure --with-pjproject-bundled --with-crypto --with-ssl=ssl --with-srtp
make menuselect

Выбираем опции которые нам необходимы

addons
codec
chan_drivers

Устанавливаем:

make && make install && make config && ldconfig

После установки добавим необходимый набор конфигураций

make basic-pbx

Запускаем asterisk от того же пользователя:

sed -i 's/ASTARGS=""/ASTARGS="-U asterisk"/g'  /usr/sbin/safe_asterisk

Создаем пользователя Asterisk и меняем владельца:

useradd -m asterisk &&
chown asterisk.asterisk /var/run/asterisk &&
chown -R asterisk.asterisk /etc/asterisk &&
chown -R asterisk.asterisk /var/{lib,log,spool}/asterisk &&
chown -R asterisk.asterisk /usr/lib/asterisk

Теперь проверим asterisk:

systemctl start asterisk
ps aux | grep asterisk
root       872  0.0  0.0 115300   780 ?        S    12:12   0:00 /bin/sh /usr/sbin/safe_asterisk
asterisk   881  2.4  0.9 1314384 36532 ?       Sl   12:12   0:01 /usr/sbin/asterisk -f -U asterisk -vvvg -c

Если видим:

Unable to connect to remote asterisk (does /var/run/asterisk/asterisk.ctl exist?)

Перезапускаем сервер и:

asterisk -vvvr

Настроим ODBC

  yum install -y mysql-connector-odbc unixODBC unixODBC-devel

Создадим базу данных и дадим все привилегии пользователю:

mysqladmin -p create asteriskcdrdb
mysql -p -e "GRANT ALL PRIVILEGES ON asteriskcdrdb.* to CDR_DB_USER@localhost identified by 'CDR_DB_PASSWORD';"
mysql -p -e "FLUSH PRIVILEGES;"

Файл:Asteriskcdrdb cdr schema.txt


Создадим realtimedb

mysqladmin -p create realtimedb
mysql -p -e "GRANT ALL PRIVILEGES ON realtimedb.* to RT_DB_USER@localhost identified by 'RT_DB_PASSWORD';"
mysql -p -e "FLUSH PRIVILEGES;"

Файл:Realtimedb SQL schema.txt

Вставляем содержимое в файл odbc.ini (если его нет, создаем)

cat >> /etc/odbc.ini << EOF
[MySQL-asteriskcdrdb]
Description=MySQL connection to 'asteriskcdrdb' database
driver=MySQL
server=localhost
database=asteriskcdrdb
Port=3306
Socket=/var/lib/mysql/mysql.sock
option=3
 
EOF

И

cat >> /etc/odbc.ini << EOF
[MySQL-realtimedb]
Description=MySQL connection to 'realtimedb' database
driver=MySQL
server=localhost
database=realtimedb
Port=3306
Socket=/var/lib/mysql/mysql.sock
option=3
 
EOF

Правильное расположение файла mysql.sock

mysql -e -p "show variables like 'socket';"
+---------------+---------------------------+
| Variable_name | VALUE                     |
+---------------+---------------------------+
| socket        | /var/lib/mysql/mysql.sock |
+---------------+---------------------------+

Asterisk Realtime Configuration Файл:Aster realtime cfg.txt

Перезагрузим Asterisk

asterisk -rx 'core restart now'

Создадим конфиг res_odbc

touch /etc/asterisk/res_odbc.conf &&
chown asterisk. /etc/asterisk/res_odbc.conf
cat >> /etc/asterisk/res_odbc.conf << EOF
[realtimedb]
enabled => yes
dsn => MySQL-realtimedb
username => RT_DB_USER
password => RT_DB_PASSWORD
pre-connect => yes
 
[asteriskcdrdb]
enabled => yes
dsn => MySQL-asteriskcdrdb
username => CDR_DB_USER
password => CDR_DB_PASSWORD
pre-connect => yes
 
EOF

Проверим коннект ODBC

asterisk -rx 'odbc show'

Если все ок, то:

ODBC DSN Settings
-----------------
 
 Name:   realtimedb
 DSN:    MySQL-realtimedb
   Number of active connections: 1 (out of 1)

 Name:   asteriskcdrdb
 DSN:    MySQL-asteriskcdrdb
   Number of active connections: 1 (out of 1)

Создадим /etc/asterisk/sorcery.conf

touch /etc/asterisk/sorcery.conf &&
chown asterisk. /etc/asterisk/sorcery.conf
cat >> /etc/asterisk/sorcery.conf << EOF
[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
 
EOF

Создадим /etc/asterisk/extconfig.conf

touch /etc/asterisk/extconfig.conf &&
chown asterisk. /etc/asterisk/extconfig.conf
cat >> /etc/asterisk/extconfig.conf << EOF
[settings]
sipusers => odbc,realtimedb,sippeers
sippeers => odbc,realtimedb,sippeers
 
dp_internal => odbc,realtimedb,dp_internal
dp_external => odbc,realtimedb,dp_external
dp_agents  => odbc,realtimedb,dp_agents
 
confbridge_static.conf => odbc,realtimedb,confbridge_ast_config
followme_static.conf => odbc,realtimedb,follow_ast_config
features_static.conf => odbc,realtimedb,feat_ast_config
 
ps_endpoints => odbc,realtimedb
ps_auths => odbc,realtimedb
ps_aors => odbc,realtimedb
ps_domain_aliases => odbc,realtimedb
ps_endpoint_id_ips => odbc,realtimedb
ps_contacts => odbc,realtimedb
 
queues => odbc,realtimedb
queue_members => odbc,realtimedb
queue_rules => odbc,realtimedb
 
EOF

Отредактируем /etc/asterisk/extensions.conf

cat >> /etc/asterisk/extensions.conf << EOF
[general]
static=yes
 
#include extensions_rt.conf
 
EOF

Создадим /etc/asterisk/extensions_rt.conf

touch /etc/asterisk/extensions_rt.conf &&
chown asterisk. /etc/asterisk/extensions_rt.conf
cat >> /etc/asterisk/extensions_rt.conf << EOF
[from-internal]
switch => Realtime/internal@dp_internal
 
[from-external]
switch => Realtime/external@dp_external
 
[from-agents] 
switch => Realtime/agents@dp_agents
 
EOF

Создадим /etc/asterisk/sip.conf

touch /etc/asterisk/sip.conf &&
chown asterisk. /etc/asterisk/sip.conf
cat >> /etc/asterisk/sip.conf << EOF
[general]
udpbindaddr = 0.0.0.0:5060
localnet=LOCAL NETWORK/MASK
transport => udp
externaddr => EXTERN IP ADDR
nat => force_rport,comedia
srvlookup => yes
directmedia => nonat
prematuremedia => no
allowguest => no
alwaysauthreject = no
useragent => Aster15Realtime
sdpsession => Aster15Realtime
disallow => all
allow => alaw
allow = ulaw
allow => opus
 
regextenonqualify=yes
 
rtptimeout => 30
rtpholdtimeout => 300
rtpkeepalive => 5
 
ignoreregexpire = yes
 
rtcachefriends => yes
rtupdate => yes
rtautoclear => no
rtsavesysname = no
EOF

Таким образом, вы получили Asterisk с поддержкой в реальном времени и статических хранилищ в MySQL.