Centos7环境搭建iSCSI服务器及客户端连接
iSCSI介绍
iSCSI(Internet Small Computer System Interface,发音为/ˈаɪskʌzi/),Internet小型计算机系统接口,又称为IP-SAN,是一种基于因特网及SCSI-3协议下的存储技术,由IETF提出,并于2003年2月11日成为正式的标准。 iSCSI使用 TCP/IP 协议(一般使用TCP端口860和3260)。 本质上,iSCSI 让两个主机通过 IP 网络相互协商然后交换SCSI命令 与传统的SCSI技术比较起来,iSCSI技术有以下三个革命性的变化: 1、把原来只用于本机的SCSI协议透过TCP/IP网络发送,使连接距离可作无限的地域延伸; 2、连接的服务器数量无限(原来的SCSI-3的上限是15); 3、由于是服务器架构,因此也可以实现在线扩容以至动态部署。
Centos7上配置iSCSI服务端
准备存储空间 1、以硬盘形式存在: 添加一块硬盘/dev/sdb 2、以文件形式存在: dd if=/dev/zero of=/data/disk.img bs=1024k count=2048
安装
# yum install targetd targetcli -y
# systemctl start targetd
# systemctl enable targetd
1、使用targetcli命令进行设置,创建iscsi磁盘
# targetcli targetcli shell version 2.1.53 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]
/> /backstores/block create idisk1 /dev/sdb Created block storage object idisk1 using /dev/sdb.
/> /backstores/fileio create idisk2 /data/disk.img
Created fileio idisk2 with size 2147483648
/> ls
o- / ............................................................................................. [...]
o- backstores .................................................................................. [...]
| o- block ...................................................................... [Storage Objects: 1]
| | o- idisk1 ............................................ [/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: 1]
| | o- idisk2 ....................................... [/data/disk.img (2.0GiB) write-back deactivated]
| | o- alua ....................................................................... [ALUA Groups: 1]
| | o- default_tg_pt_gp ........................................... [ALUA state: Active/optimized]
| o- pscsi ...................................................................... [Storage Objects: 0]
| o- ramdisk .................................................................... [Storage Objects: 0]
o- iscsi ................................................................................ [Targets: 0]
o- loopback ............................................................................. [Targets: 0]
2、创建服务端程序
/> iscsi/ create iqn.2022-05.pip.cc:server Created target iqn.2022-05.pip.cc:server. Created TPG 1. Global pref auto_add_default_portal=true Created default portal listening on all IPs (0.0.0.0), port 3260. /> ls o- / ............................................................................................. [...] o- backstores .................................................................................. [...] | o- block ...................................................................... [Storage Objects: 1] | | o- idisk1 ............................................ [/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: 1] | | o- idisk2 ....................................... [/data/disk.img (2.0GiB) write-back deactivated] | | o- alua ....................................................................... [ALUA Groups: 1] | | o- default_tg_pt_gp ........................................... [ALUA state: Active/optimized] | o- pscsi ...................................................................... [Storage Objects: 0] | o- ramdisk .................................................................... [Storage Objects: 0] o- iscsi ................................................................................ [Targets: 1] | o- iqn.2022-05.pip.cc:server ............................................................. [TPGs: 1] | o- tpg1 ................................................................... [no-gen-acls, no-auth] | o- acls .............................................................................. [ACLs: 0] | o- luns .............................................................................. [LUNs: 0] | o- portals ........................................................................ [Portals: 1] | o- 0.0.0.0:3260 ......................................................................... [OK] o- loopback ............................................................................. [Targets: 0]
3、创建服务卷
/> cd iscsi/iqn.2022-05.pip.cc:server/tpg1/ /iscsi/iqn.20...c:server/tpg1> luns/ create /backstores/block/idisk1 Created LUN 0. /iscsi/iqn.20...c:server/tpg1> luns/ create /backstores/fileio/idisk2 Created LUN 1. /iscsi/iqn.20...c:server/tpg1> ls o- tpg1 ......................................................................... [no-gen-acls, no-auth] o- acls .................................................................................... [ACLs: 0] o- luns .................................................................................... [LUNs: 2] | o- lun0 ............................................... [block/idisk1 (/dev/sdb) (default_tg_pt_gp)] | o- lun1 ........................................ [fileio/idisk2 (/data/disk.img) (default_tg_pt_gp)] o- portals .............................................................................. [Portals: 1] o- 0.0.0.0:3260 ............................................................................... [OK]
4、创建客户端连接器,并启用chap认证
/iscsi/iqn.20...c:server/tpg1> acls/ create iqn.2022-05.pip.cc:client Created Node ACL for iqn.2022-05.pip.cc:client Created mapped LUN 1. Created mapped LUN 0. /iscsi/iqn.20...c:server/tpg1> cd acls/iqn.2022-05.pip.cc:client/ /iscsi/iqn.20...pip.cc:client> set auth userid=gtms Parameter userid is now 'gtms'. /iscsi/iqn.20...pip.cc:client> set auth password=chrinedd@123456 Parameter password is now 'chrinedd@123456'.
/iscsi/iqn.20...pip.cc:client> info
chap_password: chrinedd@123456
chap_userid: gtms
wwns:
iqn.2022-05.pip.cc:client
5、配置概览
/> ls o- / ............................................................................................. [...] o- backstores .................................................................................. [...] | o- block ...................................................................... [Storage Objects: 1] | | o- idisk1 .............................................. [/dev/sdb (10.0GiB) write-thru activated] | | o- alua ....................................................................... [ALUA Groups: 1] | | o- default_tg_pt_gp ........................................... [ALUA state: Active/optimized] | o- fileio ..................................................................... [Storage Objects: 1] | | o- idisk2 ......................................... [/data/disk.img (2.0GiB) write-back activated] | | o- alua ....................................................................... [ALUA Groups: 1] | | o- default_tg_pt_gp ........................................... [ALUA state: Active/optimized] | o- pscsi ...................................................................... [Storage Objects: 0] | o- ramdisk .................................................................... [Storage Objects: 0] o- iscsi ................................................................................ [Targets: 1] | o- iqn.2022-05.pip.cc:server ............................................................. [TPGs: 1] | o- tpg1 ................................................................... [no-gen-acls, no-auth] | o- acls .............................................................................. [ACLs: 1] | | o- iqn.2022-05.pip.cc:client ................................................ [Mapped LUNs: 2] | | o- mapped_lun0 .................................................... [lun0 block/idisk1 (rw)] | | o- mapped_lun1 ................................................... [lun1 fileio/idisk2 (rw)] | o- luns .............................................................................. [LUNs: 2] | | o- lun0 ......................................... [block/idisk1 (/dev/sdb) (default_tg_pt_gp)] | | o- lun1 .................................. [fileio/idisk2 (/data/disk.img) (default_tg_pt_gp)] | o- portals ........................................................................ [Portals: 1] | o- 0.0.0.0:3260 ......................................................................... [OK] o- loopback ............................................................................. [Targets: 0]
6、重新启动服务
# systemctl restart targetd.service
Centos7连接iSCSI服务端配置
1、安装客户端连接软件
# yum install iscsi-initiator-utils-iscsiuio -y
# ls /etc/iscsi/ -l
-rw-r--r-- 1 root root 49 May 4 21:21 initiatorname.iscsi -->客户端连接器名称iqn.2022-05.pip.cc:client
-rw------- 1 root root 12602 Nov 25 00:33 iscsid.conf -->启用CHAP认证
2、编辑配置文件
# cat /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2022-05.pip.cc:client
# grep ^node.session.auth /etc/iscsi/iscsid.conf
node.session.auth.authmethod = CHAP
node.session.auth.username = gtms
node.session.auth.password = chrinedd@123456
3、启动iscsid客户端服务
# systemctl restart iscsid.service
4、发现及登录存储
# iscsiadm -m discovery -t st -p 10.0.0.101
10.0.0.101:3260,1 iqn.2022-05.pip.cc:server
# iscsiadm -m node -T iqn.2022-05.pip.cc:server -p 10.0.0.101 --login
Logging in to [iface: default, target: iqn.2022-05.pip.cc:server, portal: 10.0.0.101,3260] (multiple)
Login to [iface: default, target: iqn.2022-05.pip.cc:server, portal: 10.0.0.101,3260] successful.
5、查看结果
# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 200M 0 part /boot
├─sda2 8:2 0 2G 0 part [SWAP]
└─sda3 8:3 0 17.8G 0 part /
sdb 8:16 0 10G 0 disk
sdc 8:32 0 2G 0 disk
sr0 11:0 1 4.3G 0 rom
windows连接iSCSI服务端配置
1、打开-管理工具-iSCSI 发起程序,配置-更改,输入客户端连接器名称后确定