레이블이 asterisk인 게시물을 표시합니다. 모든 게시물 표시
레이블이 asterisk인 게시물을 표시합니다. 모든 게시물 표시

2012년 5월 3일 목요일

Resolving Audio Problems


Reference : http://www.freepbx.org/support/documentation/howtos/howto-resolving-audio-problems

One of the most common issues to plague new users is the lack of audio. Calls appear to complete, and show up in the call detail, etc. but nothing is heard by one or both of the parties on the conversation. This section of the wiki will be devoted to such problems and their solutions, and I encourage others to add to it as you encounter problems and then discover the solution, particularly if it's not posted here already.

NAT issues

Perhaps the most common problem encountered is one-way audio and 99% of the time this is caused by a NAT firewall. So here are the steps you must take to configure FreePBX to work behind a NAT firewall.

Make sure you have a resolvable address on the Internet.

If you don't want to pay a few bucks to get a static IP address, and are served by an ISP that periodically changes your IP address, then get a free account with DynDNS or some similar service. Your router may already have built-in support for one or more of these services, if so, use one that your router supports and then configure your router to automatically update your dynamic address when your ISP changes your IP address. Failing that, you can set up an updater program such as inadyn, there are instructions for doing that at this blog page.

Make use that your system knows its own name.

Once you get a DynDNS or other address that identifies your system on the Internet, put it in your etc/hosts file. For example, if you are assigned foo.dyndns.net, then open etc/hosts in your favorite text editor (nano, or Midnight Commander's editor will do - use mc -a from the command prompt to access Midnight Commander) and look for this line:
127.0.0.1 localhost
DO NOT REMOVE OR CHANGE THAT LINE. On a NEW line directly underneath it, place this line:
127.0.0.1 foo.dyndns.net
But substitute YOUR address, of course.

Add some information to your /etc/asterisk/sip_nat.conf file

If this file doesn't exist you'll have to create it, but make sure that the ownership and permissions match those of sip.conf and other files in that directory. You can use the command
touch /etc/asterisk/sip_nat.conf
To create the file. I personally use Midnight Commander's "Advanced CHOWN" feature to check and change permissions; if you are a true Linux geek you probably already have a preferred method.
Now edit the file and insert AT LEAST these two lines:
externip=your.external.dotted.IPaddess
localnet=192.168.0.0/255.255.255.0
The above localnet line assumes that your local network uses 192.168.0.x addresses, but if it uses something else, make the appropriate substitution.
Personally I use four lines, as follows:
nat=yes
externip=your.external.dotted.IPaddess
fromdomain=foo.dyndns.com
localnet=192.168.0.0/255.255.255.0
The "fromdomain" line would contain your public address, while "externip" contains the numeric IP address your ISP has assigned you (which hopefully doesn't change often).
If your ISP does change IP addresses on you frequently, and for some reason you can't/won't change ISP's or get a static IP address, and you are running at least Asterisk 1.2.x then there is an alternative way to specify your address to the system (however, note that some users find that this simply does not work as expected):
externhost=foo.dyndns.net
externrefresh=10
These are used IN PLACE OF the "externip" (and "fromdomain", if you have included that) lines. DO NOT use both "externhost" and "externip." Supposedly, "externhost" will cause Asterisk to perform DNS queries periodically, but they say it is "Not recommended for production environments!" and suggest using "externip" instead. "externrefresh" tells the system how often to refresh "externhost". If this method does not work for you, see the Addendum at the bottom of this document for another approach.

Reload SIP

After you have added whichever lines you need in sip_nat.conf, go to the Command Line Interface and type
sip reload
And hit enter. Alternately you could restart Asterisk, but that will interrupt any calls that are in progress.

Open the SIP and RTP ports to your Asterisk server

You must make sure that you open the correct UDP ports in your router's firewall and pointed at your Asterisk server. For SIP protocol, open UDP (NOT TCP) port 5060 (SIP) AND ports 10001-20000 (RTP, which must also be defined in /etc/asterisk/rtp.conf, see below). All these ports are UDP, opening the TCP ports will NOT help anything and may expose your system needlessly. While you are in your firewall configuration, you may as well also open UDP port 4569 (IAX), since sooner or later you'll probably want to accept IAX connections.

Check your /etc/asterisk/rtp.conf file

It should contain these two lines:
rtpstart=10001
rtpend=20000
If the port values are any different, change them. N.B. These MUST match what you opened in your firewall, and DO NOT start with port 10000, because it conflicts with usage in Webmin (and despite what anyone may tell you, Webmin does use UDP port 10000 in addition to TCP port 10000 - it uses the UDP port in an attempt to discover and communicate with other Webmin servers running on your network. So don't believe anyone who tells you that Webmin only uses TCP port 10000 and therefore there is no conflict).
Some people feel the need to open fewer than 10,000 ports. I don't recommend this because six months from now when you start having audio problems you may not remember that you opened fewer than the recommended number of ports, and may spend hours troubleshooting the issue. But if you are simply obsessive about open ports, remember that each open SIP connection may require as many as FOUR concurrent ports, so don't cut it down to some ridiculously small number. For the non-paranoid, I suggest sticking with the recommendations above (and remember, if a hacker is looking at ports on your system, he's going to scan ALL of them, so having fewer UDP ports open really doesn't make you any more secure).

CODEC issues

Whenever a call is placed, both ends of the call must agree on the codecs they want to use. If one end speaks only ulaw and the other end refuses to communicate using anything other than gsm, no communication is going to take place. This is why I would recommend that beginners always allow ulaw (also known as g.711u) and alaw (also known as g.711a) unless specifically instructed not to but whomever you are connecting to. There are actually five different places that codecs can be specified:
  • At an endpoint/device (phone or ATA), typically in the device's configuration.
  • In a FreePBX EXTENSION configuration, however it's best to leave those settings blank in most cases.
  • In a FreePBX TRUNK configuration, using allow= statements coupled with disallow=all. If these are omitted, then the defaults in sip.conf and iax.conf are used.
  • In sip.conf, using allow= statements coupled with disallow=all. These are the system defaults for SIP calls but can be overridden by trunk or extension settings.
  • In iax.conf, using allow= statements coupled with disallow=all. These are the system defaults for IAX calls but can be overridden by trunk or extension settings.
Note that as of Asterisk 1.4, the order of allow and disallow statements is important. If you use a disallow=all statement, it must be placed before any allow statements, because if it is placed after any allow statements it will negate them. This was not the case in Asterisk 1.2 and earlier versions.
Asterisk will attempt to translate formats if the codecs are available on the system and allowed for that leg of the call. So if you have a trunk that only allows gsm but your extensions will only communicate in ulaw, that's not a problem as long as you have allowed gsm in the trunk configuration. To see the available codecs and translations, type core show translation (or just show translation in Asterisk 1.2 and earlier) from the Command Line Interface - if there is a number showing between two codecs in the grid then translations are possible, if a single line (and it's not to the same codec) then translations are not possible, usually because one of the codecs isn't installed on the system.

Missing files/incorrect paths

If calling into an IVR or voicemail box, and the expected recording isn't played, it's possible that it's missing or not in the expected location. Did you use the System Recordings module to import the recording? If not, are you sure it's in the correct location?

Permissions/ownership issues

This most commonly occurs when people copy audio files directly onto the system and forget that it's a Linux box and that Linux is finicky about file permissions and ownership. If permissions or ownership aren't correct, Asterisk will be unable to access the file, and therefore can't play it. One thing you can try to resolve this is to run the following from the Linux command prompt:
amportal chown
This is supposed to set appropriate permissions on files used by Asterisk

Incorrect audio format

Sometimes people create system audio files using an external sound file editor, such as Audacity, in order to get better sound quality. What they don't realize is that Asterisk is very picky about the format of audio files it will play back. For example, if the file is .wav file format, Asterisk wants a file recorded at 8000 Hz, 16 bit, monaural (a.k.a. single channel) format and if you directly upload a file in any other format, the CLI may show that the file is being played, but callers hear nothing. If normal system files play correctly but the files you've created do not, check the format, especially if you've directly copied it to a particular location on the system instead of importing it with the System Recordings module.

Hardware issues

Yes, even a hardware problem can cause audio failures. In one case, a T1 card had been installed in the system but not configured, and that stopped all recorded audio from being played. So if all else fails, look for any unconfigured or misconfigured hardware device, particularly if it's a zaptel card (it appears that having ANY non-configured zaptel card in a system may cause problems with audio output).

Addendum: A Perl script to rewrite sip_nat.conf when your IP address changes

The following is a Perl script that checks your IP address using whatismyip.com, and rewrites /etc/asterisk/sip_nat.conf if the external IP address has changed. Note that you may have to install additional Perl modules, and you WILL need to modify one line in the script:
#!/usr/bin/perl

#
# This program gets the current IP address (as assigned by the ISP) from
# whatismyip.org and modifies /etc/asterisk/sip_nat.conf if the external IP
# address has changed. You can Use Webmin to install any missing Perl
# modules, and to invoke the script as cron job that runs every 5 minutes
#
use strict;
use warnings;
use WWW::Mechanize;
use Tie::IxHash;
use Data::Validate::IP qw(is_public_ipv4);
my $s_filepath = "/etc/asterisk/sip_nat.conf";
my $mech = WWW::Mechanize->new( autocheck => 1 );
$mech->get('http://whatismyip.com/automation/n09230945.asp');
$mech->success or die 'Cannot connect to http://whatismyip.com/automation/n09230945.asp';
my ($ip) = ($mech->content() =~ /(\d+\.\d+\.\d+\.\d+)/);
if (is_public_ipv4($ip)) {
 tie my %configvars, 'Tie::IxHash';
# The 'fromdomain' (& possibly 'localnet') values in the next line MUST be changed
 %configvars = ('nat' => 'yes', 'externip' => '0.0.0.0','fromdomain' => 'foo.dyndns.com','localnet' => '192.168.0.0/255.255.255.0') ;
 open IN,"<$s_filepath";
 while (my $i = <IN>) {
  chop $i;
  if ($i =~ /=/) {
   $i =~ s/\s//g;
   my ($key,$value) = split /=/,$i;
   $configvars{$key} = $value;
  }
 }
 close IN;
 if ($configvars{'externip'} ne $ip) {
  $configvars{'externip'} = $ip;
  open OUT,">$s_filepath";
  while (my ($key, $value) = each %configvars) {
   select OUT;
   print "$key=$value\n";
  };
  select STDOUT;
  close OUT;
  `/usr/sbin/asterisk -rx reload`;
 };
};
Please be sure to change foo.dyndns.com to YOUR dynamic IP address, and 192.168.0.0/255.255.255.0 to a value consistent with your local network address range (if you are not using addresses in the 192.168.0.x range).
It is suggested that you place the above script in your /var/lib/asterisk/agi-bin/ directory, make sure the permissions and ownership are set correctly (make the script executable!), backup your existing /etc/asterisk/sip_nat.conf file, and then as a test invoke the script from a command prompt, e.g. (assuming you name the script checkip.pl):
cd /var/lib/asterisk/agi-bin
perl checkip.pl
If the script exits without printing any error messages, check /etc/asterisk/sip_nat.conf to make sure that the all of the lines in it contain correct values. If all looks as it should, you can can then set up a cron job to run the script every five minutes. I did this using Webmin's System|Scheduled Cron Jobs page, but you may prefer to do it from the command line. If you get any errors about missing Perl modules when you run the script, these will have to be installed (there are Webmin modules that can do this also - look for one called "Perl Modules" or "CPAN").
One other note - if this script is running and sip_nat.conf gets deleted for any reason, the script will probably recreate it but with the wrong ownership and permissions - so if you ever accidentally delete that file, and after that Asterisk acts like it isn't there, check the permissions and ownership to make sure it is the same as for the other sip_*.conf files in /etc/asterisk.

2012년 5월 1일 화요일

Asterisk에서 Dial Plan 설정하는 extensions.conf 파일

출처 : http://jhyuns.tistory.com/entry/PracticerAsterisk%EC%9D%98-%EB%8B%A4%EC%9D%B4%EC%96%BC%ED%94%8C%EB%9E%9C%EC%9D%98-%EC%84%A4%EC%A0%95%EC%9D%84-%EC%9C%84%ED%95%9C-extensionsconf-%EC%84%A4%EB%AA%85


Asterisk에서 Dial Plan 설정하는 extensions.conf 파일

◈ 다이얼 플랜(Dial Plan)의 개요

1. 다이얼 플랜이란?
간단히 말하자면 어느 번호의 Inbound(착신)와 Oubound(발신) Call(호)를 어떻게 처리할까 하는 통화 룰을 
결정하는 것이라 할 수 있겠 습니다.(이런 부분을 Asterisk는 자유롭게 커스텀마이즈 할 수 있다는 것이, 
Asterisk의 강점입니다.)
따라서, extensions.conf 은 위와 같은 콜의 흐름을 기술해 나가는 설정 파일이라 하겠습니다.

2. extensions.conf 파일 
Extension은 , 어느 채널의 착신(처)이나 다이얼 숫자를 기동되는 명령이 됩니다.
Call이 다이얼 플랜에 따라서 어떻게 다루어질까를 결정합니다.
이 파일에 기술 되는 다이얼 플랜은,
Context(문맥), Extension(내선번호), Priority(우선순위), Application(응용부)
의 4 부분으로 구성되어집니다. (※ 위의 한글용어는 설명을 위해 임의로 붙였습니다.)

exten => extension명(내선번호), priority(우선순위), Application(응용명령)

3. Context(문맥)
다이얼 플랜을 그룹에 이름을 붙인 것이 Context가 됩니다. 어떤 Context 안에 정의된 extension는 
다른 Context에 영향을 주지 못합니다. (단 "include =>"로 관계가 연결되지 않았을 경우임.)
Context는 괄호 [ ] 안에 표기하여 사용하며, 알파벳(대,소문자), 숫자, 하이픈(-),언더스코아(_)로만
이루어진 문자로 표기합니다. 예) [out-going], [070_inbound]

Context 중에서 [general] 은 다이얼 플랜에 관한 일반 설정이 있는 Context 이고, [global]은 설정 
파일에서 사용될 전역변수(Global Variable)를 정의하는 특별한 콘텍스트명이 있습니다.

◈ 다이얼 플랜(Dial Plan) 설정하기

전번에 설명드린 sip.conf와 연장하여 /etc/asterisk/extensions.conf 파일을 설명드리고자 합니다.

전에 sip.conf에 등록하였던 내선번호 2000~2002 사이에 통화에 대한 다이얼 플랜을 예로 들어 설명하고자 합니다.

1. 우선 /etc/asterisk/extensions.conf 파일을 백업을 하여 두십시오.

# cp /etc/asterisk/extensions.conf /etc/asterisk/extensions.conf.bak

위와 같이 백업을 해두셨다면, 신규파일을 작성하면서 설명을 보는 것이 좋다고 생각됩니다.

2. 이제 아래와 같은 내용으로 /etc/asterisk/extensions.conf 를 편집합시다.

;-------------------------이하 설정-----------------------
[default];현재 설정 없음.
[lan]exten => 2000,1,Dial(SIP/2000,30)
exten => 2000,2,Congestion
exten => 2000,102,Busy

exten => 2001,1,Dial(SIP/2001,30)
exten => 2001,2,Congestion
exten => 2001,102,Busy

exten => 2002,1,Dial(SIP/2002,30)
exten => 2002,2,Congestion
exten => 2002,102,Busy


;콜 테스트용
; 9000번 번호에 다이얼 하면, 아래 행의 순서로 실행됩니다
.
exten => 9000,1,Answer()
exten => 9000,2,Wait(1)
exten => 9000,3,Playback(demo-congrats)
exten => 9000,4,Echo()
exten => 9000,5,Hangup()
;---------------------------설정 끝 ----------------------------
위 와 같이, extensions.conf을 설정하고 asterisk를 재시작하믄 간단하게나마 내선 통화와 콜백 테스트는 
할 수 있게 될 겁니다.

3. 위파일을 적용 시키려면 콘솔 화면에서 Asterisk를 재가동합니다.

# asteriskr -vvvvvr
ipbpxsrv*CLI> reload


◈ 다이얼 플랜(Dial Plan)의 각 항목 해석

9000 번으로 콜 테스트를 성공 하면, 각각의 내선번호로 걸어 보십시오. 각각의 내선번호끼리 통화가 가능하면
위 설정이 잘 적용 된것입니다. ( 앗 ! 저의 환경에서는 약간의 에코가 걸렸습니다만, 통화는 가능 햇습니다.)

그럼 위의 설정한 다이얼 플랜의 각 항목을 설명해 보겟습니다.
/etc/asterisk/extensions.conf
 1: [default]
 2: ;현재 설정 없음.
 3:
 4: [lan]
 5: exten => 2000,1,Dial(SIP/2000,30)
 6: exten => 2000,2,Congestion
 7: exten => 2000,102,Busy

 8: exten => 2001,1,Dial(SIP/2001,30)
 9: exten => 2001,2,Congestion
10: exten => 2001,102,Busy

11: exten => 2002,1,Dial(SIP/2002,30)
12: exten => 2002,2,Congestion
13: exten => 2002,102,Busy

14: ; 콜 테스트용
15: ; 9000 번호에 다이얼 하면, 아래의 행의 순서로 실행됩니다.
16: exten => 9000,1,Answer()
17: exten => 9000,2,Wait(1)
18: exten => 9000,3,Playback(demo-congrats)
19: exten => 9000,4,Echo()
20: exten => 9000,5,Hangup()

[해설]
1행    Context [default]는 sip.conf 등으로 현재 사용하고 있었습니다만,
     [general]에 기술되어 있기 때문에, 준비되어 있어라고 하는 것으로 기입했습니다.

4행    sip.conf그리고 기술한, Context [lan]을 준비합니다.

5행    exten => 2000,1,Dial(SIP/2000,30) 
      Dial()함수로 SIP의 2000(내선2000)을 불러 내며(calling), 응답 제산시간을 30초로 하고 있습니다.
      2000(내선2000)이 응답하면 통화가 가능 합니다.
      제한 시간 내에 응답하지 않을 경우, 현재의 우선 순위(priority)에+1(합계2)해, 거기에 대응한
레코드를 호출합니다.
      그리고 2000(내선2000)이 통화중인 경우 원래 호출 자체를 할 수 없는 경우는 현재의 우선 순위에
+101되어 대응 레코드가 불려 갑니다.

6행    exten => 2000,2,Congestion
      우선 순위가2, 즉 Dial() 함수로 2000을 콜링하여,
      제한 시간내에 응답하지 않았던 경우에 호출되는 부분입니다..
      Congestion 명령어는 발신측이 자르는 것을 기다립니다. 자를 때까지는 절단음이 흐릅니다.


7행    exten => 2000,102,Busy
      우선 순위가102, 즉 2000(내선2000)이 다른 곳과 통화중에 있어,
      Dial() 함수로 2000을 호출할 수 없었던 경우의 처리입니다.
      Busy명령어로 Busy음을 흘립니다.


8~10행  2001의 설정

11~13행 2002의 설정

16행   exten => 9000,1,Answer()
     9000번의 콜에 응답합니다.

17행   exten => 9000,2,Wait(1)
     착신과 동시에 음성을 발생시키면, 이야기 처음이 빠지는 일이 있으므로1초 wait 시킵니다.

18행   exten => 9000,3,Playback(demo-congrats)
     demo-congrats.gsm파일을 재생합니다. 확장자(extension)는 기입할 필요는 없습니다.

19행   exten => 9000,4,Echo()
     메세지 재생 후(선택한 녀석이라면 길다!)자신의 소리를 에코 해 줍니다.
발신자가 '#' 를 누르면 종료합니다.

20행째  exten => 9000,5,Hangup()
     끊기, 콜의 단절을 실시합니다.



방금전의 내선의 정보를 정리해 보겠습니다.(매크로 지정)

위에서는 3개의 내선번로만 다이얼 플랜을 했을 뿐입니다만, 많은 내선번홀 가지고 위와 같은 내용을 복수 써 가며 설 
정 하는 것은 큰 일입니다.
200X 로 시작되는 번호를 같은 동작을 주도록 다음과 같이 합니다.

붉은 글씨는 변경하기위하여 삭제될 문이다.
현재의 파일
 
1: [default]
 2: ;현재 설정 없음.
 3:
 4: [lan]
 5: exten => 2000,1,Dial(SIP/2000,30)
 6: exten => 2000,2,Congestion
 7: exten => 2000,102,Busy

 8: exten => 2001,1,Dial(SIP/2001,30)
 9: exten => 2001,2,Congestion
10: exten => 2001,102,Busy

11: exten => 2002,1,Dial(SIP/2002,30)
12: exten => 2002,2,Congestion
13: exten => 2002,102,Busy

14:; 콜 테스트용
15:; 9000 번호에 다이얼 하면 아래의 행 순서로 실행됩니다.
16: exten => 9000,1,Answer()
17: exten => 9000,2,Wait(1)
18: exten => 9000,3,Playback(demo-congrats)
19: exten => 9000,4,Echo()
20: exten => 9000,5,Hangup()

변경 후의 파일
녹색 글자가 바뀐 글자이다.
 1: [default]
 2: ;현재 설정 없음.
 3:
 4: [lan]
 5: exten => _200X,1,Dial(SIP/{EXTEN},30)
 6: exten => _200X,2,Congestion
 7: exten => _200X,102,Busy

 8: ; 콜 테스트용
 9: ; 9000번호로 다이얼 하면 아래의 행 순서로 실행됩니다.
10: exten => 9000,1,Answer()
11: exten => 9000,2,Wait(1)
12: exten => 9000,3,Playback(demo-congrats)
13: exten => 9000,4,Echo()
14: exten => 9000,5,Hangup()

내선마다 준비해 있었던 extension을 하나로 정리했습니다.

1.”_200X”와 같이”_”로 시작되는 경우는, 패턴 지정이라고 나타내 보입니다.2.다음의 문자를 사용할 수 있습니다.

   X : 0 - 9 의 숫자  

   Z : 1 - 9 의 숫자
   N : 2 - 9 의 숫자
   [12679] : 1,2,6,7,9
    . : 와일드 카드
   여기에서는 200X 그러니까, 2000~2009번까지를 지정해 있습니다.

3.${EXTEN} 은 입력된 내선 번호가 들어가는 환경 변수입니다.,
  "2000" 과 다이얼 되면 ${EXTEN} 는, "2000" 되어, "내선 번호 "2000" 가 호출되어집니다.



4. extensions.conf를 리로드 하려면 ,
asterisk의 화면에서
# asterisk -vvvvr
>extensions reload
을 실행 합니다.

2012년 4월 30일 월요일

CentOS 5.2 and Asterisk 1.6.x installation

Reference : http://www.voip-info.org/wiki/view/CentOS+5.2+and+Asterisk+1.6.x+installation



This is a work in progress - copied from my CentOS 5 and Asterisk 1.4.x installation page



Base Install of Asterisk on an i386 CentOS/RHEL box:

More as an aide memoir for us than anything else, but if somebody does find it useful, then that's good too!

For reasons detailed elsewhere, you're best not using a GUI, so do the installation from the command line ('linux-text' at the GRUB prompt). When you select the packages, the only one you need is 'server'. Disk partitioning, networking etc. is all entirely up to you!

At your first login, you'll be presented with a simple administration screen. Disable SELinux and (for now) the firewall.

Dependencies

The first thing to do is to get your box up to date. Try:
yum -y upgrade

and then reboot. Otherwise, to update all the installed packages, at the shell, run
yum -y update

When you've done either of the above, reboot the machine when it's finished (as it'll install a new kernel) and then run
yum -y update

again and repeat until there are no more updates.

Quick method:

Do you trust me? If so, the line below will install all the dependencies you need (and then some!) - cut and paste from here if you're happy to install things you may or may not need.
yum -y install gcc gcc-c++ kernel-devel bison \
openssl openssl-devel perl perl-Net-SSLeay perl-Crypt-SSLeay \
libtermcap-devel ncurses-devel doxygen curl-devel newt-devel \
mlocate lynx tar wget nmap bzip2 mod_ssl crontabs vixie-cron \
speex speex-devel unixODBC unixODBC-devel libtool-ltdl \
libtool-ltdl-devel mysql-connector-odbc mysql mysql-devel \
mysql-server php-mysql php-mbstring php-mcrypt flex screen \
libtiff-devel


Individual application specific dependencies

Asterisk

We've got to be able to compile it!
yum -y install gcc gcc-c++

Note that you may need to use the following if you are running a Xen enabled kernel:
yum -y install kernel-xen-devel

If you want the 'zttool' application, you'll need to:
yum -y install newt-devel

Other things you may find useful (if they're not already installed):
yum -y install mlocate lynx tar wget nmap bzip2 mod_ssl crontabs vixie-cron


Speex (optional)

Speex support depends on 'speex_preprocess_ctl' which is not available in the standard Speex packages. It may be possible to compile an older version of Speex if required.

ODBC stuff (optional)

Note that if you have already installed Asterisk, you will need to run 'configure', 'make' and 'make install' to detect ODBC and compile it in.
yum -y install unixODBC unixODBC-devel libtool-ltdl libtool-ltdl-devel


MySQL ODBC interface/connector (optional, but required if using ODBC and MySQL)

yum -y install mysql-connector-odbc

And then edit the file '/etc/odbcinst.ini' (or '/usr/local/odbcinst.ini') and replace 'Driver = /usr/lib/libmyodbc.so' with 'Driver = /usr/lib/libmyodbc3.so'

MySQL (optional)

yum -y install mysql mysql-devel mysql-server
chkconfig mysqld on
service mysqld start


PHPMyAdmin (optional)

Download the latest version from http://www.phpmyadmin.net/, unzip/unbzip/untar into /var/www/htdocs/phpmyadmin (for the time being). Make sure Apache starts on boot.
yum -y install php-mysql php-mbstring php-mcrypt
chkconfig httpd on
service httpd start

Surf to https://i.p.address/phpmyadmin and check it works.

Webmin (optional)

If SSL is required, ensure that the correct bits are installed
yum -y install openssl openssl-devel perl perl-Net-SSLeay perl-Crypt-SSLeay

Download the latest version of the RPM from http://www.webmin.com/
rpm -i webmin-VERSION
chkconfig webmin on
service webmin start

Surf to https://i.p.address:10000 and check it works.

Download and install Asterisk and components

Download

Download the latest asterisk version /usr/src/asterisk and untar the files as follows:
mkdir -p /usr/src/asterisk
cd /usr/src/asterisk
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://soft-switch.org/downloads/spandsp/spandsp-0.0.6pre18.tgz (or most current version)
wget http://downloads.digium.com/pub/libpri/libpri-1.4-current.tar.gz
tar -zxf dahdi-linux-complete-current.tar.gz
tar -zxf asterisk-1.6.1-current.tar.gz
tar -zxf spandsp-0.0.6pre18.tgz
tar -zxf libpri-1.4-current.tar.gz
tar -zxf asterisk-addons-1.6.1-current.tar.gz

You'll end up with five tar files and five directories in the directory '/usr/src/asterisk'.


SpanDSP (optional)

cd /usr/src/asterisk/spandsp-0.0.6
make clean
./configure
make
make install
cat > /etc/ld.so.conf.d/spandsp.conf << EOF
/usr/local
/usr/local/lib
EOF
ldconfig -v

Libpri (optional)

If you are using E1 cards you need to install LIBPRI. If you do want to use LIBPRI, make sure you compile and install it before you compile Asterisk. Replace 'VERSION' with the correct details.
cd /usr/src/asterisk/libpri-VERSION
make clean
make
make install


DAHDI

You're pretty much going to need DAHDI. If not for any hardware then for the dummy timer anyway. Note that the stock CentOS kernels come with a 1000HZ timer and so don't need recompiling (phew!). Replace 'VERSION' with the correct details.
cd /usr/src/asterisk/dahdi-linux-complete-VERSION
make all
make install
make config

Edit /etc/dahdi/modules, /etc/dahdi/system.conf and /etc/asterisk/chan_dahdi.conf for your site.
Set DAHDI to start automatically and then start it.
chkconfig dahdi on
service dahdi start


Asterisk

cd /usr/src/asterisk/asterisk-VERSION
make clean
./configure

Choose which options to install (audio files, voicemail storage, codecs etc.)
make menuselect
make
make install

Install sample files in /etc/asterisk, install docs/manpages and set to start on boot.
make samples
make progdocs
make config
chkconfig asterisk on

Check Asterisk starts properly:
asterisk -vvvvvvvvvvvvvvvvvvvc
stop now

If not, you've probably not been following these instructions carefully! Assuming it does start properly, you probably want to start it in the background:
service asterisk start


Asterisk-addons

cd /usr/src/asterisk/asterisk-addons-VERSION

make clean
./configure
make menuselect

Choose what you do and don't want. Unless you really need oh323, deselect it as it can be the cause of compilation woes.
make
make install

Install sample files in /etc/asterisk
make samples

Edit /etc/asterisk/cdr_mysql.conf and add 'loguniqueid=yes' to the global section.

mISDN drivers for Digium B410P (optional)

Removed - have yet to test installation with DAHDI



Configure MySQL (optional)

The information below shows table definitions for all of the tables Asterisk can use with MySQL or ODBC.

Notes

The UniqueID field in the CDR table is not necessarily unique! Due to the very very dodgy way Asterisk handles unique IDs, if you set the field to be the primary key (as advised elsewhere), you will lose data.

SQL

Note that the SIP 'qualify' field has a default value set to 'yes'. This is for two reasons. Firstly, I wrote these notes because it's how I use and want to use Asterisk. Secondly, whether qualification is enabled or not in realtime is controlled by the 'rtcachefriends' setting in sip.conf - if it's 'no', then whether 'qualify' is 'yes' or 'no' in the database is irrelevant. It makes sense therefore to enable it in the database and then turn it on or off with the 'rtcachefriends' setting.

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

    1. Database: `asterisk`
CREATE DATABASE `asterisk` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
USE `asterisk`;


    1. Table structure for table `cdr`

CREATE TABLE IF NOT EXISTS `cdr` (
`recid` mediumint(8) unsigned NOT NULL auto_increment COMMENT 'Record ID',
`calldate` datetime NOT NULL default '0000-00-00 00:00:00',
`clid` varchar(80) NOT NULL default '',
`src` varchar(80) NOT NULL default '',
`dst` varchar(80) NOT NULL default '',
`dcontext` varchar(80) NOT NULL default '',
`channel` varchar(80) NOT NULL default '',
`dstchannel` varchar(80) NOT NULL default '',
`lastapp` varchar(80) NOT NULL default '',
`lastdata` varchar(80) NOT NULL default '',
`duration` int(11) NOT NULL default '0',
`billsec` int(11) NOT NULL default '0',
`disposition` varchar(45) NOT NULL default '',
`amaflags` int(11) NOT NULL default '0',
`accountcode` varchar(20) NOT NULL default '',
`uniqueid` varchar(32) NOT NULL default '',
`userfield` varchar(255) NOT NULL default '',
PRIMARY KEY (`recid`),
KEY `calldate` (`calldate`),
KEY `dst` (`dst`),
KEY `accountcode` (`accountcode`),
KEY `src` (`src`),
KEY `disposition` (`disposition`),
KEY `uniqueid` (`uniqueid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;


    1. Table structure for table `queue_members`

CREATE TABLE IF NOT EXISTS `queue_members` (
`queue_name` varchar(128) NOT NULL default '',
`interface` varchar(128) NOT NULL default '',
`penalty` int(11) default NULL,
PRIMARY KEY (`queue_name`,`interface`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;


    1. Table structure for table `queues`

CREATE TABLE IF NOT EXISTS `queues` (
`name` varchar(128) NOT NULL,
`musiconhold` varchar(128) default 'default',
`announce` varchar(128) default NULL,
`context` varchar(128) default NULL,
`timeout` int(11) default '60',
`monitor_join` tinyint(1) default NULL,
`monitor_format` varchar(128) default NULL,
`queue_youarenext` varchar(128) default NULL,
`queue_thereare` varchar(128) default NULL,
`queue_callswaiting` varchar(128) default NULL,
`queue_holdtime` varchar(128) default NULL,
`queue_minutes` varchar(128) default NULL,
`queue_seconds` varchar(128) default NULL,
`queue_lessthan` varchar(128) default NULL,
`queue_thankyou` varchar(128) default NULL,
`queue_reporthold` varchar(128) default NULL,
`announce_frequency` int(11) default NULL,
`announce_round_seconds` int(11) default NULL,
`announce_holdtime` varchar(128) default NULL,
`periodic_announce` varchar(128) default NULL,
`periodic_announce_frequency` int(11) default NULL,

`retry` int(11) default '5',
`ringinuse` varchar(5) NOT NULL default 'no',
`autofill` varchar(5) NOT NULL default 'yes',
`autopause` varchar(5) NOT NULL default 'no',
`setinterfacevar` varchar(5) NOT NULL default 'yes',
`wrapuptime` int(11) default '30',
`maxlen` int(11) default NULL,
`servicelevel` int(11) default NULL,
`strategy` varchar(128) default 'ringall',
`joinempty` varchar(128) default 'no',
`leavewhenempty` varchar(128) default 'yes',
`eventmemberstatus` tinyint(1) default NULL,
`eventwhencalled` tinyint(1) default NULL,
`reportholdtime` tinyint(1) default NULL,
`memberdelay` int(11) default NULL,
`weight` int(11) default NULL,
`timeoutrestart` tinyint(1) default NULL,
PRIMARY KEY (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;


    1. Table structure for table `sip`

CREATE TABLE IF NOT EXISTS `sip` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(80) NOT NULL,
`host` varchar(31) NOT NULL default 'dynamic',
`nat` varchar(5) NOT NULL default 'no',
`type` enum('user','peer','friend') NOT NULL default 'friend',
`accountcode` varchar(20) default 'ACCOUNT',
`amaflags` varchar(13) default NULL,
`callgroup` varchar(10) default NULL,
`callerid` varchar(80) default NULL,
`call-limit` varchar(6) NOT NULL default '10',
`cancallforward` char(3) default 'yes',
`canreinvite` char(3) default 'no',
`context` varchar(80) default 'from-sip',
`defaultip` varchar(15) default NULL,
`dtmfmode` varchar(7) default 'rfc2833',
`fromuser` varchar(80) default NULL,
`fromdomain` varchar(80) default NULL,
`insecure` varchar(4) default NULL,
`language` char(2) default 'en',
`mailbox` varchar(50) default NULL,
`md5secret` varchar(80) default NULL,
`deny` varchar(95) default '0.0.0.0/0.0.0.0',
`permit` varchar(95) default '0.0.0.0/0.0.0.0',
`mask` varchar(95) default NULL,
`musiconhold` varchar(100) default 'default',
`pickupgroup` varchar(10) default NULL,
`qualify` char(3) default 'yes',
`regexten` varchar(80) default NULL,
`restrictcid` char(3) default NULL,
`rtptimeout` char(3) default NULL,
`rtpholdtimeout` char(3) default NULL,
`secret` varchar(80) default 'SECRET',
`setvar` varchar(100) default NULL,
`disallow` varchar(100) default 'all',
`allow` varchar(100) default 'alaw',
`fullcontact` varchar(80) NOT NULL default '',
`ipaddr` varchar(15) NOT NULL default '',
`port` smallint(5) unsigned NOT NULL default '0',
`regserver` varchar(100) default NULL,
`regseconds` int(11) NOT NULL default '0',
`username` varchar(80) NOT NULL,
`defaultuser` varchar(80) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`),
KEY `name_2` (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC AUTO_INCREMENT=301 ;


    1. Table structure for table `voicemail_messages`

CREATE TABLE IF NOT EXISTS `voicemail_messages` (
`id` int(11) NOT NULL auto_increment,
`msgnum` int(11) NOT NULL default '0',
`dir` varchar(80) default '',
`context` varchar(80) default '',
`macrocontext` varchar(80) default '',
`callerid` varchar(40) default '',
`origtime` varchar(40) default '',
`duration` varchar(20) default '',
`mailboxuser` varchar(80) default '',
`mailboxcontext` varchar(80) default '',
`recording` longblob,
PRIMARY KEY (`id`),
KEY `dir` (`dir`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1088 ;


    1. Table structure for table `voicemail_users`

CREATE TABLE IF NOT EXISTS `voicemail_users` (
`uniqueid` int(11) NOT NULL auto_increment,
`customer_id` varchar(11) NOT NULL default '0',

`context` varchar(50) NOT NULL default 'default',
`mailbox` varchar(11) NOT NULL default '0',
`password` varchar(5) NOT NULL default '6666',
`fullname` varchar(150) NOT NULL,
`email` varchar(50) NOT NULL,
`pager` varchar(50) NOT NULL,
`tz` varchar(10) NOT NULL default 'en',
`attach` varchar(4) NOT NULL default 'yes',
`saycid` varchar(4) NOT NULL default 'yes',
`dialout` varchar(10) NOT NULL,
`callback` varchar(10) NOT NULL,
`review` varchar(4) NOT NULL default 'no',
`operator` varchar(4) NOT NULL default 'no',
`envelope` varchar(4) NOT NULL default 'no',
`sayduration` varchar(4) NOT NULL default 'no',

`saydurationm` tinyint(4) NOT NULL default '1',
`sendvoicemail` varchar(4) NOT NULL default 'no',
`delete` varchar(4) NOT NULL default 'no',
`nextaftercmd` varchar(4) NOT NULL default 'yes',
`forcename` varchar(4) NOT NULL default 'no',
`forcegreetings` varchar(4) NOT NULL default 'no',
`hidefromdir` varchar(4) NOT NULL default 'yes',
`stamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
PRIMARY KEY (`uniqueid`),
KEY `mailbox_context` (`mailbox`,`context`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=101 ;

    1. ########################################################

    1. Create realtime user with approximately the right privs.

CREATE USER 'astrealtime'@'localhost' IDENTIFIED BY 'MYPASS';
GRANT FILE ON * . * TO 'astrealtime'@'localhost' IDENTIFIED BY 'MYPASS' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;
GRANT INSERT ON `asterisk`.`cdr` TO 'astrealtime'@'localhost';
GRANT SELECT , INSERT , UPDATE , DELETE ON `asterisk`.`queue_members` TO 'astrealtime'@'localhost';
GRANT SELECT , UPDATE ON `asterisk`.`queues` TO 'astrealtime'@'localhost';
GRANT SELECT , UPDATE ON `asterisk`.`sip` TO 'astrealtime'@'localhost';
GRANT SELECT , UPDATE ON `asterisk`.`voicemail_users` TO 'astrealtime'@'localhost';
GRANT SELECT , UPDATE , INSERT , DELETE ON `asterisk`.`voicemail_messages` TO 'astrealtime'@'localhost';

Configure various files

Set up CDR to MySQL

Edit /etc/asterisk/cdr_mysql.conf
[global]
hostname=localhost
dbname=asterisk
table=cdr
password=MYPASS
user=astrealtime
port=3306
sock=/var/lib/mysql/mysql.sock
userfield=1

Set up realtime

Edit res_mysql.conf
[general]
dbhost = localhost
dbname = asterisk
dbuser = astrealtime
dbpass = MYPASS
dbport = 3306
dbsock = /var/lib/mysql/mysql.sock

If you are using version 1.6.0 or lower

Edit /etc/asterisk/extconfig.conf
[settings]
queues => mysql,asterisk,queues
queue_members => mysql,asterisk,queue_members
sippeers => mysql,asterisk,sip
sipusers => mysql,asterisk,sip
voicemail => mysql,asterisk,voicemail_users

If you are using version 1.6.1 or higher

Edit /etc/asterisk/extconfig.conf
[settings]
queues => mysql,asterisk,queues
queue_members => mysql,asterisk,queue_members
sippeers => mysql,asterisk,sip
sipusers => mysql,asterisk,sip
voicemail => mysql,asterisk,voicemail_users

If mysql db resides on a different host than asterisk, you will want to use "general" for the database parameter, instead of "asterisk" in extconfig.conf

Note - You may see documentation stating that whatever is in the [] section of res_mysql.conf is to be used for the "database" field in these extconfig parameters. For example
queues => mysql,general,queues ... This seems to be false, at least in version 1.6.2.10, and you should in fact use the database name referenced in "dbname" in res_mysql.config


ODBC configuration (using settings from above)

/etc/odbcinst.ini

[MySQL]
Description = ODBC for MySQL
Driver = /usr/lib/libmyodbc3.so
;For x64 systems
;Driver = /usr/lib64/libmyodbc3.so
Setup = /usr/lib/libodbcmyS.so
FileUsage = 1
(Note the '3' which isn't in the original sample file!)

/etc/odbc.ini

; DSN definitions
[astrealtime]
Description = Asterisk realtime and other FUNC_ODBC access
Driver = MySQL
Socket = /var/lib/mysql/mysql.sock
Server = localhost
User = astrealtime
Pass = MYPASS
Database = asterisk
Option = 3

/etc/asterisk/res_odbc.conf

; Environment variables
[ENV]

; Connections
[astrealtime]
enabled => yes
dsn => astrealtime
username => astrealtime
password => MYPASS
pre-connect => yes
idlecheck => 3600

/etc/asterisk/func_odbc.conf

This really depends on why you need database access from the dialplan!



Setting up Asterisk on a vserver

Removed - have yet to test installation with DAHDIn


Troubleshooting:

If sip phones are not registering to asterisk and you receive 408 request timeout, you may need to alter iptables.
iptables -I RH-Firewall-1-INPUT -p udp --dport 5060 -j ACCEPT
iptables -I RH-Firewall-1-INPUT -p udp --dport 10000:20000 -j ACCEPT
service iptables save