User Rating: 5 / 5

Star ActiveStar ActiveStar ActiveStar ActiveStar Active

get version of OS and 64bit/32Bit

#cat /etc/*release*

#uname -a

 

disable firewall first. re-enable it later.

#setup

 

Get everything up to date

#yum -y upgrade

#yum -y update

#reboot

#yum -y update

hopefully no more updates left


Get build scripts and stuff


[32 bit]

#yum -y install gcc gcc-c++ kernel-devel bison openssl-devel \

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 \

libxml2 libxml2-devel libtiff libtiff-devel

 

[64 bit] (you might need to copy this into note pad or something to remove the returns/newlines)

 

#yum -y install gcc.x86_64 gcc-c++.x86_64 kernel-devel.x86_64 bison.x86_64 openssl-devel.x86_64 \

libtermcap-devel.x86_64 ncurses-devel.x86_64 doxygen.x86_64 curl-devel.x86_64 newt-devel.x86_64 \

mlocate.x86_64 lynx.x86_64 tar.x86_64 wget.x86_64 nmap.x86_64 bzip2.x86_64 mod_ssl.x86_64 \

crontabs.x86_64 vixie-cron.x86_64 speex.x86_64 speex-devel.x86_64 unixODBC.x86_64 \

unixODBC-devel.x86_64 libtool-ltdl.x86_64 libtool-ltdl-devel.x86_64 mysql-connector-odbc.x86_64 \

mysql.x86_64 mysql-devel.x86_64 mysql-server.x86_64 php-mysql.x86_64 php-mbstring.x86_64 \

php-mcrypt.x86_64 flex.x86_64 screen.x86_64 libxml2-devel

 

[64 bit]

#yum -y install libidn-devel krb5-devel krb5-libs zlib-devel libidn-devel

#ln -sf /lib64/libcom_err.so.2 /lib64/libcom_err.so

 

 

Install ZapTel for timing or if you have the cards.

ns-serif; line-height: 14px; font-size: 11px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"># sudo wget http://downloads.digium.com/pub/zaptel/zaptel-1.4-current.tar.gz
# sudo tar -zxvf zaptel-1.4-current.tar.gz
#cd zaptel-1.4.12.1
#./configure
#make clean
#make
#make install
#make config

 

 

 



#groupadd asterisk
#useradd -c "asterisk PBX" -d /var/lib/asterisk -g asterisk asterisk

#cd /usr/src/

#wget http://downloads.digium.com/pub/asterisk/asterisk-1.6.2.9.tar.gz

#tar -zxvf asterisk-1.6.2.9.tar.gz

#cd asterisk-1.6.2.9


#make clean

#./configure

#make menuselect

(setup what you need in the menu manager,include mysql)

#make

#make install

 

 

#make samples

#make progdocs

#make config

#chkconfig asterisk on

 

 

#asterisk -vvvvvvvvvvvvvvvvvvvc

#core stop now

#service asterisk start


edit the following files in /etc/asterisk:

 

 

#nano /etc/asterisk/indications.conf - Change default country

#nano /etc/asterisk/modules.conf - Uncomment the line 'preload => res_odbc.so'

#nano /etc/asterisk/modules.conf - Add 'noload => pbx_ael.so' to bottom of file

#nano /etc/asterisk/modules.conf - Add 'noload => codec_dahdi.so' to the bottom of the file

 

Cut and paste below to clean up everything and set some values copy from rm to EOF

Or you can manually change them.

 

 

rm /etc/asterisk/extensions.ael

cat > /etc/asterisk/extensions.conf << EOF

[general]

static=yes

writeprotect=yes

autofallthrough=yes

extenpatternmatchnew=no

clearglobalvars=yes

priorityjumping=no

userscontext=default

 

[globals]

 

[default]

 

exten => _.,1,Goto(i,1)

exten => i,1,NoOp(Invalid)

exten => i,n,Congestion()

exten => i,n,Hangup()

 

exten => h,1,NoOp(Hanging up)

EOF

rm /etc/asterisk/extensions.lua

