tongsiying

阅读|运动|自律

0%

BlockStorage-iscsi

001-常用接口:

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
snbs使用iscsi方式:参考网址:http://www.cnblogs.com/wangzhigang/p/4609392.html
注:snbs是一个卷对应一个tid,一个iqn,lun id固定是1
1.服务端启动:
/usr/sbin/tgtd 0
注:0表示带日志打印

2.添加tid
tgtadm --lld iscsi --op new --mode target --tid 3200 -T iqn.2001-04.com.example:storage.disk2.amiens.sys1.xyz

3.删除ID为[id]的target:
tgtadm --lld iscsi --op delete --mode target --tid 3200

4.将创建出来的块设备加入tid
tgtadm --lld iscsi --op new --mode logicalunit --tid 3200 --lun 1 -b volume-name
注:volume-name是在snbs上创建的卷名

5.删除lun:
tgtadm --lld iscsi --op delete --mode logicalunit --tid 3200 --lun 1

6.查询tid中的lun:
tgtadm --lld iscsi --op show --mode target

7.启动监听,端口3260
tgtadm --lld iscsi --op bind --mode target --tid 1 -I ALL
或者
开放给192.168.85.0/24网段内的主机访问
tgtadm -L iscsi -o bind -m target -t 1 -I 192.168.85.0/24

8.开日志(日志路径:/var/log/message)
tgtadm --lld iscsi --op snbslog --mode target 

10.在iscsi上查看块设备信息
tgtadm --lld iscsi --op gateway --mode target

11.打开iscsi读写io开关
tgtadm --lld iscsi --op iostat --mode target

12.扩容
tgtadm --lld iscsi --op expand --mode target --tid 1 --lun 1

13.查询服务端的iqn:
iscsiadm --mode discovery --type sendtargets --portal 10.242.180.212:3260
或者
iscsiadm -m discovery -t st -p 192.168.14.112
注:
-t --type=type  #这里可以使用的类型为sendtargets(可简写为st)、slp、fw和 isns,此选项仅用于discovery模式,且目前仅支持st、fw和isns;其中st表示允许每个iSCSItarget发送一个可用target列表给initiator;
-m  --mode op  #可用的mode有discovery, node, fw, host iface 和 session
-p  --portal=ip[:port]   #指定target服务的IP和端口;

14.iscsi客户端登录服务端iqn:
登录单个:
iscsiadm -m node --targetname iqn.2001-04.com.example:storage.disk2.amiens.sys1.xyz --portal 10.242.180.212:3260 --login
或者
iscsiadm -m node -T iqn.2001-04.com.example:storage.disk2.amiens.sys1.xyz -l
登录所有:
iscsiadm -m node -L all(登陆发现的所有目标器)
登入需验证码的节点,在登陆前需执行:
1)开启认证
iscsiadm -m node -T  iqn.2015.06.cn.hrbyg.www.ygcs.c0a802b8:wzgchap -o update --name node.session.auth.authmethod --value=CHAP
2)添加用户
iscsiadm -m node -T  iqn.2015.06.cn.hrbyg.www.ygcs.c0a802b8:wzgchap --op update --name node.session.auth.username --value=mychap
3)添加密码
iscsiadm –m node –T  iqn.2015.06.cn.hrbyg.www.ygcs.c0a802b8:wzgchap -–op update –name node.session.auth.password –value=mypassword

15.登出iqn:
退出某个目标器:
iscsiadm -m node --targetname iqn.2001-04.com.example:storage.disk2.amiens.sys1.xyz --portal 10.242.180.212:3260 --logout
或者
iscsiadm -m node -T iqn.2001-04.com.example:storage.disk2.amiens.sys1.xyz -u
退出所有目标器:
iscsiadm -m node -U all
连接死掉(断网或者target端断掉)时,使用如下指令:
iscsiadm -m node -o delete –T  iqn.2015.06.cn.hrbyg.www.ygcs.c0a802b8:wzgchap -p 192.168.14.112

16.查看target记录
iscsiadm -m node

