iSCSI 服务配置
一、iscsi 服务端配置
安装服务组件: yum -y install targetd targetcli
设置服务组件启动及开机自启:
systemctl start targetd
systemctl enable targetd
在图形化交互界面创建需要分享的硬盘或者分区:
# 如下所示:将 /dev/sdb 以 iscsi1 的名称共享:
[user@nnn ~]# 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 iscsi1 /dev/sdb
Created block storage object iscsi1 using /dev/sdb.
/backstores/block>ls
/> ls
o- / ................................................................................................. [...]
o- backstores ...................................................................................... [...]
| o- block .......................................................................... [Storage Objects: 4]
| | o- scsi1 ................................................... [/dev/sdb (30.0GiB) write-thru activated]
| | | o- alua ........................................................................... [ALUA Groups: 1]
| | | o- default_tg_pt_gp ............................................... [ALUA state: Active/optimized]
| | o- scsi2 ................................................... [/dev/sdc (30.0GiB) write-thru activated]
| | | o- alua ........................................................................... [ALUA Groups: 1]
| | | o- default_tg_pt_gp ............................................... [ALUA state: Active/optimized]
| | o- scsi3 ................................................... [/dev/sdd (20.0GiB) write-thru activated]
| | | o- alua ........................................................................... [ALUA Groups: 1]
| | | o- default_tg_pt_gp ............................................... [ALUA state: Active/optimized]
| | o- scsi4 ................................................... [/dev/sde (20.0GiB) 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: 0]
o- loopback ................................................................................. [Targets: 0]
创建iSCSI target名称,进入到 /iscsi 目录下,执行 create
命令,会自动创建 iqn
开头的 iscsi
共享项目:
/> cd /iscsi
/iscsi> create
Created target iqn.2003-01.org.linux-iscsi.scsi.x8664:sn.7e2a0b039f3e
Created TPG 1.
其次,分别在该项目的 tgp1
目录下的 acl
、luns
和 portals
目录下创建客户端连接名、共享的luns和共享地址及端口:
创建共享IP和端口有可能不成功,ls 看一下,有可能已经存在相应的端口和地址了,delete 删除即可
创建 luns:
/iscsi> cd iqn.2003-01.org.linux-iscsi.scsi.x8664:sn.7e2a0b039f3e/
/iscsi/iqn.20....d497c356ad80> cd tpg1/luns
/iscsi/iqn.20...d80/tpg1/luns> create /backstores/block/iscsi1
Created LUN 0.
/iscsi/iqn.20...d80/tpg1/luns> create /backstores/block/iscsi2
Created LUN 1.
/iscsi/iqn.20...d80/tpg1/luns> create /backstores/block/iscsi3
Created LUN 2.
/iscsi/iqn.20...d80/tpg1/luns> create /backstores/block/iscsi4
Created LUN 3.
创建客户端连接名:
/iscsi/iqn.20...d80/tpg1/luns> cd ..
/iscsi/iqn.20...d80/tpg1> cd acl
/iscsi/iqn.20...d80/tpg1/acl> create iqn.2003-01.org.linux-iscsi.scsi.x8664:sn.7e2a0b039f3e
Created Node ACL for iqn.2003-01.org.linux-iscsi.scsi.x8664:sn.7e2a0b039f3e
创建连接IP及端口:
/iscsi/iqn.20...d80/tpg1/acls> cd ..
/iscsi/iqn.20...c356ad80/tpg1> cd portals
/iscsi/iqn.20.../tpg1/portals> create 192.168.0.109
Using default IP port 3260
Created network portal 192.168.10.10:3260.
查看一下配置结果:
/iscsi/iqn.20...0b039f3e/tpg1> cd /
/> ls
o- / ................................................................................................. [...]
o- backstores ...................................................................................... [...]
| o- block .......................................................................... [Storage Objects: 4]
| | o- scsi1 ................................................... [/dev/sdb (30.0GiB) write-thru activated]
| | | o- alua ........................................................................... [ALUA Groups: 1]
| | | o- default_tg_pt_gp ............................................... [ALUA state: Active/optimized]
| | o- scsi2 ................................................... [/dev/sdc (30.0GiB) write-thru activated]
| | | o- alua ........................................................................... [ALUA Groups: 1]
| | | o- default_tg_pt_gp ............................................... [ALUA state: Active/optimized]
| | o- scsi3 ................................................... [/dev/sdd (20.0GiB) write-thru activated]
| | | o- alua ........................................................................... [ALUA Groups: 1]
| | | o- default_tg_pt_gp ............................................... [ALUA state: Active/optimized]
| | o- scsi4 ................................................... [/dev/sde (20.0GiB) 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.scsi.x8664:sn.7e2a0b039f3e .................................... [TPGs: 1]
| o- tpg1 ....................................................................... [no-gen-acls, no-auth]
| o- acls .................................................................................. [ACLs: 1]
| | o- iqn.2003-01.org.linux-iscsi.scsi.x8664:sn.7e2a0b039f3e ....................... [Mapped LUNs: 4]
| | o- mapped_lun0 ......................................................... [lun0 block/scsi1 (rw)]
| | o- mapped_lun1 ......................................................... [lun1 block/scsi2 (rw)]
| | o- mapped_lun2 ......................................................... [lun2 block/scsi3 (rw)]
| | o- mapped_lun3 ......................................................... [lun3 block/scsi4 (rw)]
| o- luns .................................................................................. [LUNs: 4]
| | o- lun0 .............................................. [block/scsi1 (/dev/sdb) (default_tg_pt_gp)]
| | o- lun1 .............................................. [block/scsi2 (/dev/sdc) (default_tg_pt_gp)]
| | o- lun2 .............................................. [block/scsi3 (/dev/sdd) (default_tg_pt_gp)]
| | o- lun3 .............................................. [block/scsi4 (/dev/sde) (default_tg_pt_gp)]
| o- portals ............................................................................ [Portals: 1]
| o- 192.168.0.109:3260 ....................................................................... [OK]
o- loopback ................................................................................. [Targets: 0]
/>
放开防火墙端口。
二、客户端配置
安装 iscsi
客户端:yum install iscsi-initiator-utils
配置客户端连接名:
[root@whdatarac1 ~]# vi /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2003-01.org.linux-iscsi.scsi.x8664:sn.7e2a0b039f3e
启动iscsi客户端,并设置开机自启
[root@whdatarac1 ~]# systemctl restart iscsid
[root@whdatarac1 ~]# systemctl enable iscsid
通过 iscsiadm
管理工具扫描远程iSCSI服务端,然后查看找到的服务端上有哪些可用的共享存储资源。
-m discovery
参数的目的是扫描并发现可用的存储资源。
-t st
参数为执行扫描操作的类型,
-p 192.168.0.109
参数为iSCSI服务端的IP地址:
[root@whdatarac1 ~]# iscsiadm -m discovery -t st -p 192.168.0.109
192.168.0.109:3260,1 iqn.2003-01.org.linux-iscsi.scsi.x8664:sn.7e2a0b039f3e
登录 iSCSI
服务端:
-m node
参数为将客户端所在主机作为一台节点服务器。
-T iqn.2003-01.org.linux-iscsi.scsi.x8664:sn.7e2a0b039f3e
参数为要使用的存储资源(也就是上面的输出结果)
-p 192.168.0.109
参数依然为对方iSCSI服务端的IP地址。
--login
或 -l
参数进行登录验证。
[root@whdatarac1 ~]# iscsiadm -m node -T iqn.2003-01.org.linux-iscsi.scsi.x8664:sn.7e2a0b039f3e -p 192.168.0.109 -l
Logging in to [iface: default, target: iqn.2003-01.org.linux-iscsi.scsi.x8664:sn.7e2a0b039f3e, portal: 192.168.0.109,3260] (multiple)
Login to [iface: default, target: iqn.2003-01.org.linux-iscsi.scsi.x8664:sn.7e2a0b039f3e, portal: 192.168.0.109,3260] successful.
然后查看,四块硬盘已经成功挂载:
[root@whdatarac1 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 60G 0 disk
├─sda1 8:1 0 500M 0 part /boot
└─sda2 8:2 0 59.5G 0 part
├─rhel-root 253:0 0 51.5G 0 lvm /
└─rhel-swap 253:1 0 8G 0 lvm [SWAP]
sdb 8:16 0 30G 0 disk
sdc 8:32 0 20G 0 disk
sdd 8:48 0 20G 0 disk
sde 8:64 0 30G 0 disk
网友评论