cat > /etc/asterisk/sip.conf << EOF

[general]

context=default

allowguest=yes

match_auth_username=yes

allowoverlap=no

allowtransfer=no

realm=pbx12.vitell.co.uk

udpbindaddr=0.0.0.0

tcpenable=no

tlsenable=no

srvlookup=yes

pedantic=no

tos_sip=cs3

tos_audio=ef

tos_video=af41

tos_text=af41

cos_sip=3

cos_audio=5

cos_video=4

cos_text=3

maxexpiry=3600

minexpiry=60

defaultexpiry=120

mwiexpiry=3600

qualifyfreq=60

qualifygap=100

qualifypeers=1

vmexten=voicemail

disallow=all

allow=alaw

mohinterpret=default

mohsuggest=default

parkinglot=plaza

language=en

relaxdtmf=yes

useragent=AsteriskPBX

sdpsession=AsteriskPBX

promiscredir=no

dtmfmode=rfc2833

videosupport=no

callevents=no

alwaysauthreject=yes

shrinkcallerid=no

allowsubscribe=yes

subscribecontext=default

notifyringing=yes

notifyhold=yes

notifycid=yes

callcounter=yes

t38pt_udptl=yes,fec,maxdatagram=400

faxdetect=no

nat=no

directmedia=no

directrtpsetup=no

EOF

 

------------------------------------------------------------ Asterisk Complete ----------------------------------------

 

Now lets get a2Billing for both asterisk server and Master SQL( just gonna use the sql for sql)

cd .. or   cd /usr/src

mkdir a2billing

 

wget http://www.asterisk2billing.org/downloads/A2Billing_1.7.1.tar.gz

tar -zxvf A2Billing_1.7.1.tar.gz

 

On Master SQL Server do the following

cd /usr/src/a2billing/DataBase/mysql-5.x

 

 

mysql -u root -p < a2billing-createdb-user.sql;

mysql -u root -p mya2billing < a2billing-mysql-schema-v1.7.0.sql;

 

will need to make a new user on the master SQL server that has permissions remotely.

 

mysql> CREATE USER 'a2bMySQL'@'10.10.10.%' IDENTIFIED BY 'yourpassdb';
mysql> GRANT ALL ON *.* TO 'a2bMySQL'@'10.10.10.%';

 

 

 

Back to Asterisk Box

 

#cp /usr/src/a2billing/a2billing.conf /etc/

#nano /etc/a2billing.conf

 

Edit a2billing.conf to  the following

 

 

[database]

hostname = 10.10.10.1

port = 3306

user = a2bMySQL

password = yourpassdb

dbname = mya2billing

dbtype = mysql

 

 

 

Edit

/etc/asterisk/res_mysql.conf

[general]

dbhost = 10.10.10.1

dbname = mya2billing

dbuser = a2bMySQL

dbpass = yourpassdb

;dbport = 3306

dbsock = /var/lib/mysql/mysql.sock

 

 

 

Edit

/etc/asterisk/extconfig.conf

[settings]

sipusers => mysql,mya2billing,cc_sip_buddies

iaxusers => mysql,mya2billing,cc_iax_buddies

sippeers => mysql,mya2billing,cc_sip_buddies

iaxpeers => mysql,mya2billing,cc_iax_buddies

 

 

 

 

 

Fix folder Permissions.

#chmod 777 /etc/asterisk

#touch /etc/asterisk/additional_a2billing_iax.conf

#touch /etc/asterisk/additional_a2billing_sip.conf

#echo \#include additional_a2billing_sip.conf >> /etc/asterisk/sip.conf

#echo \#include additional_a2billing_iax.conf >> /etc/asterisk/iax.conf

 

#chown -Rf apache /etc/asterisk/additional_a2billing_iax.conf

#chown -Rf apache /etc/asterisk/additional_a2billing_sip.conf

 

Copy sound to asterisk folder

#/usr/src/a2billing/addons/sounds/install_a2b_sounds.sh

 

Edit the Manger.conf

