Asterisk - VOIP

Montando um servidor VOIP com baixo custo.

- Necessita-se de um cartão internacional. Caso não possua, peça um na livraria saraiva, a anuidade é grátis.

http://www.livrariasaraiva.com.br/cartao-saraiva/

- Criar um servidor na Amazon Web Service. Utilizando servidores no plano Spot (Rodando apenas na memória) o custo vai lá em baixo.

http://aws.amazon.com/pt/pricing/ec2/

- Criar uma conta para terminação voip.

Voxbeam -> http://www.voxbeam.com/pt/tarifas

Brasilfone -> http://www.brasilfone.com.br/

Valor do Investimento (Sem mão de obra)

Cartão de crédito (Livraria Saraiva) = $0,00 (Anuidade grátis)

Servidor Amazon (Spot) = $ 0.004/hora ( $0.004 * 24 * 30 = $2.88/mês)

Terminação Voip Voxbeam (Standard) = $ 0.016/min (Fixo), $ 0.0295/min (Móvel)

Montando um servidor Asterisk na Amazon (ami-3a993c27)

1 - Crie um servidor e atribua um Elastic IP

No exemplo abaixo foi criado um servidor SPOT (somente na memória para teste), Amazon Linux AMI 2013.03.1 - 64bits, com Elastic ip 54.232.214.101, e ip interno 172.31.10.53

2 - Amazon - Atualizar Kernel otimizado para VOIP

# Baseado no "Amazon Linux AMI 2013.03.1 - 64bits"

Fonte: http://www.fogonacaixadagua.com.br/2009/09/compilando-um-novo-kernel-no-linux-centos-5-3-red-hat-5-3/

# yum install gcc make bison ncurses-devel rpm-build

# cd /root

# wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.4.47.tar.xz

# tar -xJf linux-3.4.47.tar.xz -C /usr/src/kernels

# wget https://www.kernel.org/pub/linux/kernel/projects/rt/3.4/patch-3.4.47-rt62.patch.bz2

# bunzip2 patch-3.4.47-rt62.patch.bz2

# mv patch-3.4.47-rt62.patch /usr/src/kernels/linux-3.4.47

# cd /usr/src/kernels/linux-3.4.47

# patch -p1 < patch-3.4.47-rt62.patch

# make clean

# cp /boot/config-`uname -r` .config

# make menuconfig

General setup -> Local version -> "-voip"

Processor type and features -> Preemption Mode -> “Fully Preemptible kernel (RT)”

Processor type and features -> Time frequency -> “1000 HZ”

Device Drivers -> Character Devices -> Enchanced Real Time Clock Support -> M

Ao sair da configuração, será solicitado que você grave as alterações feitas. Responda Yes.

# make rpm (vai demorar muito, cerca de 3 horas)

# ls -alh /root/rpmbuild/RPMS/x86_64

# rpm -ivh /root/rpmbuild/RPMS/x86_64/kernel-3.4.47_rt62_voip-1.x86_64.rpm

# ls /boot

# depmod 3.4.47-rt62-voip

# mkinitrd -v /boot/initramfs-3.4.47-rt62-voip.img 3.4.47-rt62-voip

# chmod 755 /boot/vmlinuz-3.4.47-rt62-voip

# vi /boot/grub/grub.conf

default=1

(Adicione abaixo da configuração do kernel atual)

title Amazon Linux 2013.03 VOIP (3.4.47-rt62-voip)

root (hd0)

kernel /boot/vmlinuz-3.4.47-rt62-voip root=LABEL=/ console=hvc0

initrd /boot/initramfs-3.4.47-rt62-voip.img

# reboot

3 - Instalando o Asterisk no servidor Amazon

# cp /usr/share/zoneinfo/America/Sao_Paulo /etc/localtime

# vi /etc/security/limits.conf

root soft nofile 4096

root hard nofile 8196

asterisk soft nofile 4096

asterisk hard nofile 8196

# yum install gcc gcc-c++ compat-libtermcap sqlite-devel ncurses-devel openssl-devel libxml2-devel unixODBC-devel libcurl-devel

# cd /root

# wget http://downloads.asterisk.org/pub/telephony/asterisk/asterisk-11-current.tar.gz

# tar -vzxf asterisk-11*.tar.gz

# cd /root/asterisk-11.4.0/contrib/scripts

