CentOS7原版包已经启用不提供scsi-target-utils包了,实验安装源来自aliyum
1.1 scsi-target-utils配置ISCSI服务
yum安装scsi-target-utils包
[root@iscsi-server yum.repos.d]# yum -y install scsi-target-utils
#进入/etc/tgt服务配置文件夹,编辑targets.conf文件,在文件末尾写入配置
[root@iscsi-server yum.repos.d]# cd /etc/tgt/ [root@iscsi-server tgt]# ls conf.d targets.conf tgtd.conf [root@iscsi-server tgt]# vim targets.conf <target iqn.2020-07.com.sample:target1> backing-store /dev/sdb4 #iscsi使用的块设备或者虚拟磁盘 initiator-address 192.168.1.0/24 #可供连接服务的地址 #incominguser username password #连接验证用户密码 #write-cache off #关闭写入缓存 </target>
#启动服务,tgt-admin --show查看服务信息
[root@iscsi-server tgt]# systemctl restart tgtd [root@iscsi-server tgt]# systemctl enable tgtd Created symlink from /etc/systemd/system/multi-user.target.wants/tgtd.service to /usr/lib/systemd/system/tgtd.service. [root@iscsi-server tgt]# tgt-admin --show
#如图可以看到,LUN为1即共享设备,类型为disk磁盘,大小10G,存储路径即/dev/sdb4,允许访问的ACL
1.2 iscsi-initiator-utils配置客户端
客户机上安装iscsi-initiator-utils包
[root@iscsi-client ~]# yum -y install iscsi-initiator-utils
#客户端查找iscsitarget,连接登录设备
[root@iscsi-client ~]# iscsiadm --mode discovery -t sendtargets -p 192.168.1.29:3260 192.168.1.29:3260,1 iqn.2020-07.com.sample:target1 [root@iscsi-client ~]# iscsiadm -m node -T iqn.2020-07.com.sample:target1 -p 192.168.1.29 --login(-u卸载) Logging in to [iface: default, target: iqn.2020-07.com.sample:target1, portal: 192.168.1.29,3260] (multiple) Login to [iface: default, target: iqn.2020-07.com.sample:target1, portal: 192.168.1.29,3260] successful.
#查看连接进程
[root@iscsi-client ~]# iscsiadm -m session -o show tcp: [1] 192.168.1.29:3260,1 iqn.2020-07.com.sample:target1 (non-flash)
#连接完成后本地会出现大小为10G的sdb磁盘,后续可进行格式化挂载等操作
[root@iscsi-client ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sdb 8:16 0 10G 0 disk
2. targetcli配置ISCSI target服务
[root@iscsi-server ~]# yum -y install targetcli
[root@iscsi-server ~]# targetcli \targetcli shell version 2.1.fb41 Copyright 2011-2013 by Datera, Inc and others. For help on commands, type 'help'. /> cd /backstores/fileio /backstores/fileio>create disk-1 /Storage/disk-1.img 2G Created fileio disk-1 with size 2147483648
/backstores/fileio>cd /iscsi /iscsi> create iqn.2020-07.com.test:storage.target01 Created target iqn.2020-07.com.test:storage.target01. Created TPG 1. Global pref auto_add_default_portal=true Created default portal listening on all IPs (0.0.0.0), port 3260.
/iscsi> cd iqn.2020-07.com.test:storage.target01/tpg1/luns /iscsi/iqn.20...t01/tpg1/luns> create /backstores/fileio/disk-1 Created LUN 0.
/iscsi/iqn.20...t01/tpg1/luns> cd ../acls /iscsi/iqn.20...t01/tpg1/acls>create iqn.2020-07.com.test:192.168.1.30 Created Node ACL for iqn.2020-07.com.test:192.168.1.30 Created mapped LUN 0. /iscsi/iqn.20...t01/tpg1/acls> exit Global pref auto_save_on_exit=true Last 10 configs saved in /etc/target/backup. Configuration saved to /etc/target/saveconfig.json
####用户密码验证配置
/iscsi/iqn.20...t00/tpg1/acls> set auth userid=username Unknown configuration group: auth /iscsi/iqn.20...t00/tpg1/acls> cd iqn.2020-07.com.smartmap:192.168.1.30 /iscsi/iqn.20...192.168.1.30> set auth userid=username Parameter userid is now 'username'. /iscsi/iqn.20...192.168.1.30> set auth password=password Parameter password is now 'password'.
[root@iscsi-server ~]# systemctl restart target [root@iscsi-server ~]# systemctl enable target Created symlink from /etc/systemd/system/multi-user.target.wants/target.service to /usr/lib/systemd/system/target.service. [root@iscsi-server ~]# ss -ntlp|grep 3260 LISTEN 0 256 *:3260 *:*