centos7 安装iscsi
访问量:1126
创建时间:2020-05-20
server安装
#准备磁盘
[root@mg1 ~]# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2 /dev/sdb
#安装server
[root@mg1 ~]# yum install targetd targetcli
[root@mg1 ~]# systemctl enable target
Created symlink from /etc/systemd/system/multi-user.target.wants/target.service to /usr/lib/systemd/system/target.service.
[root@mg1 ~]# systemctl start target
[root@mg1 ~]# targetcli
/> 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]
# 创建Block
/> /backstores/block create ib_vol1 /dev/sdb
Created block storage object ib_vol1 using /dev/sdb.
#定义存储节点
/> /iscsi create iqn.2020-05.com.idisk:idisk
Created target iqn.2020-05.com.idisk:idisk.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
#定义访问主机ACL,客户端配置iqn.2020-05.com.is-host:host1才能访问,注意格式。
/> /iscsi/iqn.2020-05.com.idisk:idisk/tpg1/acls create iqn.2020-05.com.is-host:host1
Created Node ACL for iqn.2020-05.com.is-host:host1
# lun关联block
/> /iscsi/iqn.2020-05.com.idisk:idisk/tpg1/luns create /backstores/block/ib_vol1
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2020-05.com.is-host:host1
/> ls
o- / .................................................................................. [...]
o- backstores ....................................................................... [...]
| o- block ........................................................... [Storage Objects: 1]
| | o- ib_vol1 .................................. [/dev/sdb (50.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.2020-05.com.idisk:idisk ................................................ [TPGs: 1]
| o- tpg1 ........................................................ [no-gen-acls, no-auth]
| o- acls ................................................................... [ACLs: 1]
| | o- iqn.2020-05.com.is-host:host1 ................................. [Mapped LUNs: 1]
| | o- mapped_lun0 ........................................ [lun0 block/ib_vol1 (rw)]
| o- luns ................................................................... [LUNs: 1]
| | o- lun0 ............................. [block/ib_vol1 (/dev/sdb) (default_tg_pt_gp)]
| o- portals ............................................................. [Portals: 1]
| o- 0.0.0.0:3260 .............................................................. [OK]
o- loopback .................................................................. [Targets: 0]
/>
客户端配置
[root@mg2 ~]# yum install -y iscsi-initiator-utils
[root@mg2 ~]# cat /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2020-05.com.is-host:host1
#查看存储
[root@mg2 ~]# iscsiadm -m discovery -t sendtargets -p 192.168.117.128
192.168.117.128:3260,1 iqn.2020-05.com.idisk:idisk
#登陆(--targetname指定登陆的target)
[root@mg2 ~]# iscsiadm -m node --login
#查看新的系统盘
[root@mg2 ~]# fdisk -l
[root@mg2 ~]# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2 /dev/sdb