Installing Asterisk and Skype on CentOS

Published on Saturday, 26 September 2009.

We want to setup a small business telephone system that uses our Skype account to make (SkypeOut) and receive (SkypeIn) calls. We wanted to keep the costs as low as possible but there will be some (what I consider to be minimal) upfront and/or ongoing charges by Skype and Digium. Costs will also be involved in providing a server to run all this on as well as any "hard phones" and "soft phones" you may want to use. We chose Polycom Soundpoint 330 phones and will give some instructions on how to make these work. There are a number of free "soft phones" out there but sometimes you get what you pay for.

As far as versions for install, here's a list:


CentOS Install

We could have installed the 32-bit version of CentOS but most servers are coming with 64-bit capable CPUs, so we will go this route. We downloaded the iso from the CentOS website and burned it to a DVD. Popped the DVD into our new servers and booted off the DVD.

After a period of time you will be prompted to either "install or upgrade in graphical mode" or "install or upgrade in text mode". We pressed ENTER to install in graphical mode.

You should then be notified that a CD has been found and will ask you if you want to test the CD. I trust my CD/DVD burner and the CentOS mirrors, so I always choose Skip.

You will then be given a CentOS welcome screen and we clicked on Next.

You are then given a language choice screen. We chose "English" then clicked Next.

You are then given a choice for a appropriate keyboard type, we chose "English" and the clicked on Next.

You are then asked to partition your hard drive. Depending on what operating system (if any) was already installed. We chose to remove all of the existing partitions and use the whole drive for the installation. We do not encrypt the system. We also do not select "Review and modify partitioning layout". We then clicked Next. We are then asked to confirm our choice, we clicked Yes.

Now you are prompted for some network settings. Hopefully, the installation will be able to find your ethernet network card(s). If so, select the appropriate ethernet card and click on Edit to change the current network settings.

You will then be prompted to Edit Interface settings. Enable IPv4 support and Disable IPv6 support. Change the IPv4 settings so that Manual Configuration is set as opposed to Dynamic IP configuration (DHCP). Enter the IP address you will be using for this server as well as the Netmask. The click OK.

You should now be back on the Network Devices screen. Under hostname, manually set your hostname to the hostname you will be using. We entered in asterisk.ardentsoft.com. Under Miscellaneous Settings, change your Gateway, Primary DNS and Secondary DNS to the appropriate settings. Then click Next.

You are then presented with a screen to select your timezone. Choose your timezone and click on Next.

You are then prompted for the password for your root account. Pick a complex but memorable password, confirm it, and click Next.

Now you are asked to select the software applications that will be installed. Make sure that only the no box is checked in the top selection area. Do NOT check the "Packages from CentOS Extras" in the additional repositories section. Select Customize Now and the click Next.

Now you are presented with a Software Picker screen. Uncheck all the software except Base and Text Based Internet and then click on Next.

You will then be prompted to begin installation of CentOS. Click on Next and then go get some coffee.

After some time and an ejected DVD, you should be prompted that your installation is complete. Remove the DVD from the holder (so it does not get sucked back in there on reboot) and click on Reboot.

After reboot, you should be greeted with a Setup Agent screen. Select Firewall Configuration. Under Firewall Configuration, set your Security Level to Disabled. Under SELinux, set it to Disabled. Click on OK. The click on Exit.

You should now be presented with a login prompt. Login as root and enter reboot. Once the system reboots, you should have a fairly pristine CentOS installation.

Optimizing CentOS

Optimizing is really the wrong word here. Our plans are to make memory and CPU consumption as lean as possible. We took a number of shortcuts in installing the various software packages here so there is definitely much that could be pared down as far as software installation. Now we won't pretend to be experts in optimizing a CentOS installation, but we will pull together a host of recommendations from others.

Chrooted DNS Server

