iscsi地址192.168.10.253 端口默认3260
exsi主机地址192.168.10.225
安装linux系统略过
安装iSCSI组件包
yum -y install targetd targetcli
systemctl start targetd
systemctl enable targetd
关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
关闭selinux
sed -i 's/enforcing/disabled/' /etc/selinux/config # 永久
setenforce 0 # 临时
开始配置客户端(借用刘遄老师的文档,自己的没保存下来)
targetcli
[root@linuxprobe ~]# targetcli
Warning: Could not load preferences file /root/.targetcli/prefs.bin.
targetcli shell version 2.1.fb34
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> create data /dev/sdb
Created block storage object data using /dev/sdb
/backstores/block> cd /
/> ls
o- / ..................................................................... [...]
o- backstores .......................................................... [...]
| o- block .............................................. [Storage Objects: 1]
| | o- data ..................... [/dev/sdb (931.5GiB) write-thru deactivated]
| o- fileio ............................................. [Storage Objects: 0]
| o- pscsi .............................................. [Storage Objects: 0]
| o- ramdisk ............................................ [Storage Objects: 0]
o- iscsi ........................................................ [Targets: 0]
o- loopback ..................................................... [Targets: 0]
创建iSCSI target名称及配置共享资源。iSCSI target名称是由系统自动生成的,这是一串用于描述共享资源的唯一字符串。稍后用户在扫描iSCSI服务端时即可看到这个字符串,因此我们不需要记住它。系统在生成这个target名称后,还会在/iscsi参数目录中创建一个与其字符串同名的新“目录”用来存放共享资源。我们需要把前面加入到iSCSI共享资源池中的硬盘设备添加到这个新目录中,这样用户在登录iSCSI服务端后,即可默认使用这硬盘设备提供的共享存储资源了。
/> cd iscsi
/iscsi>
/iscsi> create
Created target iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.6ae089c2e277.
Created TPG 1.
/iscsi> cd iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.6ae089c2e277/
/iscsi/iqn.20...6ae089c2e277> ls
o- iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.6ae089c2e277 ...... [TPGs: 1]
o- tpg1 ............................................... [no-gen-acls, no-auth]
o- acls .......................................................... [ACLs: 0]
o- luns .......................................................... [LUNs: 0]
o- portals .................................................... [Portals: 0]
/iscsi/iqn.20....6ae089c2e277> cd tpg1/luns
/iscsi/iqn.20...277/tpg1/luns> create /backstores/block/data
Created LUN 0.
设置访问控制列表(ACL)。iSCSI协议是通过客户端名称进行验证的,也就是说,用户在访问存储共享资源时不需要输入密码,只要iSCSI客户端的名称与服务端中设置的访问控制列表中某一名称条目一致即可,因此需要在iSCSI服务端的配置文件中写入一串能够验证用户信息的名称。acls参数目录用于存放能够访问iSCSI服务端共享存储资源的客户端名称。刘遄老师推荐在刚刚系统生成的iSCSI target后面追加上类似于:client的参数,这样既能保证客户端的名称具有唯一性,又非常便于管理和阅读:
/iscsi/iqn.20...277/tpg1/luns> cd ..
/iscsi/iqn.20...6ae089c2e277/tpg1> cd acls
/iscsi/iqn.20...277/tpg1/acls> create iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.6ae089c2e277:client
Created Node ACL for iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.6ae089c2e277:client
Created mapped LUN 0.
设置iSCSI服务端的监听IP地址和端口号。位于生产环境中的服务器上可能有多块网卡,那么到底是由哪个网卡或IP地址对外提供共享存储资源呢?这就需要我们在配置文件中手动定义iSCSI服务端的信息,即在portals参数目录中写上服务器的IP地址。接下来将由系统自动开启服务器192.168.10.10的3260端口将向外提供iSCSI共享存储资源服务:
/iscsi/iqn.20...277/tpg1/acls> cd ..
/iscsi/iqn.20...6ae089c2e277/tpg1> cd portals
/iscsi/iqn.20.../tpg1/portals> create 192.168.10.253
Using default IP port 3260
Could not create NetworkPortal in configFS 错误信息出现
解决办法:删除这个自动默认生成的0.0.0.端口
/iscsi/iqn.20.../tpg1/portals> delete 0.0.0.0 3260
Deleted network portal 0.0.0.0:3260
/iscsi/iqn.20.../tpg1/portals> ls
o- portals .................................................................... [Portals: 0]
/iscsi/iqn.20.../tpg1/portals> create 192.168.10.253
Using default IP port 3260
Created network portal 192.168.10.253:3260.
配置妥当后检查配置信息,重启iSCSI服务端程序并配置防火墙策略。在参数文件配置妥当后,可以浏览刚刚配置的信息,确保与下面的信息基本一致。在确认信息无误后输入exit命令来退出配置。注意,千万不要习惯性地按Ctrl + C组合键结束进程,这样不会保存配置文件,我们的工作也就白费了。最后重启iSCSI服务端程序,再设置firewalld防火墙策略,使其放行3260/tcp端口号的流量。
将esxi主机iqn名称添加到iscsi服务端的acl规则里
/iscsi/iqn.20...277/tpg1/acls> create iqn.1998-01.com.vmware:6208e06d-5fd6-0c43-d722-000c29a48bab-333c6e45
/iscsi/iqn.20...277/tpg1/acls> create iqn.1998-01.com.vmware:6208df8d-950e-4fad-2e4d-000c296dcad0-3d8d6f8f
/> ls
o- / ............................................................ .................................. [...]
o- backstores .................................................................................... [...]
| o- block ........................................................................ [Storage Objects: 1]
| | o- data ................................................. [/dev/sdb (931.5GiB) write-thru activated]
| | 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]
o- iscsi .................................................................................... [Targets: 1]
| o- iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.6ae089c2e277 ................................ [TPGs: 1]
| o- tpg1 .............................................................. ......... [no-gen-acls, no-auth]
| o- acls .................................................................................... [ACLs: 3]
| | o- iqn.1998-01.com.vmware:6208df8d-950e-4fad-2e4d-000c296dcad0-3d8d6f8f ........... [Mapped LUNs: 1]
| | | o- mapped_lun0 .............................................................[lun0 block/data (rw)]
| | o- iqn.1998-01.com.vmware:6208e06d-5fd6-0c43-d722-000c29a48bab-333c6e45 ............ [Mapped LUNs: 1]
| | | o- mapped_lun0 ............................................................. [lun0 block/data (rw)]
| | o- iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.6ae089c2e277:client .............. [Mapped LUNs: 1]
| | o- mapped_lun0 ............................................................. [lun0 block/data (rw)]
| o- luns ...................................................................................... [LUNs: 1]
| | o- lun0 .................................................... [block/data (/dev/sdb) (default_tg_pt_gp)]
| o- portals ................................................................................. [Portals: 1]
| o- 192.168.10.253:3260 .......................................................................... [OK]
o- loopback ...................................................................................... [Targets: 0]
/>
存储发现,可以新建存储完成添加。