sábado, 25 de julio de 2015

LINUX-CENTOS 6x,7x - crear RAID, mdadm

Vamos a realizar un laboratorio creando un RAID  sobre centos 6.x
las características de este ejercicio de creación de RAID son:
RAID de tipo 1
consta de 3 HDD el cual incluye 1 HDD de reemplazo (spare part).

1. Verificación de HDD 

Verificar a través de fdisk el listado de los HDD necesarios para la creación del RAID


[root@lala ~]# fdisk -l /dev/sdh

Disk /dev/sdh: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 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: 0xd0895102

[root@lala ~]# fdisk -l /dev/sdf

Disk /dev/sdf: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 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: 0x3238d218

[root@lala ~]# fdisk -l /dev/sdg

Disk /dev/sdg: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 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: 0x11df187b

[root@lala ~]# 


2. Creación de particiones en los HDD.

Crear una particion en cada uno de los HDD a utilizar, incluyendo el HDD que servirá para reemplazo.

[root@lala ~]# fdisk /dev/sdf

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (35-130, default 35): 
Using default value 35
Last cylinder, +cylinders or +size{K,M,G} (35-130, default 130): +256M

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@lala ~]# fdisk /dev/sdg

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (35-130, default 35): 
Using default value 35
Last cylinder, +cylinders or +size{K,M,G} (35-130, default 130): +256M

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@lala ~]# fdisk /dev/sdh

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (35-130, default 35): 
Using default value 35
Last cylinder, +cylinders or +size{K,M,G} (35-130, default 130): +256M

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@lala ~]# 

Una vez que se han creado las particiones, utilizar el comando partprobe para notificar al kernel la existencia de la particiones recientemente creadas. 

Si el sistema despliega el siguiente mensaje de error:

[root@lala ~]# partprobe 
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdf (Device or resource busy).  As a result, it may not reflect all of your changes until after reboot.
Warning: Unable to open /dev/sr1 read-write (Read-only file system).  /dev/sr1 has been opened read-only.

Se debe Reinciar el Server para que el kernel sea notificado de las particiones.

Luego de reiniciar, listar las particiones:
[root@lala ~]# fdisk -l /dev/sdf

Disk /dev/sdf: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 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: 0x3238d218

   Device Boot      Start         End      Blocks   Id  System
/dev/sdf2              35          68      273105   83  Linux
[root@lala ~]# fdisk -l /dev/sdg

Disk /dev/sdg: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 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: 0x11df187b

   Device Boot      Start         End      Blocks   Id  System
/dev/sdg2              35          68      273105   83  Linux
[root@lala ~]# fdisk -l /dev/sdh

Disk /dev/sdh: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 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: 0xd0895102

   Device Boot      Start         End      Blocks   Id  System
/dev/sdh2              35          68      273105   83  Linux
[root@lala ~]# 

3. Crear el RAID

Se utiliza el comando mdadm.
Los parámetros indicados en el comando son:
-C de creación
/dev/md3 que es el nombre del RAID
-l o "level" es el nivel de RAID, en este caso 1 
-x "spare part" indica cantidad de HDD de reemplazo que considera el RAID
-n indica cantidad de HDD, incluyendo la que se utiliza como reemplazo.
/dev/sdf2 /dev/sdg2 /dev/sdh2 son las particiones que serán utilizadas para conformar el RAID. 
Al colocar  "/dev/sdh2" al último, se indica esta partición como spare part.

[root@lala ~]# mdadm -C /dev/md3 -l 1 -x 1 -n 2 /dev/sdf2 /dev/sdg2 /dev/sdh2
mdadm: Note: this array has metadata at the start and
    may not be suitable as a boot device.  If you plan to
    store '/boot' on this device please ensure that
    your boot-loader understands md/v1.x metadata, or use
    --metadata=0.90
Continue creating array? yes
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md3 started.
[root@lala ~]# 

4. Agregar la configuración del RAID al archivo /etc/mdadm.conf


Escanear la información general de RAIDs
[root@lala ~]# mdadm --detail --scan
ARRAY /dev/md3 metadata=1.2 spares=1 name=lala:3 UUID=36364db0:2da15c4d:f53cae75:f104a14f
[root@lala ~]#

Agregar al archivo de configuración /etc/mdadm.conf la información obtenida en el scan de raid
[root@lala ~]# cat /etc/mdadm.conf 
# mdadm.conf written out by anaconda
MAILADDR root
AUTO +imsm +1.x -all
ARRAY /dev/md3 metadata=1.2 spares=1 name=lala:3 UUID=36364db0:2da15c4d:f53cae75:f104a14f
[root@lala ~]# 