yum -y install bind-chroot
chmod 755 /var/named/
chmod 775 /var/named/chroot/
chmod 775 /var/named/chroot/var/
chmod 775 /var/named/chroot/var/named/
chmod 775 /var/named/chroot/var/run/
chmod 777 /var/named/chroot/var/run/named/
cd /var/named/chroot/var/named/
ln -s ../../ chroot
cp /usr/share/doc/bind-*/sample/var/named/named.local /var/named/chroot/var/named/named.local
cp /usr/share/doc/bind-*/sample/var/named/named.root /var/named/chroot/var/named/named.root
touch /var/named/chroot/etc/named.conf
echo "options {" >> /etc/named.conf
echo " directory \"/var/named\";" >> /etc/named.conf
echo " dump-file \"/var/named/data/cache_dump.db\";" >> /etc/named.conf
echo " statistics-file \"/var/named/data/named_stats.txt\";" >> /etc/named.conf
echo "};" >> /etc/named.conf
echo "include \"/etc/rndc.key\";" >> /etc/named.conf
chkconfig --levels 235 named on
/etc/init.d/named start

Disable Unnecessary Services

To get a list of services that are started at boot time, do a:

chkconfig --list | grep 3:on

Name Resolution

Edit your /etc/resolv.conf file (of course using domain and local DNS settings for your network):

search ardentsoft.com
nameserver 10.0.1.1
nameserver 127.0.0.1

Edit your /etc/hosts file so that it looks like the following (of course using your IP address and hostnames where applicable):

# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1   localhost.localdomain localhost
10.0.1.227  asterisk.ardentsoft.com asterisk
::1     localhost6.localdomain6 localhost6

Disable Unnecessary Services

Now its time to disable what we don't need. On the web, we found the following recommendations and disabled them:
chkconfig anacron off
chkconfig atd off
chkconfig autofs off
chkconfig avahi-daemon off 
chkconfig bluetooth off
chkconfig cpuspeed off
chkconfig cups off
chkconfig gpm off
chkconfig hidd off
chkconfig irda off
chkconfig kudzu off
chkconfig netfs off
chkconfig nfslock off
chkconfig pcscd off
chkconfig portmap off
chkconfig rpcgssd off
chkconfig rpcidmapd off
chkconfig xfs off
chkconfig yum-updatesd off

Now let's update our system:

yum update
Lot's of things (at least 200Meg) will be updated and this will take a while. When the update finishes, reboot the system:
reboot

Now let's install some additional software:

yum install ntp php-mysql php-mbstring \
php-mcrypt phpmyadmin mysql-devel \
perl-Crypt-SSLeay lynx nmap speex \
speex-devel unixODBC-devel gnutls-devel \
libtool-ltdl-devel screen libX11-devel \
libtiff-devel php-pear php-pear-DB \
php-gd audiofile-devel  perl-DateManip \
sox wget bzip2 unzip zip nmap openssl \
lynx fileutils gcc gcc-c++ \
php php-devel php-gd php-imap php-ldap \
php-mysql php-odbc php-pear php-xml \
php-xmlrpc curl curl-devel perl-libwww-perl \
ImageMagick libxml2 libxml2-devel \
httpd-devel ruby ruby-devel apr-devel \
kernel-devel subversion libtermcap-devel bison \
mysql-server vsftpd sendmail-cf \
mod_auth_mysql

Make sure our clock is right and keeps right:

service ntpd start
chkconfig ntpd on

Installing Asterisk + FreePBX

cd /usr/src/
wget http://easynews.dl.sourceforge.net/sourceforge/lame/lame-3.98=2.tar.gz
tar -xvzf lame-* 
cd lame-*
./configure 
make
make install
cd /usr/src
wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-1.6.1-current.tar.gz
wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-addons-1.6.1-current.tar.gz
wget http://downloads.asterisk.org/pub/telephony/dahdi-linux-complete/dahdi-linux-complete-current.tar.gz
wget http://downloads.asterisk.org/pub/telephony/libpri/libpri-1.4-current.tar.gz
wget http://mirror.freepbx.org/freepbx-2.5.2.tar.gz
tar -zxf dahdi-*
tar -zxf asterisk-1.*
tar -zxf libpri-1.*
tar -zxf asterisk-addons-1.*
tar -xzf freepbx-*

For those of you needing a PRI card, let's compile libpri just for fun:

cd /usr/src/libpri-*
make clean
make
make install

Same thing for Dahdi, let's compile it in case it is used:

cd /usr/src/dahdi-linux-complete-*
make all
make install
make config

You will want to edit /etc/dahdi/modules, /etc/dahdi/system.conf and /etc/asterisk/chan_dahdi.conf for your site. In /etc/dahdi/modules, make sure and comment out any hardware not present in your machine. Then, set DAHDI to start automatically and then start it:

