SCST配置ALUA的支持

背景

在多路径配置下面,如果是主备的情况下,那么哪个盘是主盘,这个默认来说是没有办法进行配置的,这个时候需要服务端进行一个控制,来实现这个,这个是通过SCSI的协议把相关的信息保存在磁盘属性里面的,然后客户端程序再根据这个通用的标准进行主备的选择,这里不详细讲ALUA

像那种双控的盘阵,比如有两个控制器,一个主,一个备的,然后主上面有4个链路,备的上面有4个链路

多路径连上去以后,多路径软件能够把主控和备控制器进行区分,存在不同的优先级,进行分组,然后主的里面也可以根据配置去选择是单主还是多主

实现的软件

tgt这个默认是不支持这个功能的,scst是支持的,本次配置就是通过scst进行配置

配置

主target的配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
[root@lab102 ~]# cat /etc/scst.conf
HANDLER vdisk_fileio {
DEVICE disk1 {
filename /dev/rbd/rbd/testiscsi
nv_cache 1
}
}

TARGET_DRIVER iscsi {
enabled 1
TARGET iscsi_target1 {
LUN 0 disk1
enabled 1
}
}

DEVICE_GROUP dgroup1 {
DEVICE disk1

TARGET_GROUP tgroup1 {
group_id 1
state active
preferred 1

TARGET iscsi_target1 {
rel_tgt_id 1
}
}

备target的配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
[root@lab101 ~]# cat /etc/scst.conf
HANDLER vdisk_fileio {
DEVICE disk1 {
filename /dev/rbd/rbd/testiscsi
nv_cache 1
}
}

TARGET_DRIVER iscsi {
enabled 1
TARGET iscsi_target1 {
LUN 0 disk1
enabled 1
}
}
DEVICE_GROUP dgroup1 {
DEVICE disk1

TARGET_GROUP tgroup1 {
group_id 1
state nonoptimized
preferred 0

TARGET iscsi_target1 {
rel_tgt_id 1
}
}

}

关键配置
主设置

1
2
state active
preferred 1

备设置

1
2
state nonoptimized
preferred 0

iscsi客户端连接

查看连接的信息

1
2
3
4
5
6
7
8
9
10
[root@lab105 ~]# dmesg
[29885.203661] scsi host46: iSCSI Initiator over TCP/IP
[29885.220742] scsi 46:0:0:0: Direct-Access SCST_FIO disk1 360 PQ: 0 ANSI: 6
[29885.238029] scsi 46:0:0:0: alua: supports implicit TPGS
[29885.238040] scsi 46:0:0:0: alua: device eui.6238666462643332 port group 1 rel port 1
[29885.238047] scsi 46:0:0:0: alua: Attached
[29885.239421] sd 46:0:0:0: Attached scsi generic sg2 type 0
[29885.239834] sd 46:0:0:0: Power-on or device reset occurred
[29885.244954] sd 46:0:0:0: alua: transition timeout set to 60 seconds
[29885.244965] sd 46:0:0:0: alua: port group 01 state A preferred supports TOlUSNA

上面的是连接的信息,可以看到几个关键信息

1
port group 01 state A preferred

这个就是状态是A,并且preffered的

查看磁盘信息

1
2
3
4
5
6
7
8
9
10
11
12
13
[root@lab105 ~]# sg_rtpg -v /dev/sdd
report target port groups cdb: a3 0a 00 00 00 00 00 00 04 00 00 00
report target port group: pass-through requested 1024 bytes but got 16 bytes
Report list length = 16
Report target port groups:
target port group id : 0x1 , Pref=1
target port group asymmetric access state : 0x00
T_SUP : 1, O_SUP : 1, LBD_SUP : 0, U_SUP : 1, S_SUP : 1, AN_SUP : 1, AO_SUP : 1
status code : 0x02
vendor unique status : 0x00
target port count : 01
Relative target port ids:
0x01

可以看到磁盘的状态

1
Pref=1
1
2
3
4
5
6
7
8
9
10
11
12
13
[root@lab105 ~]# sg_inq /dev/sdd
standard INQUIRY:
PQual=0 Device_type=0 RMB=0 version=0x06 [SPC-4]
[AERC=0] [TrmTsk=0] NormACA=1 HiSUP=0 Resp_data_format=2
SCCS=0 ACC=0 TPGS=1 3PC=1 Protect=0 [BQue=0]
EncServ=0 MultiP=1 (VS=0) [MChngr=0] [ACKREQQ=0] Addr16=0
[RelAdr=0] WBus16=0 Sync=0 Linked=0 [TranDis=0] CmdQue=1
[SPI: Clocking=0x0 QAS=0 IUS=0]
length=66 (0x42) Peripheral device type: disk
Vendor identification: SCST_FIO
Product identification: disk1
Product revision level: 360
Unit serial number: b8fdbd32

这个命令可以看到支持了TPGS=1,需要这个显示是1就是支持了

备用节点的iscsi信息

1
2
3
4
5
6
7
8
9
10
11
[root@lab105 ~]# dmesg
[30103.927420] scsi host47: iSCSI Initiator over TCP/IP
[30103.944329] scsi 47:0:0:0: Direct-Access SCST_FIO disk1 360 PQ: 0 ANSI: 6
[30103.965061] scsi 47:0:0:0: alua: supports implicit TPGS
[30103.965072] scsi 47:0:0:0: alua: device eui.6238666462643332 port group 1 rel port 1
[30103.965079] scsi 47:0:0:0: alua: Attached
[30103.965366] sd 47:0:0:0: Attached scsi generic sg3 type 0
[30103.967790] sd 47:0:0:0: Power-on or device reset occurred
[30103.973556] sd 47:0:0:0: [sde] 41943040 512-byte logical blocks: (21.4 GB/20.0 GiB)
[30103.973562] sd 47:0:0:0: [sde] 4096-byte physical blocks
[30103.973621] sd 47:0:0:0: alua: port group 01 state N non-preferred supports TOlUSNA

可以看到状态是state N non-preferred,跟我们设置的一致

多路径配置

做最简单的配置

1
2
3
4
5
6
7
8
[root@lab105 ~]# cat /etc/multipath.conf
blacklist {
devnode "^sd[a]"
}
defaults {
user_friendly_names yes
prio "alua"
}

跟默认配置只增加了prio alua,这个就是告诉系统启用alua的

查看信息

1
2
3
4
5
6
7
[root@lab105 ~]# multipath -ll
mpathc (26238666462643332) dm-3 SCST_FIO,disk1
size=20G features='0' hwhandler='0' wp=rw
|-+- policy='service-time 0' prio=50 status=active
| `- 46:0:0:0 sdd 8:48 active ready running
`-+- policy='service-time 0' prio=10 status=enabled
`- 47:0:0:0 sde 8:64 active ready running

查询磁盘的状态,可以看到主的prio=50,备的prio=10,这个跟我们设置的一致,通过上面的设置以后,就能够在客户端这边进行多路径的主备的优先级的选择了