#nano /etc/asterisk/manager.conf

 

(Add below)

 

 

[myasterisk]

secret=mycode

read=system,call,log,verbose,command,agent,user

write=system,call,log,verbose,command,agent,user

 

(save and exit)

 

 

Copy AGI files and make executable

 

 

#cd /usr/src/a2billing/AGI

#cp a2billing.php /var/lib/asterisk/agi-bin/

#cp -Rf lib /var/lib/asterisk/agi-bin/

#chmod +x /var/lib/asterisk/agi-bin/a2billing.php

 

 

 

 

#mkdir /var/www/a2billing

#chown apache:apache /var/www/a2billing

 

 

#cp -rf /usr/src/a2billing/admin /var/www/a2billing

#cp -rf /usr/src/a2billing/agent /var/www/a2billing

#cp -rf /usr/src/a2billing/customer /var/www/a2billing

#cp -rf /usr/src/a2billing/common /var/www/a2billing

 

(use the 3 chmod is you used a ln)

 

chmod 755 /var/www/a2billing/admin/templates_c

chmod 755 /var/www/a2billing/customer/templates_c

chmod 755 /var/www/a2billing/agent/templates_c

chown -Rf apache:apache /var/www/a2billing/admin/templates_c

chown -Rf apache:apache /var/www/a2billing/customer/templates_c

 

edit apache file or httpd.. ( lame)

 

#nano /etc/httpd/conf/httpd.conf

 

find DocumentRoot and chane to below:

DocumentRoot "/var/www/a2billing"

 

service httpd restart

 

got to page http://yourip/admin/

log in and change your password

 

user: root

pass: changepassword

 

 

Now lets edit asterisk so the AGI works

# nano /etc/asterisk/extensions.conf

 

Paste below to the bottom of the file.

 

[a2billing]
; CallingCard application
exten => _X.,1,DeadAGI,a2billing.php
exten => _X.,2,Wait,2
exten => _X.,3,Hangup
[did]
; CallingCard application
exten => _X.,1,DeadAGI(a2billing.php|1|did)
Now configure httpd to start on boot
#ntsysv
arrow down to httpd and hit the space bar .tab to ok click enter

Asterisk will already start on boot :)



 


 

 

 

 

 

 

 

 

References used:

http://www.voip-info.org/wiki/view/CentOS+5+and+Asterisk+1.4.x+installation

http://www.asterisk2billing.org/cgi-bin/trac.cgi/wiki/A2Billing-1-4-Installation-deb

 

 

Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive

MySQL server replication

 

Reasons for master-slave replication using MySQL.

 

Offload some of the queries from one server to another and spread the load: One of the biggest advantages to have master-slave set up in MySQL is to be able to use master for all of the inserts and send some, if not all, select queries to slave. This will most probably speed up your application without having to diving into optimizing all the queries or buying more hardware.

 

Do backups from slave: One of the advantages people overlook is that you can use MySQL slave to do backups from. That way site is not affected at all when doing backups. This becomes a big deal when your database has grown to multiple gigs and every time you do backups using mysqldump, site lags when table locks happen. For some sites, this could mean that site goes down for few secs to minutes. If you have slave, you just take slave out of rotation (should be built into code) and run backups off the slave. You can even stop slave MySQL instance and copy the var folder instead of doing mysqldump.

 

 

For this setup we will connect the mirroring between the server through a cross over cable.

Using basically a unroute-able IP address.

 

 

Hardware Setup and user information

 

Master server ip: 10.10.10.1
Slave server ip: 10.10.10.2
Slave username: repl
Slave pw: slavepass
Your data directory is: /var/lib/mysql/



 

INSTALL MYSQL FROM RPM On All Servers

First lets get the latest RPM from MySQL and install it and verify versions

cd /

cd /usr/src

mkdir mysqlrpm

cd mysqlrpm

 

FOR: 5.1.48

wget http://dev.mysql.com/get/Downloads/MySQL-5.1/MySQL-server-5.1.48-1.glibc23.x86_64.rpm/from/http://mirror.services.wisc.edu/mysql/

