1.安装服务
[root@server ~]# yum -y install targetd targetcli #安装服务
2.启动服务
[root@localhost qtx]# systemctl start target
[root@localhost qtx]# systemctl enable target
[root@localhost qtx]# systemctl status target
3.设置防火墙
[root@localhost qtx]# firewall-cmd --add-port=3260/tcp --permanent
success
[root@localhost qtx]# firewall-cmd --reload
success
[root@localhost qtx]# firewall-cmd --list-ports
3260/tcp
一、客户端
1.指定磁盘
[root@localhost qtx]# targetcli
targetcli shell version 2.1.53
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.
/> /backstores/block create fwq0.disk1 /dev/sdb
Created block storage object fwq0.disk1 using /dev/sdb.
/> exit
Global pref auto_save_on_exit=true
Configuration saved to /etc/target/saveconfig.json
2.创建iqn名字和iscsi对象
[root@localhost qtx]# targetcli
targetcli shell version 2.1.53
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.
/> /iscsi create iqn.2022-04.com.qtx:sdb1
Created target iqn.2022-04.com.qtx:sdb1.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup/.
Configuration saved to /etc/target/saveconfig.json
3.设置iscsi对象和客户端ip
[root@localhost qtx]# targetcli
targetcli shell version 2.1.53
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.
/> /iscsi/iqn.2022-04.com.qtx:sdb1/tpg1/acls create iqn.2022-04.com.qtx:user1
Created Node ACL for iqn.2022-04.com.qtx:user1
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup/.
Configuration saved to /etc/target/saveconfig.json
4.创建lun 绑定块
[root@localhost qtx]# targetcli
targetcli shell version 2.1.53
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.
/> /iscsi/iqn.2022-04.com.qtx:sdb1/tpg1/luns create
二、客户端
1.安装工具
[root@localhost qtx]# yum -y install targetd targetcli
2.initiator命名
[root@client ~]# vim /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2022-04.com.qts:sdb1
3.启动服务
[root@localhost qtx]# systemctl start iscsi
[root@localhost qtx]# systemctl enable iscsi
[root@localhost qtx]# systemctl status iscsi
4.发现存储
[root@localhost qtx]# iscsiadm -m discovery -t st -p 192.168.190.129
192.168.190.129:3260,1 iqn.2022-04.com.qtx:sdb1
5.登陆存储 连接
[root@localhost qtx]# iscsiadm -m discovery -t st -p 192.168.190.129 -l
6.验证
[root@localhost qtx]# lsscsi
[root@localhost qtx]# gdisk /dev/sdb
Number Start (sector) End (sector) Size Code Name
1 2048 10487807 5.0 GiB 8300 Linux filesystem
2 10487808 20971486 5.0 GiB 8300 Linux filesystem
[root@localhost qtx]# partprobe /dev/sdb
[root@localhost qtx]# partprobe /dev/sdb
[root@localhost qtx]# partprobe /dev/sdb
[root@localhost qtx]# cat /proc/partitions
major minor #blocks name
8 16 10485760 sdb
8 17 5242880 sdb1
8 18 5241839 sdb2
[root@localhost qtx]# mkdir /mnt/iscsi
[root@localhost qtx]# mkfs.xfs /dev/sdb1
[root@localhost qtx]# mount /dev/sdb1 /mnt/iscsi/
[root@localhost qtx]# mount | tail -1
[root@localhost qtx]# df -hT /mnt/iscsi/
[root@localhost qtx]# targetcli
/> cd /iscsi/iqn.2022-04.com.qtx:disk1/tpg1/portals/
/iscsi/iqn.20.../tpg1/portals> delete 0.0.0.0 3260
Deleted network portal 0.0.0.0:3260
/iscsi/iqn.20.../tpg1/portals> create 192.168.192.129 3260
Using default IP port 3260
Created network portal 192.168.190.:3260.
/iscsi/iqn.20.../tpg1/portals> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup/.
Configuration saved to /etc/target/saveconfig.json
[root@localhost qtx]# systemctl restart target.service