1. 首页 > Linux教程 > 正文

Linux教程FG344-iSCSI存储配置

内容简介:本文风哥教程参考Linux官方文档、Red Hat Enterprise Linux官方文档、Ansible Automation Platform官方文档、Docker官方文档、Kubernetes官方文档和Podman官方文档等内容,详细介绍了相关技术的配置和使用方法。

风哥提示:

本文档介绍iSCSI存储的配置方法。

Part01-iSCSI Target配置

1.1 安装Target服务

# 安装targetcli
[root@storage-server ~]# dnf install -y targetcli
Updating Subscription Management repositories.
Last metadata expiration check: 0:05:23 ago on Fri Apr 4 18:40:00 2026.
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Installing:
targetcli noarch 2.1.学习交流加群风哥微信: itpux-com53-8.el9 baseos 200 k

Transaction Summary
================================================================================
Install 1 Package

Total download size: 200 k
Installed size: 500 k
Downloading Packages:
targetcli-2.1.53-8.el9.noarch.rpm 500 kB/s | 200 kB 00:00
——————————————————————————–
Total 500 kB/s | 200 kB 00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : targetcli-2.1.53-8.el9.noarch 1/1
Running scriptlet: targetcli-2.1.53-8.更多视频教程www.fgedu.net.cnel9.noarch 1/1
Verifying : targetcli-2.1.53-8.el9.noarch 1/1

Installed:
targetcli-2.1.53-8.el9.noarch

Complete!

# 启动服务
[root@storage-server ~]# systemctl enable –now target
Created symlink /etc/sys更多学习教程公众号风哥教程itpux_comtemd/system/multi-user.target.wants/target.service → /usr/lib/systemd/system/target.service.

# 进入targetcli配置
[root@storage-server ~]# targetcli
targetcli shell version 2.1.53
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]

1.2 创建iSCSI Target

# 创建后端存储
/> cd /backstores/block
/backstores/block> create name=disk1 dev=/dev/sdb
Created block storage object disk1 using /dev/sdb.

/backstores/block> create name=disk2 dev=/dev/sdc
Created block storage object disk2 using /dev/sdc.

/backstores/block> cd /

# 创建iSCSI Target
/学习交流加群风哥QQ113257174> cd /iscsi
/iscsi> create iqn.2026-04.com.example:storage
Created target iqn.2026-04.com.example:storage.
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> cd iqn.2026-04.com.example:storage/tpg1/acls
/iscsi/iqn.20…orage/tpg1/acls> create iqn.2026-04.com.example:client1
Created Node ACL for iqn.2026-04.com.example:client1

/iscsi/iqn.20…orage/tpg1/acls> cd ..

# 创建LUN
/iscsi/iqn.20…example:storage/tpg1> cd luns
/iscsi/iqn.20…orage/tpg1/luns> create /backstores/block/disk1
Created LUN 0.
/iscsi/iqn.20…orage/tpg1/luns> create /backstores/block/disk2
Created LUN 1.

# 配置门户
/iscsi/iqn.20…orage/tpg1/luns> cd ../portals
/iscsi/iqn.20…/tpg1/portals> ls
o- portals ………………………………………… [Portals: 1]
o- 0.0.0.0:3260 ……………………………………… [OK]

/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.1.10
Using default IP port 3260
Created network portal 192.168.1.10:3260.

# 保存配置
/iscsi/iqn.20…/tpg1/portals> cd /
/> saveconfig
Configuration saved to /etc/target/saveconfig.json
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup/.
Configuration saved to /etc/target/saveconfig.json

# 验证配置
[root@storage-server ~]# targetcli ls
o- / ……………………………………………………. […]
o- backstores ………………………………………….. […]
| o- block ……………………………….. [Storage Objects: 2]
| o- disk1 ……………. [/dev/sdb (931.5GiB) write-thru activated]
| o- disk2 ……………. [/dev/sdc (931.5GiB) write-thru activated]
o- iscsi ………………………………………… [Targets: 1]
o- iqn.2026-04.com.example:storage ………………… [TPGs: 1]
o- tpg1 …………………………….. [no-gen-acls, no-auth]
o- acls ………………………………………. [ACLs: 1]
| o- iqn.2026-04.com.example:client1 …………… [Mapped LUNs: 2]
| o- mapped_lun0 ……………………… [lun0 block/disk1 (rw)]
| o- mapped_lun1 ……………………… [lun1 block/disk2 (rw)]
o- luns ………………………………………. [LUNs: 2]
| o- lun0 ……………………… [block/disk1 (/dev/sdb)]
| o- lun1 ……………………… [block/disk2 (/dev/sdc)]
o- portals …………………………………. [Portals: 1]
o- 192.168.1.10:3260 …………………………….. [OK]