17.查看session
iscsiadm -m session (相当于iscsiadm -m session -P 0
iscsiadm -m session -P 3  (0-3均可,默认为0)

18.设置开机自动登录
sudo iscsiadm -m node -o update -n node.startup -v automatic (可与-T选项结合使用,manual为手动的)
注:open-iscsi配置文件在/etc/iscsi目录下。

19.# 将LUN的gateway切换到指定gateway。该操作是异步的,同时需要LUN不为切换状态(主动切换gateway上的卷,有利于gateway升级)
tgtadm --lld iscsi --op transfer --mode target --tid=1 --lun=1 --initiator-address 10.37.2.16:8585

002-超时设置:

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
有三种超时:
前端块设备超时时间:-------设置无限大
iscsi tgt配置文件超时时间:-------设置无限大
tgt里面读写超时时间:-------我们灵活设置,就可以控制整体的超时了

前端块设备超时时间:
以iscsiadm添加LUN的计算机上,编辑配置文件 /etc/udev/rules.d/50-udev.rules
ACTION=="add", SUBSYSTEM=="scsi" , ATTRS{model}=="SNBS-DISK", RUN+="/bin/sh -c 'echo 86400 > /sys$$DEVPATH/timeout'"
配置好后,添加LUN后,假设对应sdu,执行下面指令,看一下是不是86400
cat /sys/block/sdu/device/timeout
【需要重新logout logn生效】

iscsi tgt配置文件超时时间:
之前让调研iscsi不产生超时,一直阻塞io的方法,结论如下:
/etc/iscsi/iscsid.conf                                                                  -----------该配置文件可以配置iscsi 客户端的io超时时间
# To specify the length of time to wait for session re-establishment
# before failing SCSI commands back to the application when running
# the Linux SCSI Layer error handler, edit the line.
# The value is in seconds and the default is 120 seconds.
# Special values:
# - If the value is 0, IO will be failed immediately.
# - If the value is less than 0, IO will remain queued until the session
# is logged back in, or until the user runs the logout command.
node.session.timeo.replacement_timeout = 120                        
---------------默认是120重试,可以自己配置时间或者使用小于0的值不重试,将io一直挂住
3600 是重试3600秒
86400

tgt里面读写超时时间:
下面命令配合错误码和重试:
# 操作超时,单位:秒
# 设置写超时
tgtadm --lld iscsi --op timeout --mode target --name=write --value=86400
# 设置读超时
tgtadm --lld iscsi --op timeout --mode target --name=read --value=86400

# 重试超时,单位:秒
# 设置写重试超时
tgtadm --lld iscsi --op timeout --mode target --name=writeretry --value=86400
# 设置读重试超时
tgtadm --lld iscsi --op timeout --mode target --name=readretry --value=86400

# 切换/重连超时,单位:秒
# 切换等待时间
tgtadm --lld iscsi --op timeout --mode target --name=switch --value=86400
# 切回等待时间,10的倍数
tgtadm --lld iscsi --op timeout --mode target --name=recovery --value=86400
# LUN状态FAULT,恢复重连超时,10的倍数
tgtadm --lld iscsi --op timeout --mode target --name=reconnect --value=86400

查看是否设置成功:
tgtadm --lld iscsi --op gateway --mode target

003-更换tgtd端口:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
更换tgtd3260端口方法:
1.启动tgtd指定端口
tgtd --iscsi portal=0.0.0.0:3261
进程必须如下图所示:
[root@snbs-208 one-vol]# ps -ef|grep tgtd
root 13943 12998 0 14:35 pts/1 00:00:00 grep --color=auto tgtd
root 28410 1 1 Mar02 ? 06:03:05 /usr/sbin/tgtd --iscsi portal=0.0.0.0:3261
root 28411 28410 0 Mar02 ? 00:00:08 /usr/sbin/tgtd --iscsi portal=0.0.0.0:3261

2.先查看当前的端口
[root@host102442554 snbs]# tgtadm --lld iscsi --op show --mode portal
Portal: [::]:3260,1
Portal: 0.0.0.0:3260,1

3.删除3260端口
tgtadm --lld iscsi --op delete --mode portal --param portal=0.0.0.0:3260
tgtadm --lld iscsi --op delete --mode portal --param portal=[::]:3260

4.新增3261端口
tgtadm --lld iscsi --op new --mode portal --param portal=0.0.0.0:3261
tgtadm --lld iscsi --op new --mode portal --param portal=[::]:3261

查询:
tgtadm --lld iscsi --op show --mode portal

004-iscsi的客户端守护进程:

1
2
3
iscsi的客户端:上执行
service iscsi start
systemctl status iscsi

005-iscsi安装:

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
安装iscsi-target-utils(服务端)
10.242.180.21010.242.180.21110.242.180.212上执行
1)下载源码svn:
https://d.svncode.cnsuning.com/svn/snbs/branches/snbs_V0.5/c/tgt-1.0.73
2)源码安装:
进入tgt-1.0.73目录
执行make
在执行 make install
iscsi-target-utils服务端配置:
1.在根目录下创建 snbs_config文件,里面配置gateway的ip和端口,例如:
10.242.180.207:8585
10.242.180.208:8585
10.242.180.209:8585
(一个卷对应一个gateway)

