Asterisk RPM Spec
This directory contains a SPEC and some other supporting files for building RPM packages for Asterisk. The process I follow is below followed by some notes on what customizations I've included.
Building the RPM
Start with a physical or virtual machine with adequate resources for Asterisk. I typically use 2 CPUs, 2GB RAM, 10G drive, and an Ethernet LAN interface. A second inteface exposed externally can also be added but I typically deploy behind a NAT'ing firewall and don't need it.
Install CentOS-7 Minimal, configure a static network, configure NTP, install VM tools if necessary, disable selinux, install SSH keys, apply any pending updates and reboot.
Next, we install some basics.
[root@pbx]# yum install -y deltarpm epel-release yum-cron firewalld [root@pbx]# yum install -y vim tcpdump bind-utils net-tools lsof bash-completion wget
Then install the necessary packaging tools.
[root@pbx]# yum install -y rpm-build redhat-rpm-config rpmdevtools yum-utils
Setup the build environment. We never build RPMs as root, right?
[root@pbx]# useradd build [root@pbx]# su - build [build@pbx]$ rpmdev-setuptree [build@pbx]$ wget -O rpmbuild/SPECS/asterisk.spec https://raw.githubusercontent.com/pdugas/rpms/master/asterisk/asterisk.spec [build@pbx]$ spectool -g -R rpmbuild/SPECS/asterisk.spec ... downloading sources ... [build@pbx]$ exit [root@pbx]#
Install the dependencies. You can run this while the sources are being downloaded.
[root@pbx]# yum-builddep -y ~build/rpmbuild/SPECS/asterisk.spec
Now build the RPMs:
[root@pbx]# su - build [build@pbx]$ rpmbuild -ba rpmbuild/SPECS/asterisk.spec ... get some coffee ... [build@pbx]$ exit
Install them. Not that this will make sure httpd and mariadb-server are installed as well since our setup depends on them.
[root@pbx]# yum localinstall ~build/rpmbuild/RPMS/x86_64/asterisk-13.7.2-*.rpm [root@pbx]# yum localinstall ~build/rpmbuild/RPMS/x86_64/asterisk-sounds-*.rpm
Enable and start Apache, and MariaDB.
[root@pbx]# systemctl enable httpd [root@pbx]# systemctl enable mariadb [root@pbx]# systemctl start httpd [root@pbx]# systemctl start mariadb
Create the database and schema. Change secret to something appropriate.
[root@pbx]# mysql MariaDB [(none)]> CREATE DATABASE asterisk; MariaDB [(none)]> CREATE USER 'asterisk'@'localhost' IDENTIFIED BY 'secret'; MariaDB [(none)]> GRANT ALL PRIVILEGES ON asterisk.* TO 'asterisk'@'localhost'; MariaDB [(none)]> FLUSH PRIVILEGES; MariaDB [(none)]> EXIT; [root@pbx]# mysql -u asterisk -p asterisk < /usr/share/doc/asterisk-*/asterisk-schema.sql Password: [root@pbx]#
Setup the ODBC connection to the database. Create
[asterisk] Driver=MySQL Database=asterisk Server=localhost port=3306 Socket=/var/lib/mysql/mysql.sock
Edit /etc/asterisk/res_odbc.conf and change the password setting in the [asterisk] section to whatever database password you used above in step 10.
Enable and start Asterisk.
[root@pbx]# systemctl enable asterisk [root@pbx]# systemctl start asterisk
Open up the firewall for Asterisk and Apache
[root@pbx]# firewall-cmd --zone=public --add-port=80/tcp --permanent [root@pbx]# firewall-cmd --zone=public --add-port=443/tcp --permanent [root@pbx]# firewall-cmd --zone=public --add-port=5060/udp --permanent [root@pbx]# firewall-cmd --zone=public --add-port=10000-20000/udp --permanent [root@pbx]# firewall-cmd --reload
Configure DHCP for the phones. See here.
Now you need to adjust the Asterisk configs in /etc/asterisk. Edit
pjsip_wizard.confto setup your SIP trunks and extensions users. Edit
voicemail.confto create voicemail boxes. Edit
extensions.confto adjust the dialplan. They all should be commented to explain the needed changes.
That should do it. Get to the console like so:
[root@pbx]# asterisk -rvvv Asterisk 13.7.2, Copyright (C) 1999 - 2014, Digium, Inc. and others. Created by Mark Spencer <email@example.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. ========================================================================= Connected to Asterisk 13.7.2 currently running on svr1 (pid = 13253) svr1*CLI>
- BuildRequires - We add a number of BuildRequires entres in the Spec File so almost all of the optional Asterisk modules and features are enabled. We don't enable Dahdi and other hardware support since we don't typically use it and don't want to add the extra kernel requirements where we use the resulting RPMs.
- Custom Sounds - We keep custom sounds separate from the stock sound files. Use the /var/lib/asterisk/sounds/custom/ directory for these.
- Sound Packages - We build asterisk-sounds-en-* packages for formats
that are enabled. ULAW and G722 are enabled by default. Call rpmbuild
with --define "ulaw 0" to disable ULAW. Replace ulaw with wav, alaw,
gsm, g722, g729, sln16, siren7, or siren14 for other formats.
Replace the 0 with 1 to enable them. i.e.
rpmbuild -ba asterisk.spec --define "wav 1"
- Polycom Phones - We use Polycom phones so we include the firmware and boot files in this package. We use phoneprov to provision them.
- Non-Root - We run Asterisk as the asterisk user rather than root and have made the necessary permissions adjustments on the folders where logs and data are stored.
- systemd Support - We include a service definition to start/stop Asterisk using systemd since this is the standard for Redhat these days.