iscsi多路径配置方式

约定不等于承诺〃 2022-12-25 15:54 404阅读 0赞

学习一个服务的过程:

1、此服务器的概述:名字,功能,特点,端口号
2、安装
3、配置文件的位置
4、服务启动关闭脚本,查看端口
5、此服务的使用方法
6、修改配置文件,实战举例
7、排错(从下到上,从内到外)

内容:

•实战:配置IP SAN多路径实现磁盘挂载高可用
•实战:在应用服务器上使用udev规则为target创建固定名字的软链接

ISCSI多路径应用

如果存储服务器到交换机只有一条线路的时候,那么一条线路出线故障,整个就没法使用了,所以多线路可以解决这个问题,避免单点故障
在这里插入图片描述
通过VMware模拟多路径,使用下面的拓扑:
在这里插入图片描述
实验环境: 63,64配置双网卡 。
服务端:63.cn IP:192.168.1.63 ens32 ,br ; IP:192.168.2.63 ens35 , vmnet4
客户端:64.cn IP:192.168.1.64 ens32 ,br ; IP:192.168.2.64 ens35 , vmnet4

将63配置成ip san,将63上的sdb1分区,通过ip san 共享出去。
服务器端: target 63
客户端: initiator 64

配置网络环境:
xuegod63 添加一块网卡:
在这里插入图片描述
生成ens35配置文件,配置IP ,192.168.2.63

  1. 63 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens35

在这里插入图片描述

  1. 63 Desktop]# ifdown ens35;ifup ens35

安装tgtd服务器:

  1. 63 Desktop]# yum install -y scsi-target-utils

准备一个磁盘: sda4

  1. 63 ~]# fdisk /dev/sda #划分出sda4 分区
  2. WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
  3. switch off the mode (command 'c') and change display units to
  4. sectors (command 'u').
  5. Command (m for help): p
  6. Disk /dev/sda: 21.5 GB, 21474836480 bytes
  7. 255 heads, 63 sectors/track, 2610 cylinders
  8. Units = cylinders of 16065 * 512 = 8225280 bytes
  9. Sector size (logical/physical): 512 bytes / 512 bytes
  10. I/O size (minimum/optimal): 512 bytes / 512 bytes
  11. Disk identifier: 0x000b8b35
  12. Device Boot Start End Blocks Id System
  13. /dev/sda1 * 1 26 204800 83 Linux
  14. Partition 1 does not end on cylinder boundary.
  15. /dev/sda2 26 1301 10240000 83 Linux
  16. /dev/sda3 1301 1428 1024000 82 Linux swap / Solaris
  17. Command (m for help): n
  18. Command action
  19. e extended
  20. p primary partition (1-4)
  21. p
  22. Selected partition 4
  23. First cylinder (1428-2610, default 1428):
  24. Using default value 1428
  25. Last cylinder, +cylinders or +size{ K,M,G} (1428-2610, default 2610): +1G
  26. Command (m for help): w
  27. The partition table has been altered!
  28. Calling ioctl() to re-read partition table.
  29. WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
  30. The kernel still uses the old table. The new table will be used at
  31. the next reboot or after you run partprobe(8) or kpartx(8)
  32. Syncing disks.
  33. 63 ~]#reboot

配置target ,把sda4分区共享出去
修改配置文件

  1. vim /etc/tgt/targets.conf #写入以下内容
  2. 在参考这段内容并在段内容后,追加以下红色标记内容:
  3. #<target iqn.2008-09.com.example:server.target4>
  4. 76 # direct-store /dev/sdb # Becomes LUN 1
  5. 77 # direct-store /dev/sdc # Becomes LUN 2
  6. 78 # direct-store /dev/sdd # Becomes LUN 3
  7. 79 # write-cache off
  8. 80 # vendor_id MyCompany Inc.
  9. 81 #</target>
  10. 为:
  11. <target iqn.2015-01.cn.xuegod.www:target_san1>
  12. backing-store /dev/sda4
  13. initiator-address 192.168.1.64
  14. initiator-address 192.168.2.64 #在访问控制列表中添加一个客户端
  15. vendor_id xuegod
  16. product_id target1
  17. </target>