2.在根目录下面创建snbs_rdwr_sock文件,作为本地域套接字使用
touch /snbs_rdwr_sock


安装iscsi-initiator(客户端)
10.242.180.21010.242.180.21110.242.180.212上执行
yum install iscsi-initiator-utils.x86_64

1.iscsi-initiator(客户端)安装:
yum install iscsi-initiator

2.scsi-target-utils(服务端)安装:
下载源码svn:
https://d.svncode.cnsuning.com/svn/snbs/branches/snbs_V0.5/c/tgt-1.0.73
源码安装:
进入tgt-1.0.73目录
执行make
在执行 make install

3.其他配置:
在根目录下创建 snbs_config文件,里面配置tgtmaster的ip和端口
例如:
[root@host102442554 snbs]# cat /snbs_config
10.238.161.1:8989
10.238.161.2:8989
10.238.161.3:8989

4.启动iscsiServer
说明:为了使用方便,在iscsi服务端起一个server进程来实现tgtadm命令转http接口
启动命令:
/home/snbs/Iscsiserver/server -log_dir=/mnt/snbslog/snbs/Iscsiserver -v=0 Iscsi -ip=10.238.160.1 -masterip=10.238.161.1,10.238.161.2,10.238.161.3 -masterport=8383
涉及接口:查看server版本
[root@xgto01n010244025044 ~]# curl "http://127.0.0.1:9527/sys/ver?pretty=y"
{
"ChunkSize": "268435456",
"Version": "version SNBS_beatle-CentOS7.3-191012a-256M linux amd64"
}

006-tgtadm结果注释:

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
参考网址:http://blog.chinaunix.net/uid-30212356-id-5520549.html
Target 120: iqn.2019-01.com.suning:storage.snbs.7b33be00-2c30-4020-afe6-5d1c5c643f28
System information:
Driver: iscsi
State: ready
I_T nexus information:
I_T nexus: 22385
Initiator: iqn.2008-11.org.linux-kvm:1fa616b5-048b-4ef3-8a58-f1ca317ea381 alias: none
Connection: 0
IP Address: 10.238.160.1
LUN information:
LUN: 0
Type: controller
SCSI ID: IET 00780000
SCSI SN: beaf1200
Size: 0 MB, Block size: 1
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
SWP: No
Thin-provisioning: No
Backing store type: null
Backing store path: None
Backing store flags:
LUN: 1
Type: disk
SCSI ID: IET 00780001
SCSI SN: beaf1201
Size: 536871 MB, Block size: 512 #磁盘大小及块大小
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
SWP: No
Thin-provisioning: No
Backing store type: rdwr #访问类型
Backing store path: 7b33be00-2c30-4020-afe6-5d1c5c643f28 #关联设备(snbs的卷)
Backing store flags:
Account information:#客户端登录信息
ACL information:#授权信息
ALL

注:lun0是一个controller,而lun1则是一个磁盘;

007-iSCSICHAP认证不完全攻略:

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
iSCSI CHAP认证不完全攻略【带验证整理】:https://blog.csdn.net/sinchb/article/details/8433994
建立新账号
tgtadm --lld iscsi --op new --mode account --user han --password 123.com
显示账户信息
tgtadm --lld iscsi --op show --mode account
将一个账户和一个target邦定 (bind)
tgtadm --lld iscsi --op bind --mode account --tid 1 --user han 

一、 什么是CHAP?
Challenge-Handshake Authentication Protocol
iSCSI initiators and targets prove their identity to each other using the CHAP protocol, which includes a mechanism to prevent cleartext passwords from appearing on the wire.
翻译:
挑战握手验证协议
iSCSI发起方和目标方使用CHAP协议相互证明其身份,该协议包括一种防止明文密码出现在线路上的机制。

