asterisk/freepbx HA Failover cluster on top of heartbeat, pacemaker, nfs, drbd

vladimir simeonov
15/11/2013

Настоящите инструкции представят сбор от различни how-to за изграждане на asterisk failover cluster базиран на:

asterisk

freepbx

mysql

pacemaker

heartbeat

apache2

за по – лесно изграждане и поддръжка на инсталацията, цялостната архитектура е разделена на 3 слоя. показано на диаграмата:

за изграждане на mysql/nfs failover cluster – Tier 3, следвайте инструкциите тук:

http://myboot.lordofdeath.net/2013/02/part1-load-balancing-web-cluster-with.html

Стъпки за изграждане на asterisk/freepbx failover cluster на Tier 2:

tier2-node1: 192.168.236.71

tier2-node2: 192.168.236.72

shared-IP: 192.168.236.66

t2-node1/t2-node2 –

/etc/hosts

127.0.0.1       localhost

192.168.236.71     t2-node1

192.168.236.72     t2-node2

# The following lines are desirable for IPv6 capable hosts

::1     ip6-localhost ip6-loopback

fe00::0 ip6-localnet

ff00::0 ip6-mcastprefix

ff02::1 ip6-allnodes

ff02::2 ip6-allrouters

t2-node1 –

/etc/network/interfaces

auto lo

iface lo inet loopback

# The primary network interface

auto eth0

iface eth0 inet static

address 192.168.236.71

netmask 255.255.255.0

gateway 192.168.236.1

# dns-* options are implemented by the resolvconf package, if installed

dns-nameservers 192.168.236.1

t2-node2 –

/etc/network/interfaces

auto lo

iface lo inet loopback

# The primary network interface

auto eth0

iface eth0 inet static

address 192.168.236.72

netmask 255.255.255.0

gateway 192.168.236.1

# dns-* options are implemented by the resolvconf package, if installed

dns-nameservers 192.168.236.1

Инсталираме необходимите пакети:

t3-node1/t3-node2 –

apt-get install -y heartbeat pacemaker build-essential nfs-common

Конфигурираме Heartbeat:

cat <<EOF > /etc/heartbeat/ha.cf

logfacility daemon

keepalive 2

deadtime 15

warntime 5

initdead 120

udpport 694

bcast eth0

auto_failback on

node t2-node1

node t2-node2

use_logd yes

crm respawn

ping_group internal 192.168.236.1

deadping 12

EOF

Подменете адресите от група Internal с адреси на рутер или dns сървър, които да служат за witness в случай, че двата Nodes изгубят връзка помежду си, но продължат да работят – “split brain”.

Възможно е при по – специална конфигурация на мрежата, забраняваща broadcasting, да се наложи промяна на bcast eth0 с

ucast eth0 192.168.236.71

ucast eth0 192.168.236.72

t2-node2 only:

( echo -ne “auth 1\n1 sha1 “; \

dd if=/dev/urandom bs=512 count=1 | openssl md5 ) \

> /etc/ha.d/authkeys

chmod 600 /etc/ha.d/authkeys

service heartbeat start

Копираме генерирания файл с ключове на хост t2-node2:

rsync -avzlH /etc/ha.d/authkeys t2-node2:/etc/ha.d/

t2-node1/t2-node2:

echo ‘192.168.235.66:/srv/nfs /srv    nfs     rw,soft,lock,intr 0 0’ >> /etc/fstab

mount -a

Следват инструкциите свързани с Asterisk/FreePBX инсталиране:

apt-get install -y build-essential linux-headers-`uname -r` openssh-server apache2 mysql-client bison flex php5 php5-curl php5-cli php5-mysql php-pear php-db php5-gd curl sox libncurses5-dev libssl-dev mpg123 libxml2-dev libnewt-dev sqlite3 libsqlite3-dev pkg-config automake libtool autoconf git subversion uuid uuid-dev

t2-node1-

mkdir -p /srv/apache2/conf

mkdir -p /srv/apache2/www

mkdir -p /srv/asterisk/conf

mkdir /srv/asterisk/dahdi

ln -s /srv/asterisk/dahdi /etc/dahdi

