iscsi和多路径

    技术2022-07-13  71

    iscsi和多路径

    Iscsi分为存储端和客户端,iscsi存储端即用于存放硬盘存储资源的服务器,而iscsi客户端则是用户使用的软件,用于获取远程服务端的存储资源。 Iscsi主要为远程块存储设备提供数据传输和管理。 多路径可以实现服务器和存储系统之间以最优的路径进行通信。 多路径可以实现故障切换和恢复,保障了业务的连续性,避免了因故障节点造成的业务中断。 多路径实现了在控制器间的负载均衡

    Iscsi实现网络存储,提供存储端的叫target,使用存储端的是initiator。Target上可以提供存储空间,initiator负责连接iscsi设备,在iscsi设备中创建文件系统,以及存取数据,在initiator上看上去是多了一块硬盘。

    多路径需要配合存储在一起使用

    运行效果 客户端查看磁盘

    Disk /dev/sdc:21 .5 GB,21473787904 bytes, 41940992 sectors Units = sectorsof 1 * 512 = 512 bytes Sector size (logical/ physica1):512 bytes/ 512 bytes I/0 size (mi ni mum/ optimal):512 bytes / 4194304 bytes Disk /dev/sdb:21.5 GB,21473787904 bytes, 41940992 sectors Units = sectorsof 1 * 512 =512 bytes . Sector size ( logical/ physica1):512 bytes/ 512 bytes I/0 size (mi ni mum/optima1): 512 bytes / 4194304 bytes

    查看链路

    mpatha ( 36001 4054e02babeaf6a45e8a1385b2a6) dm-2 LIO_ORG,storagel size= 20G features='O' hwhandler= 'O' wp=rw | -+- policy='service -time O' prio= 1 status=active ‘-3:0:0:0 sdc 8:32 active readyrunning |-+- policy= 'service-time 0' prio= 1 status=enabled '-4:0:0:0 sdb 8:16 active ready running

    实验步骤 1.安装两台虚拟机(存储端和客户端) 存储端添加一张硬盘

    存储端 2.查看磁盘,使之分区不格式化,并生效

    [root@localhost ~]#fdisk -l [root@localhost ~]#fdisk /dev/sdb [root@localhost ~]#ll /dev/sdb1

    3.配置yum源,安装targetcli软件工具

    [root@localhost ~]#yum install -y targetcli

    4.重启target服务并开机自启,关闭防火墙并永久关闭

    [root@localhost ~]#systemctl restart target [root@localhost ~]#systemctl enable target [root@localhost ~]#systemctl disable firewalld [root@localhost ~]#systemctl stop firewalld

    4.进入targetcli服务器

    (1)使用/dev/sdb 1建立块存储storage1 /> /backstores/block create storage1 /dev/sdb 1 Created block storage object storage1 using /dev/sdb1. (2)建立target对象 /> /iscsi create iqn.2020-06.com.cloud:0617 Created target iqn.2020-06. com.cloud:0617. Created TPG 1。 (3)建立ACL允许客户端访问 /> /iscsi/iqn.2020-06.com.cloud:0617/tpg1 /acls create iqn.1994-05.com.redhat:556539d5c2fa Created Node ACL for iqn. 1994-05. com. redhat: 556539d5c2fa (4)创建LUN和存储设备相关联 /> /iscsi/iqn.2020-06.com.cloud:0617/tpg1/luns create/backstores/block/storagel Created LUN 0 Created LUN 0->0 mapping in node ACL iqn.1994-05.com.redhat:556539d5c2fa (5)放行端口 /> /iscsi/iqn.2020-06.com.cloud:0617/tpg1/ portals/ create 192.168.80.136 using default IP port 3260 Created network portal 192.168.80.136:3260 />. /iscsi/ iqn.2020-06.com.c1oud:0617/tpg1/portals/create 192.168.80.137 using default IP port 3260 Created network portal 192.168.80.137:3260 (6)保存并退出 /> saveconfig Last 10 configs saved in /etc/target/backup. Configuration saved to /etc/ target/saveconfig.json /> exit Global pref auto_save_on_ exit=true Last 10 configs saved in /etc/target/backup 。 configuration saved to /etc/ target/ saveconfig. jison

    客户端 5.配置yum源,安装iscsi-initiator-utils

    [root@localhost ~]#yum install -y iscsi*

    6.查询iqn名称

    [root@localhost ~]#cat /etc/iscsi /initiatorname iscsi InitiatorName=iqn.1994-05.com.redhat:556539d5c2fa

    7.发现存储

    [root@localhost ~]#iscsiadm -m discovery -t st -p 192.168.80.136 192.168.80.136:3260,1 iqn.2020-06.com.coud:0617 192.168.80.137:3260,1 iqn.2020-06.com.cloud:0617

    8.登录存储

    [root@localhost ~]#iscsiadm -m node 192.168.80.136 Logging in to [iface: default, target:iqn.2020-06.com.c1oud:0617,portal:192.168.80.136, 3260] [multiple] Logging in to [iface: default, target:iqn.2020-06.com.cloud:0617, portal: 192.168.80.137,3260] [multiple] Login to [iface: default, target:iqn.2020-06.com.cloud:0617,portal: 192.168.80.136,3260] successful. Login to [iface: default,target:iqn.2020-06.com.cloud:0617, portal: 192.168.80.137.32601 successful.

    9.查看磁盘

    Disk /dev/sdc:21 .5 GB,21473787904 bytes, 41940992 sectors Units = sectorsof 1 * 512 = 512 bytes Sector size (logical/ physica1):512 bytes/ 512 bytes I/0 size (mi ni mum/optimal):512 bytes /4194304 bytes Disk /dev/sdb:21.5 GB,21473787904 bytes, 41940992 sectors Units = sectorsof 1 * 512 =512 bytes . Sector size (logical/physica1):512 bytes/ 512 bytes I/0 size (mi ni mum/optima1): 512 bytes /4194304 bytes

    在以上的基础上安装多路径软件 在存储端添加一张网卡 1.安装多路径软件

    [root@localhost ~]#yum istall -y device-mapper-multipath.x86_64

    2.启动服务

    [root@localhost ~]#mpathconf --enable [root@localhost ~]#systemctl start multipathd

    3.Fdisk -查看合并的设备 由于sdb和sdc是同一个远端存储设备,所以信息一致, 被多路径驱动发现后会生成一- 个设备文件/dev/mapper/mpatha。

    Disk /dev/mappen /mpatha: 21.5 GB,21473787904 bytes, 41940992 seors

    4.格式化

    [root@localhost ~]#mkfs.exit4 /dev/mapper/mpatha

    5.挂载使用

    [root@localhost ~]#mkdir /yx [root@localhost ~]#mount / dev/mapper/ mpatha / yx [root@localhost ~]#df -h /dev/mapper/ mpatha 20G 45M19G 1% /yx

    6.查看链路

    [root@localhost ~]#multipath -ll mpatha ( 36001 4054e02babeaf6a45e8a 1385b2a6) dm-2 LIO_ORG,storage1 size=20G features='O' hwhandler= '0' wp=rw |-+- policy='service- time 0' prio= 1 status= active ‘-3:0:0:0 sdc 8:32 active ready running |-+- policy= 'service -time 0' prio= 1 status=enabled '-4:0:0:0 sdb 8:16 active ready running

    模拟故障 1.关闭一张存储端的网卡 2.查看链路状态

    [root@localhost ~]#multipath -ll mpatha (36001 4054e02babeaf6a45e8a 1 385b2a6) dm-2 LIO_ORG,storage1 size= 20G features='0' hwhandler='0' wp= rw | -+- policy='service -time O' prio= 1 status=active ’-3:0:0:0 sdc 8:32 active ready running |-+- policy= 'service-time 0' prio= 1 status=encabled ‘-4:0:0:0 sdb 8:1 6 active undef running

    3.仍然可以写数据

    [root@localhost yx]#mkdir video lost+found video
    Processed: 0.009, SQL: 9