二、 iSCSI支持两种级别的chap 认证:
Initiator authentication和Target authentication
2.1 Initiator 认证要求:
    在initiator尝试连接到一个target的时候,initator需要提供一个用户名和密码给target供target进行认证。下面我们称这个用户名密码为incoming账号,即:incoming账号是initiator端提供给target端,供target端认证的账号。
2.2 target 认证要求:
    在initiator尝试连接到一个target的时候,target需要提供一个用户名和密码给initiator供initiator进行认证。与之对应的是outcoming账号,即:outcoming账号是target端提供给initiator端,供initiator认证的账号。
    Initiator认证可以在没有target 认证的时候应用,这种只要求target验证initiator的CHAP认证也称为Uni-directional Authentication,单向认证(target做验证)
    target认证则要求initiator认证被同时应用才可以,也就是说,initiator和target需要相互认证,这种认证被称为Bi-directional Authentication,相互认证
    iSCSI CHAP认证的密码长度必须介于12到16个字符(但是下面测试的时候字符长度都没有超过12字符,也没有问题,这个问题需要进一步求证),空格是合法的密码字符,所以”I Love iSCSI!!!!”是一个合法的密码!

三、 建立iscsi target lun
3.1在target端建立target
    按照下面的步骤建立有两个lun的target
(1)创建一个target
tgtadm --lld iscsi --op new --mode target --tid 1 -T 1qn.2012-12:disk0
(2)给这个target分配两个设备sdb,sdc
tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 1 -b /dev/sdb
tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 2 -b /dev/sdc
(3)将ACL设置为ALL
    ACL 是Access Control Lists 的缩写,访问控制列表,只有在这个列表中的ip才有权限访问本target。我们设置为ALL,默认所有ip都可以访问,当然,我们可以指定某些ip,只有这些ip才可以访问。
tgtadm --lld iscsi --op bind --mode target --tid 1 -I ALL (最后那个参数是大写字母I,不是数字1)
(4)看看我们创建的target
    [root@iscsiB ~]# tgt-admin --show
Target 1: 1qn.2012-12:disk0
    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
            Prevent removal: 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: 10737 MB, Block size: 512
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: rdwr
            Backing store path: /dev/sdb
            Backing store flags: 
        LUN: 2
            Type: disk
            SCSI ID: IET     00010002
            SCSI SN: beaf12
            Size: 5369 MB, Block size: 512
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: rdwr
            Backing store path: /dev/sdc
            Backing store flags: 
    Account information:
    ACL information:
        ALL
    我们可以看到有两个lun(lun0是控制器,不算)。而Account information则为空。

四、 配置initiator单向认证
设置initiator单向认证,要现在target端新建一个账号以及密码,并把这个账号绑定到特定的target上,然后再在initiator端的iscsi.conf文件中配置这个账号和密码。
4.1.在target端创建redhat账号,密码是redhat123
tgtadm --lld iscsi --mode account --op new --user redhat --password redhat123
4.2. 在target端将账号绑定到指定的target
tgtadm --lld iscsi --mode account --op bind --tid 1 --user redhat
tgtadm --lld iscsi --mode target --op show
    root@iscsiB ~]# tgt-admin --show
Target 1: 1qn.2012-12:disk0
    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
            Prevent removal: 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: 10737 MB, Block size: 512
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: rdwr
            Backing store path: /dev/sdb
            Backing store flags: 
        LUN: 2
            Type: disk
            SCSI ID: IET     00010002
            SCSI SN: beaf12
            Size: 5369 MB, Block size: 512
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: rdwr
            Backing store path: /dev/sdc
            Backing store flags: 
    Account information:
        redhat
    可以看到,redhat这个账号已经绑定到我们刚刚建立的target上了。
4.3.配置initiator端
4.3.1.在initiator端配置iscsid.conf文件
    打开这个文件,并找到CHAP Settings,先开启CHAP认证,然后填写账号密码。注意不要填错!!!