注释:
default-driver iscsi #此配置文件默认全部注释,使用iscsi驱动

  1. 63 Desktop]#systemctl restart tgtd
  2. 63 Desktop]# netstat -antup | grep 3260
  3. tcp 0 0 0.0.0.0:3260 0.0.0.0:* LISTEN 3130/tgtd
  4. tcp 0 0 :::3260 :::* LISTEN 3130/tgtd
  1. 查看状态tgt-admin —show

    63 Desktop]# tgt-admin —show
    Target 1: iqn.2015-01.cn.xuegod.www:target_san1

    1. System information:
    2. Driver: iscsi
    3. State: ready
    4. I_T nexus information:
    5. LUN information:
    6. LUN: 0
    7. Type: controller
    8. SCSI ID: IET 00010000
    9. SCSI SN: beaf10
    10. Size: 0 MB, Block size: 1
    11. Online: Yes
    12. Removable media: No
    13. Readonly: No
    14. Backing store type: null
    15. Backing store path: None
    16. Backing store flags:
    17. LUN: 1
    18. Type: disk
    19. SCSI ID: IET 00010001
    20. SCSI SN: beaf11
    21. Size: 5372 MB, Block size: 512
    22. Online: Yes
    23. Removable media: No
    24. Readonly: No
    25. Backing store type: rdwr
    26. Backing store path: /dev/sda4
    27. Backing store flags:
    28. Account information:
    29. ACL information: #允许哪些客户端可以访问
    30. 192.168.1.64
    31. 192.168.2.64

开机启动:

  1. 63 Desktop]# chkconfig tgtd on

配置客户端: 64

安装包:

  1. 64 ~]# rpm -ivh /mnt/Packages/iscsi-initiator-utils-6.2.0.872-34.el6.x86_64.rpm

需要先发现target存储,再启动客户端服务,才有效

  1. 64 ~]# iscsiadm -m discovery -t sendtargets -p 192.168.1.63:3260
  2. Starting iscsid: [ OK ] #发现时,会自动把iscsid服务启动
  3. 192.168.1.63:3260,1 iqn.2015-01.cn.xuegod.www:target_san1
  4. 64 ~]#systemctl restart scsi # 根据/var/lib/iscsi/ 中发现的信息,识别设备
  5. Stopping iscsi: [ OK ]
  6. Starting iscsi: [ OK ]

开机自动启动:

  1. 64 ~]# systemctl enable iscsi
  2. 64 ~]# systemctl enable iscsid

查看发现到新硬盘:

  1. 64 ~]# ls /dev/sdb
  2. /dev/sdb

在xuegod63服务端查看链接状态

  1. 63 ~]# netstat -antup | grep 3260
  2. tcp 0 0 0.0.0.0:3260 0.0.0.0:* LISTEN 1999/tgtd
  3. tcp 0 0 192.168.1.63:3260 192.168.1.64:46553 ESTABLISHED 1999/tgtd
  4. tcp 0 0 :::3260 :::* LISTEN 1999/tgtd

客户端从另一条线路发现设备:

  1. 64 ~]# iscsiadm -m discovery -t sendtargets -p 192.168.2.63
  2. 192.168.2.63:3260,1 iqn.2015-01.cn.xuegod.www:target_san1
  3. 64 ~]# rpm -ivh /mnt/Packages/tree-1.5.3-2.el6.x86_64.rpm
  4. 64 ~]# tree /var/lib/iscsi/
  5. /var/lib/iscsi/
  6. ├── ifaces
  7. ├── isns
  8. ├── nodes
  9. └── iqn.2015-01.cn.xuegod.www:target_san1
  10. ├── 192.168.1.63,3260,1
  11. └── default
  12. └── 192.168.2.63,3260,1
  13. └── default
  14. ├── send_targets
  15. ├── 192.168.1.63,3260
  16. ├── iqn.2015-01.cn.xuegod.www:target_san1,192.168.1.63,3260,1,default -> /var/lib/iscsi/nodes/iqn.2015-01.cn.xuegod.www:target_san1/192.168.1.63,3260,1
  17. └── st_config
  18. └── 192.168.2.63,3260
  19. ├── iqn.2015-01.cn.xuegod.www:target_san1,192.168.2.63,3260,1,default -> /var/lib/iscsi/nodes/iqn.2015-01.cn.xuegod.www:target_san1/192.168.2.63,3260,1
  20. └── st_config