chkconfig dahdi on
service dahdi start

useradd -c "Asterisk PBX" -d /var/lib/asterisk asterisk
mkdir /var/run/asterisk
mkdir /var/log/asterisk
chown -R asterisk:asterisk /var/run/asterisk
chown -R asterisk:asterisk /var/log/asterisk
chown -R asterisk:asterisk /var/lib/php/session/

edit /etc/httpd/conf/httpd.conf. About line 231, change User and Group from apache to asterisk. And on line 327 change AllowOverride from None to All.

Now let's make asterisk:

cd /usr/src/asterisk-*
make clean
./configure
make
make install

cd /usr/src/freepbx-2.*
/etc/init.d/mysqld start
mysqladmin create asterisk
mysqladmin create asteriskcdrdb
mysql asterisk < SQL/newinstall.sql
mysql asteriskcdrdb < SQL/cdr_mysql_table.sql
mysql
GRANT ALL PRIVILEGES ON asteriskcdrdb.* TO asteriskuser@localhost IDENTIFIED BY 'SOMEPASSWORD';
GRANT ALL PRIVILEGES ON asterisk.* TO asteriskuser@localhost IDENTIFIED BY 'SOMEPASSWORD';
flush privileges;
\q
mysqladmin -u root password 'SOMEPASSWORD'

cd /usr/src/freepbx-2.5.2
./start_asterisk start
./install_amp --username=asteriskuser --password=SOMEPASSWORD
chkconfig httpd on
chkconfig mysqld on
echo "/usr/local/sbin/amportal start" >> /etc/rc.local
reboot

Because we don't use any DAHDI hardware, we added in the modules section (near bottom) of /etc/asterisk/modules.conf:

noload => codec_dahdi.so

Now let's compile some asterisk addons:

cd /usr/src/asterisk-addons-1.6.1*
make clean
./configure
make 
make install

edit /var/www/html/recordings/includes/main.conf.php. Set $ari_admin_password = "SOMEPASSWORD";

Edit /etc/mail/sendmail.mc

define(`SMART_HOST', `relay.DOMAIN.com)dnl
MASQUERADE_AS(`pbx.DOMAIN.com')dnl
FEATURE(`masquerade_envelope')dnl
cd /etc/mail
make -C /etc/mail

Edit /etc/asterisk/sip_nat.conf

localnet=192.168.1.0/255.255.255.0
externhost=pbx.DOMAIN.com (Set your external hostname name here)
externrefresh=10
fromdomain=DOMAIN.com (Set your external domain name here)
nat=yes
qualify=yes
canreinvite=no

Edit /etc/asterisk/sip_custom.conf

allow=gsm
allow=h261
allow=h263
allow=h263p
videosupport=yes

Edit /etc/asterisk/iax_custom.conf

allow=gsm
allow=h261
allow=h263
allow=h263p
videosupport=yes

asterisk -rx reload

Fix music on hold directory

ln -s /var/lib/asterisk/moh /var/lib/asterisk/mohmp3
asterisk -rx reload

Fix AMPportal auth type: Edit /etc/amportal.conf, set AUTHTYPE to database.

Add some extra sounds

cd /var/lib/asterisk/sounds
wget http://downloads.digium.com/pub/telephony/sounds/asterisk-extra-sounds-en-gsm-current.tar.gz
tar zxvf asterisk-extra-sounds-en-gsm-current.tar.gz 

Polycom Soundpoint 330

Setup FTP server

useradd polycom
passwd polycom   <= will prompt for new password
edit your /etc/vsftpd/vsftpd.conf file:
uncomment: chroot_list_enable=YES
append: userlist_deny=NO
create a file /etc/vsftpd/chroot_list
place the word polycom in the file
append the word "polycom" to the end of the file /etc/vsftpd/user_list
service vsftpd restart
cd /home/polycom
chmod u-w .
mkdir contacts
mkdir log
mkdir overrides
chown polycom:polycom log
chown polycom:polycom contacts
chown polycom:polycom overrides
chkconfig vsftpd on
service vsftpd start

To reset 330 to default factory settings, hold down 1 3 5 7 for a few seconds, you'll be asked for the admin password.

The default admin password is 4 5 6.