vim /etc/iscsi/iscsid.conf  #将相关项前面的注释符#删除掉 
node.session.auth.authmethod = CHAP   //开启CHAP认证
node.session.auth.username = redhat    //配置账号
node.session.auth.password = redhat123  //密码
4.3.2.重启iscsid服务
/etc/init.d/iscsid restart (似乎不是必要的,如果你不能重启iscsid,请查看是否已经登录到某些target了,如果是,就先logout)
4.3.3登录到target目标
iscsiadm -m discovery -t sendtargets -p 192.168.10.185(必须先discovery!!!)
iscsiadm -m node -T 1qn.2012-12:disk0 -p 192.168.10.185 -l
如果配置的用户名密码不正确,则登录的时候会显示如下认证错误
[root@Cherish ~]# iscsiadm -m node -T 1qn.2012-12:disk0 -p 192.168.10.185 --login
Logging in to [iface: default, target: 1qn.2012-12:disk0, portal: 192.168.10.185,3260] (multiple)
iscsiadm: Could not login to [iface: default, target: 1qn.2012-12:disk0, portal: 192.168.10.185,3260].
iscsiadm: initiator reported error (24 - iSCSI login failed due to authorization failure)
iscsiadm: Could not log into all portals 
注意:修改配置文件的用户名密码后,必须重新discovery目标ip之后才能用新的用户名密码login到target,否则也会提示上述认证错误。

五、 双向认证(也称为mutul认证、相互认证、双向认证)
5.1.在target端创建outgoing账号
tgtadm --lld iscsi --op new --mode account --user out_redhat --password out_redhat123
5.2. 在target端将账号绑定到相应的target
tgtadm --lld iscsi --mode account --op bind --tid 1 --user out_redhat --outgoing
tgtadm --lld iscsi --mode target --op show
root@iscsiB ~]# tgt-admin --show
Target 1: 1qn.2012-12:disk0
    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
            Prevent removal: 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: 10737 MB, Block size: 512
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: rdwr
            Backing store path: /dev/sdb
            Backing store flags: 
        LUN: 2
            Type: disk
            SCSI ID: IET     00010002
            SCSI SN: beaf12
            Size: 5369 MB, Block size: 512
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: rdwr
            Backing store path: /dev/sdc
            Backing store flags: 
    Account information:
        redhat
        out_redhat (outgoing)  //注意这个标识
    ACL information:
        ALL
5.3.在initiator端配置iscsid.conf文件
    vim /etc/iscsi/iscsid.conf
node.session.auth.username_in = out_redhat
node.session.auth.password_in = out_redhat123
5.4.在initiator端登录到target
iscsiadm -m node -T 1qn.2012-12:disk0 -p 192.168.10.185 --logout
/etc/init.d/iscsid reload(不是必要的)
iscsiadm -m discovery -t sendtargets -p 192.168.10.185(必须要重新discovery!!!)
iscsiadm -m node -T 1qn.2012-12:disk0 -p 192.168.10.185 –login
注意:在双向认证过程中,必须保证incoming和outgoing的账号密码都正确!!!

六、 绑定多个incoming账号
6.1为一个target创建多个incoming和outgoing账号
(1)再创建两个账号
tgtadm --lld iscsi --mode account --op new --user chenbin --password chenbin123
tgtadm --lld iscsi --mode account --op new --user out_chenbin --password out_chenbin123
创建后我们看看有几个账号了?
[root@iscsiB ~]# tgtadm --lld iscsi --mode account --op show
Account list:
        out_chenbin
        chenbin
        out_redhat
redhat
 (2)将这两个账号分别绑定到目前这个target
[root@iscsiB ~]# tgtadm --lld iscsi --mode account --op bind --tid 1 --user chenbin
[root@iscsiB ~]# tgt-admin --show
Target 1: 1qn.2012-12:disk0
    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
            Prevent removal: 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: 10737 MB, Block size: 512
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: rdwr
            Backing store path: /dev/sdb
            Backing store flags: 
        LUN: 2
            Type: disk
            SCSI ID: IET     00010002
            SCSI SN: beaf12
            Size: 5369 MB, Block size: 512
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: rdwr
            Backing store path: /dev/sdc
            Backing store flags: 
    Account information:
        redhat
        chenbin
        out_redhat (outgoing)
    ACL information:
        ALL
