Como CREAR un CLUSTER de Alta Disponibilidad
¿Que es un CLUSTER?
Un Cluster es un equipo de como minimo dos maquinas que forman un servidor.
La tarea de los equipos es dar servicio a los clientes, de forma permaente, y si alguna de las maquinas servidoras se cae entra en funcionamiento la otra maquina servidor.
Procederemos a montar un Clusster con dos maquinas virtuales montados sobre Virtual Box.
Para ello necesitaremos crear 2 maquinas.
El software necesario es:
Sistema operativo - "Debian-603-i386"
link de descarga- www.debian.org
Software para el cluster - Heart Beat
Se descarga directamente desde la linea de comando.
Software para el RAID de los discos - DRBD
Se descarga Directamente desde la linea de comando.
PASOS a seguir en la Instalacion del Cluster
Creacion de las maqinas virtuales.
Creamos las maquinas virtuales con sistemas operativos Debian.6.0.3
Instalacion de sist. Operativos bajamos el iso del sist. Operativo de
la pagina de www.debian .org eligimos el cd 1de 32bits y creamos la 1º maq. Virual con la siguiente coinfiguracion:
En el proceso de instalacion del sisitema, elegimos como lengua del sistema Inglés, con teclado Español.
En el disco "0" dividimos la particion de 10GB. 1GB para particion (Swap) y y el tamaño restante para el sistema (ext3como raiz)
En el disco "1" esta sin ningun tipo de particion durante la instalacion
ya que lo vamos a particionar y configurar posteriormente.
Configuramos el nombre de la maquina como "primaria". Creamos, 2 usuarios:
root- *debian
petar- *debian
instalamos el sistema con los sigientes paquetes / Aplicaciones :
web server ; open ssh server; y los paquetes predeterminados del sistema ( sin entorno grafico )
Configuramos el adaptador de red con los siguientes datos en el fichero:
root@primaria:~# vi /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
allow-hotplug eth0
iface eth0 inet static
address 192.168.2.175
netmask 255.255.255.0
gateway 192.168.2.1
Configuramos los DNS para poder tener acceso a red externa en el fichero:
root@primaria:~# vi /etc/resolv.conf
nameserver 192.168.2.1
Configuramos las IP's y hostnames en el fichero de los 2 nodos:
root@primaria:~# vi /etc/hosts
127.0.0.1 localhost
192.168.2.175 primaria
192.168.2.176 segundaria
# 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
root@primaria:~#
vamos a proceder a instalar el paquete "HeartBeat" que nos va a facilitar la conmutacion entre las dos maquinas, proporcionandonos un servicio de alta disponibilidad, es decir si falla una maquina pasa el trafico a la otra:
root@primaria:~# apt-get install heartbeat
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
cluster-agents cluster-glue fancontrol gawk libcluster-glue libcorosync4 libcurl3 libesmtp5 libglib2.0-0 libglib2.0-data libheartbeat2 libltdl7 libnet1 libnspr4-0d libnss3-1d libopenhpi2
libopenipmi0 libsensors4 libsnmp-base libsnmp15 libssh2-1 libxml2-utils libxslt1.1 lm-sensors openhpid pacemaker shared-mime-info
Suggested packages:
snmp-mibs-downloader sensord read-edid i2c-tools
The following NEW packages will be installed:
cluster-agents cluster-glue fancontrol gawk heartbeat libcluster-glue libcorosync4 libcurl3 libesmtp5 libglib2.0-0 libglib2.0-data libheartbeat2 libltdl7 libnet1 libnspr4-0d libnss3-1d
libopenhpi2 libopenipmi0 libsensors4 libsnmp-base libsnmp15 libssh2-1 libxml2-utils libxslt1.1 lm-sensors openhpid pacemaker shared-mime-info
0 upgraded, 28 newly installed, 0 to remove and 0 not upgraded.
Need to get 12.5 MB of archives.
After this operation, 34.8 MB of additional disk space will be used.
Do you want to continue [Y/n]? y
Unavez descargado e instalado el HEARTBEAT
Debemos modificar 3 ficheros en cada una de las maquinas, estos se encuentran en /etc/ha.d:
En el primer fichero llamado "authkeys" especificaremos las claves, para nuestro caso usaremos el metodo inseguro CRC (que tiene menos carga de CPU) asumiendo que tenemos un buen firewall configurado, podemos usar md5, o sha1 para mayor seguridad:
root@primaria:cd /etc/ha.d/
root@primaria:/etc/ha.d# vi authkeys
auth 1
1 crc
root@primaria:/etc/ha.d#
En el 2º fichero "ha.cf " especificaremos las opciones de configuración de heartbeat, indicamos donde queremos guardar los logs, en keepalive le indicamos que los latidos se enviarán cada 2 segundos, en deadtime especificamos que si un nodo no responde en 30 segundos está muerto, en warntime le decimos que si no responde en 10 segundos nos lanzará una alerta, en el inicio antes de considerar un nodo muerto esperaremos 120 segundos para evitar problemas con el arranque del servicio, usaremos el puerto UDP 649 para la comunicación entre las máquinas, en unicast indicaremos nuestro dispositivo ethernet e indicamos que mandamos latidos por unicast a la ip del otro nodo (peer), ponemos el parámetro failback en ON para indicar el comportamiento en caso de recuperación de un nodo caído, estando en ON este recuperará todos los servicios al volver a estar activo si lo dejamos en OFF, los servicios residirán en el nodo espejo hasta que este caiga, finalmente indicamos que nodos forman el servicio y un dispositivo ethernet para broadcast:
root@primaria:/etc/ha.d# vi ha.cf
root@primaria:/etc/ha.d#
root@primaria:/etc/ha.d# cat ha.cf
# File to write debug messages to
debugfile /var/log/ha-debug
#
#
# File to write other messages to
#
logfile /var/log/ha-log
#
#
# Facility to use for syslog()/logger
#
logfacility local0
#
#
# A note on specifying "how long" times below...
#
# The default time unit is seconds
# 10 means ten seconds
#
# You can also specify them in milliseconds
# 1500ms means 1.5 seconds
#
#
# keepalive: how long between heartbeats?
#
keepalive 2
#
# deadtime: how long-to-declare-host-dead?
#
# If you set this too low you will get the problematic
# split-brain (or cluster partition) problem.
# See the FAQ for how to use warntime to tune deadtime.
#
deadtime 30
#
# warntime: how long before issuing "late heartbeat" warning?
# See the FAQ for how to use warntime to tune deadtime.
#
warntime 10
#
#
# Very first dead time (initdead)
#
# On some machines/OSes, etc. the network takes a while to come up
# and start working right after you've been rebooted. As a result
# we have a separate dead time for when things first come up.
# It should be at least twice the normal dead time.
#
initdead 120
#
#
# What UDP port to use for bcast/ucast communication?
#
udpport 694
# Set up a unicast / udp heartbeat medium
# ucast [dev] [peer-ip-addr]
#
# [dev] device to send/rcv heartbeats on
# [peer-ip-addr] IP address of peer to send packets to
#
ucast eth0 192.168.2.176
#
auto_failback on
# Tell what machines are in the cluster
# node nodename ... -- must match uname -n
node primaria
node segundaria
bcast eth0
root@primaria:/etc/ha.d#
La IP virtual (linux-ha): 192.168.2.10 (en esta ip se ofrece el servicio de alta disponibilidad)
En el 3º fichero "haresources", especificaremos los servicios que debe manejar heartbeat (en este caso apache ), este fichero es el mismo en los dos nodos:
root@primaria:/etc/ha.d# vi haresources
root@primaria:/etc/ha.d# cat haresources
primaria IPaddr2::192.168.2.10/24/eth0 apache2
root@primaria:/etc/ha.d#
Una vez creado y guardado el fichero vamos a proceder a dar permisos de solo lectura/escritura al usuario "root", ya que es un fichero de seguridad.
root@primaria:/etc/ha.d# ls -lrt
total 40
drwxr-xr-x 2 root root 4096 May 4 2010 cts
drwxr-xr-x 2 root root 4096 May 4 2010 conf
-rw-r--r-- 1 root root 692 May 4 2010 README.config
-rwxr-xr-x 1 root root 745 May 4 2010 harc
-rw-r--r-- 1 root root 2090 Oct 20 2010 shellfuncs
drwxr-xr-x 2 root root 4096 Jan 22 18:21 resource.d
drwxr-xr-x 2 root root 4096 Jan 22 18:21 rc.d
-rw-r--r-- 1 root root 13 Jan 22 18:36 authkeys
-rw-r--r-- 1 root root 1759 Jan 22 18:46 ha.cf
-rw-r--r-- 1 root root 48 Jan 22 18:54 haresources
root@primaria:/etc/ha.d#
root@primaria:/etc/ha.d#
root@primaria:/etc/ha.d# chmod 600 authkeys
root@primaria:/etc/ha.d#
root@primaria:/etc/ha.d# ls -lrt
total 40
drwxr-xr-x 2 root root 4096 May 4 2010 cts
drwxr-xr-x 2 root root 4096 May 4 2010 conf
-rw-r--r-- 1 root root 692 May 4 2010 README.config
-rwxr-xr-x 1 root root 745 May 4 2010 harc
-rw-r--r-- 1 root root 2090 Oct 20 2010 shellfuncs
drwxr-xr-x 2 root root 4096 Jan 22 18:21 resource.d
drwxr-xr-x 2 root root 4096 Jan 22 18:21 rc.d
-rw------- 1 root root 13 Jan 22 18:36 authkeys
-rw-r--r-- 1 root root 1759 Jan 22 18:46 ha.cf
-rw-r--r-- 1 root root 48 Jan 22 18:54 haresources
root@primaria:/etc/ha.d#
Una vez terminada la configuracion de la maquina virtual"primaria" vamos a proceder a clonar la maquina "primaria" (en estado apagado) para obtener la segunda maquina virual "segundaria".
Para hacerlo hacemos click en la aquina apagada damos buton derecho y seleccionamos "clonar"
y seguimos las instrucciones:
Nos vamos al Virtual Box, selecionamos la maquina que desamos clonar (en este caso Primaria)
hacemos click con buton derecho y le damos a clonar (Segunda opcion en el sub menu)
Nos deberia salir esta imagen
Seleccionamos Clonacion completa hacemos click en Clonar
y Ya deberiamos tener la clonacion hecha.
Una vez clonada la maquina se aplican estas configuraiones:
root@segundaria:/etc/ha.d# cat /etc/hostname
segundaria
root@segundaria:/etc/ha.d# cat /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
allow-hotplug eth0
iface eth0 inet static
address 192.168.2.176
netmask 255.255.255.0
gateway 192.168.2.1
root@segundaria:/etc/ha.d#
root@segundaria:/etc/ha.d# cat /etc/ha.d/ha.cf
# File to write debug messages to
debugfile /var/log/ha-debug
#
#
# File to write other messages to
#
logfile /var/log/ha-log
#
#
# Facility to use for syslog()/logger
#
logfacility local0
#
#
# A note on specifying "how long" times below...
#
# The default time unit is seconds
# 10 means ten seconds
#
# You can also specify them in milliseconds
# 1500ms means 1.5 seconds
#
#
# keepalive: how long between heartbeats?
#
keepalive 2
#
# deadtime: how long-to-declare-host-dead?
#
# If you set this too low you will get the problematic
# split-brain (or cluster partition) problem.
# See the FAQ for how to use warntime to tune deadtime.
#
deadtime 30
#
# warntime: how long before issuing "late heartbeat" warning?
# See the FAQ for how to use warntime to tune deadtime.
#
warntime 10
#
#
# Very first dead time (initdead)
#
# On some machines/OSes, etc. the network takes a while to come up
# and start working right after you've been rebooted. As a result
# we have a separate dead time for when things first come up.
# It should be at least twice the normal dead time.
#
initdead 120
#
#
# What UDP port to use for bcast/ucast communication?
#
udpport 694
# Set up a unicast / udp heartbeat medium
# ucast [dev] [peer-ip-addr]
#
# [dev] device to send/rcv heartbeats on
# [peer-ip-addr] IP address of peer to send packets to
#
ucast eth0 192.168.2.175
#
auto_failback on
# Tell what machines are in the cluster
# node nodename ... -- must match uname -n
node primaria
node segundaria
bcast eth0
root@segundaria:/etc/ha.d#
root@segundaria:/etc/ha.d#
root@segundaria:/etc/ha.d# cat haresources
primaria IPaddr2::192.168.2.10/24/eth0 apache2
root@segundaria:/etc/ha.d#
Reiniciamos el servicio "heartbeat" en las 2 maquinas virtuales para poder sincrnizar:
root@primaria:~# /etc/init.d/heartbeat restart
Stopping High-Availability services: Done.
Waiting to allow resource takeover to complete:
Done.
Starting High-Availability services: IPaddr2[2114]: INFO: Resource is stopped
Done.
root@primaria:~#
root@segundaria:~# /etc/init.d/heartbeat restart
Stopping High-Availability services: Done.
Waiting to allow resource takeover to complete:
Done.
Starting High-Availability services: IPaddr2[2114]: INFO: Resource is stopped
Done.
Una vez instalado y configurado el servicio de alta disponibilidad, procedemos a insertar un pagina web en el servidor apache2 en el directorio siguiente, para comprobar el correcto funcionamiento
root@primaria:/etc/apache2/sites-available# cd /var/www/
root@primaria:/var/www# ls -lrt
total 8
-rw-r--r-- 1 root root 193 Jan 22 20:53 index.html_old
drwxr-xr-x 11 root root 4096 Jan 22 21:16 pag.web
root@primaria:/var/www#
root@primaria:/var/www# ls -lrt pag.web/
total 40
drwxr-xr-x 2 root root 4096 Jan 22 21:16 pag.5
drwxr-xr-x 2 root root 4096 Jan 22 21:16 pag.4
drwxr-xr-x 2 root root 4096 Jan 22 21:16 pag.3
drwxr-xr-x 2 root root 4096 Jan 22 21:16 pag.2
drwxr-xr-x 2 root root 4096 Jan 22 21:16 p.3
drwxr-xr-x 2 root root 4096 Jan 22 21:16 p.2
drwxr-xr-x 2 root root 4096 Jan 22 21:16 p.1
-rwxr-xr-x 1 root root 1639 Jan 22 21:16 index.html
drwxr-xr-x 2 root root 4096 Jan 22 21:16 img
drwxr-xr-x 2 root root 4096 Jan 22 21:16 enl
root@primaria:/var/www#
root@primaria:/var/www#
Editamos el ficheros de configuracion de apache2 para indicar la ruta exacta donde esta nuestro fichero "index.html", despues reiniciamos el servicio de apache2:
root@primaria:/var/www# cd /etc/apache2/sites-available/
root@primaria:/etc/apache2/sites-available# ls -lrt
total 12
-rw-r--r-- 1 root root 7469 Sep 26 00:18 default-ssl
-rw-r--r-- 1 root root 959 Jan 22 21:23 default
root@primaria:/etc/apache2/sites-available#
root@primaria:/etc/apache2/sites-available# cat default
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/pag.web/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
root@primaria:/etc/apache2/sites-available#
root@primaria:/etc/apache2/sites-available#
root@primaria:/etc/apache2/sites-available# /etc/init.d/apache2 restart
Restarting web server: apache2apache2: Could not reliably determine the server's fully qualified domain name, using 192.168.2.175 for ServerName
... waiting apache2: Could not reliably determine the server's fully qualified domain name, using 192.168.2.175 for ServerName
.
root@primaria:/etc/apache2/sites-available#
root@segundaria:/var/www#
root@segundaria:/var/www# ls -lrt
total 8
-rw-r--r-- 1 root root 210 Jan 22 20:54 index.html_old
drwxr-xr-x 11 root root 4096 Jan 22 21:40 pag.web
root@segundaria:/var/www# cd pag.web/
root@segundaria:/var/www/pag.web# ls -lrt
total 40
drwxr-xr-x 2 root root 4096 Jan 22 21:40 pag.5
drwxr-xr-x 2 root root 4096 Jan 22 21:40 pag.4
drwxr-xr-x 2 root root 4096 Jan 22 21:40 pag.3
drwxr-xr-x 2 root root 4096 Jan 22 21:40 pag.2
drwxr-xr-x 2 root root 4096 Jan 22 21:40 p.3
drwxr-xr-x 2 root root 4096 Jan 22 21:40 p.2
drwxr-xr-x 2 root root 4096 Jan 22 21:40 p.1
-rwxr-xr-x 1 root root 1639 Jan 22 21:40 index.html
drwxr-xr-x 2 root root 4096 Jan 22 21:40 img
drwxr-xr-x 2 root root 4096 Jan 22 21:40 enl
root@segundaria:/var/www/pag.web#
root@segundaria:/var/www/pag.web#
root@segundaria:/var/www/pag.web# cat /etc/apache2/sites-available/default
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/pag.web/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
root@segundaria:/var/www/pag.web#
root@segundaria:/var/www/pag.web# /etc/init.d/apache2 restart
Restarting web server: apache2apache2: Could not reliably determine the server's fully qualified domain name, using 192.168.2.176 for ServerName
... waiting apache2: Could not reliably determine the server's fully qualified domain name, using 192.168.2.176 for ServerName
.
root@segundaria:/var/www/pag.web#
Ya tenemos la pagina insertada en los dos nodos
esto significa que haora desde cualquier host en nuestra area local marcando la direccion 192.168.2.10 en la barra del navegador nos deberia slair la pagina web que hemos subido a nuestro servidor (solo en area local)
Ahora vamos a proceder instalar el RAID "DRBD"
Este software nos va a ayudar aque cualquier cambio que apliquemos se va reflejar a los dos discos de las dos maqunas, esto nos quita de hacer los cambios a los nodos por ceparado conque se haga en el fichero del DRBD se aplican los cambios a todos los nodos del Cluster.
Vamos a utilizar el disco de 2GB que al prnicipio creamos y lo dejamos sin ningun tipo de particion.
root@primaria:~# fdisk -l
Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000e36f9
Device Boot Start End Blocks Id System
/dev/sda1 1 122 975872 82 Linux swap / Solaris
Partition 1 does not end on cylinder boundary.
/dev/sda2 122 1306 9507840 83 Linux
Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/sdb doesn't contain a valid partition table
root@primaria:~#
root@primaria:~# fdisk /dev/sdb
Una vez dentro utilizaremos el comando "m" para que nos salgan las distinas opciones de "fdisk"
Nosotros vamos a utilizar en 1º lugar la opcion "n" para crear particion primaria
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
segimos las instrucciones para realizar la particion del disco
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-261, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-261, default 261):
Using default value 261
Command (m for help):
imprimios por pantalla el resultado de la careacion de la particion
Command (m for help): p
Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x38c246e8
Device Boot Start End Blocks Id System
/dev/sdb1 1 261 2096451 83 Linux
Command (m for help):
para guardar los cambios utilizaremos la opcion "w"
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
una vez realizada la tarea de guardar los cambios vamos a reiniciar la maquin "init 6"
una vez reiniciada la maquina vamos a descargar el paquete de DRBD:
root@primaria:~#
root@primaria:~# apt-get install drbd8-utils
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
drbd8-utils
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 193 kB of archives.
After this operation, 582 kB of additional disk space will be used.
Get:1 http://ftp.es.debian.org/debian/ squeeze/main drbd8-utils i386 2:8.3.7-2.1 [193 kB]
Fetched 193 kB in 2s (66.8 kB/s)
Selecting previously deselected package drbd8-utils.
(Reading database ... 39788 files and directories currently installed.)
Unpacking drbd8-utils (from .../drbd8-utils_2%3a8.3.7-2.1_i386.deb) ...
Processing triggers for man-db ...
Setting up drbd8-utils (2:8.3.7-2.1) ...
root@primaria:~#
una vez instalado el paquete de DRBD vamos a proceder a crear y configurar el fichero de configuracion de DRBD
root@primaria:/etc/drbd.d# vi data1.res
resource data1 {
protocol C;
startup {
degr-wfc-timeout 120; # 2 minutes.
}
disk {
on-io-error detach;
}
net {
}
syncer {
rate 10M;
al-extents 257;
}
on primaria {
device /dev/drbd1;
disk /dev/sdb1;
address 192.168.2.175:7788;
meta-disk internal;
}
on segundaria {
device /dev/drbd1;
disk /dev/sdb1;
address 192.168.2.176:7788;
meta-disk internal;
}
para ver la configuracionn que hemos realizado utilizamos el siguiente comando
root@primaria:/etc/drbd.d# ls -lrt
total 8
-rw-r--r-- 1 root root 1425 Jul 17 2010 global_common.conf
-rw-r--r-- 1 root root 435 Feb 5 15:03 data1.res
root@primaria:/etc/drbd.d#
todos los pasos han de ser hechos en la maquina segundaria.
Unavez terminados los pasos se reinician las dos maquinas.
En la maquina "primaria" ejecutamos el comando siguiente para crear el drbd del "data1":
root@primaria:~# drbdadm create-md data1
--== Thank you for participating in the global usage survey ==--
The server's response is:
you are the 12600th user to install this version
Writing meta data...
initializing activity log
NOT initialized bitmap
New drbd meta data block successfully created.
success
En caso de que se muestre un error de que no se puede crear el drbd, es debido a que la particion "/dev/sdb1" en nuestro caso de 2GB esta formateada en ext3 y tenemos que lanzar el comando:
dd if=/dev/zero of=/dev/sdb1
Posteriormente volver a probar con el comado anterior.
Reiniciamos las maquinas y posteriormente ejecutamos el comando en la maquina "primaria":
root@primaria:~#
root@primaria:~# drbdsetup /dev/drbd1 primary -o
Observamos con el siguiente comando que los discos se estan sincronizandos:
root@primaria:~#
root@primaria:~# /etc/init.d/drbd status
drbd driver loaded OK; device status:
version: 8.3.7 (api:88/proto:86-91)
srcversion: EE47D8BF18AC166BE219757
m:res cs ro ds p mounted fstype
1:data1 Connected Secondary/Secondary Inconsistent/Inconsistent C
root@primaria:~# cat /proc/drbd
version: 8.3.7 (api:88/proto:86-91)
srcversion: EE47D8BF18AC166BE219757
1: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r----
ns:268288 nr:0 dw:0 dr:268488 al:0 bm:16 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:1828060
[=>..................] sync'ed: 12.9% (1828060/2096348)K
finish: 0:02:42 speed: 11,256 (10,316) K/sec
root@primaria:~# cat /proc/drbd
version: 8.3.7 (api:88/proto:86-91)
srcversion: EE47D8BF18AC166BE219757
1: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r----
ns:302080 nr:0 dw:0 dr:302280 al:0 bm:18 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:1794268
[=>..................] sync'ed: 14.5% (1794268/2096348)K
finish: 0:02:38 speed: 11,260 (10,416) K/sec
root@primaria:~# cat /proc/drbd
version: 8.3.7 (api:88/proto:86-91)
srcversion: EE47D8BF18AC166BE219757
1: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r----
ns:393216 nr:0 dw:0 dr:393416 al:0 bm:24 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:1703132
[==>.................] sync'ed: 19.0% (1703132/2096348)K
finish: 0:02:30 speed: 11,260 (10,344) K/sec
root@primaria:~#
Un vez terminado el proceso observamos en el fichero de "LOG" el resultado:
root@primaria:~# cat /proc/drbd
version: 8.3.7 (api:88/proto:86-91)
srcversion: EE47D8BF18AC166BE219757
1: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r----
ns:2096348 nr:0 dw:0 dr:2096548 al:0 bm:128 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:0
root@primaria:~#
Si en la maquina "primaria" se muestra este resultado significa que el proceso de sincronizacion esta terminado con la maquina "segundaria".
Procedemos a dar formato a la particion de la maquina primaria:
root@primaria:~# mke2fs -j /dev/drbd1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
131072 inodes, 524087 blocks
26204 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=536870912
16 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information:
done
This filesystem will be automatically checked every 39 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
una vez formateada la maquina la ponemos como disco segundario en el DRBD para poder dar formato al disco de la maquina Segundaria que actuara como dico primario en el DRBD
root@primaria:/# drbdadm secondary data1
drbdadm secondary data1
una vez que la hemos cambiado procedemos a cambiar la segundaria a disco primario
root@segundaria:/# drbdadm primary data1
ahora procedemos a formatear la maquina segundaria
root@segundaria:~# mke2fs -j /dev/drbd1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
131072 inodes, 524087 blocks
26204 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=536870912
16 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information:
done
This filesystem will be automatically checked every 33 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
una vez configurada la maquina Segundaria volvemos al esatdo anterior
Primaria = disco primario Segundaria = disco segundario
procedemos a montar la particion previamente formateada al sistema para poder empezar a crear ficheros /datos en el cluster.
Todos los datos creados en la particion del DRBD de alguna de las maquinas estaran replicados en la otra maquina.
Para ello creamos una carpeta "data" en el directorio raiz que la utilizaremos para montar en ella la particion del DRBD:
root@primaria:~# mkdir /data/
Montamos la partiion con el comando "mount" (para dosmontar (umount) ):
root@primaria:~# mount /dev/drbd1 /data/
Despues todo lo que se guarde en /data/ estara guardado en las dos maquinas.
POR FIN tenemos nuestro Cluster de Alta Disponibilidad instalado.