# 配置防火墙
[root@storage-server ~]# firewall-cmd –permanent –add-port=3260/tcp
success
[root@storage-server ~]# firewall-cmd –reload
success

Part02-iSCSI Initiator配置

2.1 安装Initiator

# 安装iscsi-initiator-utils
[root@client-server ~]# dnf install -y iscsi-initiator-utils
Updating Subscription Management repositories.
Last metadata expiration check: 0:05:23 ago on Fri Apr 4 18:50:00 2026.
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Installing:
iscsi-initiator-utils x86_64 6.2.1.4-10.el9 baseos 200 k

Transaction Summary
================================================================================
Install 1 Package

Total download size: 200 k
Installed size: 500 k
Downloading Packages:
iscsi-initiator-utils-6.2.1.4-10.el9.x86_64.rpm 500 kB/s | 200 kB 00:00
——————————————————————————–
Total 500 kB/s | 200 kB 00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : iscsi-initiator-utils-6.2.1.4-10.el9.x86_64 1/1
Running scriptlet: iscsi-initiator-utils-6.2.1.4-10.el9.x86_64 1/1
Verifying : iscsi-initiator-utils-6.2.1.4-10.el9.x86_64 1/1

Installed:
iscsi-initiator-utils-6.2.1.4-10.el9.x86_64

Complete!

# 配置Initiator名称
[root@client-server ~]# cat /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2026-04.com.example:client1

# 启动服务
[root@client-server ~]# systemctl enable –now iscsid
Created symlink /etc/systemd/system/multi-user.target.wants/iscsid.service → /usr/lib/systemd/system/iscsid.service.

2.2 连接iSCSI Target

# 发现Target
[root@client-server ~]# iscsiadm -m discovery -t st -p 192.168.1.10
192.168.1.10:3260,1 iqn.2026-04.com.example:storage

# 查看发现记录
[root@client-server ~]# iscsiadm -m node
192.168.1.10:3260,1 iqn.2026-04.com.example:storage

# 登录Target
[root@client-server ~]# iscsiadm -m node -T iqn.2026-04.com.example:storage -p 192.168.1.10 -l
Logging in to [iface: default, target: iqn.2026-04.com.example:storage, portal: 192.168.1.10,3260]
Login to [iface: default, target: iqn.2026-04.com.example:storage, portal: 192.168.1.10,3260] successful.

# 查看会话
[root@client-server ~]# iscsiadm -m session
tcp: [1] 192.168.1.10:3260,1 iqn.2026-04.com.example:storage (non-flash)

# 查看磁盘
[root@client-server ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 931.5G 0 disk
sdb 8:16 0 931.5G 0 disk
sdc 8:32 0 931.5G 0 disk

# 格式化并挂载
[root@client-server ~]# mkfs.xfs /dev/sda
[root@client-server ~]# mkdir /data/iscsi
[root@client-server ~]# mount /defrom PG视频:www.itpux.comv/sda /data/iscsi

# 配置自动登录
[root@client-server ~]# iscsiadm -m node -T iqn.2026-04.com.example:storage -p 192.168.1.10 –op update -n node.startup -v automatic

# 登出Target
[root@client-server ~]# iscsiadm -m node -T iqn.2026-04.com.example:storage -p 192.168.1.10 -u
Logging out of session [sid: 1, target: iqn.2026-04.com.example:storage, portal: 192.168.1.10,3260]
Logout of [sid: 1, target: iqn.2026-04.com.example:storage, portal: 192.168.1.10,3260] successful.

风哥针对iSCSI配置建议:

  • 使用专用网络传输iSCSI
  • 配置CHAP认证提高安全性
  • 使用多路径提高可用性
  • 定期检查连接状态
  • 合理规划LUN大小

本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html

联系我们

在线咨询:点击这里给我发消息

微信号:itpux-com

工作日:9:30-18:30,节假日休息