Instalación de iSCSI en CentOS 6

Instalación de iSCSI en CentOS 6

Con la salida de CentOS 6, la guía para el uso de discos iSCSI en CentOS 5 queda desactualizada. Vamos a ver como usar discos iSCSI en CentOS 6:

El primer cambio se trata de la variable ETHTOOL_OPTS, que deberemos pasar a usar udev. En el fichero /etc/udev/rules.d/70-persistent-net.rules, añadimos lo siguiente para nuestras interfaces iSCSI:
SUBSYSTEM=="net", ACTION=="add", NAME=="eth2", RUN+="/sbin/ethtool -A eth2 autoneg on rx on tx on"
SUBSYSTEM=="net", ACTION=="add", NAME=="eth3", RUN+="/sbin/ethtool -A eth3 autoneg on rx on tx on"
Pasamos a instalar tanto el paquete iscsi-initiator-utils como el device-mapper-multipath para el multipath:
yum install iscsi-initiator-utils
yum install device-mapper-multipath -y
Añadimos los scripts al inicio del sistema:
chkconfig --add iscsi
chkconfig iscsi on
chkconfig --add multipathd
chkconfig multipathd on
Y arrancamos los daemons:
/etc/init.d/iscsi start
/etc/init.d/iscsid start
/etc/init.d/multipathd start
Definimos las interfaces que queremos usar:
# iscsiadm -m iface
default tcp,<empty>,<empty>,<empty>,<empty>
iser iser,<empty>,<empty>,<empty>,<empty>
Suponiendo las interfaces eth2 y eth3 las dedicadas a iSCSI, las añadimos con:
# iscsiadm -m iface -I eth2 -o new
New interface eth2 added
# iscsiadm -m iface -I eth3 -o new
New interface eth3 added
# iscsiadm -m iface -I eth2 -n iface.net_ifacename -v eth2 -o update
eth2 updated.
# iscsiadm -m iface -I eth3 -n iface.net_ifacename -v eth3 -o update
eth3 updated.
Verificamos que se hayan añadido bien:
# iscsiadm -m iface
default tcp,<empty>,<empty>,<empty>,<empty>
iser iser,<empty>,<empty>,<empty>,<empty>
eth3 tcp,<empty>,<empty>,eth3,<empty>
eth2 tcp,<empty>,<empty>,eth2,<empty>
# ls /var/lib/iscsi/ifaces/
eth2  eth3
# cat /var/lib/iscsi/ifaces/eth*
# BEGIN RECORD 2.0-872.41.el6
iface.iscsi_ifacename = eth2
iface.net_ifacename = eth2
iface.transport_name = tcp
iface.vlan_id = 0
iface.vlan_priority = 0
iface.iface_num = 0
iface.mtu = 0
iface.port = 0
# END RECORD
# BEGIN RECORD 2.0-872.41.el6
iface.iscsi_ifacename = eth3
iface.net_ifacename = eth3
iface.transport_name = tcp
iface.vlan_id = 0
iface.vlan_priority = 0
iface.iface_num = 0
iface.mtu = 0
iface.port = 0
# END RECORD
Con las interfaces definidas, pasamos a configurar el multipath, que por defecto esta totalmente deshabilitado:
# multipath -v3
Oct 01 18:54:36 | DM multipath kernel driver not loaded
Oct 01 18:54:36 | /etc/multipath.conf does not exist, blacklisting all devices.
Oct 01 18:54:36 | A sample multipath.conf file is located at
Oct 01 18:54:36 | /usr/share/doc/device-mapper-multipath-0.4.9/multipath.conf
Oct 01 18:54:36 | You can run /sbin/mpathconf to create or modify /etc/multipath.conf
Oct 01 18:54:36 | DM multipath kernel driver not loaded
Podemos habilitarlo con mpathconf:
/sbin/mpathconf --enable
Deberemos adaptar el fichero de configuración /etc/multipath.conf con lo siguiente para una Dell EquaLogic:
blacklist {
        devnode "^(ram|raw|loop|fd|md|dm-|sr|scd|st)[0-9]*" # altres
        devnode "^hd[a-z][0-9]*" # cdrom

        device {
                vendor "Dell"
                product "*"
        }
}

devices {
     device {
          vendor                  "EQLOGIC"
          product                 "100E-00"
          path_grouping_policy    multibus
   getuid_callout    "/sbin/scsi_id --page=0x83 --whitelisted --device=/dev/%n"
          features                "1 queue_if_no_path"
          path_checker            readsector0
          path_selector           "round-robin 0"
          failback                immediate
          rr_min_io               10
          rr_weight               priorities
     }
}

