Friday, July 24, 2009

Configuring Asterisk/trixbox for Kuwait



WARNING: I want to alert everyone to NOT use trixbox due to security concerns.

I've been told by some guys in asterisk-related IRC channels that trixbox has known security problems and is not fixing them.

A quick search turns many results.

There are alternatives and I will document their installation process in a later post.



Introduction


This post talks about how to setup a Private Branch Exchange (PBX) using an open-source solution called Asterisk. It's similar to solutions from Panasonic, Cisco, or Avaya for houses, offices or enterprises, only provides various features at very low cost.

What is Asterisk?


Asterisk is a software implementation of a PBX, that is, it's an application that runs on top of an Operating System. It allows you to receive and make phone calls over your telephone landlines (analog or digital) and over the network. And yes, it's free.

Why use it?


A small PBX from Panasonic that offers 2 input phone lines and about 8 extensions, with 6 phones comes around at 170 KD. You're limited to Panasonic's phones and you can't carry your extension outside the house (or wherever you implemented the solution). If you want wireless phones, you have to buy proprietary Access Points (APs) from Panasonic and if you have Wireless Access Points in your place, it's gonna look ugly to have 2 APs next to each other!

Asterisk works on standard network protocols and equipment. This means you can connect a computer, laptop, or a phone that uses the standard SIP protocol (newer mobile phone models support SIP, too!). This also means that if you have a wireless AP at home to distribute your Internet connection, you can buy a wireless phone which will work with Asterisk!

Another great option is that since it's all networked together, you can connect to your extension over the Internet. Say you implement Asterisk in your house, configure your mobile phone to connect to Asterisk, then anyone who calls you at home, will have the phone call sent to you over the Internet to your mobile phone!

What features does it offer?


Everything a normal PBX does, and more!
  • Voice mail

  • Voice mail to email

  • Conference calling

  • Interactive Voice Response (IVR) / phone menus

  • Automatic call distribution

  • Fax to email

  • Call queues

  • And more!

Check out the list on Asterisk's website.

What is trixbox?


trixbox (all in small letters) is an Asterisk-based distribution, that combines Asterisk and a few more packages to enhance the PBX functionality and experience.

