Building a compact Asterisk server with AstLinux
Introduction
"AstLinux has been designed with running from Compact Flash memory in
mind. However, it can also be installed to a regular hard drive like
other distributions. AstLinux currently occupies around 40mb of disk
space, so any Compact Flash card (or hard drive) of 64mb or larger will
work perfectly. AstLinux is also the premier Asterisk Live CD.
The AstLinux ISO image is very small, yet it includes two AstLinux
versions (net4801 and i586), Windows AutoRun support, and of course,
el-torrito booting."
Whereabouts
- The important files are /etc/rc.conf, and /etc/rc.modules
- Boot-time scripts live in /etc/init.d/
- To load Zaptel at boot time, edit ZAPMODS in rc.modules
- To stop asterisk : "asterisk -vvvvvvvvr", and "stop now"
to exit
- To start asterisk in a console (useful to check that it starts OK) : "asterisk
-vvvvvc"
- To start asterisk in regular mode: either "asterisk &" or (BAD??)
"safe_asterisk" or "# /etc/init.d/asterisk start"
Setup using a pre-compiled image
- If using a USB card read, insert the CF card in the reader before
connecting it to the USB port
- wget
- flash the CF card with
it: gunzip -c AstLinux-0.4.8-i586.img.gz > /dev/sdd . This will
create a 128MB ext2fs partition /dev/sdd1
How to install image in
existing partition?
- Boot with the CF card
- If using DHCP, make sure the PC got an address. If not, you can log
on as root/astlinux, and assign an address manually.
- From a remote host, https://astlinux_ip_address, and log on as admin/astlinux
(Note: You MUST use HTTPS, not HTTP)
- You can also connect to the server with SSH
- To check the options used to compile PHP, aim at https://astlinux_ip_address/admin/phpinfo.php
Post-install customizing
For changes to survive a reboot, you must be using AstLinux with UnionFS,
or remount the root partition in read-write mode.
Changing mini_httpd's admin password
htpasswd /var/www/admin/.htpasswd admin (CHECK: same as through the web interface
General > Setup?)
Changing the root password
Even with UnionFS overlaid on the read-only root partition, I had to make
the root partition read-write for passwd to work:
- # mount -o remount rw /
- # passwd
- # mount -o ro,remount /
/etc/ssh/sshd_config
/etc/rc.conf
TIMEZONE=Europe/Paris
TZ_TIMEZONE=CET-1
ZAPMODS
/etc/zaptel.conf
/etc/asterisk/zapata.conf
/etc/asterisk/sip.conf
/etc/asterisk/extension.conf
/etc/profile
alias ll='ls -laF --color=auto'
stty erase ^H
/etc/mini_httpd.conf
#port=443
#ssl
Running cron jobs
Crontab files live in /var/spool/cron/crontabs/ . To edit eg. root's contrab,
type "crontab -e root". To list all the cron jobs for this user, type
"crontab -l root". /usr/bin/crontab is actually a symlink to /bin/busybox.
Since /var lives in RAM, if you want cron jobs to survive a reboot, create
a symlink to the CF card:
- /etc/init.d/cron stop
- rm -F /var/spool/cron/crontabs
- ln -s /stat/var/spool/cron/crontabs /var/spool/cron/crontabs
- /etc/init.d/cron start
- ps | grep cron
- crontab -e root
- 0,30 * * * * /tmp/myscript.phpcli
- crontab -l root
Setting the NIC to 10BT
- # cat /etc/rc.conf
- ifconfig_de0="inet 192.168.1.1 netmask 255.255.255.0 media 10baseT/UTP"
-
- # /etc/rc.d/netif restart
-
- # ifconfig
- de0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
- inet 192.168.1.1 netmask
0xffffff00 broadcast 192.168.1.255
- ether 00:80:c8:47:32:a1
- media: Ethernet 10baseT/UTP
To compile one's own version of AstLinux
(source)
Important! When plugged into a USB CF reader, partitions appear as
/dev/ssdX, but could be seen as eg. /dev/hdaX in the AstLinux host. Keep this in mind
when referencing partitions in configuration files.
You might want to first try to compile using the default options, before
adding/removing packages.
- Get a fast host, as compiling Astlinux can take a while
- yum groupinstall 'Development Tools'
- (some might already be installed by the above step) yum install ncurses-devel
wget bzip2 zlib-devel rsync unzip subversion flex texinfo nasm bison byacc
sox dosfstools
- useradd compile
- su - compile
- svn co https://astlinux.svn.sourceforge.net/svnroot/astlinux/trunk astlinux-trunk
- cd astlinux-trunk
- cp astlinux.config .config
- make oldconfig
- make menuconfig: You could do like me, and go into "Package Selection
for the target" to remove the following packages: Arno's Firewall Support,
Asterisk PRI Support, Asterisk chan_misdn Support, Asterisk Application
Bundle - mISDN, mISDN, iftop, ipsec-tools, iptables, madwifi, netsnmp, openvpn,
rhino, tcpdump, wanpipe, wireless tools, oslec. Add SQLite!
If you
remove all ISDN-related packages, you must also remove one line in package/asterisk/asterisk.mk:
"--with-pri=$(STAGING_DIR)/usr \"
If you add sqlite, you'll have to edit package/sqlite/sqlite.mk so
it matches the version of the source code available on the site
If
you want to enable SQLite for PHP, edit less package/php5/php5.mk,
and change the adhoc line to say "--with-sqlite". If you already
have the latest and greatest version compiled, you can tell PHP to use that
external library with "--with-sqlite=/usr/lib/libsqlite3.so.0"
Samba
- make
Note:
- If "make" fails, it might be because of errors in the make
file. For instance, ./package/sqlite/sqlite.mk includes the version number,
and must be incremented every time a new version comes out, or AstLinux
will fail downloading the source code
- If you are missing some .sha1 files, which are checksum's to validate
that a file has downloaded correctly, either create your own sha1sum file
for that package, or disable sha1sum checks for that package by adding it
to the list of excludes in toolchain/file_exclude:
sha1sum dl/libpcap-0.9.7.tar.gz
> dl/libpcap-0.9.7.tar.gz.sha1
sha1sum dl/sqlite-3.5.4.tar.gz >
dl/sqlite-3.5.4.tar.gz.sha1
- If you don't know what a package does in the "Package Selection"
section of menuconfig, there's a Help option that gives a bit of information
- Once built, the filesystem will be located in eg. ./build_i586/root
- The compiled SQLite library is located in /usr/lib/, and the command-line
client sqlite3 is located in /usr/bin
If you need to start again
- cd astlinux-trunk
- make clean
- rm -Rf toolchain_build_i586
- rm -Rf build_i586
- (Up to you: If you modified some of the .mk files) rm -Rf package
- rm astlinux-trunk-*
- rm -Rf astlinux-trunk-*
- svn update
- cp astlinux.config .config
- make oldconfig
- make menuconfig
- make
Installing the new build on a CF card
- Use fdisk /dev/sdd to delete any existing partition
- Create a new, 128MB FAT16 filesystem. This new boot partition will contain
the runnix bootloader and the Astlinux image(s)
- fdisk -l : Verify that your filesystem Id is 6 and the System is FAT16
and that the first partition is bootable.
- Format the partition with mkdosfs -F 16 /dev/sdd1 (yes, it only
takes a split second)
- Download Runnix.
Extract the files into a temporary location on your development system's
hard drive
- cd runnix-<version> ; ./syslinux /dev/sdd1 ; cat mbr.bin
> /dev/sdd
- Mount the CF card: mkdir /mnt/cf ; mount /dev/sdd1 /mnt/cf
- Copy the runnix files to the CF drive: cp -R rootfs_vfat/* /mnt/cf
- You might need to edit /os/default.conf and /syslinux.cf
- At a minimum you'll need an <image>.run file and the associated
<image>.run.sha1 file which will be used to validate the image: cd
astlinux-trunk/astlinux-trunk-XXX ; cp * /mnt/cf/os.
For now, edit
KCMD line in the .run.conf to remove references to astkd and asturw (see
later)
- Take a look : ls -alh /mnt/cf . runnix is the kernel, runnix.img is
the initrd file, syslinux.cfg defines how runnix starts, and /os is the
directory where your target operating system images go
- Boot with the CF card, and aim at https://astlinux_ip/
Important: Change the default password to root, and to the web server's admin
as well!
Updating AstLinux on the CF card
- mount /dev/sdd1 /mnt/cf
- (optional, to save space) rm /mnt/cf/os/astlinux-trunk-XXX* (previous version)
- cd astlinux-trunk/astlinux-trunk-XXX
- vi astlinux-trunk-1566.run.conf (remove astkd, add asturw)
- cp * /mnt/cf/os
- umount /mnt/cf
- Boot with the CF card, and aim at https://astlinux_ip/
Making configuration sticky
By default, AstLinux is read-only, with some parts of it read-write because
they're pointing to a filesystem in RAM. This is organized through /etc/fstab.
It's fine to have /tmp and /var pointing to RAM, but you probably want to
edit files in /etc/, and have those changes survive a reboot. Incidently, /etc/rc.conf
has the Zaptel interface commentend out by default, which means that it doesn't
get loaded at boot time.
To achieve this, you can tell AstLinux to use UnionFS, so that you have read-write
access to the whole root filesystem:
- Boot AstLinux
- If not already done, use fdisk to create a second partition on the Compact
Flash on eg. /dev/hda2. To be safe, reboot.
- mkfs.ext2 /dev/hda2
- e2fsck /dev/hda2
- mount -o,remount rw /oldroot/cdrom
- vi /oldroot/cdrom/os/astlinux-trunk-XXX.run.conf:
KCMD="root=/dev/ram0 rw init=/linuxrc astlinux=geni586
astimg=astlinux-trunk-1540.run astkd=/dev/sda1 asturw=/dev/hda2
astlive ide=nodma"
- rm /etc/rc.conf ; cp /tmp/etc/rc.conf /etc ; vi /etc/rc.conf
- rm /etc/zaptel.conf ; cp /tmp/etc/zaptel.conf /etc ; vi /etc/zaptel.conf
- rm /etc/asterisk; mkdir /etc/asterisk; (why?) cp /tmp/etc/asterisk/* /etc/asterisk/
- Reboot
Now, changes made to /etc/ should be sticky because they're actually made
to /dev/hda2. Generally speaking, in case you modified a file, the version in the AstUrw (/oldroot/mnt/asturw/)
will take precedence. If you want to delete this file and have AstLinux use
the read-only version, remove the file from /oldroot/mnt/asturw/.
Creating a new partition on the CF card
- mount -o rw,remount /
- fdisk /dev/hda : Type n, p, <partition number, eg. 2>, <size
of partition>, p, w
- fdisk -l /dev/hda
- mkfs.ext2 /dev/hda2
- reboot
- mkdir /mnt/new_part
- mount -o noatime /dev/hda2 /mnt/new_part/
Adding your own PHP pages to mini_httpd
If you chose mini_httpd instead of lighttpd, to add your very own PHP scripts,
make the root partition read-write if it isn't already by using UnionFS, add the pages, make them executable,
and make sure the file is owned by ??.??:
- cd /var/www
- vi test.php
- chmod a+x test.php
- https://astlinux/test.php
Compiling the Python APSW thin SQLite3 wrapper
On a CentOS host:
- run yum install python python-devel
- wget http://initd.org/pub/software/pysqlite/apsw/3.3.13-r1/apsw-3.3.13-r1.zip
- unzip apsw-3.3.13-r1.zip ; cd apsw-3.3.13-r1
- wget http://www.sqlite.org/sqlite-3.5.4.tar.gz
- tar xzvf sqlite-3.5.4.tar.gz
- mv sqlite-3.5.4 sqlite3
- cd sqlite3
- env CC="gcc -fPIC" CFLAGS="-DHAVE_DLOPEN" ./configure
--enable-threadsafe --disable-tcl
- make
- cp .libs/*.a .
- cd ..
- python setup.py install
- cp /usr/lib/python2.4/site-packages/apsw.so /srv/www/lighttpd/
From the AstLinux host:
- cd /usr/lib/python2.4/site-packages
- wget http://www.acme.com/apsw.so
- # python
- Python 2.4.2 (#1, Jan 26 2008, 17:41:42)
- [GCC 4.1.2] on linux2
- Type "help", "copyright", "credits" or
"license" for more information.
- >>> import apsw
- libc.so.6: aborted attempt to load python!
Questions
- When starting Asterisk myself through either safe_asterisk
or asterisk&, why does ps show several Asterisk processes
listed as "asterisk -p -I"?
- Web server says "This server's current IP address is 192.168.0.1"
: 0.1 was the PC from which I SSHed, but AstLinux is 192.168.0.4!
- How to use the FR keyboard? Does AstLinux support other keyboard layouts besides US
English? How would I change it, and make it sticky so I don't
have to rerun the command with every reboot?
- Even after editing /os/astlinux-trunk-1540.run.conf, I still
get "Something else is wrong with /dev/sdd2. Run e2fsck"
when booting up:
KCMD="root=/dev/ram0 rw init=/linuxrc
astlinux=geni586 astimg=astlinux-trunk-1540.run astkd=/dev/sdd2
astlive ide=nodma"
- Test alternatives Lighttpd and appweb
- When booting up, AstLinux says "Something else is wrong
with /dev/sdd2. Run e2fsch", although running it makes
no difference at the next reboot.
- Why doesn't "CTRL-C" work in sqlite3, either from
Putty or SecureCRT? Why do arrows show eg. "^[[A"?
#
stty intr '^C' erase '^H'
CTRL-C doesn't work to cancel
the current command CTRL-D exits BACKSPACE works
- In "less", up/down arrows don't work. "/"
to search for a word doesn't work either (check that it's the
right way to search for words, like in vi)
- How to correct the way SH mishandles BACKSPACE, DEL, and
direction arrows?
- Why two configuration files for mini_httpd? /etc/mini_httpd-http.conf
and /etc/mini_httpd.conf
|
Resources