iscsi多路径配置方式

学习一个服务的过程:

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

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

在这里插入图片描述

63 Desktop]# ifdown ens35;ifup ens35

安装tgtd服务器:

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

准备一个磁盘: sda4

63 ~]# fdisk /dev/sda    #划分出sda4 分区
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): p

Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x000b8b35
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          26      204800   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              26        1301    10240000   83  Linux
/dev/sda3            1301        1428     1024000   82  Linux swap / Solaris

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Selected partition 4
First cylinder (1428-2610, default 1428): 
Using default value 1428
Last cylinder, +cylinders or +size{K,M,G} (1428-2610, default 2610): +1G

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.
63 ~]#reboot

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

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

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

63 Desktop]#systemctl restart tgtd 
63 Desktop]# netstat  -antup | grep 3260
tcp        0      0 0.0.0.0:3260                0.0.0.0:*                   LISTEN      3130/tgtd           
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
    System information:
        Driver: iscsi
        State: ready
    I_T nexus information:
    LUN information:
        LUN: 0
            Type: controller
            SCSI ID: IET     00010000
            SCSI SN: beaf10
            Size: 0 MB, Block size: 1
            Online: Yes
            Removable media: No
            Readonly: No
            Backing store type: null
            Backing store path: None
            Backing store flags: 
        LUN: 1
            Type: disk
            SCSI ID: IET     00010001
            SCSI SN: beaf11
            Size: 5372 MB, Block size: 512
            Online: Yes
            Removable media: No
            Readonly: No
            Backing store type: rdwr
            Backing store path: /dev/sda4
            Backing store flags: 
    Account information:
    ACL information:  #允许哪些客户端可以访问
        192.168.1.64
        192.168.2.64

开机启动:

63 Desktop]# chkconfig tgtd on

配置客户端: 64

安装包:

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

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

64 ~]# iscsiadm -m discovery -t sendtargets -p 192.168.1.63:3260
Starting iscsid:         [  OK  ]  #发现时,会自动把iscsid服务启动
192.168.1.63:3260,1 iqn.2015-01.cn.xuegod.www:target_san1

64 ~]#systemctl restart  scsi  # 根据/var/lib/iscsi/  中发现的信息,识别设备
Stopping iscsi:                                            [  OK  ]
Starting iscsi:                                            [  OK  ]

开机自动启动:

64 ~]# systemctl enable iscsi
64 ~]# systemctl enable iscsid

查看发现到新硬盘:

64 ~]# ls /dev/sdb
/dev/sdb

在xuegod63服务端查看链接状态

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

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

64 ~]# iscsiadm -m discovery -t sendtargets -p 192.168.2.63
192.168.2.63:3260,1 iqn.2015-01.cn.xuegod.www:target_san1
64 ~]# rpm -ivh /mnt/Packages/tree-1.5.3-2.el6.x86_64.rpm 
64 ~]# tree /var/lib/iscsi/
/var/lib/iscsi/
├── ifaces
├── isns
├── nodes
│   └── iqn.2015-01.cn.xuegod.www:target_san1
│       ├── 192.168.1.63,3260,1
│       │   └── default
│       └── 192.168.2.63,3260,1
│           └── default
├── send_targets
│   ├── 192.168.1.63,3260
│   │   ├── 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
│   │   └── st_config
│   └── 192.168.2.63,3260
│       ├── 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
│       └── st_config

识别出硬盘并查看:

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

挂载硬盘测试数据:

64 ~]# fdisk /dev/sdb   #使用sdb中所有空间,创建sdb1分区
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x337c0db1.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

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): 1
First cylinder (1-1019, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1019, default 1019): 
Using default value 1019

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

Calling ioctl() to re-read partition table.
Syncing disks.

64 ~]# mkfs.ext4 /dev/sdb1
64 ~]# mount /dev/sdb1 /opt/
64 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2             9.7G  3.7G  5.5G  41% /
tmpfs                 569M     0  569M   0% /dev/shm
/dev/sda1             194M   28M  157M  15% /boot
/dev/sr0              3.4G  3.4G     0 100% /mnt
/dev/sdb1             5.0G  138M  4.6G   3% /opt

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

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

在这里插入图片描述

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

解决方法:

64 ~]#mount -t xfs -o nouuid /dev/sdb1 /opt

64 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2             9.7G  3.7G  5.5G  41% /
tmpfs                 569M     0  569M   0% /dev/shm
/dev/sda1             194M   28M  157M  15% /boot
/dev/sr0              3.4G  3.4G     0 100% /mnt
/dev/sdc1             5.0G  138M  4.6G   3% /tmp/sdc1
/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还可以检测链路上的负载情况,动态地进行负载均衡。

安装多路经软件

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

使用默认配置文件启动

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

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

64 ~]# umount /opt/
64 ~]# umount /tmp/sdc1/

64 ~]# /etc/init.d/iscsi restart
64 ~]# systemctl restart multipathd
64 ~]# multipath -ll
3600000000e00000000010001(远程存储设备id)dm-2 xuegod(厂商) ,target1(产品ID)         
size=5.0G features='0' hwhandler='0' wp=rw
|-+- policy='service-time 0' prio=1 status=active   #默认使用active的链路
| `- 34:0:0:1 sdb 8:16 active ready running
`-+- policy='service-time 0' prio=1 status=enabled  #有效的链路,但不是活动链路
  `- 35:0:0:1 sdc 8:32 active ready running
#默认配置并不会实现负载均衡,只会实现高可用的效果。

# (3600000000e00000000010001)  远程存储设备的产品信息,由于sda和sdb对应的都是远端同一个存储,所以产品信息是一样的,最后被多路经驱动发现,所以为他们生成了一个设备文件/dev/mapper/mpatha

# ll /dev/mapper/mpatha*
lrwxrwxrwx 1 root root 7 113 09:02 /dev/mapper/mpatha -> ../dm-2
lrwxrwxrwx 1 root root 7 113 09:02 /dev/mapper/mpathap1 -> ../dm-3

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

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

vim /etc/multipath.conf   

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

multipaths {
        multipath {
                wwid   "360000000000000000e00000000010001"   #填写硬盘产品关键信息
                alias                   webdata   #自定义名字
                path_grouping_policy    multibus
                 path_selector           "round-robin 0"
                failback                 manual
                rr_weight               priorities
                no_path_retry           5
        }
}
multipaths {
        multipath {
                wwid   "360000000000000000e00000000010001"   #填写硬盘产品关键信息
                alias                   webdata   #自定义名字
                path_grouping_policy    multibus
                 path_selector           "round-robin 0"
                failback                 manual
                rr_weight               priorities
                no_path_retry           5
        }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

寰宇001

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值