Asterisk for Raspberry Pi on ArchLinux: Difference between revisions

From KlavoWiki
Jump to navigationJump to search
No edit summary
 
(117 intermediate revisions by the same user not shown)
Line 1: Line 1:
Note: '''Work In Progress'''
If you don't want to follow these instructions and would prefer to download an image you can do so by downloading the image from [[Asterisk for Raspberry Pi Image]].


These instructions work for the Raberry Pi B-512 version with 512 MB RAM and not the 256MB version. You can follow these instruction for the 256MB version but you will have to skip the perl modules which is used for fax2mail and Google's text to speech.
The following instructions are based on Arch Linux ARM (archlinux-hf-2013-07-22.img.zip)


If you don't want to follow these instuctions and would prefer to download an image you can do so by downloading the image from [[Asterisk for Rasberry Pi Image]].
= Write Image to SD Card =
Using [http://launchpad.net/win32-image-writer/+download Win32DiskImager] and the latest version of [http://www.raspberrypi.org/downloads Arch Linux ARM] from Raspberry Pi write the image to the SD card.


Once the image is written insert the SD card into the Raspberry Pi and boot.  The device will get an IP address from DHCP.
= Update OS =
<pre>
<pre>
The following instructions are based on Arch Linux ARM (archlinux-hf-2012-09-18.zip)
pacman-key --init
pacman -Syu --noconfirm
reboot
</pre>


Write image to sdcard and boot Rasberry Pi.
= Utilities =
Install utilities to help with setup/administration
<pre>
pacman -S --noconfirm vim mlocate zip unzip
</pre>


expand sdcard to use full capacity
== vi to vim ==
  #  fdisk /dev/mmcblk0
<pre>
    d (delete)
pacman -R --noconfirm vi
    2 (partition 2)
ln -s /usr/bin/vim /usr/bin/vi
    n (new)
</pre>
    p (primary partition)
    2 (partition 2 as previously deleted)
    enter (accept default start sector)
    enter (accept default end sector)
    w (write changes)


  # reboot
== Create ll alias ==
<pre>
vi /root/.profile
</pre>


  # resize2fs /dev/mmcblk0p2
Add the following line
  # reboot
<pre>
alias ll="ls -la --color --group-directories-first --time-style=\"+%Y-%m-%d %H:%M\""
</pre>


create swap file
= Time Synchronisation =
  # fallocate -l 256M /swapfile
<pre>
  # chmod 600 /swapfile
cp -f /usr/share/zoneinfo/Australia/Brisbane /etc/localtime
  # mkswap /swapfile
</pre>
  # swapon /swapfile


  # vi /etc/fstab
= Set IP Address =
      /swapfile none swap defaults 0 0  (add)


<pre>
vi /boot/cmdline.txt
</pre>


Add the following text.  Make sure there is no carriage return at the end of the file and that everything is located on one line
<pre>
ip=192.168.1.11::192.168.1.254:255.255.255.0:rpi:eth0:off
</pre>


update operating system
Set DNS Servers, DNS suffix and DNS search.
  # pacman -Syu
<pre>
  # reboot
vi /etc/resolv.conf
</pre>
add the lines
<pre>
domain mydomain.com
search mydomain.com
nameserver 192.168.1.254
</pre>


Install utilities to help with setup/administration
After reboot check network settings
  # pacman -S initscripts vim mlocate zip unzip
<pre>
ip addr show dev eth0
</pre>


other useful commands
<pre>
ip addr add 192.168.17.250/24 dev eth0
ip route add 192.168.0.0/16 via 192.168.25.253 dev eth0


change vi to vim
  # pacman -R vi
  # ln -s /usr/bin/vim /usr/bin/vi


  # vim /root/.profile
ip addr delete 192.168.17.250/24 dev eth0
        alias ll="ls -la"
ip route delete 192.168.0.0/16 via 192.168.25.253 dev eth0
</pre>


enable sound card in Linux
= Expand Partition =
  # vim /etc/rc.conf
Now that the device has booted log on and change the default partition from 2 GB to the maximum partition of your SD card.
        MODULES=(snd-bcm2835)
<pre>
fdisk /dev/mmcblk0
d (delete)
2 (partition 2)
n (new)
p (primary partition)
2 (partition 2 as previously deleted)
enter (accept default start sector)
enter (accept default end sector)
w (write changes)


Regional settings
reboot
  # vim /etc/locale.gen (enable en_AU ISO-8859-1)
</pre>
  # vim /etc/rc.conf
  # locale-gen


Time Synchronisation
Once the rPi has rebooted
  # cp /usr/share/zoneinfo/Australia/Brisbane /etc/localtime
<pre>
resize2fs /dev/mmcblk0p2
reboot
</pre>


  # pacman -R openntpd


  # pacman -S ntp
= Swap File =
  # ntpdate ntp.bri.connect.com.au
As the rPi has limited RAM, either 256 or 512 depending on your version we'll create a swap file to allow application to use higher memory if required.


  # vim /etc/rc.conf
I would recommend allocating the size of the swap file to be that equal to the RAM size.
remove hwclock
<pre>
        add ntpdate
fallocate -l 512M /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
</pre>


Edit hostnamer and network settings
The swap file is now active.  We now need to ensure that it is used at boot.
  #  vim /etc/hostname
<pre>
  #  vim /etc/hosts
vi /etc/fstab
</pre>
add the line to the file
<pre>
/swapfile none swap defaults 0 0
</pre>


  #  vim /etc/dhcpcd.conf
= Enable Sound Card =
          add line: nohook resolv.conf
<pre>
        remove line: nohook lookup-hostname
vi /etc/rc.conf
</pre>


  #  vim /etc/resolv.conf
add the line
domain klaverstyn.com
search klaverstyn.com
nameserver 192.168.13.1


<pre>
MODULES=(snd-bcm2835)
</pre>
<pre>
pacman -S --noconfirm alsa-utils
</pre>
Test with
<pre>
aplay /usr/share/sounds/alsa/Front_Left.wav && aplay /usr/share/sounds/alsa/Front_Center.wav && aplay /usr/share/sounds/alsa/Front_Right.wav
</pre>


change IP address details
= Regional settings =
  # vim /etc/conf.d/network
Enable AU or country specific entries.
<pre>
vi /etc/locale.gen
</pre>


interface=eth0
<pre>
address=192.168.1.1
vi /etc/rc.conf
netmask=255.255.255.0
locale-gen
broadcast=192.168.0.255
</pre>
gateway=192.168.0.254


  # vim /etc/systemd/system/network.service
= Hostname =
<pre>
vi /etc/hostname
</pre>


[Unit]
= Asterisk Packages =
Description=Network Connectivity
Asterisk uses initscripts to start, stop and manage the asterisk service.  This causes a conflict with network and ntpdate.  We need to install initscripts but remove the networking and clock functions.
Wants=network.target
<pre>
Before=network.target
pacman -S --noconfirm initscripts
</pre>


[Service]
<pre>
Type=oneshot
vi /etc/rc.conf
RemainAfterExit=yes
</pre>
EnvironmentFile=/etc/conf.d/network
Remove '''ntpdate''', '''networking''' and '''sshd''' from DEAMONS=()
ExecStart=/sbin/ip link set dev ${interface} up
<br><br>
ExecStart=/sbin/ip addr add ${address}/${netmask} broadcast ${broadcast} dev ${interface}
ExecStart=/sbin/ip route add default via ${gateway}
ExecStop=/sbin/ip addr flush dev ${interface}
ExecStop=/sbin/ip link set dev ${interface} down


[Install]
Install prerequisites for Asterisk.
WantedBy=multi-user.target
<pre>
pacman -S --noconfirm gcc make hgsvn libxml2 libnewt sqlite subversion mysql spandsp speex
systemctl enable mysqld.service
systemctl start mysqld.service
</pre>


== Secure mysql ==
<pre>
/usr/bin/mysql_secure_installation
</pre>


  # systemctl disable dhcpcd@eth0.service
= Install Asterisk =
  # systemctl enable network.service
Download and install Asterisk. You can refer to [[Asterisk Install]] if required, but only Asterisk is required.


  # reboot


== Set Asterisk to Automatic ==
<pre>
vi /etc/rc.conf
</pre>
and add '''asterisk''' to DEAMONS


== logrotate ==
<pre>
/etc/logrotate.d/asterisk
</pre>
add the following lines to the file
<pre>
/var/log/asterisk/messages /var/log/asterisk/*log {
  missingok
  notifempty
  rotate 12
  weekly
  create 0640 root root
  postrotate
      /usr/sbin/asterisk -rx 'logger reload' > /dev/null 2> /dev/null
  endscript
}
</pre>


install required packages for asterisk
==  logger ==
  # pacman -S gcc make hgsvn libxml2 libnewt sqlite subversion mysql spandsp speex
<pre>
  # systemctl enable mysqld.service
vi /etc/asterisk/logger.conf
  # systemctl start mysqld.service
</pre>
change from:
<pre>
;dateformat=%F %T
</pre>to
<pre>
dateformat=%F %T %Z
</pre>


= Sendmail =
<pre>
pacman -R --noconfirm heirloom-mailx
rm /etc/mail.rc.pacsave
pacman -S --noconfirm ssmtp
</pre>


secure mysql
<pre>
  # /usr/bin/mysql_secure_installation
vi /etc/ssmtp/ssmtp.conf
</pre>
and add the lines
<pre>
mailhub=192.168.13.3
hostname=rpi.klaverstyn.com
FromLineOverride=yes
</pre>
Edit aliases if required
<pre>
vi /etc/ssmtp/revaliases
</pre>


stop services to free memory
= Install Apache =
ensure correct time
<pre>
  # systemctl stop ntpd.service
pacman -S --noconfirm apache php-apache php php-gd
  # systemctl stop mysqld.service
</pre>


install asterisk
<pre>
vi /etc/httpd/conf/httpd.conf
</pre>
and modify the following
<pre>
AllowOverride All
DirectoryIndex index.php index.html index.htm index.html.var
</pre>


<pre>
systemctl enable httpd.service
</pre>


Set asterisk service to start automatically
= Configure php =
  # vim /etc/rc.conf
<pre>
  add asteirsk to DEAMONS=
vi /etc/php/php.ini
</pre>
uncomment
<pre>
extension=mysqli.so
extension=mysql.so
</pre>


Locate date.timezone and change accordingly.
<pre>
date.timezone = Australia/Brisbane
</pre>


Install Sendmail
For a list of [http://php.net/manual/en/timezones.php time zones]
  # pacman -R heirloom-mailx
  # rm /etc/mail.rc.pacsave
  # pacman -S ssmtp
  # vi /etc/ssmtp/ssmtp.conf
          mailhub=192.168.13.3
          hostname=rpi.klaverstyn.com
          FromLineOverride=yes


<pre>
vi /etc/httpd/conf/httpd.conf
</pre>
add the following lines in thier respective sections
<pre>
LoadModule php5_module modules/libphp5.so
Include conf/extra/php5_module.conf
AddHandler application/x-httpd-php .php
</pre>


install Apache, PHP and aCDR
uncomment the following lines
  # pacman -S apache php-apache php php-gd
<pre>
TypesConfig conf/mime.types
MIMEMagicFile conf/magic
</pre>


  # vim /etc/httpd/conf/httpd.conf
<pre>
        AllowOverride All
vi /etc/httpd/conf/mime.types
        DirectoryIndex index.php index.html index.htm index.html.var
</pre>
add the following line
<pre>
application/x-httpd-php5 php php5
</pre>
 


  # systemctl enable httpd.service
<pre>
systemctl start httpd.service
</pre>


  # vim /etc/php/php.ini
'''Note''': The web root is /srv/http/
      uncomment
          extension=mysqli.so
          extension=mysql.so


  # vim /etc/httpd/conf/httpd.conf
= CDR =
          LoadModule php5_module modules/libphp5.so (add)
Refer to the [[Cdr | Call Detail Records]] page which will allow Asterisk to write the CDR records to the database.
          Include conf/extra/php5_module.conf      (add)
          TypesConfig conf/mime.types              (uncomment)
          MIMEMagicFile conf/magic                  (uncomment)
          AddHandler application/x-httpd-php .php  (add)


  # vim /etc/httpd/conf/mime.types
== aCDR ==
          application/x-httpd-php5 php php5
aCDR is a web appliction that allows you to search throught your CDR records. View the [[aCDR]] page on installation.
 


  # systemctl start httpd.service
= Backup Script =
Refer to [[Asterisk Backup Shell Script]] for the script itself.
<pre>
pacman -S --noconfirm smbclient
</pre>


Note: The web root is /srv/http/
= perl =
NOTE: To install the perl module requires more RAM that what is available on the 256MB model of the rPi.  Make sure you have a swap file otherwise this section will fail.
<pre>
pacman -S --noconfirm perl perl-yaml libyaml perl-libwww sox mpg123
</pre>


== Text to Speech ==
<pre>
PERL_MM_USE_DEFAULT=1 perl -MCPAN -e "install Bundle::LWP"
PERL_MM_USE_DEFAULT=1 perl -MCPAN -e "install CGI::Util"
</pre>


Backup Script
<pre>
  # pacman -S smbclient
wget https://github.com/zaf/asterisk-googletts/blob/master/googletts.agi
mv googletts.agi /var/lib/asterisk/agi-bin/
chmod 755 /var/lib/asterisk/agi-bin/googletts.agi
</pre>


== fax2mail ==
<pre>
cd /usr/src
wget http://search.cpan.org/CPAN/authors/id/R/RO/ROSCH/mime-construct-1.11.tar.gz
tar xzvf mime-construct-1.11.tar.gz
rm -f mime-construct-1.11.tar.gz
cd mime-construct-1.11
perl Makefile.PL
make install
cd ..
</pre>


<pre>
PERL_MM_USE_DEFAULT=1 perl -MCPAN -e "install Bundle::LWP"
PERL_MM_USE_DEFAULT=1 perl -MCPAN -e "install Proc::WaitStat"
PERL_MM_USE_DEFAULT=1 perl -MCPAN -e "install MIME::Types"
</pre>


google text to speech
<pre>
  # pacman -S perl-libwww sox mpg123
wget http://www.klaverstyn.com.au/david/asterisk/files/fax2mail
  # perl -MCPAN -e "install Bundle::LWP"
mv fax2mail /usr/sbin/
  # perl -MCPAN -e "install CGI::Util"
chmod 755 /usr/sbin/fax2mail
mkdir /var/spool/asterisk/fax
</pre>


= Reference =
http://wiki.archlinux.org/index.php/Systemd<br>
http://wiki.archlinux.org/index.php/Configuring_Network<br>
http://wiki.archlinux.org/index.php/Beginners%27_Guide<br>
http://wiki.archlinux.org/index.php/LAMP#PHP<br>
http://raw.github.com/Evilpaul/RPi-config/master/config.txt




reference:
[[Category : ArchLinux]] [[Category : Asterisk]]  [[Category : Raspberry Pi]]
https://wiki.archlinux.org/index.php/Systemd
https://wiki.archlinux.org/index.php/Configuring_Network
https://wiki.archlinux.org/index.php/Beginners%27_Guide
https://wiki.archlinux.org/index.php/LAMP#PHP
</pre>
[[Category : Asterisk]]  [[Category : Rasberry Pi]]

Latest revision as of 11:30, 12 March 2014

If you don't want to follow these instructions and would prefer to download an image you can do so by downloading the image from Asterisk for Raspberry Pi Image.

The following instructions are based on Arch Linux ARM (archlinux-hf-2013-07-22.img.zip)

Write Image to SD Card

Using Win32DiskImager and the latest version of Arch Linux ARM from Raspberry Pi write the image to the SD card.

Once the image is written insert the SD card into the Raspberry Pi and boot. The device will get an IP address from DHCP.

Update OS

pacman-key --init
pacman -Syu --noconfirm
reboot

Utilities

Install utilities to help with setup/administration

pacman -S --noconfirm vim mlocate zip unzip

vi to vim

pacman -R --noconfirm vi
ln -s /usr/bin/vim /usr/bin/vi

Create ll alias

vi /root/.profile

Add the following line

alias ll="ls -la --color --group-directories-first --time-style=\"+%Y-%m-%d %H:%M\""

Time Synchronisation

cp -f /usr/share/zoneinfo/Australia/Brisbane /etc/localtime

Set IP Address

vi /boot/cmdline.txt

Add the following text. Make sure there is no carriage return at the end of the file and that everything is located on one line

ip=192.168.1.11::192.168.1.254:255.255.255.0:rpi:eth0:off

Set DNS Servers, DNS suffix and DNS search.

vi /etc/resolv.conf

add the lines

domain mydomain.com
search mydomain.com
nameserver 192.168.1.254

After reboot check network settings

ip addr show dev eth0

other useful commands

ip addr add 192.168.17.250/24 dev eth0
ip route add 192.168.0.0/16 via 192.168.25.253 dev eth0


ip addr delete 192.168.17.250/24 dev eth0
ip route delete 192.168.0.0/16 via 192.168.25.253 dev eth0

Expand Partition

Now that the device has booted log on and change the default partition from 2 GB to the maximum partition of your SD card.

fdisk /dev/mmcblk0
d (delete)
2 (partition 2)
n (new)
p (primary partition)
2 (partition 2 as previously deleted)
enter (accept default start sector)
enter (accept default end sector)
w (write changes)

reboot

Once the rPi has rebooted

resize2fs /dev/mmcblk0p2
reboot


Swap File

As the rPi has limited RAM, either 256 or 512 depending on your version we'll create a swap file to allow application to use higher memory if required.

I would recommend allocating the size of the swap file to be that equal to the RAM size.

fallocate -l 512M /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile

The swap file is now active. We now need to ensure that it is used at boot.

vi /etc/fstab

add the line to the file

/swapfile none swap defaults 0 0

Enable Sound Card

vi /etc/rc.conf

add the line

MODULES=(snd-bcm2835)
pacman -S --noconfirm alsa-utils

Test with

aplay /usr/share/sounds/alsa/Front_Left.wav && aplay /usr/share/sounds/alsa/Front_Center.wav && aplay /usr/share/sounds/alsa/Front_Right.wav

Regional settings

Enable AU or country specific entries.

vi /etc/locale.gen
vi /etc/rc.conf
locale-gen

Hostname

vi /etc/hostname

Asterisk Packages

Asterisk uses initscripts to start, stop and manage the asterisk service. This causes a conflict with network and ntpdate. We need to install initscripts but remove the networking and clock functions.

pacman -S --noconfirm initscripts 
vi /etc/rc.conf

Remove ntpdate, networking and sshd from DEAMONS=()

Install prerequisites for Asterisk.

pacman -S --noconfirm gcc make hgsvn libxml2 libnewt sqlite subversion mysql spandsp speex
systemctl enable mysqld.service
systemctl start mysqld.service

Secure mysql

/usr/bin/mysql_secure_installation

Install Asterisk

Download and install Asterisk. You can refer to Asterisk Install if required, but only Asterisk is required.


Set Asterisk to Automatic

vi /etc/rc.conf

and add asterisk to DEAMONS

logrotate

/etc/logrotate.d/asterisk 

add the following lines to the file

/var/log/asterisk/messages /var/log/asterisk/*log {
   missingok
   notifempty
   rotate 12
   weekly
   create 0640 root root
   postrotate
       /usr/sbin/asterisk -rx 'logger reload' > /dev/null 2> /dev/null
   endscript
}

logger

vi /etc/asterisk/logger.conf

change from:

;dateformat=%F %T

to

dateformat=%F %T %Z

Sendmail

pacman -R --noconfirm heirloom-mailx
rm /etc/mail.rc.pacsave
pacman -S --noconfirm ssmtp
vi /etc/ssmtp/ssmtp.conf

and add the lines

mailhub=192.168.13.3
hostname=rpi.klaverstyn.com
FromLineOverride=yes

Edit aliases if required

vi /etc/ssmtp/revaliases

Install Apache

pacman -S --noconfirm apache php-apache php php-gd 
vi /etc/httpd/conf/httpd.conf

and modify the following

AllowOverride All
DirectoryIndex index.php index.html index.htm index.html.var
systemctl enable httpd.service

Configure php

vi /etc/php/php.ini

uncomment

extension=mysqli.so
extension=mysql.so

Locate date.timezone and change accordingly.

date.timezone = Australia/Brisbane

For a list of time zones

vi /etc/httpd/conf/httpd.conf

add the following lines in thier respective sections

LoadModule php5_module modules/libphp5.so
Include conf/extra/php5_module.conf
AddHandler application/x-httpd-php .php

uncomment the following lines

TypesConfig conf/mime.types
MIMEMagicFile conf/magic
vi /etc/httpd/conf/mime.types

add the following line

application/x-httpd-php5		php php5


systemctl start httpd.service

Note: The web root is /srv/http/

CDR

Refer to the Call Detail Records page which will allow Asterisk to write the CDR records to the database.

aCDR

aCDR is a web appliction that allows you to search throught your CDR records. View the aCDR page on installation.

Backup Script

Refer to Asterisk Backup Shell Script for the script itself.

pacman -S --noconfirm smbclient

perl

NOTE: To install the perl module requires more RAM that what is available on the 256MB model of the rPi. Make sure you have a swap file otherwise this section will fail.

pacman -S --noconfirm perl perl-yaml libyaml perl-libwww sox mpg123

Text to Speech

PERL_MM_USE_DEFAULT=1 perl -MCPAN -e "install Bundle::LWP"
PERL_MM_USE_DEFAULT=1 perl -MCPAN -e "install CGI::Util"
wget https://github.com/zaf/asterisk-googletts/blob/master/googletts.agi
mv googletts.agi /var/lib/asterisk/agi-bin/
chmod 755 /var/lib/asterisk/agi-bin/googletts.agi

fax2mail

cd /usr/src
wget http://search.cpan.org/CPAN/authors/id/R/RO/ROSCH/mime-construct-1.11.tar.gz
tar xzvf mime-construct-1.11.tar.gz
rm -f mime-construct-1.11.tar.gz
cd mime-construct-1.11
perl Makefile.PL
make install 
cd ..
PERL_MM_USE_DEFAULT=1 perl -MCPAN -e "install Bundle::LWP"
PERL_MM_USE_DEFAULT=1 perl -MCPAN -e "install Proc::WaitStat"
PERL_MM_USE_DEFAULT=1 perl -MCPAN -e "install MIME::Types"
wget http://www.klaverstyn.com.au/david/asterisk/files/fax2mail
mv fax2mail /usr/sbin/
chmod 755 /usr/sbin/fax2mail
mkdir /var/spool/asterisk/fax

Reference

http://wiki.archlinux.org/index.php/Systemd
http://wiki.archlinux.org/index.php/Configuring_Network
http://wiki.archlinux.org/index.php/Beginners%27_Guide
http://wiki.archlinux.org/index.php/LAMP#PHP
http://raw.github.com/Evilpaul/RPi-config/master/config.txt