iscsi-分区类型
iSCSI简介(Internet SCSI):
iSCSI 小型计算机系统接口,IBM公司研发,用于在IP网络上运行SCSI协议;解决了 SCSI需要直连存储设备的局限性;可以不停机扩展存储容量,iSCSI 将 SCSI 接口与 Ethernet 技术结合,使服务器可与使用 IP 网络的存储装置互相交换数据;基于 TCP/IP 协议,创建 SAN,以数据块级别在多个数据存储网络间进行传输
iSCSI 主要功能:
在 TCP/IP 网络上的主机系统(initiator 启动器)和存储设备(target 目标器)之间进行数据的封装和可靠传输。
iSCSI 启动器是客户端设备,启动器可以由软件或硬件实现;
·软件:iscsi-initiator-utils(RPM 免费提供的 Linux-Open-iSCSI 驱动)
·硬件:iSCSI HBA(或 TCP 卸载引擎[TOE] 卡) -> 本质使一个专用以太网卡,
其上的 SCSI ASIC 可以从系统CPU内卸载所有工作(TCP 和 SCSI 命令)
iSCSI 目标是 iSCSI 网络的“服务器”组件。通常为一个存储设备
环境准备
两台RHEL虚拟机(拍初始化快照):
-
node1(192.168.22.77)target端( iSCSI服务端)
- client1(192.168.22.107)initiator端( iSCSI客户端)
一、iSCSI配置
target端分区
[root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 40G 0 disk ├─sda1 8:1 0 512M 0 part /boot └─sda2 8:2 0 25.5G 0 part ├─rhel-swap 253:0 0 512M 0 lvm [SWAP] └─rhel-root 253:1 0 25G 0 lvm / sr0 11:0 1 3.6G 0 rom /mnt/cdrom [root@localhost ~]# fdisk /dev/sda Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): p Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 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 Disk label type: dos Disk identifier: 0x0009ed86 Device Boot Start End Blocks Id System /dev/sda1 * 2048 1050623 524288 83 Linux /dev/sda2 1050624 54544383 26746880 8e Linux LVM Command (m for help): n Partition type: p primary (2 primary, 0 extended, 2 free) e extended Select (default p): Using default response p Partition number (3,4, default 3): First sector (54544384-83886079, default 54544384): Using default value 54544384 Last sector, +sectors or +size{K,M,G} (54544384-83886079, default 83886079): +5G Partition 3 of type Linux and of size 5 GiB is set Command (m for help): p Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 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 Disk label type: dos Disk identifier: 0x0009ed86 Device Boot Start End Blocks Id System /dev/sda1 * 2048 1050623 524288 83 Linux /dev/sda2 1050624 54544383 26746880 8e Linux LVM /dev/sda3 54544384 65030143 5242880 83 Linux Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) Syncing disks. [root@localhost ~]# partprobe /dev/sda
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 40G 0 disk
├─sda1 8:1 0 512M 0 part /boot
├─sda2 8:2 0 25.5G 0 part
│ ├─rhel-swap 253:0 0 512M 0 lvm [SWAP]
│ └─rhel-root 253:1 0 25G 0 lvm /
└─sda3 8:3 0 5G 0 part
sr0 11:0 1 3.6G 0 rom /mnt/cdrom
配置yum仓库(all)
vim /etc/yum.repos.d/a.repo [a] name=a baseurl=file:///mnt/cdrom enabled=1 gpgcheck=0
[root@localhost ~]# mkdir /mnt/cdrom [root@localhost ~]# mount /dev/sr0 /mnt/cdrom mount: /dev/sr0 is write-protected, mounting read-only [root@localhost ~]# [root@localhost ~]# [root@localhost ~]# yum repolist Loaded plugins: langpacks, product-id, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. a | 4.1 kB 00:00:00 (1/2): a/group_gz | 134 kB 00:00:00 (2/2): a/primary_db | 3.4 MB 00:00:00 repo id repo name status a a 4,371 repolist: 4,371
关闭防火墙及selinux(all)
[root@localhost ~]# systemctl stop firewalld [root@localhost ~]# systemctl disable firewalld rm '/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service' rm '/etc/systemd/system/basic.target.wants/firewalld.service' [root@localhost ~]# setenforce 0
target端配置:
1.安装targetcli
[root@node1 ~]# yum -y install targetcli
2. 运行targetcli
[root@localhost ~]# targetcli
2.1 创建后端存储
/> backstores/block create name=nsd dev=/dev/sda3
2.2 创建target
/> iscsi/ create iqn.2019-06.vip.kklinux:node1
注意:IQN 的格式为:iqn.年份-月份.反向域名:自定义标识
如:iqn.2019-06.vip.kklinux:node1;其中的字母均应为小写,即使输入时包含大写,命令执行后,系统会自动转换成小写。
2.3 创建lun逻辑单元
/iscsi> cd /iscsi/iqn.2019-06.vip.kklinux:node1/tpg1/luns
/iscsi/iqn.20...de1/tpg1/luns> create /backstores/block/nsd
2.4 配置acl访问控制(设置访问服务时客户端声称的名字)
/iscsi> cd /iscsi/iqn.2019-06.vip.kklinux:node1/tpg1/acls
/iscsi/iqn.20...de1/tpg1/acls>create iqn.2019-06.vip.kklinux:client1
//客户端配置的名称应与上面一致
如果需要配置用户和密码
cd /iscsi/iqn.2019-06.vip.kklinux:node1/tpg1/acls/iqn.2019-06.vip.kklinux:client1 /iscsi/iqn.20...kklinux:client1> set auth userid=username /iscsi/iqn.20...kklinux:client1> set auth password=password
2.5 退出
/iscsi/iqn.20...de1/tpg1/acls> exit
3. 重启target服务,并设置开机自启
systemctl restart target
systemctl enable target
initiator端配置:
1. 装包iscsi-initiator-utils
[root@client1 ~]# yum install -y iscsi-initiator-utils
2. 修改配置文件
[root@client1 ~]# vi /etc/iscsi/initiatorname.iscsi InitiatorName=iqn.2019-06.vip.kklinux:client1 //名称应与服务端acl配置的名称一致
如果target端配置了用户和密码还需添加
node.session.auth.authmethod = CHAP node.session.auth.username = username node.session.auth.password = password
3. 重启服务 iscsid
[root@client1 ~]# systemctl restart iscsid //更新IQN标识。注意是:iscsid
4. 发现服务端IQN
[root@client1~]# iscsiadm -m discovery -t st -p 192.168.22.77
192.168.22.77:3260,1 iqn.2019-06.vip.kklinux:node1
5. 识别服务端共享
[root@client1 ~]# systemctl restart iscsi [root@client1 ~]# systemctl enable iscsi [root@client1 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 60G 0 disk ├─sda1 8:1 0 2M 0 part ├─sda2 8:2 0 1G 0 part /boot └─sda3 8:3 0 34G 0 part ├─rhel-root 253:0 0 30G 0 lvm / └─rhel-swap 253:1 0 4G 0 lvm [SWAP] sdb 8:16 0 5G 0 disk sr0 11:0 1 3.5G 0 rom /mnt/cdrom