[CentOS7]iSCSI存储

生产环境

[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
  • 安装iSCSI工具
yum -y install targetcli
  • 创建iSCSI目录
# mkdir /iscsi_disks
  • 执行命令
# targetcli
Warning: Could not load preferences file /root/.targetcli/prefs.bin.
targetcli shell version 2.1.fb49
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 storage1 /dev/sda3
Created block storage object storage1 using /dev/sda3
# 创建iSCSI链接
/> iscsi/ create iqn.2020-03.com.leoshi.example:storage1
Created target iqn.2020-03.com.leoshi.example:storage1.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
# ACL 秘钥
/> iscsi/iqn.2020-03.com.leoshi.example:storage1/tpg1/acls create iqn.2020-03.com.leoshi.example:testkey
Created Node ACL for iqn.2020-03.com.leoshi.example:testkey
# 创建LUN
/> iscsi/iqn.2020-03.com.leoshi.example:storage1/tpg1/luns create /backstores/block/storage1
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2020-03.com.leoshi.example:testkey
# 查看配置
/> ls
o- / ......................................................................................................................... [...]
  o- backstores .............................................................................................................. [...]
  | o- block .................................................................................................. [Storage Objects: 1]
  | | o- storage1 ....................................................................... [/dev/sda3 (40.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-03.com.leoshi.example:storage1 ........................................................................... [TPGs: 1]
  |   o- tpg1 ............................................................................................... [no-gen-acls, no-auth]
  |     o- acls .......................................................................................................... [ACLs: 1]
  |     | o- iqn.2020-03.com.leoshi.example:testkey ............................................................... [Mapped LUNs: 1]
  |     |   o- mapped_lun0 .............................................................................. [lun0 block/storage1 (rw)]
  |     o- luns .......................................................................................................... [LUNs: 1]
  |     | o- lun0 .................................................................. [block/storage1 (/dev/sda3) (default_tg_pt_gp)]
  |     o- portals .................................................................................................... [Portals: 1]
  |       o- 0.0.0.0:3260 ..................................................................................................... [OK]
  o- loopback ......................................................................................................... [Targets: 0]
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup/.
Configuration saved to /etc/target/saveconfig.json
# 查看监听端口3260是否存在
[root@localhost ~]# netstat -nltap
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1182/master
tcp        0      0 0.0.0.0:3260            0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1027/sshd
tcp        0      0 172.16.1.55:22          172.16.1.1:55969        ESTABLISHED 1897/sshd: root@pts
tcp6       0      0 ::1:25                  :::*                    LISTEN      1182/master
tcp6       0      0 :::22                   :::*                    LISTEN      1027/sshd
# 开机自启动
# systemctl enable target
# 开启防火墙
# firewall-cmd --add-service=iscsi-target --permanent
success
# firewall-cmd --reload
success

END

posted @ 2020-03-16 14:42  LeoShi2020  阅读(273)  评论(0编辑  收藏  举报