Собираем 2 сервера Asterisk+FreePBX в отказоустойчивый кластер.
Настраиваем сихронизацию файлов между серверами (lsyncd):
cat >/etc/init.d/lsyncd<<EOT
#!/bin/bash
# description: lsyncd
# processname: lsyncd
. /etc/rc.d/init.d/functions
config="/etc/lsyncd/lsyncd.conf.lua"
lsyncd="/usr/bin/lsyncd"
lockfile="/var/lock/lsyncd"
prog="lsyncd"
RETVAL=0
start() {
pgrep -fx "$lsyncd $config">/dev/null
if [ $? -eq 0 ]; then
echo -n $"$prog is already running: "
echo
RETVAL=0
return $RETVAL
else
echo -n $"Starting $prog: "
$lsyncd $config
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch $lockfile
return $RETVAL
fi
}
stop() {
echo -n $"Stopping $prog: "
echo
killall $lsyncd>/dev/null 2>&1
rm -f $lockfile>/dev/null 2>&1
pgrep -fx "$lsyncd $config">/dev/null 2>&1
if [ $? -eq 0 ]; then
RETVAL=1
return $RETVAL
else
RETVAL=0
return $RETVAL
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status $lsyncd
;;
*)
echo -n "Usage: lsyncd {start|stop|restart|status}"
echo
exit 1
esac
exit $?
EOT
chmod +x /etc/init.d/lsyncd
На первом сервере:
cat >/etc/lsyncd/lsyncd.conf.lua<<EOT
settings{
logfile = "/var/log/lsyncd/lsyncd.log",
statusFile = "/var/log/lsyncd/lsyncd-status.log",
statusInterval = 10
}
sync{
default.rsyncssh,
source="/etc/asterisk",
host="10.77.10.3",
targetdir="/etc/asterisk",
rsync = {
archive = true,
compress = false,
whole_file = false
}
}
sync{
default.rsyncssh,
source="/var/lib/asterisk",
host="10.77.10.3",
targetdir="/var/lib/asterisk",
rsync = {
archive = true,
compress = false,
whole_file = false
}
}
sync{
default.rsyncssh,
source="/var/spool/asterisk",
host="10.77.10.3",
targetdir="/var/spool/asterisk",
rsync = {
archive = true,
compress = false,
whole_file = false
}
}
sync{
default.rsyncssh,
source="/usr/lib64/asterisk",
host="10.77.10.3",
targetdir="/usr/lib64/asterisk",
rsync = {
archive = true,
compress = false,
whole_file = false
}
}
sync{
default.rsyncssh,
source="/var/www/html",
host="10.77.10.3",
targetdir="/var/www/html",
excludeFrom="/var/www/html/admin/im ages/asterisknow.png",
rsync = {
archive = true,
compress = false,
whole_file = false
}
}
sync{
default.rsyncssh,
source="/tftpboot",
host="10.77.10.3",
targetdir="/tftpboot",
rsync = {
archive = true,
compress = false,
whole_file = false
}
}
EOT
На втором тоже самое, но меняем IP.
Далее настройка Corosync.
chkconfig corosync on
chkconfig drbd off
chkconfig mysqld off
chkconfig pacemaker on
cp /etc/corosync/corosync.conf.example /etc/corosync/corosync.conf
export ais_addr=`ip addr show eth0 | grep "inet " | awk '{print $4}' | sed 's/255/0/'`
sed -i "s/.*bindnetaddr:.*/bindnetaddr:\ $ais_addr/g" /etc/corosync/corosync.conf
cat <<-END >>/etc/corosync/corosync.conf
service {
# Load the Pacemaker Cluster Resource Manager
ver: 0
name: pacemaker
}
aisexec {
user: root
group: root
}
END
cat <<-END >>/etc/corosync.conf
aisexec {
user: root
group: root
}
END
И можно его стартовать.
service corosync start
Под базу будет отдельный раздел который будет монтироваться к активному серверу утилитой DRBD.
Готовим раздел:
dd if=/dev/zero of=/dev/sdb bs=1M
fdisk /dev/sdb
n, p, 1
w
Устанавливаем и настраиваем drbd (на обоих серверах):
yum install drbd kmod-drbd
cat <<-END >>/etc/drbd.d/asterisk.res
resource shared {
protocol C;
disk {
on-io-error detach;
}
startup {
wfc-timeout 15;
degr-wfc-timeout 60;
}
net {
cram-hmac-alg sha1;
shared-secret "asiod";
}
on sr-ast01-s01-01 {
device /dev/drbd0;
disk /dev/sdb1;
address 10.77.10.2:7789;
meta-disk internal;
}
on sr-ast01-s01-02 {
device /dev/drbd0;
disk /dev/sdb1;
address 10.77.10.3:7789;
meta-disk internal;
}
}
END
drbdadm create-md shared
/etc/init.d/drbd start
modprobe drbd
echo "modprobe drbd" > /etc/rc.local
Только на 1-м сервере:
drbdadm primary shared
drbdadm primary --force shared
mkfs.ext3 -m0 /dev/drbd0
mv /var/lib/mysql /var/lib/mysql.loc
mkdir /var/lib/mysql
cp -R /var/lib/mysql.loc/* /var/lib/mysql
mount -t ext3 /dev/drbd0 /var/lib/mysql
chown -Rh mysql. /var/lib/mysql
drbdadm disconnect shared
drbdadm -- --clear-bitmap new-current-uuid shared
drbdadm -- --overwrite-data-of-peer primary shared
drbdadm secondary shared
drbdadm detach shared
drbdadm up shared
Почти все готов. Конфиг для Corosync. Только на активной ноде:
crm configure
property no-quorum-policy=ignore
property stonith-enabled=false
rsc_defaults resource-stickiness=50
primitive ClusterIP IPaddr2 params ip=10.77.10.1 cidr_netmask=24 op monitor interval=30s
primitive DRBD-MOUNT Filesystem params device="/dev/drbd0" directory="/var/lib/mysql" fstype=ext3
primitive DRBD_meta ocf:linbit:drbd params drbd_resource=shared op monitor interval=15s
primitive
p_MYSQL mysql params op start timeout=120s interval=0 op stop
timeout=120s interval=0 op monitor interval=20s timeout=30s
primitive
ASTERISK lsb:asterisk op monitor interval=30 op start interval=0s
timeout=120s op stop interval=0s timeout=120s meta migration-threshold=1
primitive
LSYNCD lsb:lsyncd op monitor interval=30 op start interval=0s
timeout=120s op stop interval=0s timeout=120s meta migration-threshold=5
group g_mysql DRBD-MOUNT p_MYSQL ClusterIP ASTERISK LSYNCD
ms ms_drbd_mysql DRBD_meta meta master-max=1 master-nodemax=1 clone-max=2 clone-node-max=1 notify=true
colocation c_mysql_on_drbd inf: g_mysql ms_drbd_mysql:Master
order o_drbd_before_mysql inf: ms_drbd_mysql:promote g_mysql:start
commit
exit
Чтобы сервера могли синхронить файлы, необходимо обменяться ssh ключами:
ssh-keygen -t rsa
ssh-copy-id -i ~/.ssh/id_rsa root@10.77.10.3
service corosync restart
Комментариев нет:
Отправить комментарий