defaults {
        user_friendly_names yes
}
Por defecto, Linux comprueba el path inverso de un paquete para evitar que entren paquetes que no se esperan por una interfaz sino por otra. Como queremos utilizar dos interfaces al mismo tiempo en la misma red, deberemos quitar el filtro por camino inverso y habilitar el log de marcianos (paquetes eliminados por el filtro) para ayudar a detectar problemas:
net.ipv4.conf.all.log_martians=1
net.ipv4.conf.eth2.rp_filter=0
net.ipv4.conf.eth3.rp_filter=0
Comprobamos la configuración de multipath con:
# multipath -v3
Oct 01 12:57:34 | ram0: device node name blacklisted
(...)
Oct 01 12:57:34 | sda: device node name blacklisted
Oct 01 12:57:34 | dm-0: device node name blacklisted
Oct 01 12:57:34 | dm-1: device node name blacklisted
===== no paths =====
Nos indica que no hay paths porque aún no hemos añadido ningún disco. Procedemos a buscar el nombre del iniciador iSCSI:
# cat /etc/iscsi/initiatorname.iscsi 
InitiatorName=iqn.1994-05.com.redhat:0002e00dead
Para luego asignar un disco a dicho iniciador:
Añadiendo disco iSCSI
Añadiendo disco iSCSI
Una vez tengamos el disco presentado, reiniciamos los daemons:
# iscsiadm -m session -u
# /etc/init.d/iscsi restart
# /etc/init.d/iscsid restart
# /etc/init.d/multipathd restart
Hacemos el discovery para buscar el disco que hemos asignado al servidor:
# iscsiadm -m discovery -p 192.168.1.1 -t st
192.168.1.1:3260,1 iqn.2001-05.com.equallogic:0-000906-00a4e0800-005000ec00650697-lamp-gladiator
192.168.1.1:3260,1 iqn.2001-05.com.equallogic:0-000906-00a4e0800-005000ec00650697-lamp-gladiator
Y habilitamos el login automático al reiniciar (También de puede modificar en el /etc/iscsi/iscsid.conf):
# iscsiadm -m node -L automatic
Finalmente, comprobamos que usamos el multipath haciendo logout de todos los discos:
# iscsiadm -m session -u
Logging out of session [sid: 1, target: iqn.2001-05.com.equallogic:0-000906-00a4e0800-005000ec00650697-lamp-gladiator, portal: 192.168.1.1,3260]
Logging out of session [sid: 2, target: iqn.2001-05.com.equallogic:0-000906-00a4e0800-005000ec00650697-lamp-gladiator, portal: 192.168.1.1,3260]
Logout of [sid: 1, target: iqn.2001-05.com.equallogic:0-000906-00a4e0800-005000ec00650697-lamp-gladiator, portal: 192.168.1.1,3260] successful.
Logout of [sid: 2, target: iqn.2001-05.com.equallogic:0-000906-00a4e0800-005000ec00650697-lamp-gladiator, portal: 192.168.1.1,3260] successful.
Y volvemos a hacer login:
[root@gladiator ~]# iscsiadm -m node -l 
Logging in to [iface: eth3, target: iqn.2001-05.com.equallogic:0-000906-00a4e0800-005000ec00650697-lamp-gladiator, portal: 192.168.1.1,3260] (multiple)
Logging in to [iface: eth2, target: iqn.2001-05.com.equallogic:0-000906-00a4e0800-005000ec00650697-lamp-gladiator, portal: 192.168.1.1,3260] (multiple)
Login to [iface: eth3, target: iqn.2001-05.com.equallogic:0-000906-00a4e0800-005000ec00650697-lamp-gladiator, portal: 192.168.1.1,3260] successful.
Login to [iface: eth2, target: iqn.2001-05.com.equallogic:0-000906-00a4e0800-005000ec00650697-lamp-gladiator, portal: 192.168.1.1,3260] successful.
Mediante el comando multipath veremos el estado:
# multipath -v2
create: mpathb (36090a08880e0a41897066567ec0050b1) undef EQLOGIC,100E-00
size=600G features='1 queue_if_no_path' hwhandler='0' wp=undef
`-+- policy='round-robin 0' prio=1 status=undef
  |- 4:0:0:0 sdb 8:16 undef ready running
  `- 3:0:0:0 sdc 8:32 undef ready running
# multipath -ll
mpathb (36090a08880e0a41897066567ec0050b1) dm-2 EQLOGIC,100E-00
size=600G features='1 queue_if_no_path' hwhandler='0' wp=rw
`-+- policy='round-robin 0' prio=1 status=active
  |- 4:0:0:0 sdb 8:16 active ready running
  `- 3:0:0:0 sdc 8:32 active ready running
En la cabina también podemos comprobar si el tráfico entre interfaces es simétrico:
Trafico iSCSI simétrico
Trafico iSCSI simétrico
Dado el dispositivo que se cree:
# ls /dev/mapper/mpathb  -l
lrwxrwxrwx 1 root root 7 Oct  1 19:00 /dev/mapper/mpathb -> ../dm-2
Con este disco podemos crear un volume group LVM y luego crear un sistema de ficheros en un logical volume:
# pvcreate  /dev/mapper/mpathb 
  Writing physical volume data to disk "/dev/mapper/mpathb"
  Physical volume "/dev/mapper/mpathb" successfully created
# vgcreate iscsi /dev/mapper/mpathb 
  Volume group "iscsi" successfully created
# lvcreate -L 400G -n www iscsi
  Logical volume "www" created
Para que dicho sistema de ficheros se monte al inicio del sistema, deberemos añadir la opción _netdev en el fstab:
/dev/iscsi/www  /var/www  ext4 defaults,noatime,_netdev 

Comentarios