centos 7 iscsi配置

测试环境

centos 7.2
服务端:192.168.184.139
客户端:192.168.184.133

iscsi简介

iSCSI(internet SCSI)技术由IBM公司研究开发,是一个供硬件设备使用的、可以在IP协议的上层运行的SCSI指令集,这种指令集合可以实现在IP网络上运行SCSI协议,使其能够在诸如高速千兆以太网上进行路由选择。iSCSI技术是一种新储存技术,该技术是将现有SCSI接口与以太网络(Ethernet)技术结合,使服务器可与使用IP网络的储存装置互相交换资料。

iSCSI 的主要功能是在TCP/IP 网络上的主机系统(启动器 initiator)和存储设备(目标器 target)之间进行大量数据的封装和可靠传输过程。iSCSI可分享的设备类型有很多,包括镜像文件(*.img)、分区(partition)、物理硬盘、raid设备、逻辑卷等。

服务端iscsi target安装

yum install -y targetcli

[root@#localhost ~]# yum install -y targetcli
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror.bit.edu.cn
 * extras: mirrors.huaweicloud.com
 * updates: mirrors.huaweicloud.com
Package targetcli-2.1.53-1.el7_9.noarch already installed and latest version
Nothing to do
[root@#localhost ~]# 

客户端iscsi initiator安装

yum install -y iscsi-initiator-utils
配置iSCSI Target服务

服务端配置

在192.168.184.139上进入targetcli中进行设置
[root@server1 ~]# targetcli

[root@Centos ~]# targetcli
targetcli shell version 2.1.53
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.

/>

cd backstores/block

[root@localhost ~]# targetcli 
Warning: Could not load preferences file /root/.targetcli/prefs.bin.
targetcli shell version 2.1.fb41
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.

/> ls
o- / ......................................................................................................................... [...]
  o- backstores .............................................................................................................. [...]
  | o- block .................................................................................................. [Storage Objects: 0]
  | o- fileio ................................................................................................. [Storage Objects: 0]
  | o- pscsi .................................................................................................. [Storage Objects: 0]
  | o- ramdisk ................................................................................................ [Storage Objects: 0]
  o- iscsi ............................................................................................................ [Targets: 0]
  o- loopback ......................................................................................................... [Targets: 0]
/> cd backstores/block 
/backstores/block> 

建立块存储

/> cd backstores/block 
/backstores/block> create nsd /dev/sdb
Created block storage object nsd using /dev/sdb.
/backstores/block> create iqn.2019-05.com.share-disk:server
Missing required parameter dev
/backstores/block> cd ..
/backstores> ls
o- backstores ................................................................................................................ [...]
  o- block .................................................................................................... [Storage Objects: 1]
  | o- nsd ............................................................................. [/dev/sdb (10.0GiB) write-thru deactivated]
  |   o- alua ..................................................................................................... [ALUA Groups: 1]
  |     o- default_tg_pt_gp ......................................................................... [ALUA state: Active/optimized]
  o- fileio ................................................................................................... [Storage Objects: 0]
  o- pscsi .................................................................................................... [Storage Objects: 0]
  o- ramdisk .................................................................................................. [Storage Objects: 0]
/backstores>

配置iscsi target命名

create iqn.2019-05.com.share-disk:server

/iscsi> cd /iscsi 
/iscsi> ls
o- iscsi .............................................................................................................. [Targets: 0]
/iscsi> create iqn.2019-05.com.share-disk:server
Created target iqn.2019-05.com.share-disk:server.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/iscsi> 

设置acl

/iscsi> cd iqn.2019-05.com.share-disk:server/tpg1/acls 
/iscsi/iqn.20...ver/tpg1/acls> create iqn.2019-05.com.share-disk:node33
Created Node ACL for iqn.2019-05.com.share-disk:node33
/iscsi/iqn.20...ver/tpg1/acls> ls
o- acls .................................................................................................................. [ACLs: 1]
  o- iqn.2019-05.com.share-disk:node33 ............................................................................ [Mapped LUNs: 0]
/iscsi/iqn.20...ver/tpg1/acls>

创建lun

/> cd /backstores/block/nsd/
/backstores/block/nsd> pwd
/backstores/block/nsd
/backstores/block/nsd> cd /iscsi/iqn.2019-05.com.share-disk:server/tpg1/luns 
/iscsi/iqn.20...ver/tpg1/luns> create /backstores/block/nsd 
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2019-05.com.share-disk:node33
/iscsi/iqn.20...ver/tpg1/luns> ls
o- luns .................................................................................................................. [LUNs: 1]
  o- lun0 ................................................................................ [block/nsd (/dev/sdb) (default_tg_pt_gp)]
/iscsi/iqn.20...ver/tpg1/luns>

配置portal

/iscsi/iqn.20...k:server/tpg1> cd portals/
/iscsi/iqn.20.../tpg1/portals> ls
o- portals ............................................................................................................ [Portals: 1]
  o- 0.0.0.0:3260 ............................................................................................................. [OK]
/iscsi/iqn.20.../tpg1/portals> delete 0.0.0.0 3260
Deleted network portal 0.0.0.0:3260
/iscsi/iqn.20.../tpg1/portals> create 192.168.184.139 3260
Using default IP port 3260
Created network portal 192.168.184.139:3260.
/iscsi/iqn.20.../tpg1/portals>

配置验证用户名和密码

/iscsi/iqn.20...ver/tpg1/acls> cd iqn.2019-05.com.share-disk:node33/
/iscsi/iqn.20...e-disk:node33> set auth userid=qin
Parameter userid is now 'qin'.
/iscsi/iqn.20...e-disk:node33> set auth password=111111
Parameter password is now '111111'.
/iscsi/iqn.20...e-disk:node33>

保存服务端配置信息并退出

/iscsi/iqn.20...e-disk:node33> cd /
/> saveconfig 
Last 10 configs saved in /etc/target/backup/.
Configuration saved to /etc/target/saveconfig.json
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup/.
Configuration saved to /etc/target/saveconfig.json
[root@Centos ~]#

192.168.184.133客户端操作

查找服务端iscsi设备

[root@localhost /]# iscsiadm -m discovery -t st -p 192.168.184.139
192.168.184.139:3260,1 iqn.2019-05.com.share-disk:server

登录服务端:
iscsiadm -m node -T iqn.2019-05.com.share-disk:server -p 192.168.184.139 -l

[root@localhost /]# iscsiadm -m node -T iqn.2019-05.com.share-disk:server -p 192.168.184.139  -l
Logging in to [iface: default, target: iqn.2019-05.com.share-disk:server, portal: 192.168.184.139,3260] (multiple)
iscsiadm: Could not login to [iface: default, target: iqn.2019-05.com.share-disk:server, portal: 192.168.184.139,3260].
iscsiadm: initiator reported error (12 - iSCSI driver not found. Please make sure it is loaded, and retry the operation)
iscsiadm: Could not log into all portals
[root@localhost /]# 

报错:

Logging in to [iface: default, target: iqn.2019-05.com.share-disk:server, portal: 192.168.184.139,3260] (multiple)
iscsiadm: Could not login to [iface: default, target: iqn.2019-05.com.share-disk:server, portal: 192.168.184.139,3260].
iscsiadm: initiator reported error (12 - iSCSI driver not found. Please make sure it is loaded, and retry the operation)
iscsiadm: Could not log into all portals

解决:重启服务器后,报新的错误

[root@localhost ~]# iscsiadm -m node -T iqn.2019-05.com.share-disk:server -p 192.168.184.139  -l
Logging in to [iface: default, target: iqn.2019-05.com.share-disk:server, portal: 192.168.184.139,3260] (multiple)
iscsiadm: Could not login to [iface: default, target: iqn.2019-05.com.share-disk:server, portal: 192.168.184.139,3260].
iscsiadm: initiator reported error (24 - iSCSI login failed due to authorization failure)
iscsiadm: Could not log into all portals

解决:配置chap验证密码
vi /etc/iscsi/iscsid.conf

# *************
# CHAP Settings
# *************

# To enable CHAP authentication set node.session.auth.authmethod
# to CHAP. The default is None.
node.session.auth.authmethod = CHAP

# To set a CHAP username and password for initiator
# authentication by the target(s), uncomment the following lines:
node.session.auth.username = qin
node.session.auth.password = 111111

配置/etc/iscsi/initiatorname.iscsi

[root@localhost iscsi]# cat initiatorname.iscsi 
InitiatorName=iqn.2019-05.com.share-disk:node33
[root@localhost iscsi]# 

再次登录:

[root@localhost ~]# iscsiadm -m node -T iqn.2019-05.com.share-disk:server -p 192.168.184.139  -l
Logging in to [iface: default, target: iqn.2019-05.com.share-disk:server, portal: 192.168.184.139,3260] (multiple)
iscsiadm: Could not login to [iface: default, target: iqn.2019-05.com.share-disk:server, portal: 192.168.184.139,3260].
iscsiadm: initiator reported error (24 - iSCSI login failed due to authorization failure)
iscsiadm: Could not log into all portals

还是报错认证失败,参考https://blog.csdn.net/manom/article/details/89331283

[root@localhost nodes]# rm -rf *
[root@localhost nodes]# cd ..
[root@localhost iscsi]# ls
ifaces  isns  nodes  send_targets  slp  static
[root@localhost iscsi]# cd send_targets/
[root@localhost send_targets]# ls
192.168.184.133,3260  192.168.184.139,3260
[root@localhost send_targets]# rm -rf *
[root@localhost send_targets]# cd ..
[root@localhost iscsi]# tree /var/lib/iscsi/
bash: tree: command not found...
[root@localhost iscsi]# yum install tree
Loaded plugins: fastestmirror, langpacks
base                                                                                                                                                | 3.6 kB  00:00:00     
extras                                                                                                                                              | 2.9 kB  00:00:00     
updates                                                                                                                                             | 2.9 kB  00:00:00     
Loading mirror speeds from cached hostfile
 * base: mirrors.huaweicloud.com
 * extras: mirrors.huaweicloud.com
 * updates: mirrors.cqu.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.6.0-10.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================================================================================
 Package                               Arch                                    Version                                         Repository                             Size
===========================================================================================================================================================================
Installing:
 tree                                  x86_64                                  1.6.0-10.el7                                    base                                   46 k

Transaction Summary
===========================================================================================================================================================================
Install  1 Package

Total download size: 46 k
Installed size: 87 k
Is this ok [y/d/N]: y
Downloading packages:
tree-1.6.0-10.el7.x86_64.rpm                                                                                                                        |  46 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : tree-1.6.0-10.el7.x86_64                                                                                                                                1/1 
  Verifying  : tree-1.6.0-10.el7.x86_64                                                                                                                                1/1 

Installed:
  tree.x86_64 0:1.6.0-10.el7                                                                                                                                               

Complete!
[root@localhost iscsi]# tree /var/lib/iscsi/
/var/lib/iscsi/
├── ifaces
├── isns
├── nodes
├── send_targets
├── slp
└── static

6 directories, 0 files
[root@localhost iscsi]# iscsiadm -m discovery -t st -p 192.168.184.139  
192.168.184.139:3260,1 iqn.2019-05.com.share-disk:server
[root@localhost iscsi]# iscsiadm -m node -T iqn.2019-05.com.share-disk:server  -p 192.168.184.139 -l
[root@localhost iscsi]# fdisk -l

Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000c3579

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      616447      307200   83  Linux
/dev/sda2          616448     4812799     2098176   82  Linux swap / Solaris
/dev/sda3         4812800    62914559    29050880   83  Linux

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 4194304 bytes

[root@localhost iscsi]#

登录成功,在192.168.184.132上fdisk -l可以看到139上共享的磁盘/dev/sdb

[root@localhost iscsi]# fdisk -l

Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000c3579

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      616447      307200   83  Linux
/dev/sda2          616448     4812799     2098176   82  Linux swap / Solaris
/dev/sda3         4812800    62914559    29050880   83  Linux

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 4194304 bytes

故障处理

1、启动targetcli报错ImportError: cannot import name ALUATargetPortGroup故障
故障现象:

当前环境
[root@centos7-router ~]# more /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core)

安装targetcli工具包
# yum install targetcli

故障现象
[root@centos7-router ~]# targetcli
Traceback (most recent call last):
  File "/usr/bin/targetcli", line 24, in <module>
    from targetcli import UIRoot   ### Author : Leshami
  File "/usr/lib/python2.7/site-packages/targetcli/__init__.py", line 18, in <module>
    from .ui_root import UIRoot   ### Blog : http://blog.csdn.net/leshami
  File "/usr/lib/python2.7/site-packages/targetcli/ui_root.py", line 30, in <module>
    from .ui_backstore import complete_path, UIBackstores
  File "/usr/lib/python2.7/site-packages/targetcli/ui_backstore.py", line 29, in <module>
    from rtslib_fb import ALUATargetPortGroup
ImportError: cannot import name ALUATargetPortGroup

参考资料:
1、https://www.cnblogs.com/gispathfinder/p/8833488.html CentOS7系列–3.2CentOS7中配置iSCSI服务
2、https://blog.csdn.net/manom/article/details/89331283 iSCSI客户端登陆认证失败

  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值