wget http://dev.mysql.com/get/Downloads/MySQL-5.1/MySQL-client-5.1.48-1.glibc23.x86_64.rpm/from/http://mirror.services.wisc.edu/mysql/

 

FOR: 5.1.49

wget http://dev.mysql.com/get/Downloads/MySQL-5.1/MySQL-client-5.1.49-1.glibc23.x86_64.rpm/from/http://mirror.services.wisc.edu/mysql/

wget http://dev.mysql.com/get/Downloads/MySQL-5.1/MySQL-server-5.1.49-1.glibc23.x86_64.rpm/from/http://mysql.llarian.net/

 

 

FOR: 5.1.48

rpm -i MySQL-server-5.1.48-1.glibc23.x86_64.rpm

rpm -i MySQL-client-5.1.48-1.glibc23.x86_64.rpm
FOR: 5.1.49

rpm -i MySQL-server-5.1.49-1.glibc23.x86_64.rpm

rpm -i MySQL-client-5.1.49-1.glibc23.x86_64.rpm
if upgrading use -U instead of -i
do a reboot
log back in
# mysql
mysql> select version();
+-----------+
| version() |
+-----------+
| 5.1.48    |
+-----------+
1 row in set (0.00 sec)
mysql>exit;
make sure you got the right version compare to rpm files version from what mysql told you

 

 

Setting Up Master Server:

OK.. Time to modify the ini or cnf file

# service mysql stop

lets find the ini or cnf

#find / -name 'my.ini'

#find / -name 'my.cnf'

 

if you don't find the file we will make our own.

cd /etc

nano my.cnf

 

if you found the file type:

nano [full path to you file]

 

paste the following into your master:

 

[mysqld]
skip-name-resolve
log-bin=mysql-bin
server-id=1
innodb_flush_log_at_trx_commit=1
sync_binlog=1
max_connections=100000
max_connect_errors=1844674407370954751
key_buffer = 2048M
max_allowed_packet = 2M
table_cache = 512
sort_buffer_size = 512M
read_buffer_size = 8M                                                    $
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 32
query_cache_type = 1
query_cache_limit = 1M
query_cache_size = 32M
thread_concurrency = 16
long_query_time = 5
innodb_file_per_table

 

 

if your still in nano press ctrl-o, then click enter.  that should save it.

ctrl-x, to exit

 

#service mysql restart

 

mysqladmin variables | grep server_id

server_id should = 1 . if this is set to 1 and not 0 then your server is now a master.

 

 

Setting up the Slave Server

It is exactly the same as above except for the information in the my.cnf file is as follows

 

 

[mysqld]
server-id=2
skip-name-resolve
slave_net_timeout=30 connect_timeout=20 max_connect_errors=1844674407370954751

 

 

#mysqladmin variables | grep server_id

server_id should = 1 . if this is set to 2 and not 0 then your server is now a salve( well sorta).

If you have more then 1 slave repeat the above and increment the server-id as you see fit.

 

 

 

Master Server: Creating Salve users.

you can use 1 user for all your slaves or how ever you see fit.

I'm going to use just one

 

Get back on the master box

we will create a new MySQL user with replication permissions.

mysql> CREATE USER 'repl'@'10.10.10.2' IDENTIFIED BY 'slavepass';
mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'10.10.10.2';

 

 

 

If you Have a really large Database and don't want to wait for replication

(lets say over a few 100 megs )

Do a dump of data to move to slave

Login to master server:

mysqldump -u root --all-databases --single-transaction --master-data=1 > masterdump.sql

copy file to you slave.

 

On slave:

import dump on slave

mysql < masterdump.sql

 

 

 

Setup Slave to talk to Master:

Let us tell the slave which master to connect to and what login/password to use:

Get on your slave box(es)

 

mysql> CHANGE MASTER TO MASTER_HOST='10.10.10.1', MASTER_USER='repl', MASTER_PASSWORD='slavepass';

 

Let us start the slave:

mysql> start slave;


You can check the status of the slave by typing

mysql> show slave status\G;


if you have a big database and didn't dump your seconds behind master will take a few to get back to zero.

Also you may wanna note the top of the list..

Should say waiting for events from master.. If it is stuck on Connection you need to trouble shoot.

See below... a few sections below

 

 

 

 

 

 

Use When re-syncing Databases and you need the file and binary location

On Master:

mysql> FLUSH TABLES WITH READ LOCK;

mysql>SHOW MASTER STATUS;

Do not close this session or exit mysql otherwise you will lose the lock.

After you update your salve then you can exit;

 

On Slave(s) using logifle and pos from above.

 

mysql>
CHANGE MASTER TO MASTER_HOST='10.10.10.1',MASTER_USER='repl',MASTER_PASSWORD='slavepass',
MASTER_LOG_FILE='mysql-bin.000002',MASTER_LOG_POS=1710;

 

 

 

You can also do this to append everything new and wipe out any errors

 

Step 1. On the Slave
Issue the following commands to mysql:
mysql>STOP SLAVE; # stop the Slave I/O threads
mysql>RESET SLAVE; # forget about all the relay log files
services mysql stop     # stop the database

Step 2. On the Master
Issue the following commands to mysql:
mysql> RESET MASTER; # reset the bin log counter and wipe out bin log files
mysql> FLUSH TABLES WITH READ LOCK; # flush buffers and LOCK tables (both MyISAM and InnoDB)
mysql> show master status\G
*************************** 1. row ***************************
File: mysql-bin.000001
Position: 98
Binlog_Do_DB:
Binlog_Ignore_DB:
1 row in set (0.00 sec)

 

Dump Master... import to slave

 

then this

 

mysql>
CHANGE MASTER TO MASTER_HOST='10.10.10.1',MASTER_USER='repl',MASTER_PASSWORD='slavepass',
MASTER_LOG_FILE='mysql-bin.000002',MASTER_LOG_POS=98;

 

 

 

Useful things:

Get MySQL version.

  • mysql
  • select version();

 

 

Stop and start mysql

  • service mysql stop
  • service mysql start

(note its not mysqld for 5.1x)

 

 

 

Trouble Shooting Connection:

Check connection between servers:

on server 1: type

# telenet 10.10.10.2 3306

on server 2: type

# telenet 10.10.10.1 3306

 

You should basically get a message say MySQL won't allow you.( this is good)

if you get can't connect.. check your IP tables and ports an firewalls

 

if you are good connection wise.

Make sure you used the right IP address when you created your users and granted permissions.

Check your passwords, etc..

 

Also on the salve(s) try

mysql> show slave status;

without the \G to see a little more detail on the failure.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

When the replication gets interrupted (either via a clean server shutdown or a forced one), replication refuses to restart citing the following error:

ERROR 1201: Could not initialize master info structure, more error messages can be found in the MySQL error log

 

The master.info file is present in the data directory and has all the required information in it but MySQL refuses to use it. Searching on the net did not yield anything definitive.

The simplest way to restart replication from this point is to re-enter the master.info data manually. Do the following:

  1. STOP SLAVE
  2. RESET SLAVE
  3. CHANGE MASTER TO MASTER_HOST=’your_master’, MASTER_USER=’your_login’, MASTER_PASSWORD=’your_password’, MASTER_LOG_FILE=’log_file’, MASTER_LOG_POS=log_position
  4. START SLAVE

At this point you want to execute ‘SHOW SLAVE STATUS’ and check to see if everything is running. Most times MySQL will stop since it tried to replay a duplicate record from the logs. We need to tell MySQL to skip that record and continue:

  1. SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1
  2. START SLAVE

That should get replication up and running again.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

References:

http://dev.mysql.com/doc/refman/5.1/en/replication-howto.html

 

16.1.1.4. Obtaining the Replication Master Binary Log Coordinates

the below is use to start replication from a binary point

http://dev.mysql.com/doc/refman/5.1/en/replication-howto-masterstatus.html