5. Formatear el RAID y montar como directorio.

se puede formatear con cualquier tipo de FS. Sin embargo utilizaremos ext4 por sus características de journaling.

[root@lala ~]# mkfs.ext4 /dev/md3 -L MYRAID3
mke2fs 1.41.12 (17-May-2010)
Filesystem label=MYRAID3
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
68272 inodes, 272832 blocks
13641 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67633152
34 block groups
8192 blocks per group, 8192 fragments per group
2008 inodes per group
Superblock backups stored on blocks: 
8193, 24577, 40961, 57345, 73729, 204801, 221185

Writing inode tables: done                            
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 20 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@lala ~]# 

Crear un directorio para montar el RAID
[root@lala ~]# mkdir /myraid3

Montar el RAID en el directorio
[root@lala ~]# mount -t ext4 /dev/md3 /myraid3
[root@lala ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_lala-LogVol01
                       13G  849M   11G   8% /
tmpfs                 499M     0  499M   0% /dev/shm
/dev/md0              485M   25M  436M   6% /boot
/dev/md3              259M   11M  235M   5% /myraid3
[root@lala ~]# 

Para que sea montado cada vez que se inicie el Server, agregar la configuración en /etc/fstab
[root@lala ~]# cat /etc/fstab | grep myraid
/dev/md3 /myraid3 ext4 defaults 1 2
[root@lala ~]# 

6. Verificar detalle del RAID

Se puede verificar el detalle de estado de los HDD contenidos en el RAID

[root@lala ~]# mdadm --detail /dev/md3
/dev/md3:
        Version : 1.2
  Creation Time : Sat Jul 25 15:25:37 2015
     Raid Level : raid1
     Array Size : 272832 (266.48 MiB 279.38 MB)
  Used Dev Size : 272832 (266.48 MiB 279.38 MB)
   Raid Devices : 2
  Total Devices : 3
    Persistence : Superblock is persistent

    Update Time : Sat Jul 25 15:27:50 2015
          State : clean 
 Active Devices : 2
Working Devices : 3
 Failed Devices : 0
  Spare Devices : 1

           Name : lala:3  (local to host lala)
           UUID : 36364db0:2da15c4d:f53cae75:f104a14f
         Events : 17

    Number   Major   Minor   RaidDevice State
       0       8       82        0      active sync   /dev/sdf2
       1       8       98        1      active sync   /dev/sdg2

       2       8      114        -      spare   /dev/sdh2
[root@lala ~]#

Los datos importantes son:
sdf2 y sdg2 son las "Active devices"
sdf2 es "spare device"

7. Marcar un HDD como unidad fallida para visualizar el funcionamiento del spare part

Cuando se detecta que uno de los HDD está con falla, es necesario marcarlo como failed para que el software RAID tome la unidad de reemplazo disponible para activarla. 

Para marcar un HDD fallido:
  [root@lala ~]# mdadm --fail /dev/md3 /dev/sdf2
mdadm: set /dev/sdf2 faulty in /dev/md3
[root@lala ~]# 

Luego, al volver a desplegar el detalle del RAID, aparece la undidad de reemplazo funcionando, y la unidad fallida toma su lugar como de reemplazo. 
[root@lala ~]# mdadm --detail /dev/md3
/dev/md3:
        Version : 1.2
  Creation Time : Sat Jul 25 15:25:37 2015
     Raid Level : raid1
     Array Size : 272832 (266.48 MiB 279.38 MB)
  Used Dev Size : 272832 (266.48 MiB 279.38 MB)
   Raid Devices : 2
  Total Devices : 3
    Persistence : Superblock is persistent

    Update Time : Sat Jul 25 15:30:21 2015
          State : clean 
 Active Devices : 2
Working Devices : 2
 Failed Devices : 1
  Spare Devices : 0

           Name : lala:3  (local to host lala)
           UUID : 36364db0:2da15c4d:f53cae75:f104a14f
         Events : 36

    Number   Major   Minor   RaidDevice State
       2       8      114        0      active sync   /dev/sdh2
       1       8       98        1      active sync   /dev/sdg2

       0       8       82        -      faulty spare   /dev/sdf2
[root@lala ~]# 

Se puede notar:
sdg2 y sdh2 son "Active devices"
sdf2 es la spare device.

Fuente de información:


No hay comentarios:

Publicar un comentario