再绑定一个incoming账号没有问题,我们再绑定一个outgoing账号试试
[root@iscsiB ~]# tgtadm --lld iscsi --mode account --op bind --tid 1 --user out_chenbin --outgoing
tgtadm: this target already has an outgoing account
我们会发现,tgtadm会提示,已经有一个outgoing账号。综上所述,对于一个target,可以绑定多个incoming账号,但是outgoing账号只能绑定一个。也就是说,对于不同initiator端,我们可以设置不同的incoming账号;但是所有的initiator端的outcoming账号必须是一致的。(以上结论只针对某个特定的target)
6.2.解绑定和删除账号
(1)解绑定incoming账号chenbin
[root@iscsiB ~]# tgtadm --lld iscsi --mode account --op unbind --tid 1 --user chenbin
(2)解绑定outgoing账号out_redhat
[root@iscsiB ~]# tgtadm --lld iscsi --mode account --op unbind --tid 1 --user out_redhat --outgoing
[root@iscsiB ~]# tgt-admin -s
Target 1: 1qn.2012-12:disk0
    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
            Prevent removal: 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: 10737 MB, Block size: 512
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: rdwr
            Backing store path: /dev/sdb
            Backing store flags: 
        LUN: 2
            Type: disk
            SCSI ID: IET     00010002
            SCSI SN: beaf12
            Size: 5369 MB, Block size: 512
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: rdwr
            Backing store path: /dev/sdc
            Backing store flags: 
    Account information:
        redhat
    ACL information:
        ALL
我们看到,只剩下一个账号了
(3)删除一个账号
[root@iscsiB ~]# tgtadm --lld iscsi --mode account --op delete --user chenbin
[root@iscsiB ~]# tgtadm --lld iscsi --mode account --op show
Account list:
    out_chenbin
    out_redhat
redhat

七、 几种特殊情况的处理
如果target端口未绑定任何账号,则initiator端无论是否开启CHAP验证,无论是否设置里用户名密码 都不会进行验证
如果target端绑定了incoming账号或者outgoing账号,则initiator端口必须开启CHAP验证,并设置好账号和密码,否则不能login
如果target端口绑定了incoming账号,没有绑定outgoing账号,但是initiator端口开启了CHAP认证,并设置了incoming和outgoing账号,则无法login(因为无法通过initiator认证)

008-targets.conf

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
https://www.cnblogs.com/wuchanming/p/4019660.html
https://blog.csdn.net/sinchb/article/details/8433994

事实上,除了 backing-store 之外,在这个配置文件当中还有一些比较特别的参数可以讨论看看 (man tgt-admin):
backing-store (虚拟的装置), direct-store (实际的装置): 设定装置时,如果你的整颗磁盘是全部被拿来当 iSCSI 分享之用,那么才能够使用 direct-store 。不过,根据网络上的其他文件, 似乎说明这个设定值有点危险的样子。所以,基本上还是建议单纯使用模拟的 backing-store 较佳。例如鸟哥的简单案例中,就通通使用 backing-store 而已
initiator-address (用户端地址): 如果你想要限制能够使用这个 target 的客户端来源,才需要填写这个设定值。基本上,不用设定它 (代表所有人都能使用的意思), 因为我们后来会使用 iptables 来规范可以联机的客户端嘛!
incominguser (用户账号密码设定): 如果除了来源 IP 的限制之外,你还想要让使用者输入账密才能使用你的 iSCSI target 的话,那么就加用这个设定项目。 此设定后面接两个参数,分别是账号与密码啰。
write-cache [off|on] (是否使用快取): 在预设的情况下,tgtd 会使用快取来增快速度。不过,这样可能会有遗失数据的风险。所以,如果你的数据比较重要的话, 或许不要使用快取,直接存取装置会比较妥当一些。
上面的设定值要怎么用呢?现在,假设你的环境中,仅允许 192.168.100.0/24 这个网段可以存取 iSCSI target,而且存取时需要帐密分别为 vuser, vpasswd ,此外,不要使用快取,那么原本的配置文件之外,还得要加上这样的参数才行 (基本上,使用上述的设定即可,底下的设定是多加测试用的,不需要填入你的设定中)。


[root@www ~]# vim /etc/tgt/targets.conf
<target iqn.2014-10.net.vlnb:vdisk>
  backing-store /home/iscsi/disk1.img
  backing-store /dev/sda7
  backing-store /dev/server/iscsi01
  initiator-address 192.168.100.0/24
incominguser vbirduser vbirdpasswd
write-cache off
</target>

</target>这样的配置,backing-store的顺序决定了lun号码的顺序,上面的配置中/dev/sdb1会是Lun1,/dev/sdc会是lun2
若想要为每个逻辑设备指定想要指定的lun号码,需要将每个backing-store封装在target中并独立指定lun号码。
#include /etc/tgt/temp/*.conf
default-driver iscsi
<target iqn.2017-03.com.longshuai:test.disk1>
        <backing-store /dev/sdb1>
              lun 5
        </backing-store>
        <backing-store /dev/sdc>
              lun 6
        </backing-store>
        incominguser <incoming_username> <PASSWORD>
        outgoinguser <outgoing_username> <PASSWORD> 
        initiator-address 192.168.100.0/24
