目录
1、简介
2、目标规划
3、 坏境准备
4、配置ISCSI服务端
5、ISCSI服务客户端配置
iSCSI主要是通过TCP/IP的技术,将存储设备端通过iSCSI target功能,组成可以提供磁盘的服务器端,再通过iSCSI initiator(iSCSI初始化用户)功能,成为能够挂载使用iSCSI target的客户端,如此便能够通过iSCSI协议来进行磁盘的应用。
iSCSI target:存储设备端,存放磁盘的RAID设备,可将Linux主机仿真为iSCSI target,以供其他主机使用;
iSCSI initiator:安装iSCSI initiator之后才能够使用target提供的磁盘服务,通常为服务器
Server主机名 |
服务端ip |
iscsi名称 |
访问权限控制列表 |
iscsi01.brick.com |
192.168.79.131 |
iqn.2022-11.com.brick.iscsi01:server |
iqn.2022-11.com.brick:client01 |
192.168.79.134 | iqn.2022-11.com.brick.iscsi02:server | iqn.2022-11.com.brick:client01 | |
双网卡,主要是模拟2个 iSCSI target存储设备端 | |||
Client主机名 |
客户端ip |
访问服务端ip |
|
test01.brick.com |
192.168.79.132 |
192.168.79.131 | 192.168.79.134 |
模拟连接2个 iSCSI targe |
虚拟机添加一块磁盘,划分为3个LV
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 30G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 29G 0 part
├─centos-root 253:0 0 27G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 10G 0 disk
[root@localhost ~]# pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created.
[root@localhost ~]# vgcreate /dev/iscsi01 /dev/sdb
Volume group "iscsi01" successfully created
[root@localhost ~]# lvcreate -L 2G -n test1 iscsi01
Logical volume "test1" created.
[root@localhost ~]# lvcreate -L 2G -n test2 iscsi01
Logical volume "test2" created.
[root@localhost ~]# lvcreate -l 100%FREE -n test3 iscsi01
Logical volume "test3" created.
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root centos -wi-ao---- 26.99g
swap centos -wi-ao---- 2.00g
test1 iscsi01 -wi-a----- 2.00g
test2 iscsi01 -wi-a----- 2.00g
test3 iscsi01 -wi-a----- <6.00g
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 30G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 29G 0 part
├─centos-root 253:0 0 27G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 10G 0 disk
├─iscsi01-test1 253:2 0 2G 0 lvm
├─iscsi01-test2 253:3 0 2G 0 lvm
└─iscsi01-test3 253:4 0 6G 0 lvm
[root@localhost ~]# mount /dev/cdrom /mnt/ #挂载镜像
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost ~]# mkdir -p /etc/yum.repos.d/back
[root@localhost ~]# mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/back/ #对原有的yum源进行备份
[root@localhost ~]# cd /etc/yum.repos.d/back/
[root@localhost back]# cp CentOS-Base.repo ../
[root@localhost back]# cd ../
[root@localhost yum.repos.d]# vi CentOS-Base.repo #修改yum源
[root@localhost yum.repos.d]# cat CentOS-Base.repo
[root@test01 mnt]# cat /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-Base
baseurl=file:///mnt
gpgcheck=1
gpgkey=file:///RPM-GPG-KEY-CentOS-7
[root@localhost yum.repos.d]# yum clean all
已加载插件:fastestmirror
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
正在清理软件源: base
Cleaning up list of fastest mirrors
Other repos take up 156 M of disk space (use --verbose for details)
[root@localhost yum.repos.d]# yum repolist
已加载插件:fastestmirror
Determining fastest mirrors
base | 3.6 kB 00:00:00
(1/2): base/group_gz | 153 kB 00:00:00
(2/2): base/primary_db | 6.1 MB 00:00:00
源标识 源名称 状态
base CentOS-7 - Base 10,073
repolist: 10,073
[root@localhost yum.repos.d]# yum install targetcli -y #安装ISCSI服务端
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 targetcli.noarch.0.2.1.53-1.el7_9 将被 安装
--> 正在处理依赖关系 python-rtslib >= 2.1.fb41,它被软件包 targetcli-2.1.53-1.el7_9.noarch 需要
--> 正在处理依赖关系 python-ethtool,它被软件包 targetcli-2.1.53-1.el7_9.noarch 需要
--> 正在处理依赖关系 python-configshell,它被软件包 targetcli-2.1.53-1.el7_9.noarch 需要
--> 正在检查事务
---> 软件包 python-configshell.noarch.1.1.1.26-1.el7 将被 安装
--> 正在处理依赖关系 python-urwid,它被软件包 1:python-configshell-1.1.26-1.el7.noarch 需要
--> 正在处理依赖关系 python-six,它被软件包 1:python-configshell-1.1.26-1.el7.noarch 需要
--> 正在处理依赖关系 pyparsing,它被软件包 1:python-configshell-1.1.26-1.el7.noarch 需要
---> 软件包 python-ethtool.x86_64.0.0.8-8.el7 将被 安装
--> 正在处理依赖关系 libnl.so.1()(64bit),它被软件包 python-ethtool-0.8-8.el7.x86_64 需要
---> 软件包 python-rtslib.noarch.0.2.1.74-1.el7_9 将被 安装
--> 正在处理依赖关系 python-kmod,它被软件包 python-rtslib-2.1.74-1.el7_9.noarch 需要
--> 正在检查事务
---> 软件包 libnl.x86_64.0.1.1.4-3.el7 将被 安装
---> 软件包 pyparsing.noarch.0.1.5.6-9.el7 将被 安装
---> 软件包 python-kmod.x86_64.0.0.9-4.el7 将被 安装
---> 软件包 python-six.noarch.0.1.9.0-2.el7 将被 安装
---> 软件包 python-urwid.x86_64.0.1.1.1-3.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
===========================================================================================================================================================
Package 架构 版本 源 大小
===========================================================================================================================================================
正在安装:
targetcli noarch 2.1.53-1.el7_9 base 75 k
为依赖而安装:
libnl x86_64 1.1.4-3.el7 base 128 k
pyparsing noarch 1.5.6-9.el7 base 94 k
python-configshell noarch 1:1.1.26-1.el7 base 68 k
python-ethtool x86_64 0.8-8.el7 base 34 k
python-kmod x86_64 0.9-4.el7 base 57 k
python-rtslib noarch 2.1.74-1.el7_9 base 104 k
python-six noarch 1.9.0-2.el7 base 29 k
python-urwid x86_64 1.1.1-3.el7 base 654 k
事务概要
===========================================================================================================================================================
安装 1 软件包 (+8 依赖软件包)
总下载量:1.2 M
安装大小:5.2 M
Downloading packages:
-----------------------------------------------------------------------------------------------------------------------------------------------------------
总计 5.8 MB/s | 1.2 MB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
警告:RPM 数据库已被非 yum 程序修改。
正在安装 : python-six-1.9.0-2.el7.noarch 1/9
正在安装 : pyparsing-1.5.6-9.el7.noarch 2/9
正在安装 : python-kmod-0.9-4.el7.x86_64 3/9
正在安装 : python-rtslib-2.1.74-1.el7_9.noarch 4/9
正在安装 : libnl-1.1.4-3.el7.x86_64 5/9
正在安装 : python-ethtool-0.8-8.el7.x86_64 6/9
正在安装 : python-urwid-1.1.1-3.el7.x86_64 7/9
正在安装 : 1:python-configshell-1.1.26-1.el7.noarch 8/9
正在安装 : targetcli-2.1.53-1.el7_9.noarch 9/9
验证中 : python-urwid-1.1.1-3.el7.x86_64 1/9
验证中 : libnl-1.1.4-3.el7.x86_64 2/9
验证中 : python-ethtool-0.8-8.el7.x86_64 3/9
验证中 : python-rtslib-2.1.74-1.el7_9.noarch 4/9
验证中 : targetcli-2.1.53-1.el7_9.noarch 5/9
验证中 : python-kmod-0.9-4.el7.x86_64 6/9
验证中 : python-six-1.9.0-2.el7.noarch 7/9
验证中 : pyparsing-1.5.6-9.el7.noarch 8/9
验证中 : 1:python-configshell-1.1.26-1.el7.noarch 9/9
已安装:
targetcli.noarch 0:2.1.53-1.el7_9
作为依赖被安装:
libnl.x86_64 0:1.1.4-3.el7 pyparsing.noarch 0:1.5.6-9.el7 python-configshell.noarch 1:1.1.26-1.el7 python-ethtool.x86_64 0:0.8-8.el7
python-kmod.x86_64 0:0.9-4.el7 python-rtslib.noarch 0:2.1.74-1.el7_9 python-six.noarch 0:1.9.0-2.el7 python-urwid.x86_64 0:1.1.1-3.el7
完毕!
[root@localhost yum.repos.d]# systemctl start target #启动
[root@localhost yum.repos.d]# systemctl status target #查询服务状态
● target.service - Restore LIO kernel target configuration
Loaded: loaded (/usr/lib/systemd/system/target.service; disabled; vendor preset: disabled)
Active: active (exited) since 日 2022-11-13 00:22:34 CST; 9s ago
Process: 1388 ExecStart=/usr/bin/targetctl restore (code=exited, status=0/SUCCESS)
Main PID: 1388 (code=exited, status=0/SUCCESS)
11月 13 00:22:34 localhost.localdomain systemd[1]: Starting Restore LIO kernel target configuration...
11月 13 00:22:34 localhost.localdomain target[1388]: No saved config file at /etc/target/saveconfig.json, ok, exiting
11月 13 00:22:34 localhost.localdomain systemd[1]: Started Restore LIO kernel target configuration.
[root@localhost yum.repos.d]# systemctl enable target #开机自启
Created symlink from /etc/systemd/system/multi-user.target.wants/target.service to /usr/lib/systemd/system/target.service.
[root@localhost yum.repos.d]# systemctl disable firewalld #开机补启动防火墙
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost yum.repos.d]# systemctl stop firewalld #关闭防火墙
[root@localhost yum.repos.d]# vi /etc/selinux/config #关闭selinux
[root@localhost yum.repos.d]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
[root@localhost yum.repos.d]# hostnamectl set-hostname iscsi01.brick.com #修改主机名
[root@localhost yum.repos.d]# init 6 #重启
Connection closing...Socket close.
Connection closed by foreign host.
Disconnected from remote host(inter_test_192.168.79.131) at 00:28:25.
Type `help' to learn how to use Xshell prompt.
[root@iscsi01 /]# targetcli
Warning: Could not load preferences file /root/.targetcli/prefs.bin.
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- ramdisk .............................................. [Storage Objects: 0]
o- iscsi .......................................................... [Targets: 0]
o- loopback ....................................................... [Targets: 0]
/>
注:targetcli是用于管理iSCSI服务端存储资源的专用配置命令,它提供交互式配置功能,将iSCSI共享资源的配置内容抽象成“目录”的形式,只需将各类配置信息填入到相应的“目录”中即可。
#以下步骤涉及到的目录
/backstores/block:iSCSI服务端配置共享设备的位置(在这里添加要共享的磁盘设备并重命名)
/> backstores/block create test1 /dev/iscsi01/test1
Created block storage object test1 using /dev/iscsi01/test1.
/> backstores/block create test2 /dev/iscsi01/test2
Created block storage object test2 using /dev/iscsi01/test2.
/> backstores/block create test3 /dev/iscsi01/test3
Created block storage object test3 using /dev/iscsi01/test3.
/> ls
o- / ......................................................................................................................... [...]
o- backstores .............................................................................................................. [...]
| o- block .................................................................................................. [Storage Objects: 3]
| | o- test1 ................................................................ [/dev/iscsi01/test1 (2.0GiB) write-thru deactivated]
| | | o- alua ................................................................................................... [ALUA Groups: 1]
| | | o- default_tg_pt_gp ....................................................................... [ALUA state: Active/optimized]
| | o- test2 ................................................................ [/dev/iscsi01/test2 (2.0GiB) write-thru deactivated]
| | | o- alua ................................................................................................... [ALUA Groups: 1]
| | | o- default_tg_pt_gp ....................................................................... [ALUA state: Active/optimized]
| | o- test3 ................................................................ [/dev/iscsi01/test3 (6.0GiB) write-thru deactivated]
| | 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: 0]
o- loopback ......................................................................................................... [Targets: 0]
/>
注:/iscsi/iqn......xxx/tpg1:通过在/iscsi目录执行create命令生成iSCSI target名称时自动生成的与iSCSI target名称同名的目录的子目录
acls:用于存放能够访问iSCSI服务端共享存储资源的验证信息
luns:用于存放可共享的硬盘设备(/backstores/block只是一个预备资源池,但没声明可共享)
portals:用于存放iscsi服务端的ip地址5
/> #模拟两台ISCSI服务器
/> iscsi/ create iqn.2022-11.com.brick.iscsi01:server
Created target iqn.2022-11.com.brick.iscsi01:server.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/> iscsi/ create iqn.2022-11.com.brick.iscsi02:server
Created target iqn.2022-11.com.brick.iscsi02:server.
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.2022-11.com.brick.iscsi01:server/tpg1/acls create iqn.2022-11.com.brick:client01
Created Node ACL for iqn.2022-11.com.brick:client01
/> iscsi/iqn.2022-11.com.brick.iscsi01:server/tpg1/luns create /b
/backstores/block/test1 /backstores/block/test2 /backstores/block/test3 /bin/ /boot/
/> iscsi/iqn.2022-11.com.brick.iscsi01:server/tpg1/luns create /backstores/block/test1
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2022-11.com.brick:client01
/> iscsi/iqn.2022-11.com.brick.iscsi01:server/tpg1/luns create /backstores/block/test2
Created LUN 1.
Created LUN 1->1 mapping in node ACL iqn.2022-11.com.brick:client01
/> iscsi/iqn.2022-11.com.brick.iscsi02:server/tpg1/acls create iqn.2022-11.com.brick:client01
Created Node ACL for iqn.2022-11.com.brick:client01
/> iscsi/iqn.2022-11.com.brick.iscsi02:server/tpg1/luns create /backstores/block/test3
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2022-11.com.brick:client01
/> #修改portals
/> iscsi/iqn.2022-11.com.brick.iscsi01:server/tpg1/portals/ delete 0.0.0.0 3260
Deleted network portal 0.0.0.0:3260
/> iscsi/iqn.2022-11.com.brick.iscsi02:server/tpg1/portals/ delete 0.0.0.0 3260
Deleted network portal 0.0.0.0:3260
/> iscsi/iqn.2022-11.com.brick.iscsi01:server/tpg1/portals/ create 192.168.79.131 3260
Using default IP port 3260
Created network portal 192.168.79.131:3260.
/> iscsi/iqn.2022-11.com.brick.iscsi02:server/tpg1/portals/ create 192.168.79.134 3260
Using default IP port 3260
Created network portal 192.168.79.134:3260.
/> #最初始化的/> ls
o- / ......................................................................................................................... [...]
o- backstores .............................................................................................................. [...]
| o- block .................................................................................................. [Storage Objects: 3]
| | o- test1 .................................................................. [/dev/iscsi01/test1 (2.0GiB) write-thru activated]
| | | o- alua ................................................................................................... [ALUA Groups: 1]
| | | o- default_tg_pt_gp ....................................................................... [ALUA state: Active/optimized]
| | o- test2 .................................................................. [/dev/iscsi01/test2 (2.0GiB) write-thru activated]
| | | o- alua ................................................................................................... [ALUA Groups: 1]
| | | o- default_tg_pt_gp ....................................................................... [ALUA state: Active/optimized]
| | o- test3 .................................................................. [/dev/iscsi01/test3 (6.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: 2]
| o- iqn.2022-11.com.brick.iscsi01:server .............................................................................. [TPGs: 1]
| | o- tpg1 ............................................................................................... [no-gen-acls, no-auth]
| | o- acls .......................................................................................................... [ACLs: 1]
| | | o- iqn.2022-11.com.brick:client01 ....................................................................... [Mapped LUNs: 2]
| | | o- mapped_lun0 ................................................................................. [lun0 block/test1 (rw)]
| | | o- mapped_lun1 ................................................................................. [lun1 block/test2 (rw)]
| | o- luns .......................................................................................................... [LUNs: 2]
| | | o- lun0 ............................................................ [block/test1 (/dev/iscsi01/test1) (default_tg_pt_gp)]
| | | o- lun1 ............................................................ [block/test2 (/dev/iscsi01/test2) (default_tg_pt_gp)]
| | o- portals .................................................................................................... [Portals: 1]
| | o- 192.168.79.131:3260 .............................................................................................. [OK]
| o- iqn.2022-11.com.brick.iscsi02:server .............................................................................. [TPGs: 1]
| o- tpg1 ............................................................................................... [no-gen-acls, no-auth]
| o- acls .......................................................................................................... [ACLs: 1]
| | o- iqn.2022-11.com.brick:client01 ....................................................................... [Mapped LUNs: 1]
| | o- mapped_lun0 ................................................................................. [lun0 block/test3 (rw)]
| o- luns .......................................................................................................... [LUNs: 1]
| | o- lun0 ............................................................ [block/test3 (/dev/iscsi01/test3) (default_tg_pt_gp)]
| o- portals .................................................................................................... [Portals: 1]
| o- 192.168.79.134:3260 .............................................................................................. [OK]
o- loopback ......................................................................................................... [Targets: 0]
/> #配置完成
/> 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@localhost ~]# #修改主机名
[root@localhost ~]# hostnamectl set-hostname test01.brick.com
[root@localhost ~]# #关闭防火墙
[root@localhost ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# #关闭Selinux
[root@localhost ~]# vi /etc/selinux/config
[root@localhost ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
[root@localhost ~]# init 6
Connection closing...Socket close.
Connection closed by foreign host.
Disconnected from remote host(test1_192.168.79.132) at 12:56:26.
Type `help' to learn how to use Xshell prompt.
[root@test01 ~]# #挂载yum源
[root@test01 ~]# mount /dev/cdrom /mnt
mount: 在 /dev/sr0 上找不到媒体
[root@test01 ~]# #查看虚拟机是否连接ISO镜像
[root@test01 ~]# mount /dev/cdrom /mnt
mount: /dev/sr0 写保护,将以只读方式挂载
[root@test01 ~]# rm -rf /etc/yum.repos.d/*
[root@test01 ~]# cd /etc/yum.repos.d/
[root@test01 yum.repos.d]# scp [email protected]:/etc/yum.
yum.conf yum.repos.d/
[root@test01 yum.repos.d]# scp [email protected]:/etc/yum.repos.d/*.repo ./
The authenticity of host '192.168.79.131 (192.168.79.131)' can't be established.
ECDSA key fingerprint is SHA256:RqX2HnBB90KNzIrKyY7yCTJRMwibwXa8rvZ1BOqizLk.
ECDSA key fingerprint is MD5:12:76:62:cb:44:18:7a:92:fd:45:bc:84:8d:bd:dd:54.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.79.131' (ECDSA) to the list of known hosts.
[email protected]'s password:
CentOS-Base.repo 100% 537 200.5KB/s 00:00
[root@test01 yum.repos.d]# cat CentOS-Base.repo
[root@test01 mnt]# cat /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-Base
baseurl=file:///mnt
gpgcheck=1
gpgkey=file:///RPM-GPG-KEY-CentOS-7
[root@test01 yum.repos.d]# #也可以自己创建一个文件,按照格式书写。
[root@test01 mnt]# yum install iscsi-initiator-utils
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 iscsi-initiator-utils.x86_64.0.6.2.0.874-22.el7_9 将被 安装
--> 正在处理依赖关系 iscsi-initiator-utils-iscsiuio >= 6.2.0.874-22.el7_9,它被软件包 iscsi-initiator-utils-6.2.0.874-22.el7_9.x86_64 需要
--> 正在检查事务
---> 软件包 iscsi-initiator-utils-iscsiuio.x86_64.0.6.2.0.874-22.el7_9 将被 安装
--> 解决依赖关系完成
依赖关系解决
===========================================================================================================================================================
Package 架构 版本 源 大小
===========================================================================================================================================================
正在安装:
iscsi-initiator-utils x86_64 6.2.0.874-22.el7_9 base 423 k
为依赖而安装:
iscsi-initiator-utils-iscsiuio x86_64 6.2.0.874-22.el7_9 base 94 k
事务概要
===========================================================================================================================================================
安装 1 软件包 (+1 依赖软件包)
总下载量:517 k
安装大小:2.5 M
Is this ok [y/d/N]: Y
Downloading packages:
-----------------------------------------------------------------------------------------------------------------------------------------------------------
总计 92 MB/s | 517 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : iscsi-initiator-utils-iscsiuio-6.2.0.874-22.el7_9.x86_64 1/2
正在安装 : iscsi-initiator-utils-6.2.0.874-22.el7_9.x86_64 2/2
验证中 : iscsi-initiator-utils-6.2.0.874-22.el7_9.x86_64 1/2
验证中 : iscsi-initiator-utils-iscsiuio-6.2.0.874-22.el7_9.x86_64 2/2
已安装:
iscsi-initiator-utils.x86_64 0:6.2.0.874-22.el7_9
作为依赖被安装:
iscsi-initiator-utils-iscsiuio.x86_64 0:6.2.0.874-22.el7_9
完毕!
[root@test01 mnt]# 添加acl访问控制列表
[root@test01 mnt]# echo InitiatorName=iqn.2022-11.com.brick:client01 > /etc/iscsi/initiatorname.iscsi
[root@test01 mnt]# cat /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2022-11.com.brick:client01
[root@test01 mnt]# systemctl restart iscsid
[root@test01 mnt]# systemctl enable iscsid
Created symlink from /etc/systemd/system/multi-user.target.wants/iscsid.service to /usr/lib/systemd/system/iscsid.service.
[root@test01 mnt]# systemctl status iscsid
● iscsid.service - Open-iSCSI
Loaded: loaded (/usr/lib/systemd/system/iscsid.service; enabled; vendor preset: disabled)
Active: active (running) since 日 2022-11-13 13:15:03 CST; 11s ago
Docs: man:iscsid(8)
man:iscsiuio(8)
man:iscsiadm(8)
Main PID: 1343 (iscsid)
Status: "Ready to process requests"
CGroup: /system.slice/iscsid.service
└─1343 /sbin/iscsid -f
11月 13 13:15:03 test01.brick.com systemd[1]: Starting Open-iSCSI...
11月 13 13:15:03 test01.brick.com systemd[1]: Started Open-iSCSI.
iscsiadm命令详解
iscsiadm是个模式化的工具,其模式可通过-m或--mode选项指定,
常见的模式有discoverydb、node、fw、session、host、iface几个,
如果没有额外指定其它选项,则discoverydb和node会显示其相关的所有记录;
session用于显示所有的活动会话和连接,fw显示所有的启动固件值,host显示所有的iSCSI主机,
iface显示/var/lib/iscsi/ifaces目录中的所有ifaces设定。
-l --login |
登入节点(服务器) |
-t --type=type |
这里可以使用的类型为sendtargets(可简写为st)、slp、fw和 isns,此选项仅用于discovery模式,且目前仅支持st、fw和isns;其中st表示允许每个iSCSItarget发送一个可用target列表给initiator; |
-p --portal=ip[:port] |
指定target服务的IP和端口 |
-m --mode |
可用的mode有discovery, node, fw, host iface 和 session |
-T --targetname=targetname |
用于指定target的名字 |
-u --logout |
登出节点(服务器) |
-o --op=OPEARTION |
指定针对discoverydb数据库的操作,其仅能为new、delete、update、show和nonpersistent其中之一 |
[root@test01 ~]# iscsiadm -m discovery -t st -p 192.168.79.131 #查询发现记录
192.168.79.131:3260,1 iqn.2022-11.com.brick.iscsi01:server
192.168.79.134:3260,1 iqn.2022-11.com.brick.iscsi02:server
[root@test01 ~]# iscsiadm -m node show #查看iscsi发现记录,show 可以忽略
192.168.79.131:3260,1 iqn.2022-11.com.brick.iscsi01:server
192.168.79.134:3260,1 iqn.2022-11.com.brick.iscsi02:server
[root@test01 ~]# iscsiadm -m node -o delete -T iqn.2022-11.com.brick.iscsi02:server #删除目标iscsi发现记录
[root@test01 ~]# iscsiadm -m node -o delete #删除所有目标
[root@test01 ~]# iscsiadm -m node -T iqn.2022-11.com.brick.iscsi01:server -p 192.168.79.131 -l #登陆记录
[root@test01 ~]# iscsiadm -m node -L all #登录所有记录
[root@test01 ~]# iscsiadm -m node -u #退出所有登陆
[root@test01 ~]# iscsiadm -m session #查看连接记录
[root@test01 ~]# iscsiadm -m node -o show -T iqn.2022-11.com.brick.iscsi01:server #查看数据结构的树状信息
[root@test01 ~]# iscsiadm -m node –T iqn.2022-11.com.brick.iscsi01:server -p 192.168.79.131 -o update -n node.startup -v automatic #开机自动登陆或者修改/etc/iscsi/iscsid.conf文件,将:#node.startup = automatic 一行前面的#去掉改成node.startup = automatic
#操作步骤 1发现2登录3开机启动5挂载硬盘6配置开机自动挂载
[root@test01 ~]# iscsiadm -m discovery -t st -p 192.168.79.131 #发现目标
192.168.79.131:3260,1 iqn.2022-11.com.brick.iscsi01:server
192.168.79.134:3260,1 iqn.2022-11.com.brick.iscsi02:server
[root@test01 ~]# iscsiadm -m node -T iqn.2022-11.com.brick.iscsi01:server -p 192.168.79.131 -l #登陆目标
Logging in to [iface: default, target: iqn.2022-11.com.brick.iscsi01:server, portal: 192.168.79.131,3260] (multiple)
Login to [iface: default, target: iqn.2022-11.com.brick.iscsi01:server, portal: 192.168.79.131,3260] successful.
[root@test01 ~]# iscsiadm -m session
tcp: [13] 192.168.79.131:3260,1 iqn.2022-11.com.brick.iscsi01:server (non-flash)
[root@test01 ~]# iscsiadm -m node –T iqn.2022-11.com.brick.iscsi01:server -p 192.168.79.131 -o update -n node.startup -v automatic #开机自动登陆
[root@test01 ~]# iscsiadm -m session
tcp: [13] 192.168.79.131:3260,1 iqn.2022-11.com.brick.iscsi01:server (non-flash)
[root@test01 ~]# lsblk #查看是否成功,多了 /dev/sdb /dev/sdc
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 2G 0 disk
sdc 8:32 0 2G 0 disk
sr0 11:0 1 9.6G 0 rom
[root@test01 ~]# init 6 #重启确认是否成功
Connection closing...Socket close.
Connection closed by foreign host.
Disconnected from remote host(test1_192.168.79.132) at 16:16:10.
Type `help' to learn how to use Xshell prompt.
Connecting to 192.168.79.132:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
WARNING! The remote SSH server rejected X11 forwarding request.
Last login: Sun Nov 13 16:21:36 2022 from 192.168.79.1
[root@test01 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 2G 0 disk
sdc 8:32 0 6G 0 disk
sdd 8:48 0 2G 0 disk
sr0 11:0 1 9.6G 0 rom
后面有时间更新