# ./install_prereq install

# cd /root/asterisk-11.4.0

# ./configure

# make menuselect

# make

# make install

# make samples

# make config

# make install-logrotate

# vi /root/.bash_profile

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib

export PATH LD_LIBRARY_PATH

# asterisk -vvvc

# echo "/usr/sbin/safe_asterisk" >> /etc/rc.local

# yum update

# hostname

# vi /etc/hosts

127.0.0.1 localhost … resultadoDoHostname

# cd /etc/asterisk

# mv sip.conf sip.conf.ori

# mv extensions.conf extensions.conf.ori

asterisk.conf

[options]

internal_timing=yes

logger.conf

dateformat=%F %T

messages => notice,warning,error,security

sip.conf

[general]

port=5060

bindaddr=0.0.0.0

externip=54.232.214.101

localnet=172.31.0.0/255.255.240.0

disallow=all

allow=gsm

allow=ulaw

allow=alaw

allow=ilbc

alwaysauthreject=yes

allowguest=yes

nat=force_rport,comedia

qualify=yes

canreinvite=no

sipreinvite=no

insecure=port,invite

[voxbeam_outbound]

type=peer

defaultuser=voxbeam_outbound

secret=your_asterisk_password

host=sbc.voxbeam.com

context=voxbeam_outbound

[voxbeam_inbound]

type=peer

defaultuser=voxbeam_inbound

secret=your_asterisk_password

host=95.211.119.240

context=voxbeam_inbound

[contato]

fromuser=visitante

defaultuser=contato

context=disca

type=friend

host=dynamic

secret=sua_senha_de_contato

extensions.conf

[general]

TIMEOUT=14400

[disca]

exten => _3788270766,1,Dial(SIP/voxbeam_outbound/0011103553788270766,40,tT)

same => n,Set(TIMEOUT(absolute)=${TIMEOUT})

same => n,HangUp()

exten => _037XXXXXXXX,1,NoOp(CALLERID: ${CALLERID(all)} EXTEN: ${EXTEN})

same => n,Set(TIMEOUT(absolute)=${TIMEOUT})

same => n,Dial(SIP/voxbeam_outbound/001110355${EXTEN:1},40,tT)

same => n,HangUp()

exten => _0XXXXXXXXXX,1,NoOp(CALLERID: ${CALLERID(all)} EXTEN: ${EXTEN})

same => n,Set(TIMEOUT(absolute)=${TIMEOUT})

same => n,Dial(SIP/001110355${EXTEN:1}@sbc.voxbeam.com,40,tT)

same => n,HangUp()

exten => _0XXXXXXXXXXX,1,NoOp(CALLERID: ${CALLERID(all)} EXTEN: ${EXTEN})

same => n,Set(TIMEOUT(absolute)=${TIMEOUT})

same => n,Dial(SIP/001110355${EXTEN:1}@sbc.voxbeam.com,40,tT)

same => n,HangUp()

exten => 12345,1,Answer()

same => n,Set(TIMEOUT(absolute)=${TIMEOUT})

same => n,Wait(2)

same => n,Playback(hello-world)

same => n,Record(/tmp/teste.gsm,3,10)

same => n,Playback(/tmp/teste)

same => n,HangUp()

exten => h,1,NoOp(CALLERID: ${CALLERID(all)} EXTEN: ${EXTEN})

same => n,HangUp()

3 - Configurando Fail2Ban

# cd /root

# wget https://codeload.github.com/fail2ban/fail2ban/tar.gz/0.8.10

# mv 0.8.10 fail2ban-0.8.10.tar.gz

# tar vzxf fail2ban-0.8.10.tar.gz

# cd fail2ban-0.8.10

# python setup.py install

# vi /etc/fail2ban/jail.conf

bantime = 259200

findtime = 60

[asterisk-tcp]

enabled = true

maxretry = 3

bantime = 259200

[asterisk-udp]

enabled = true

...

maxretry = 3

bantime = 259200

# cat /root/fail2ban-0.8.10/testcases/files/logs/asterisk >> /var/log/asterisk/messages

# fail2ban-regex /var/log/asterisk/messages /etc/fail2ban/filter.d/asterisk.conf

# echo "" > /var/log/asterisk/messages

# fail2ban-client start

# echo "/usr/bin/fail2ban-client start" >> /etc/rc.local