iSCSI之基于用户的认证及基于配置文件创建iSCSI
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iSCSI之基于用户的认证及基于配置文件创建iSCSI相关的知识,希望对你有一定的参考价值。
承接上文 ->http://11107124.blog.51cto.com/11097124/1884645
被之前discovery的target信息会保存在此(discovery 的数据库)
[[email protected] mnt]# cd /var/lib/iscsi/
[[email protected] iscsi]# ls
ifaces isns nodes send_targets slp static
[[email protected] iscsi]# ls send_targets/
[[email protected] mnt]# ls /var/lib/iscsi/send_targets/192.168.139.2,3260/
iqn.2016-12.com.zxl:store1.disk1,192.168.139.2,3260,1,default st_config
192.168.139.2,3260
http://11107124.blog.51cto.com/11097124/1884645
更多关于iSCSI配置在这里
[[email protected] iscsi]# vim /etc/iscsi/iscsid.conf
node.startup = automatic \\节点开启式自动启动
# CHAP Settings \\与CHAP双向认证有关的设置
#node.session.auth.authmethod = CHAP
# To set a CHAP username and password for initiator\\server对client端进行认证时的账号和密码
#node.session.auth.username = username \\
#node.session.auth.password = password
# To set a CHAP username and password for target\\client对server认证时的账号和密码
#node.session.auth.username_in = username_in
#node.session.auth.password_in = password_in
下面则是一般用系统默认的与各种关于时间的定以,一般用系统默认便可以,很少改
node.session.timeo.replacement_timeout = 120
node.conn[0].timeo.login_timeout = 15 \\登入超时时间
node.conn[0].timeo.logout_timeout = 15 \\登出超时时间
node.conn[0].timeo.noop_out_interval = 5 \\登出时间间隔
node.conn[0].timeo.noop_out_timeout = 5 \\登出时间
node.session.err_timeo.abort_timeout = 15 \\session会话时间
下面开始定义关于基于用户的认证
首先进行登出target关联的LUN
[[email protected] iscsi]# iscsiadm -m node -T iqn.2016-12.com.zxl:store1.disk1 -p 192.168.139.2 -u
Logging out of session [sid: 1, target: iqn.2016-12.com.zxl:store1.disk1, portal: 192.168.139.2,3260]
Logout of [sid: 1, target: iqn.2016-12.com.zxl:store1.disk1, portal: 192.168.139.2,3260] successful.
[[email protected] iscsi]# fdisk -l \\可以发现/dev/sdc盘不见了
但是discovery 的数据库仍然在,只要开机后iscsi服务一启动,它会自动登录discovery数据库中早已发现的target
直接删除discovery的数据库
[[email protected] iscsi]# iscsiadm -m node -T iqn.2016-12.com.zxl:store1.disk1 -p 192.168.139.2 -o delete
[[email protected] iscsi]# ls /var/lib/iscsi/send_targets/192.168.139.2,3260/
st_config \\192.168.139.2,3260目录下已近没有了记录数据,将这个目录页删了
[[email protected] iscsi]# rm -rf /var/lib/iscsi/send_targets/192.168.139.2,3260/
先创建一个server对client认证的账号,并与target的tid绑定
[[email protected] ~]# tgtadm --lld iscsi --mode account --op new --user zxl --password 888
创建的用户为:zxl 密码:888
[[email protected] ~]# tgtadm --lld iscsi --mode account --op bind --tid 1 --user zxl
[[email protected] ~]# tgtadm --lld iscsi --mode target --op show
Account information:
zxl
ACL information:
192.168.139.0/24
[[email protected] iscsi]# vim /etc/iscsi/iscsid.conf \\开启以下3项
node.session.auth.authmethod = CHAP
node.session.auth.username = zxl
node.session.auth.password = 888
[[email protected] iscsi]# iscsiadm -m discovery -t st -p 192.168.139.2
192.168.139.2:3260,1 iqn.2016-12.com.zxl:store1.disk1
OK,可以发现,进行target登录
[email protected] iscsi]# iscsiadm -m node -T iqn.2016-12.com.zxl:store1.disk1 -p 192.168.139.2 -l
Login to [iface: default, target: iqn.2016-12.com.zxl:store1.disk1, portal: 192.168.139.2,3260] successful.
OK,登入成功
[[email protected] iscsi]# fdisk -l \\但是变成sdd了,sdc被上次登入使用,信息未清除
Disk /dev/sdd: 5379 MB, 5379300864 bytes
[[email protected] iscsi]# mount /dev/sdd1 /mnt
[[email protected] iscsi]# cd /mnt
[[email protected] mnt]# ll \\挂载后可以看到文件都在
total 20
-rw-r--r--. 1 root root 47 Dec 21 10:28 issue
drwx------. 2 root root 16384 Dec 21 10:27 lost+found
用node4试试,先删除node4的discovery数据库
[[email protected] mnt]# iscsiadm -m node -T iqn.2016-12.com.zxl:store1.disk1 -p 192.168.139.2 -u
[[email protected] mnt]# iscsiadm -m node -T iqn.2016-12.com.zxl:store1.disk1 -p 192.168.139.2 -o delete
[[email protected] mnt]# ls /var/lib/iscsi/send_targets/192.168.139.2,3260/
st_config
[[email protected] mnt]# rm -rf /var/lib/iscsi/send_targets/192.168.139.2,3260/
此时还没有对node4的配置文件进行修改看能不能发现并登入
[email protected] mnt]# iscsiadm -m discovery -t st -p 192.168.139.2
192.168.139.2:3260,1 iqn.2016-12.com.zxl:store1.disk1
[[email protected] mnt]# iscsiadm -m node -T iqn.2016-12.com.zxl:store1.disk1 -p 192.168.139.2 -l
iscsiadm: initiator reported error (24 - iSCSI login failed due to authorization failure)
iscsiadm: Could not log into all portals
可以看到能发现但是不能登入
[[email protected] iscsi]# vim /etc/iscsi/iscsid.conf \\开启以下3项
node.session.auth.authmethod = CHAP
node.session.auth.username = zxl
node.session.auth.password = 888
[[email protected] mnt]# service iscsi restart
[[email protected] mnt]# iscsiadm -m node -T iqn.2016-12.com.zxl:store1.disk1 -p 192.168.139.2 -l
Login to [iface: default, target: iqn.2016-12.com.zxl:store1.disk1, portal: 192.168.139.2,3260] successful.
登入成功
iscsi-initiator-utils 不支持discovery(用账号密码认证时不能用discovery发现),必须首先开放IP认证才能discovery,然后才能用账号密码登入发现的target
如何关机重启tgtd服务后自动创建target和lun?
通过编辑配置文件的方法
[[email protected] ~]# cp /etc/tgt/targets.conf /etc/tgt/targets.conf.bak \\先备份文件
[[email protected] ~]# vim /etc/tgt/targets.conf \\进行如下编辑
# backing-store /dev/LVM/somedevice
#</target>
<target iqn.2016-12.com.zxl:store1.disk1>
backing-store /dev/sdb1 \\如果有多个盘这项可以重复
lun 1
incominguser zxl 888 \\incominguser对server来说对client进行用户认证为 \\incoming,outgoinguser为client对server认证
initiator-address 192.168.139.0/24
</target>
重启服务前要先让client的登入退出
[[email protected] mnt]# iscsiadm -m node -T iqn.2016-12.com.zxl:store1.disk1 -p 192.168.139.2 -u
[[email protected] mnt]# iscsiadm -m node -T iqn.2016-12.com.zxl:store1.disk1 -p 192.168.139.2 -u
[[email protected] ~]# service tgtd restart
Stopping SCSI target daemon: [ OK ]
Starting SCSI target daemon: [ OK ]
[[email protected] ~]# tgtadm --lld iscsi --mode target --op show
Target 1: iqn.2016-12.com.zxl:store1.disk1
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:
Account information:
zxl
ACL information:
192.168.139.0/24
[[email protected] mnt]# iscsiadm -m node -T iqn.2016-12.com.zxl:store1.disk1 -p 192.168.139.2 -u
Logout of [sid: 2, target: iqn.2016-12.com.zxl:store1.disk1, portal: 192.168.139.2,3260] successful.
登入成功
可以看到根据配置文件定义的/usr/sbin/tgt-admin命令自动建好了target和lun,哪怕关机重启都可以自动创建
本文出自 “11097124” 博客,请务必保留此出处http://11107124.blog.51cto.com/11097124/1884811
以上是关于iSCSI之基于用户的认证及基于配置文件创建iSCSI的主要内容,如果未能解决你的问题,请参考以下文章