Document published by: Telesoft Integrando Technologies http://www.netsecuritysolutionsltda.com/spanish/index.php?option=com_content&task=view&id=144&Itemid=183 Costado Sur Galería Simán, Reparto Serrano. Managua, Nicaragua Tel.: (505) 2250-9698 ▲ Fax: (505) 2270-4598 ▲ Celular: (505) 8855-3700 ▲ rdc@aplitel.com
With much help from Steph, I have roughly translated the line-by-line instruction portion of the original PDF to English. The English portion could probably use a considerable amount of cleanup, but it is a place to start! I believe that you should be able to follow the English portion, but would recommend downloading the original PDF and have it side-by-side with this document, so that this document will be easier to follow.
Thanks to Steph for lending me her Spanish skills to start this translation!
Procedimiento para Instalar Elastix como Cluster Con la ayuda de este articulo vamos a implementar el servicio de alta disponibilidad para Elastix con el uso de las herramientas DRBD y Heartbeat que permiten crear en tiempo real un sistema de espejado remoto de dispositivos de bloques locales (similar a un RAID 1 pero por TCP). Ambos servidores se verán como una sola entidad. Para comprender un poco mejor lo que estamos haciendo procederemos a explicar los componentes necesarios para crear el Cluster.
Procedure to Install Elastix as Cluster With the help of this article we will implement the service for high availability Elastix using DRBD and Heartbeat tools to create a real-time system for remote mirroring of local block devices (like RAID 1 but TCP). Both servers will be as a single entity. To understand a little better what we are doing we will explain the components needed to create the Cluster.
DRBD
• Que es drbd?
• Instalación
• Configuración
• Pruebas
DRBD
• What is drbd?
• Installation
• Configuration
• Testing
Que es DRBD?
DRBD es un dispositivo de bloques que está diseñado para construir “clusters " de alta disponibilidad. Esto es hecho por medio de una copia idéntica de todo un dispositivo de bloques a través de una red. Esto podría ser visto como un RAID-1 de red.
¿Cual es el alcance de DRBD?
DRBD toma los datos, los escribe en el disco local y los envía al otro " host”. En el otro “host”, éste pone los datos en el disco. Pongamos el siguiente ejemplo:
Tenemos nodo1 " master-elastix.com” con Dirección IP 192.168.25.124 y nodo2 “slave-elastix.com” con dirección IP 192.168.25.125, las particiones físicas son el nodo1 /dev/sda3 y en el nodo2 /dev/sda3, pueden ser cualquier partición, en lo posible que sean del mismo tamaño ya que si no vamos a desperdiciarlo que sobre de la más grande “RAID1”.
DRBD is a block device that is designed to build clusters high availability. This is done through an identical copy of an entire block device over a network. This could be seen as a RAID-1 network.
What is the scope of DRBD?
DRBD takes the data, writes to local disk and sends them to another “host”. In another host, it puts the data on disk. Take the following example:
We nodo1 “master-elastix.com” with IP address 192.168.25.124 and node2 “slave-elastix.com” with IP address 192.168.25.125, the physical partitions are nodo1 / dev/sda3 and the node2 / dev/sda3, can be any partition, if possible that are the same size as if we are not going to waste on the most Large “RAID1”.
Heartbeat
• Que es y que hace?
• Instalación
• Configuración
Que es y que hace heartbeat?
El software heartbeat trabaja enviando latidos (ping), los cuales verifican si el nodo principal está activo o no, estos pings enviados por heartbeat requieren una respuesta por parte del nodo principal, si al cabo de un cierto tiempo el nodo no responde dichos ping, heartbeat determina que ese nodo se encuentra inactivo o caído y automáticamente activa el nodo secundario para que asuma el control de la red y los servicios, en nuestro ejemplo vamos a usar lo siguiente para mantener la línea del ejemplo con drbd:
nodo1 con dirección IP 192.168.25.124 (Nodo principal)
nodo2 con dirección IP 192.168.25.125 (Nodo secundario)
Heartbeat
• What is and who does?
• Installation
• Configuration
Is and that heartbeat?
The software works by sending heartbeat heartbeat (ping), which checks if the primary node is active or not, the heartbeat pings sent by a call response from the primary node, if after a certain time the node answered the ping, heartbeat determines that the node is idle or dropped and automatically activates the node to assume control of the network and services, in our example we will use the following to keep the line drbd example:
nodo1 with IP address 192.168.25.124 (primary node)
node2 with IP address 192.168.25.125 (node)
Con este funcionamiento tenemos que el administrador de red, puede estar tranquilo, ya que en caso de que ocurra un problema con el nodo principal, el nodo secundario asumirá el control automáticamente, luego tendrá que trabajar para volver a colocar el línea el nodo primario caído producto de un fallo de hardware, pero lo bueno es que uno puede realizar dicho trabajo sin preocuparse, ya que el secundario está cubriendo los servicios del primario, con esto lo que logramos es una alta disponibilidad de servicios, como veremos en este caso, estaremos dando alta disponibilidad al servidor de telefonía Elastix.
With this operation we have the network administrator, you can rest easy, because in case a of problem with the primary node, the node will automatically take control, then you will have to work to replace the line down the primary node product of a hardware failure, but the good news is that one can perform such work without worry, because the secondary is covering the primary, this is what we achieved a high availability of services, as we shall see in this case, we providing high availability to the telephony server Elastix.
Instalación
Ahora que ya comprendimos lo que vamos hacer, procederemos a instalar los programas necesarios para nuestro cluster de Elestix.
Installation
Now that we understood what we do, we will install the software needed for our cluster of Elestix.
1.- Cuando arrancamos con el CD de instalación de Elastix, en el prompt de boot escribimos “advanced” para realizar el particionamiento manual del disco duro.
When doing the initial install, choose advanced for manually partitioning the drive.
Cuando aparezca la pantalla de particiones seleccionar la última opción que se refiere a crear particiones. Después eliminar todas las particiones y crearles a como se muestra a continuación:
Choose the create partition option, and create in the following order.
Suponiendo que nuestro disco duro es /dev/sda, un esquema podría ser:
/dev/sda1 (ext3) para /
/dev/sad2 (swap)
Assuming that your hard disk is / dev / sda, a scheme could be:
/ dev/sda1 (ext3) to /
/ dev/sad2 (swap)
Dejar suficiente espacio libre para lo que deseamos replicar en ambos servidores (Esta partición la vamos a crear después) Estas dos particiones no deben ocupar todo el tamaño del disco, ya que debemos dejar espacio suficiente para crear la partición donde van a residir los datos que van a ser replicados entre ambos servidores, este espacio libre debería ser similar en ambos servidores.
Leave enough space for what we want to replicate on both servers (this partition we will create later) These two partitions should not occupy the entire size of the disk, and we must leave enough space to create the partition where will the data reside will be replicated between two servers, this space should be similar on both servers.
En nuestro caso, el servidor Primario se llamara master-elastix.com y el servidor Secundario se llamara slave-elastix.com
In this case, we have the primary as master-elastix.com and the secondary is slave-elastix.com.
Seguimos con los pasos para la instalación normal de Elastix.
From that point we’ll continue with the normal steps for Elastix.
Para la implementación de clustering necesitamos los siguientes RPMs:
For the implementation of clustering we need the following RPMs:
• drbd
• kmod-drbd
• OpenIPMI-libs
• heartbeat-pils
• openhpi
• heartbeat-stonith
• heartbeat
Puede descargarlos de http://asterisk.aplitel.info/asterisk.htm
You can download them at: http://asterisk.aplitel.info/asterisk.htm
Copiar todos los RPM en el directorio /usr/src/
Copy all of the RPM’s into the directory /usr/src/
wget http://asterisk.aplitel.info/files/drbd-8.0.11-1.el5.centos.i386.rpm
wget http://asterisk.aplitel.info/files/kmod-drbd-8.0.12-1.2.6.18_53.1.19.el5.i686.rpm
wget http://asterisk.aplitel.info/files/OpenIPMI-libs-2.0.6-5.el5.4.i386.rpm
wget http://asterisk.aplitel.info/files/heartbeat-pils-2.1.2-3.el5.centos.i386.rpm
wget http://asterisk.aplitel.info/files/openhpi-2.8.1-2.el5.7.i386.rpm
wget http://asterisk.aplitel.info/files/heartbeat-stonith-2.1.2-3.el5.centos.i386.rpm
wget http://asterisk.aplitel.info/files/heartbeat-2.1.2-3.el5.centos.i386.rpm
rpm -ivh drbd-x.y.z-xyz.rpm
Ahora vamos a crear la partición que contendrá los datos que se replicaran, para esto ejecutamos el comando:
Now we create the partition that will contain the data to be replicated, using the following command:
fdisk /dev/sda
Luego siguiendo la ayuda del comando creamos una tercera partición que sería /dev/sda3 de tipo ext3 que ocupara el tamaño que dejamos libre en el particionamiento manual a tiempo de instalación.
Later, following the help of the command, we create a third partition that is /dev/sda3, type ext3 that would occupy the size that was left free when doing the manual partition during installation.
Pasos
1.- Presionamos la letra n (add a new partition)
2.- Presionamos la letra p (Primary partition)
3.- Escribimos el número 3 (Partition number)
4.- Presionamos Enter un par de veces hasta que nos aparezca el Command de nuevo. (Press enter a few times, until the Command appears again.)
5.- Luego presionamos la letra t para cambiar el partition’s system id. (Press “t” to change the partition system id) 6.- Escribimos la partición 3 (Press 3 to choose partition.)
7.- En HEX code escribimos 83 que es la partición de Linux (Choose HEX 83 for type)
8.- Por ultimo escribimos la letra w para salvar los cambios. (Press “w” to save changes)
9.- Después reiniciamos el servidor para que la nueva tabla este disponible. (Restart the server to make the partition available)
Ahora procederemos a formatear la nueva partición con el siguiente comando:
Now proceed to format the following partition with the following command.
mke2fs -j /dev/sda3
Configuración de DRBD
DRBD (http://www.drbd.org/) nos permitirá replicar la partición declarada en ambos miembros del cluster, en nuestro caso /dev/sda3. Para realizar esto crea un dispositivo de bloques virtual llamado /dev/drbd0.
DRDB allows us to write the declared partition in both members of the cluster. In our case, /dev/sda3. To make this happen, we need to create a virtual partition called /dev/drdb3.
Vamos a configurar el archivo /etc/drbd.conf, así:
Edit the config file /etc/drdb.conf:
resource "r0" {
protocol A;
disk { on-io-error pass_on; }
startup { wfc-timeout 5; degr-wfc-timeout 3; }
syncer { rate 100M; }
on master.telesoft.com {
device /dev/drbd0;
disk /dev/sda3;
address 192.168.25.124:7789;
meta-disk internal;
}
on slave.telesoft.com {
device /dev/drbd0;
disk /dev/sda3;
address 192.168.25.125:7789;
meta-disk internal;
}
}
Donde: (Do this on the primary and secondary)
master-elastix.com (192.168.25.124) Servidor Primario
slave-elastix.com (192.168.25.125) Servidor Secundario
Se recomienda que el archivo /etc/hosts agregar
It is recommended that you add the following to /etc/hosts
192.168.25.124 master.telesoft.com master
192.168.25.125 slave.telesoft.com slave
Antes de seguir se debe de cambiar el nombre del servidor en la interface web de Elastix:
Before continuing, you should change the name of the server in the Elastix web interface
Ahora procederemos a ejecutar los siguientes comandos
Now we are going to execute the following commands.
dd if=/dev/zero bs=1M count=1 of=/dev/sda3; sync
El archivo /etc/drbd.conf debe ser el mismo para ambos servidores, ahora creamos el dispositivo de bloques virtual /dev/drbd0, ejecutando también en ambos servidores el comando:
The file, /etc/drdb.conf should be the same for both servers, now we create the virtual partition /dev/drdb0, and then execute the following command on both servers:
drbdadm create-md r0
Levantamos el servicio:
Then start the service:
service drbd start
Con esto se empezaran a sincronizar las particiones, puedo visualizarlo ejecutando el comando:
With this, they will start to sycronize the partitions, to see this execute:
service drbd status
Y obtendremos una salida como esta:
And we will see something like this:
[root@master-elastix ~]# service drbd status
drbd driver loaded OK; device status:
version: 8.0.3 (api:86/proto:86)
SVN Revision: 2881 build by buildsvn@c5-i386-build, 2007-05-13 08:22:43
0: cs:SyncSource st:Secondary/Secondary ds:UpToDate/Inconsistent A r---
ns:96764 nr:0 dw:0 dr:104928 al:0 bm:91 lo:1 pe:4 ua:256ap:0
[====>...............] sync'ed: 22.0% (368336/464976)K
finish: 0:00:30 speed: 12,080 (12,080) K/sec
resync: used:2/31 hits:6291 misses:8 starving:0 dirty:0 changed:8
act_log: used:0/127 hits:0 misses:0 starving:0 dirty:0 changed:0
Inicialmente ambos servidores serán Secundarios, debo declarar quien será el Primario.
Initially, both servers will be secondary, we need to set who is the primary. Ahora SOLO en el servidor PRIMARIO:
Now enter this command on the primary server:
drbdsetup /dev/drbd0 primary -o
Y obtendré una salida como esta:
And then we will see this:
[root@master-elastix ~]# service drbd status
drbd driver loaded OK; device status:
version: 8.0.3 (api:86/proto:86)
SVN Revision: 2881 build by buildsvn@c5-i386-build, 2007-05-13 08:22:43
0: cs:Connected st:Primary/Secondary ds:UpToDate/UpToDate A r---
ns:464976 nr:0 dw:0 dr:464976 al:0 bm:170 lo:0 pe:0 ua:0 ap:0
resync: used:0/31 hits:28977 misses:85 starving:0 dirty:0 changed:85
act_log: used:0/127 hits:0 misses:0 starving:0 dirty:0 changed:0
Podemos saber el ROL del servidor donde nos encontramos, ejecutando el comando:
We can determine the role of the server by executing:
drbdadm state r0
En el servidor Primario deberiamos ver:
In the primary server, we will see:
[root@master-elastix ~]# drbdadm state r0
Primary/Secondary
Y en el servidor Secundario:
In the secondary server, we will see:
[root@slave-elastix ~]# drbdadm state r0
Secondary/Primary
Ahora ya es posible montar la particion virtual /dev/drbd0, pero antes se debe formatear usando ext3, así:
Now it is possible to mount the virtual partition /dev/drdb0, but first you should format the partition using ext3 with the following command:
mke2fs -j /dev/drbd0
mkdir /replica
mount /dev/drbd0 /replica
Procederemos a copiar dentro de /replica la data que queramos replicar, incluyendo archivos de configuración de servicios, en el caso de Elastix serian los siguientes directorios:
Now we will copy the following directories, including the configuration files, into the new partition. In the case of Elastix, it is the following directories:
• /etc/asterisk
• /var/lib/asterisk
• /usr/lib/asterisk
• /var/spool/asterisk
• /var/lib/mysql
• /var/log/asterisk
A modo de ejemplo lo haremos con /etc/asterisk, así:
Use the following example to copy the needed filesin the /etc/asterisk directory:
cd /replica
tar -zcvf etc-asterisk.tgz /etc/asterisk
tar -zxvf etc-asterisk.tgz
rm -rf /etc/asterisk
ln -s /replica/etc/asterisk /etc/asterisk
Recordar de reiniciar el servicio de mysql una vez finalizado este paso
Restart MySQL with the following command:
service mysqld restart
Lo mismo debemos hacer con los demás directorios.
We should do the same with the rest of the directories.
Notas
Para declarar un nodo como primario (role)
To declare a node as primary:
drbdadm primary r0
Para declara un nodo como secundario (role)
To declare a node as secondary:
drbdadm secondary r0
Acordarse de que para declarar como secundario hay que desmontar la unida /replica) y antes de desmontarla detener el servicio de mysqld
Remember, to declare as a secondary, you first have to unmount /replica, and before unmounting, stop MySQL.
umount /replica
Ahora se debe proceder a instalar Heartbeat, que es el software que hace el cluster propiamente.
Now you can install Heartbeat, the software determines if the cluster is working properly.
Configuracion de Heartbeat
Acordarse de apagar los servicios que se iniciaran con el heartbeat
Remember to stop any services that are started by Heartbeat.
chkconfig asterisk off
chkconfig zaptel off
chkconfig mysqld off
chkconfig httpd off
Esto se hace ya que el Heartbeat iniciara estos servicios cuando el servidor sea master. Debemos copiar los archivos de configuración de Heartbeat (http://www.linux- ha.org/) de la documentación que viene con el paquete al directorio de configuración /etc/ha.d, asi:
Heartbeat will initiate these services from the master server. We should copy the Heartbeat configuration files from the documentation to the config directory /etc/ha.d, using:
cp /usr/share/doc/heartbeat-2.1.2/ha.cf /etc/ha.d/
cp /usr/share/doc/heartbeat-2.1.2/haresources /etc/ha.d/
cp /usr/share/doc/heartbeat-2.1.2/authkeys /etc/ha.d/
Ahora vamos a editar el archivo /etc/ha.d/ha.cf
Edit the file, /etc/ha.d/ha.cf
cd /etc/ha.d
vi ha.cf
Y agregamos al final estas líneas: Add these lines to the end:
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 20
warntime 10
initdead 40
udpport 694
bcast eth0 # Linux
auto_failback off
node master.telesoft.com
node slave.telesoft.com
Luego el archivo /etc/ha.d/haresources
Afterwards, edit /etc/ha.d/haresources
cd /etc/ha.d vi haresources
Y agregamos al final la línea:
Add the following line to the end:
master.telesoft.com drbddisk::r0 Filesystem::/dev/drbd0::/replica::ext3 IPaddr::192.168.25.126/24/eth0/192.168.25.255 asterisk zaptel mysqld httpd
Finalmente el archivo /etc/ha.d/authkeys Finally, edit the file /etc/ha.d/authkeys
cd /etc/ha.d
vi authkeys
Y agregamos al final las líneas:
And again, add these lines to the end of the file:
auth 1
1 sha1 elastix
Le damos el siguiente permiso al archivo /etc/ha.d/authkeys
We will give the following permissions to the file /etc/ha.d/authkeys
cd /etc/ha.d
chmod 600 authkeys
Todos los archivos anteriores deben ser iguales en ambos servidores. All of the files above should be the same on both servers.
Configuramos heartbeat con soporte chkconfig, asi:
Configure heartbeat to start with:
chkconfig –add heartbeat
Ahora, antes de iniciar los servicios de heartbeat, debemos reiniciar el servicio drbd en ambos servidores, así:
Now, before starting the services of heartbeat, we should restart drdb on both servers, like this:
service drbd restart
Verificamos que ambos servidores se encuentren en estado Secundario, así:
Verify that both servers are found to be in the secondary state using:
drbdadm state r0
[root@master-elastix ~]# drbdadm state r0
Secondary/Secondary
Si es así, procedemos a levantar el servicio heartbeat, así:
If this is correct, we start the heartbeat service:
service heartbeat start
Una vez hecho esto, esperaremos unos momentos hasta que heartbeat monte la partición /replica en el servidor Primario, lo verificamos así:
Once you have done so, wait a few moments while heartbeat mounts the partition /replica on the primary server. Confirm this using:
drbdadm state r0
[root@master-elastix ~]# drbdadm state r0
Primary/Secondary
df -h
[root@master-elastix ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/hdc1 9.5G 1.5G 7.6G 17% /
tmpfs 501M 0 501M 0% /dev/shm
/dev/drbd0 9.2G 150M 8.6G 2% /replica
La partición /replica solo se montara en el servidor cuyo estado sea Primario, es decir, si por algún motivo el servidor master-elastix.com falla entonces slave- elastix.com asumirá el estado de Primario y por ende levantara la partición /replica, la cual contendrá la información replicada entre ambos equipos.
The partition /replica will only mount on the server whose status is Primary. If for some reason master-elastix.com fails, then slave-elastix.com will assume the Primary role and mount the partition /replica with the information replicated from the other machine.
Esperar a que termine de hacer la sincronización de los dos servidores, este proceso se puede observar con el comando:
Wait until it finishes doing the synchronization between the two machines, this process can be observed by issuing the following command:
watch cat /proc/drbd
Cuanto tenemos los dos nodos en modo stand alone, con un cs:StandAlone st:Secondary/Unknown ds:UpToDate/DUnknown lo más probable es que tengamos que realizar una resincronizacion de la data, para ello basta con ejecutar:
When we have the two nodes in stand alone mode cs:StandAlone st:Secondary/Unknown ds:UpToDate/DUnknown, it is probable that we will have to do a resynchronization of the data
En el servidor que no está UpTodate
In the server that is not up to date, execute:
drbdadm – –discard-my-data connect all
Luego en el servidor que esta UpToDate
Afterwards, on the up to date server, execute:
drbdadm connect all
Los nodos empezaran a re-sincronizarse, transfiriendo los datos desde el nodo con datos OK, al nodo con los datos corruptos.
The nodes will begin re-synchronizing themselves, transferring the data from the server with good data to the node with corrupted data.