mv /etc/apache2/* /srv/apache2/conf/

rmdir /etc/apache2/

ln -s /srv/apache2/conf /etc/apache2

mv /var/www/index.html /srv/apache2/www/

rmdir /var/www

ln -s /srv/apache2/www /var/www

t2-node2-

rm -r /etc/apache2

ln -s /srv/apache2/conf /etc/apache2

rm -r /var/www

ln -s /srv/apache2/www /var/www

ln -s /srv/asterisk/dahdi /etc/dahdi

t2-node1/t2-node2-

pear install db

Install Dependencies for Google Voice

Install iksemel

cd /usr/src

wget https://iksemel.googlecode.com/files/iksemel-1.4.tar.gz

tar xf iksemel-1.4.tar.gz

cd iksemel-1.4

./configure

make

make install

Install and Configure Asterisk

Download Asterisk source files.

cd /usr/src

wget http://downloads.asterisk.org/pub/telephony/dahdi-linux-complete/dahdi-linux-complete-current.tar.gz

wget http://downloads.asterisk.org/pub/telephony/libpri/libpri-1.4-current.tar.gz

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

Compile and install DAHDI.

cd /usr/src

tar xvfz dahdi-linux-complete-current.tar.gz

cd dahdi-linux-complete-*

make all

make install

make config

mv /etc/dahdi/* /srv/asterisk/dahdi/

rmdir /etc/dahdi

ln -s /srv/asterisk/dahdi /etc/dahdi

Compile and install LIBPRI.

cd /usr/src

tar xvfz libpri-1.4-current.tar.gz

cd libpri-*

make

make install

Compile and install Asterisk

cd /usr/src

tar xvfz asterisk-11-current.tar.gz

cd asterisk-*

./configure

contrib/scripts/get_mp3_source.sh

make menuselect

make

make install

make config

adduser asterisk --disabled-password --no-create-home --gecos "Asterisk User"

Install and Configure FreePBX

Download and extract FreePBX.

export VER_FREEPBX=2.11

cd /usr/src

svn co http://www.freepbx.org/v2/svn/freepbx/branches/${VER_FREEPBX} freepbx

cd freepbx

t2-node1-

mkdir /srv/asterisk/lib

mv /etc/asterisk/* /srv/asterisk/conf/

rmdir /etc/asterisk

ln -s /srv/asterisk/conf /etc/asterisk

mv /var/lib/asterisk/* /srv/asterisk/lib

rmdir /var/lib/asterisk

ln -s /srv/asterisk/lib /var/lib/asterisk

mkdir /srv/asterisk/{run,log,spool}

rmdir /var/run/asterisk/

chown asterisk. /var/run/asterisk

chown -R asterisk. /etc/asterisk

mv /var/spool/asterisk/* /srv/asterisk/spool/

rmdir /var/spool/asterisk/

ln -s /srv/asterisk/spool /var/spool/asterisk

mv /var/log/asterisk/* /srv/asterisk/log/

rmdir /var/log/asterisk

ln -s /srv/asterisk/log /var/log/asterisk

chown -R asterisk. /var/{lib,log,spool}/asterisk

chown -R asterisk. /usr/lib/asterisk

chown -R asterisk. /srv/asterisk/

chown -R asterisk. /srv/apache2/www/

mv /etc/php5 /srv/

ln -s /srv/php5 /etc/php5

sed -i 's/\(^upload_max_filesize = \).*/\120M/' /etc/php5/apache2/php.ini

sed -i 's/\(APACHE_RUN_USER\|APACHE_RUN_GROUP\).*/\1=asterisk/' /etc/apache2/envvars

t2-node2-

rm -r /etc/asterisk/

ln -s /srv/asterisk/conf /etc/asterisk

rm -r /var/lib/asterisk

ln -s /srv/asterisk/lib /var/lib/asterisk

rmdir /var/run/asterisk/

ln -s /srv/asterisk/run /var/run/asterisk

rm -r /var/spool/asterisk/

ln -s /srv/asterisk/spool /var/spool/asterisk

rm -r /var/log/asterisk

ln -s /srv/asterisk/log /var/log/asterisk

mysql server (192.168.235.66):

export ASTERISK_DB_PW=amp109 

mysqladmin -u root create asterisk -p

mysqladmin -u root create asteriskcdrdb -p

mysql -u root asterisk -p < SQL/newinstall.sql 

mysql -u root asteriskcdrdb -p < SQL/cdr_mysql_table.sql

./install_amp --webroot /var/www/freepbx

amportal a ma installall

amportal a reload

ln -s /var/lib/asterisk/moh /var/lib/asterisk/mohmp3

cd /etc/asterisk

rm ccss.conf confbridge.conf features.conf sip.conf iax.conf logger.conf extensions.conf sip_notify.conf

t2-node1/t2-node2-

apt-get install sipsak ntp postfix

echo 'export export OCF_ROOT="/usr/lib/ocf"' >> /etc/environment

cat <<EOF > /etc/apache2/sites-available/localhost

<VirtualHost 127.0.0.1:80> ServerName localhost <Location /server-status> SetHandler server-status Order deny,allow Deny from all Allow from 127.0.0.1 </Location> </VirtualHost>

EOF

a2ensite localhost

след приключване на инсталацията е време да се конфигурира pacemaker

t2-node1-

crm configure edit

node $id=”733f9f25-58cd-486e-810c-b441fba7d61e” t2-node2 node $id=”90f76594-4d7f-46d1-b094-cce7319da8ae” t2-node1

primitive ResourceMonitor ocf:pacemaker:ClusterMon \

        params pidfile=”/var/run/crm_mon.pid” htmlfile=”/var/tmp/crm_mon.html” extra_options=”-T [email protected] -H localhost:25″ \

        op monitor interval=”10s” timeout=”20s”

primitive P_APACHE ocf:heartbeat:apache \ params configfile=”/srv/apache2/conf/apache2.conf” httpd=”/usr/sbin/apache2″ statusurl=”http://localhost/server-status” \ op monitor interval=”40s” \ meta target-role=”Started” primitive P_IP ocf:heartbeat:IPaddr2 \ params ip=”192.168.236.66” cidr_netmask=”24″ nic=”eth0″ \ op monitor interval=”10s” primitive p_asterisk ocf:heartbeat:asterisk \ params user=”asterisk” group=”asterisk” realtime=”true” \ op monitor interval=”10s” \ meta target-role=”Started” group HAServices P_IP p_asterisk P_APACHE \ meta target-role=”Started” colocation ASTERISK inf: p_asterisk P_IP colocation WEB_SITE inf: P_APACHE P_IP order START_ORDER inf: P_IP:start p_asterisk:start P_APACHE:start

property $id=”cib-bootstrap-options” \ dc-version=”1.1.6-9971ebba4494012a93c03b40a2c58ec0eb60f50c” \ cluster-infrastructure=”Heartbeat” \ expected-quorum-votes=”1″ \ stonith-enabled=”false” \ no-quorum-policy=”ignore” rsc_defaults $id=”rsc-options” \ resource-stickiness=”100″

текста в синьо не се променя!!!! в червено е посочен адреса, който трябва да се промени!!!

 

Comments are closed !