</target>


启动 iSCSI target 以及观察相关端口口与磁盘信息
再来则是启动、开机启动,以及观察 iSCSI target 所启动的埠口啰:



/etc/iscsi/iscsid.conf:主要的配置文件,用来连结到 iSCSI target 的设定;

initiator 的实际设定
首先,我们得要知道 target 提供了啥咚咚啊,因此,理论上,不论是 target 还是 initiator 都应该是要我们管理的机器才对。 而现在我们知道 target 其实有设定账号与密码的,所以底下我们就得要修改一下 iscsid.conf 的内容才行。
修改 /etc/iscsi/iscsid.conf 内容,并启动 iscsi
这个档案的修改很简单,因为里面的参数大多已经预设做的不错了,所以只要填写 target 登入时所需要的帐密即可。 修改的地方有两个,一个是侦测时 (discovery) 可能会用到的帐密,一个是联机时 (node) 会用到的帐密:
[root@clientlinux ~]# vim /etc/iscsi/iscsid.conf
node.session.auth.username = vbirduser <==在 target 时设定的
node.session.auth.password = vbirdpasswd <==约在 53, 54
discovery.sendtargets.auth.username = vbirduser <==约在 67, 68
discovery.sendtargets.auth.password = vbirdpasswd
[root@clientlinux ~]# chkconfig iscsid on
[root@clientlinux ~]# chkconfig iscsi on

009-issci延时放大

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
issci延时放大
两个卷比一个卷平均时延多了1ms,四个卷比一个时延多了4ms。
前端指tgt之前的io栈

iptables -nL|wc -l 
发现iptable中的rule有数万条之多,且绝大多数是垃圾,清理垃圾之后,性能测试正常,包括iscsi本地大块写时延放大、多个卷随机写时延放大等问题。
为何虚机(应该是迁移导致)会残留这么多rule,

两个卷比一个卷平均时延多了1ms,四个卷比一个时延多了4ms。
前端指tgt之前的io栈


问题所在:issci客户端所在的计算节点存在大量iptable的rule会导致该问题

iptables导入导出
导出:
iptables-save > iptables.bak

导入:
iptables-restore < iptables.bak

如何判断iptables有残留:
这个是实体机中看到的虚机网卡,

就会创建带有6396244相关chain和rules
iptables -N neutron-openvswi-of5afefd0-f等等
(neutron-openvswi-of5afefd0-f是iptables -nL中查询出来的)

现在48上有
iptables -N neutron-openvswi-of52a694e-a
我差了一下网卡,没有带52a694e名字的网卡

解决:(重启防火墙)
解决重启iptables(防火墙):
service iptables status    # 查看iptables状态
service iptables restart   # iptables服务重启
service iptables stop      # iptables服务禁用

为啥计算节点需要开防火墙:
当前网络模式下 是通过iptables实现虚机安全组功能的




如果想清空的话,先执行
/sbin/iptables -P INPUT ACCEPT
然后执行
/sbin/iptables -F
通过iptables -L 看到如下信息
Chain INPUT (policy DROP 0 packets, 0 bytes)  (注意 是DROP)
执行/sbin/iptables -F就肯定立马断开连接
当执行了
/sbin/iptables -P INPUT ACCEPT
再次通过iptables -L看信息的话就是
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
所以现在是可以安全使用
/sbin/iptables -F了


查看现在iptables规则:
iptables -L -n -v
Bash
清空配置:
iptables -F #清楚规则链中已有的条目;使用iptables -F 要小心,搞不好,你就马上同服务器断开连接了
iptables -X #删除没有用户配置文件相关的chain
iptables -Z #清空规则链中的数据包计算器和字节计数器;

010-lsscsi -t

1
2
3
4
5
http://sg.danny.cz/scsi/lsscsi.html#mozTocId944699
lsscsi -t
[25:0:0:1] disk iqn.2019-01.com.suning:storage.snbs.test001,t,0x1 /dev/sdc
[87:0:0:0] storage iqn.2019-01.com.suning:storage.snbs.test001-link001,t,0x1 -
[87:0:0:1] disk iqn.2019-01.com.suning:storage.snbs.test001-link001,t,0x1 /dev/sdd
赞赏一下吧~