1、安装工具
[root@localhost /]# yum -y install iscsi-initiator-utils
2、给 initiator 命名(默认不修改)
[root@localhost /]# vim /etc/iscsi/initiatorname.iscsi
3、启动服务
[root@localhost /]# systemctl start iscsi
[root@localhost /]# systemctl enable iscsi
Created symlink from /etc/systemd/system/remote-fs.target.wants/iscsi.service to /usr/lib/systemd/system/iscsi.service.
[root@localhost /]# systemctl status iscsi
● iscsi.service - Login and scanning of iSCSI devices
Loaded: loaded (/usr/lib/systemd/system/iscsi.service; enabled; vendor preset: disabled)
Active: inactive (dead)
Condition: start condition failed at 四 2022-04-28 21:01:36 CST; 26s ago
Docs: man:iscsiadm(8)
man:iscsid(8)
4月 27 16:17:48 localhost.localdomain systemd[1]: Unit iscsi.service cannot ...
4月 27 16:17:48 localhost.localdomain systemd[1]: Unit iscsi.service cannot ...
4月 27 16:20:16 localhost.localdomain systemd[1]: Unit iscsi.service cannot ...
Hint: Some lines were ellipsized, use -l to show in full.
4、发现存储
iscsiadm -m discovery -t st -p 10.213.132.24
```
iscsiadm -m discovery -t st -p 10.213.132.24
iscsiadm: cannot make connection to 10.213.132.24: Connection refused
```
5、登陆存储 / 连接 target
iscsiadm -m discovery -t st -p 10.213.132.24 -l
10.213.132.30:3260,2461 iqn.2007-11.com.nimblestorage:nimblegroup-g4f9e7cc0916de8eb
10.213.132.31:3260,2461 iqn.2007-11.com.nimblestorage:nimblegroup-g4f9e7cc0916de8eb
Logging in to [iface: default, target: iqn.2007-11.com.nimblestorage:nimblegroup-g4f9e7cc0916de8eb, portal: 10.213.132.30,3260] (multiple)
Logging in to [iface: default, target: iqn.2007-11.com.nimblestorage:nimblegroup-g4f9e7cc0916de8eb, portal: 10.213.132.31,3260] (multiple)
Login to [iface: default, target: iqn.2007-11.com.nimblestorage:nimblegroup-g4f9e7cc0916de8eb, portal: 10.213.132.30,3260] successful.
Login to [iface: default, target: iqn.2007-11.com.nimblestorage:nimblegroup-g4f9e7cc0916de8eb, portal: 10.213.132.31,3260] successful.
6、验证 iscsi 连接,查看是否得到外界磁盘
lsscsi
0:0:66:0] enclosu HUAWEI Expander 12Gx16 131 -
[0:2:0:0] disk AVAGO HW-SAS3508 5.06 /dev/sda
[0:2:1:0] disk AVAGO HW-SAS3508 5.06 /dev/sdb
[0:2:2:0] disk AVAGO HW-SAS3508 5.06 /dev/sdc
[0:2:3:0] disk AVAGO HW-SAS3508 5.06 /dev/sdd
[15:0:0:0] disk Nimble Server 1.0 /dev/sde
[16:0:0:0] disk Nimble Server 1.0 /dev/sdf
然后就可以像操作本地磁盘一样来操作 iscsi 磁盘 了。由于iscsi使用了多链路,所以我们multipath做链路聚合
安装multipath软件
yum install -y device-mapper-multipath
rpm -qa | grep multipath
device-mapper-multipath-0.4.9-123.el7.x86_64
device-mapper-multipath-libs-0.4.9-123.el7.x86_64
生成multipath配置执行命令mpathconf --enable
在/etc目录下生成配置文件multipath.conf
mpathconf --enable
systemctl restart multipathd
修改mulipath 配置文件(系统盘排除)
vim /etc/multipath.conf
defaults {
user_friendly_names yes
}
设置黑名单列表,示例环境sda、sdb磁盘为系统RAID盘,故而排除
blacklist {
devnode "^sd[a-b]"
}
multipaths {
multipath {
path_grouping_policy multibus
#path_checker readsector0
prio "random"
path_selector "round-robin 0"
}
}
devices {
device {
vendor "vcluster"
product "12.2.12"
path_checker readsector0
path_selector "round-robin 0"
failback immediate
no_path_retry fail
}
修改multipath配置修改配置文件/etc/mulipath.conf信息如下,之后执行命令重启服务
systemctl restart multipathd
刷新所有多路径配置:
multipath -F
查看multipath状态
*multipath -ll*
此时本地可以看到新增的虚拟磁盘 /dev/mapper/mpatha
,该虚拟磁盘通过两条iscsi路径提供,当前配置为主备模式(同一时刻只有一条路径处于活动状态,可写入数据)
多路径格式化,对磁盘操作提示要分区
fdisk -l
Disk /dev/mapper/mpatha: 10995.1 GB, 10995116277760 bytes, 21474836480 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
格式化磁盘
mkfs -t ext4 /dev/mapper/mpatha
挂载磁盘
mkdir /data
mount /dev/mapper/mpatha /data
df -h
写入开机启动项,并挂载
echo '/dev/mapper/mpatha /data ext4 defaults 0 0' >> /etc/fstab
mount -a
df -h