识别出硬盘并查看:

  1. 64 ~]# /etc/init.d/iscsi restart
  2. Stopping iscsi: [ OK ]
  3. Starting iscsi: [ OK ]
  4. 64 ~]# ls /dev/sd*
  5. /dev/sda /dev/sda1 /dev/sda2 /dev/sda3 /dev/sdb /dev/sdc

挂载硬盘测试数据:

  1. 64 ~]# fdisk /dev/sdb #使用sdb中所有空间,创建sdb1分区
  2. Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
  3. Building a new DOS disklabel with disk identifier 0x337c0db1.
  4. Changes will remain in memory only, until you decide to write them.
  5. After that, of course, the previous content won't be recoverable.
  6. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
  7. WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
  8. switch off the mode (command 'c') and change display units to
  9. sectors (command 'u').
  10. Command (m for help): n
  11. Command action
  12. e extended
  13. p primary partition (1-4)
  14. p
  15. Partition number (1-4): 1
  16. First cylinder (1-1019, default 1):
  17. Using default value 1
  18. Last cylinder, +cylinders or +size{ K,M,G} (1-1019, default 1019):
  19. Using default value 1019
  20. Command (m for help): w
  21. The partition table has been altered!
  22. Calling ioctl() to re-read partition table.
  23. Syncing disks.
  24. 64 ~]# mkfs.ext4 /dev/sdb1
  25. 64 ~]# mount /dev/sdb1 /opt/
  26. 64 ~]# df -h
  27. Filesystem Size Used Avail Use% Mounted on
  28. /dev/sda2 9.7G 3.7G 5.5G 41% /
  29. tmpfs 569M 0 569M 0% /dev/shm
  30. /dev/sda1 194M 28M 157M 15% /boot
  31. /dev/sr0 3.4G 3.4G 0 100% /mnt
  32. /dev/sdb1 5.0G 138M 4.6G 3% /opt

注:可以看到sdb1可以正常使用

  1. 64 ~]# ls /dev/sdc* #查看不到sdc1
  2. /dev/sdc
  3. 64 ~]# /etc/init.d/iscsi restart #重启iscsi服务,重新挂载存储
  4. Stopping iscsi: [ OK ]
  5. Starting iscsi: [ OK ]
  6. 64 ~]# ls /dev/sdc*
  7. /dev/sdc /dev/sdc1
  8. 64 ~]# mkdir /tmp/sdc1
  9. 64 ~]# mount /dev/sdc1 /tmp/sdc1/
  10. 64 ~]# mount /dev/sdb1 /opt 挂载报错了吧?

在这里插入图片描述

  1. [root@xuegod64 ~]# blkid /dev/sdc1 /dev/sdb1 # 对比一下,发现UUID一样的

解决方法:

  1. 64 ~]#mount -t xfs -o nouuid /dev/sdb1 /opt
  2. 64 ~]# df -h
  3. Filesystem Size Used Avail Use% Mounted on
  4. /dev/sda2 9.7G 3.7G 5.5G 41% /
  5. tmpfs 569M 0 569M 0% /dev/shm
  6. /dev/sda1 194M 28M 157M 15% /boot
  7. /dev/sr0 3.4G 3.4G 0 100% /mnt
  8. /dev/sdc1 5.0G 138M 4.6G 3% /tmp/sdc1
  9. /dev/sdb1 5.0G 138M 4.6G 3% /opt