I used both trixbox and AsteriskNow (another distro), but felt more comfortable with trixbox, and this post assumes the use of trixbox 2.6.2 Community Edition (CE) based on Asterisk 1.4 (1.6 exists but I haven't explored it as it seems to be still in beta).

trixbox also offers a business edition, as well as the original Asterisk. Feel free to visit their websites and explore the options.

Table of Contents



  1. Hardware Requirements and Configuration


    1. Addon Card

    2. Computer Specifications


  2. Download trixbox

  3. Installing trixbox

  4. Configuration


    1. Network Configuration

    2. Create An Extension

    3. General Settings

    4. Outbound Routes

    5. Trunks

    6. Inbound Routes

    7. Configuring Caller ID


  5. Applying Settings

  6. Installing a softphone

  7. Configuring Ekiga

  8. Notes

  9. Sources

  10. Image Index



1. Hardware Requirements and Configuration


Below are the required hardware specifications and addon cards. Read carefully!

1.1 Addon Card


To connect Asterisk to an analog phone line (Public Switched Telephone Network / PSTN, also known as Plain Old Telephone Service / POTS), you need a PCI card that converts signals from analog to digital and vice-versa.

Companies typically sell a base PCI card and pluggable modules. On Amazon.com, the base card from Digium is TDM410P and the module required to connect the machine to PSTN is called X100M.

The X100M enables what is called an FXO port. FXO port is the port you connect your PSTN line to. The other type of ports is called FXS; you connect analog phones to this port.
To easily remember these ports, follow this:
FXS -> Station -> Phone device.
FXO -> Office -> PSTN line.

A company called OpenVox offers the same base card and the FXO port for much less than Digium.

1.2 Computer Specifications


My test computer is a stretch to what I actually need for home. According to what I read online of previous implementations, each phone call requires 33MHz of CPU power. People were able to achieve 40 concurrent calls over an 800MHz processor with 256MB RAM!

My PC is a Pentium D 3.0GHz with 1GB RAM. Pentium D is dual core, so I have 6GHz at my disposal!
Initial installation takes 1.3GB only, so you could do fine with a 20GB hard disk for a home setup.

2. Download trixbox


trixbox has known security problems. USE AT YOUR OWN RISK! Alternatives are: AsteriskNow and PBX in a Flash.

I will post on how to install one of those in a later post.

Download trixbox CE here. Make sure to get the 2.6.x version as it's based on Asterisk 1.4.

3. Installing trixbox


After you download the ISO file, burn it on a CD as an image using your favorite burning software. Before proceeding with the installation, make sure you have installed the module on the base card and the card is plugged properly into the PCI port. Load the CD into the PC and boot up the CD.

By default, trixbox uses all disks in the computer; use "advanced" to make up your own partitioning, that is, when the CD boots, type "advanced" (without double quotes) and press enter.

Proceed with defaults unless otherwise specified below.

Upon reaching the partitioning stage, deselect disks that you don't want to be touched, and select: Remove all partitions & create default layout. (It's still safer to physically remove disks you don't want to be touched). Formatting the disk takes a long time. They use ext3 filesystem by default.

The password you type during setup is used to login to the machine later for any maintenance you may need (not required for web configuration). SSH is enabled by default, with root access.

4. Configuration


Skip section 4.1 if you have a router assigning dynamic IPs. If you wish to assign a static IP, then follow its steps.

4.1 Network Configuration


If you don't have a DHCP server running (A router that assigns IP addresses to devices on the network), define the IP manually by logging in to the terminal, using the username "root" (case sensitive!) and the password you chose during installation.

In the command prompt (shell), type: system-config-network
Press enter to select the proper device, then go to "Use DHCP" and press the space bar to deselect it and enable the other options.

Static IP: Make up an IP that is not used by any other device on the network.
Netmask: 255.255.255.0 should be a safe bet.
Default gateway IP: The IP of your router.
Quite to save.

When going back to the shell type: service network restart

Now you should be able to login to the web interface: http://<static ip>

On the top-right, click the link "switch" -- user: maint, pass: password. [image1]

4.2 Create An Extension


You'll first create an extension for yourself to receive and make phone calls from using your computer.
After you login, you'll reach the home page [image2]. Click on the PBX menu then choose "PBX Settings." Now you are at the System Status page [image3]. Click the Extensions link in the left menu, then select "Generic SIP Device" from the drop list and click "Submit" [image4].

SIP Device:
* User extension: 200 (safe bet. make sure you don't use a range of existing system extensions)
* Display name: Your name
* Secret: <alphanumeric>

* Vocie mail: Enabled
* Voicemail password: <numeric>
* Email: your full email address.
* Pager: Leave it blank
* Email attachment: Yes
* Play CID: Yes
[submit]

4.3 General Settings


* Ringtime Default: Reduced it to 5 seconds for testing
* Find users in the company directory: First or last
* Announce extension: Yes
* Country: United States (Default)
* 24-hour format: No (Changed it from Yes so that time service is said in AM/PM -- mom is not a fan of the 24 hour format)
* Check updates: No (Not a fan of background checking & installation...)
[submit]

4.4 Outbound Routes


This defines how you're going to call outside. The info below means that you dial 9 to get an external line, then it will dial the rest of the number.

* Default auto-created route: 0 9_outside: Details:
Password: left it blank
Dial patterns: 9|. (Default)
No need to submit as nothing has changed

4.5 Trunks


A trunk is a phone line (PSTN) in this case. In cases of using ISDN, it means having 30 lines at your disposal. The trunks page [image5] shows the available trunking options.

Auto created trunk: Trunk ZAP:
* Outbound Caller ID: Your phone number
* Never override: Checked
* Max channels: 1 (Since it's a phone line, it can make only one phone call at a time)
[submit]
Note that the above are not required, but recommended.

4.6 Inbound Routes


Where and how should incoming calls be treated. Remember, these are just basics to get things started.

I created a general rule for all phone numbers [image6]: Leave all fields blank & scroll down to "Set Destination"
* Select "Extension" and choose your extension (should be the only one for now)
[submit]
This will redirect all phone calls to your extension (for now)

4.7 Getting Caller ID to work


It doesn't work out of the box, and it requires that you have Caller ID (CID) service enabled by the Ministry of Communication!

I figured that since we had telephone lines way back, it's most likely similar to the British system, and what do you know, I was right! :D

PBX menu -> Config File Editor -> zapata.conf [image7]
Add these lines below threewaycalling

cidsignalling=v23 ;added manually: valid values: bell, v23, dtmf
cidstart=polarity ;added manually: valid values: usehist, ring, polarity

[Update]

5. Applying Settings


After you've done all this, there's an orange link at the top [image8], just below the menus, click it to save the new settings [image9] and then go to System menu -> System Maint -> Reset Now [image10] and [image11]. This will restart the Asterisk service and activate the new settings.

6. Installing a softphone


Now you just need to test it out with a softphone (software on a PC/laptop). I used Ekiga for my tests. You can download it for free here.
How can you not use this client, when they advertise their client with a picture of a cute girl?! ;p
Feel free to use any softphone you find suitable. The settings below should apply to any.

7. Configuring Ekiga


When you first run Ekiga, ignore/skip the initial account creation stuff. When the main window appears, go to Edit -> Accounts, then click on Account menu and add a SIP account:

Name: Display name
Registrar: The static IP you chose for trixbox
User: Your extension number
Authentication user: Your extension number
Password: the "secret: you chose while creating your extension
Timeout: Leave it at its default value.

If everything is fine, it will say that your account has been registered. Go to the web interface and click on PBX -> PBX Settings, and you'll see that you have 1 phone online.

8. Notes


* trixbox runs on CentOS, which is a RedHat Enterprise spin-off. RPMs will work fine with it.
* trixbox runs smartd and it did detect bad sectors on one of the disks!
* When the system boots, before using the web interface, memory usage is: 70MB. After doing the configurations over the web: 120MB.
* During a call from my laptop to my mobile over a landline, the CPU is 2% utilized. Memory usage didn't change.
* Asterisk writes a lot of data into its log files and they grow quite fast. Keep an eye at /var/log/asterisk/full
* In theory, each phone call requires 30-33MHz of CPU power, so a 3GHz CPU can handle 90 concurrent calls using G711 encoded audio. If you use A-law codec, you can achieve about 310 concurrent calls.
There are reports that have tested 700 concurrent calls on a Pentium4 2.5GHz + 2GB RAM machine. See Asterisk Dimensioning link below.

9. Sources and References


http://asteriskathome.sourceforge.net/handbook/#Section_5.2
http://forums.digium.com/viewtopic.php?t=75&sid=774813d31e64cb58ab179fe5b01de953
http://www.voip-info.org/wiki/view/Asterisk+and+UK+Caller+ID
http://www.ainslie.org.uk/callerid/cli_faq.htm#Q_6
http://www.voip-info.org/wiki/view/Asterisk+dimensioning
http://www.labnol.org/internet/design/add-text-captions-align-images-html-css/2309/

10. Image Index



Image 1: Login Screen

Image 2: Home

Image 3: System Status and PBX Settings

Image 4: Extensions

Image 5: Trunks

Image 6: Inbound Routes

Image 7: Config File Editor

Image 8: Apply Settings

Image 9: Confirm Applying Settings

Image 10: System Maintenance

Image 11: Restarting Asterisk Service

Wednesday, May 20, 2009

DB2 Container Rebalancing: Choosing the right filesystems

Our ERP software's database spans over multiple filesystems for better load balancing, but mixing high-load and low-load database tables on the same filesystem. Also, filesystem are grouped in volume groups that reside on different physical disks.

To better understand this, here's how our production SAN is devised:

Array 2 is one of two database data arrays, and is created over 6 hard disks in RAID level 5.
Array 2 contains two Logical Drives: SAPappShared and SAPdataDrv2. These will be mapped to the operating system (OS) as physical disks.

 




Here you can see that the 3rd array spans over different disks. This is to optimize data load times when requesting data from the database.
The two red/white disks are hot-spares that will substitute any failed disk immediately.
You can also see that this array reside on a different controller (B), while the previous is on (A). The controller handles I/O requests from the OS.

 




Database logs are written to a RAID level 1 array spanned over 2 disks. Logs are written always so it's better to keep them away from data to not hamper the performance.






From what you saw above, you can count 6 Logical Drives that relate to the database. The database uses only 4 of them: Log, Data1-1, Data1-2 and Data2. The Heartbeat drives are used by the cluster services of the OS.



Now, moving to the OS: IBM's AIX. We run version 5.3L.

On AIX, you cannot create a filesystem on a physical disk directly. The physical disk has to belong to a Volume Group. A volume group can house multiple physical disks, whether internal disks or attached through storage or network. A volume group can contain multiple filesystems. This all falls under the topic of the Logical Voume Manager, which I will not talk about here.

Back to our setup above, from AIX's point of view, the Logical Drives are shown as physical disks:
# lspv
hdisk0 00c3b3f0feb38826 rootvg active
hdisk1 00c3b3f0d832abbc rootvg active
hdisk2 00c3b3e0fbad39e6 hrtvg1
hdisk3 00c3b3e0fbb076c8 saplogsvg active
hdisk4 00c3b3e0fbef90aa sapdatavg1 active
hdisk5 00c3b3e0fbf2e9bf sapdatavg2 active
hdisk6 00c3b3f0168bedbb sapdatavg3 active

You can see from the list above that each Logical Drive is a physical disk and moreover, each has been put to a separate volume group.

These are filesystems spanned over the volume group on hdisk4:
# lspv -l hdisk4
hdisk4:
LV NAME LPs PPs DISTRIBUTION MOUNT POINT
db2lv 2 2 00..02..00..00..00 /db2/EHP/db2ehp
db2dumplv 24 24 00..01..00..00..23 /db2/EHP/db2dump
sapdata6lv 280 280 123..00..00..135..22 /db2/EHP/sapdata6
sapdata3lv 340 340 13..132..135..00..60 /db2/EHP/sapdata3
loglv2 1 1 00..01..00..00..00 N/A

Before continuing, let's talk about database usage, to be able to justify the next moves.

Since the database tables have been split over multiple filesystems, some of the filesystems have high growth rate. Our database (IBM's DB2) can span the contents of a table over multiple filesystems; a load balancing technique. It does this through its concept of rebalancing containers. (In DB2, tables reside in Tablespaces and a tablespace consists of one or more containers).

So, if we create a second container of a high growth table, it will take half of it and dump it over the new container and in the future, it will write to both in a load balancing form.

Now, to be able to achieve a true sense of load balancing, in filesystem utilization and database performance, ideally these two filesystems (that house the high growth table) should be on different controllers, so that data requested residing on both filesystems can be served in parallel by the controllers.

If you're doing the rebalancing after going live with the system (which is the case mostly), then you'd need to know which physical disk on the OS goes to which controller.

Here, you see that each Logical Drive has a unique identifier called Logical Unit Number (LUN).

The LUN is represented as a hex value on AIX.





From the shell, type "lspv" to list the physical volumes, then "lsattr -El " to list the attributes of one of the disks. The value "lun_id" is what you want. See the output below.

# lspv
hdisk0 00c3b3f0feb38826 rootvg active
hdisk1 00c3b3f0d832abbc rootvg active
hdisk2 00c3b3e0fbad39e6 hrtvg1
hdisk3 00c3b3e0fbb076c8 saplogsvg active
hdisk4 00c3b3e0fbef90aa sapdatavg1 active
hdisk5 00c3b3e0fbf2e9bf sapdatavg2 active
hdisk6 00c3b3f0168bedbb sapdatavg3 active

# lsattr -El hdisk4
PR_key_value none Persistant Reserve Key Value True
cache_method fast_write Write Caching method False
ieee_volname 600A0B80003260360000A92E472997CA IEEE Unique volume name False
lun_id 0x0005000000000000 Logical Unit Number False
max_transfer 0x100000 Maximum TRANSFER Size True
prefetch_mult 1 Multiple of blocks to prefetch on read False
pvid 00c3b3e0fbef90aa0000000000000000 Physical volume identifier False
q_type simple Queuing Type False
queue_depth 10 Queue Depth True
raid_level 5 RAID Level False
reassign_to 120 Reassign Timeout value True
reserve_policy single_path Reserve Policy True
rw_timeout 30 Read/Write Timeout value True
scsi_id 0x10400 SCSI ID False
size 173670 Size in Mbytes False
write_cache yes Write Caching enabled False

# lsattr -El hdisk6
PR_key_value none Persistant Reserve Key Value True
cache_method fast_write Write Caching method False
ieee_volname 600A0B80003260360000A9AA472EA49C IEEE Unique volume name False
lun_id 0x000c000000000000 Logical Unit Number False
max_transfer 0x100000 Maximum TRANSFER Size True
prefetch_mult 1 Multiple of blocks to prefetch on read False
pvid 00c3b3f0168bedbb0000000000000000 Physical volume identifier False
q_type simple Queuing Type False
queue_depth 10 Queue Depth True
raid_level 5 RAID Level False
reassign_to 120 Reassign Timeout value True
reserve_policy single_path Reserve Policy True
rw_timeout 30 Read/Write Timeout value True
scsi_id 0x10500 SCSI ID False
size 294225 Size in Mbytes False
write_cache yes Write Caching enabled False

Using the above commands, finding which disk belongs to which controller on a SAN on AIX becomes like baby steps ;)

We did a rebalance on one of the containers today. The container's size was about 50GB and it took about an hour on an IBM DS4800 SAN hooked with fiber to the database node residing on an IBM pSeries (570) machine: 4 POWER5 processors allocated and 30GB of RAM.

I tried looking up time estimation for rebalancing containers on DB2 on Google, but didn't find anything useful. Luckily, things went on smoothly.
The error file "db2diag.log" had the following with regards to rebalancing:

2009-05-18-01.05.59.552039+180 E106271503A342     LEVEL: Warning
PID : 799110 TID : 1 PROC : db2rebal 0
INSTANCE: db2ehp NODE : 000
FUNCTION: DB2 UDB, buffer pool services, sqlb_rebalance, probe:2876
MESSAGE : ADM6062I Rebalance for table space "EHP#BTABD" (ID "17") has been
completed.

2009-05-18-01.05.59.552281+180 I106271846A295 LEVEL: Warning
PID : 799110 TID : 1 PROC : db2rebal 0
INSTANCE: db2ehp NODE : 000
FUNCTION: DB2 UDB, buffer pool services, sqlb_rebalance, probe:2876
MESSAGE : PoolID 17: Last extent moved was #1866949

During the rebalancing period, the container being worked on was not showing in the list on the ERP software (SAP) and threw some errors. It was working fine on the database level however. After the process completed, SAP reported the new containers properly.

Tuesday, May 19, 2009

Zombie Twitter Tweets

According to this piece of news, Tweleted is a website that hosts deleted Twitter posts.

Did you make a boo-boo and posted your private email? Your password? Your girlfriend's phone number?
Too bad! Someone else has most likely got hold of it already! HAHA!

In my opinion, Twitter is quite intrusive to one's personal life, even when it's by choice. You make it quite easy for "Big Brother" or anyone eyeing your account to collect data.

If you're too lazy to read the article above, I'll summarize an important section: Hijackers present games to encourage people to share information; like name of your pet and first name of your favorite teacher.

Looking at the new measure that NBK took in Kuwait, these can be used wildly!