实例5: 在存储客户端xuegod64上配置多路径
多路径软件Device Mapper Multipath(DM-Multipath)可以将服务器节点和存储阵列之间的多条I/O链路配置为一个单独的设备。这些I/O链路是由不同的线缆、交换机、控制器组成的SAN物理链路。Multipath将这些链路聚合在一起,生成一个单独的新的设备。
1.DM-Multipath概览:
(1)数据冗余
DM-Multipath可以实现在active/passive模式下的灾难转移。在active/passive模式下,只有一半的链路在工作,如果链路上的某一部分(线缆、交换机、控制器)出现故障,DM-Multipath就会切换到另一半链路上。
(2)提高性能
DM-Multipath也可以配置为active/active模式,从而I/O任务以round-robin的方式分布到所有的链路上去。通过配置,DM-Multipath还可以检测链路上的负载情况,动态地进行负载均衡。

安装多路经软件

  1. 64 ~]# yum install device-mapper-multipath -y

使用默认配置文件启动

  1. 64 ~]# cp /usr/share/doc/device-mapper-multipath-0.4.9/multipath.conf /etc/
  2. 64 ~]# systemctl restart multipathd
  3. 64 ~]# multipath -ll #没有输出消息。 表示出错了。

解决:把正在使用中的sdb1和sdbc1卸载了

  1. 64 ~]# umount /opt/
  2. 64 ~]# umount /tmp/sdc1/
  3. 64 ~]# /etc/init.d/iscsi restart
  4. 64 ~]# systemctl restart multipathd
  5. 64 ~]# multipath -ll
  6. 3600000000e00000000010001(远程存储设备iddm-2 xuegod(厂商) ,target1(产品ID
  7. size=5.0G features='0' hwhandler='0' wp=rw
  8. |-+- policy='service-time 0' prio=1 status=active #默认使用active的链路
  9. | `- 34:0:0:1 sdb 8:16 active ready running
  10. `-+- policy='service-time 0' prio=1 status=enabled #有效的链路,但不是活动链路
  11. `- 35:0:0:1 sdc 8:32 active ready running
  12. #默认配置并不会实现负载均衡,只会实现高可用的效果。
  13. # (3600000000e00000000010001) 远程存储设备的产品信息,由于sda和sdb对应的都是远端同一个存储,所以产品信息是一样的,最后被多路经驱动发现,所以为他们生成了一个设备文件/dev/mapper/mpatha
  14. # ll /dev/mapper/mpatha*
  15. lrwxrwxrwx 1 root root 7 1月 13 09:02 /dev/mapper/mpatha -> ../dm-2
  16. lrwxrwxrwx 1 root root 7 1月 13 09:02 /dev/mapper/mpathap1 -> ../dm-3

如图:
在这里插入图片描述

实战2:修改配置文件,启动高可用负载均衡模式,并自定义多路经设备文件的名字:

  1. vim /etc/multipath.conf

注销掉下面三行内容
在这里插入图片描述
请在此模版下写内容:
在这里插入图片描述
在74行以下插入以下内容:

  1. multipaths {
  2. multipath {
  3. wwid "360000000000000000e00000000010001" #填写硬盘产品关键信息
  4. alias webdata #自定义名字
  5. path_grouping_policy multibus
  6. path_selector "round-robin 0"
  7. failback manual
  8. rr_weight priorities
  9. no_path_retry 5
  10. }
  11. }
  12. multipaths {
  13. multipath {
  14. wwid "360000000000000000e00000000010001" #填写硬盘产品关键信息
  15. alias webdata #自定义名字
  16. path_grouping_policy multibus
  17. path_selector "round-robin 0"
  18. failback manual
  19. rr_weight priorities
  20. no_path_retry 5
  21. }
  22. }

发表评论

表情:
评论列表 (有 0 条评论,404人围观)

还没有评论,来说两句吧...

相关阅读

    相关 ISCSI路径配置(二)

    [搭建iscsi存储系统(一)][iscsi] (1).配置ISCSI多路径实现磁盘挂载高可用   如果存储服务器到交换机只有一条线路的时候,那么一条线路出现故障,整个就没

    相关 ISCSI

    一:什么是iSCSI? iSCSI 是一种 SAN的设备而 SAN的设备主要是提供 Server 存储体的空间.相较于传统的 SAN 是以光纤为传输媒体而 iSCSI(In