iscsi服务端
服务器信息:
master-all Centos7.5 192.168.230.202 /dev/sdb为20G磁盘
node-1 Centos7.5 192.168.230.203
环境初始化
安装scsi工具
[root@master-all ~]# yum -y install scsi-target-utils
磁盘分区
[root@master-all ~]# fdisk /dev/sdb
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.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x8339e5e7.
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): e
Partition number (1-4, default 1):
First sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039):
Using default value 41943039
Partition 1 of type Extended and of size 20 GiB is set
Command (m for help): n
Partition type:
p primary (0 primary, 1 extended, 3 free)
l logical (numbered from 5)
Select (default p): l
Adding logical partition 5
First sector (4096-41943039, default 4096):
Using default value 4096
Last sector, +sectors or +size{K,M,G} (4096-41943039, default 41943039): +2G
Partition 5 of type Linux and of size 2 GiB is set
Command (m for help): n
Partition type:
p primary (0 primary, 1 extended, 3 free)
l logical (numbered from 5)
Select (default p): l
Adding logical partition 6
First sector (4200448-41943039, default 4200448):
Using default value 4200448
Last sector, +sectors or +size{K,M,G} (4200448-41943039, default 41943039): +2G
Partition 6 of type Linux and of size 2 GiB is set
Command (m for help): n
Partition type:
p primary (0 primary, 1 extended, 3 free)
l logical (numbered from 5)
Select (default p): l
Adding logical partition 7
First sector (8396800-41943039, default 8396800):
Using default value 8396800
Last sector, +sectors or +size{K,M,G} (8396800-41943039, default 41943039): +2G
Partition 7 of type Linux and of size 2 GiB is set
Command (m for help): n
Partition type:
p primary (0 primary, 1 extended, 3 free)
l logical (numbered from 5)
Select (default p): l
Adding logical partition 8
First sector (12593152-41943039, default 12593152):
Using default value 12593152
Last sector, +sectors or +size{K,M,G} (12593152-41943039, default 41943039): +2G
Partition 8 of type Linux and of size 2 GiB is set
Command (m for help): n
Partition type:
p primary (0 primary, 1 extended, 3 free)
l logical (numbered from 5)
Select (default p): l
Adding logical partition 9
First sector (16789504-41943039, default 16789504):
Using default value 16789504
Last sector, +sectors or +size{K,M,G} (16789504-41943039, default 41943039): +2G
Partition 9 of type Linux and of size 2 GiB is set
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0x8339e5e7
Device Boot Start End Blocks Id System
/dev/sdb1 2048 41943039 20970496 5 Extended
/dev/sdb5 4096 4198399 2097152 83 Linux
/dev/sdb6 4200448 8394751 2097152 83 Linux
/dev/sdb7 8396800 12591103 2097152 83 Linux
/dev/sdb8 12593152 16787455 2097152 83 Linux
/dev/sdb9 16789504 20983807 2097152 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
数据存储类型
可以选择lvm或者raid进行挂载
创建物理卷、卷组、逻辑卷
[root@master-all ~]# pvcreate /dev/sdb5
Physical volume "/dev/sdb5" successfully created.
[root@master-all ~]# vgcreate vgs /dev/sdb5
Volume group "vgs" successfully created
[root@master-all ~]# lvcreate -L 1G -n lvs vgs
Logical volume "lvs" created.
创建软Raid5
-C 表示创建新的RAID设备
11 / 18
-v 输出详细信息
-a=yes 表示若对应的设备文件不存在则自动创建
-n3 指定磁盘数量
-l5 RAID级别
-Q 查询设备信息
-D 显示设备详细信息
UUID 表示设备的唯一ID号
[root@master-all ~]# yum -y install mdadm
[root@master-all ~]# mdadm -Cv /dev/md5 -a yes -n4 -l5 /dev/sdb[6-9]
mdadm: layout defaults to left-symmetric
mdadm: layout defaults to left-symmetric
mdadm: chunk size defaults to 512K
mdadm: size set to 2094080K
mdadm: Fail create md5 when using /sys/module/md_mod/parameters/new_array
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md5 started.
启动服务
[root@master-all ~]# systemctl start tgtd
[root@master-all ~]# netstat -lnpt|grep tgtd
tcp 0 0 0.0.0.0:3260 0.0.0.0:* LISTEN 17330/tgtd
tcp6 0 0 :::3260 :::* LISTEN 17330/tgtd
放通防火墙
[root@master-all ~]# firewall-cmd --zone=public --add-port=3260/tcp --permanent
[root@master-all ~]# firewall-cmd --reload
创建iSCSI对象
使用tgtadm工具创建target
-L、--lld 指定驱动类型,如“-L iscsi”
-o、--op 指定操作类型,如“-o new” 表示创建,如“-o delete” 表示删除
-m、--mode 指定管理目标,如“-m target” 表示ISCSI对象
-t、--tid 指定对象ID号,如“-t 1” 表示第一对象
-T、--targetname 指定iSCSI对象的名称
[root@master-all ~]# tgtadm -L iscsi -o new -m target -t 1 -T 2020-04.cc.ym68.store:lvm
[root@master-all ~]# tgtadm -L iscsi -o new -m target -t 2 -T 2020-04.cc.ym68.store:raid
为客户端分配存储空间
仍然使用tgtdam管理工具
-l、--lun 指定LUN的ID号,如“-l 1”
-b、--backing-store 指定块设备位置,如“-b /dev/md5”
-I、--initiator-addres 指定客户机地址,如“-I 192.168.200.130”
-m logicalunit -m lu 表示管理目标为LUN
-o bind 绑定客户机地址
[root@master-all ~]# tgtadm -L iscsi -o new -m lu -t 1 -l 1 -b /dev/vgs/lvs
[root@master-all ~]# tgtadm -L iscsi -o bind -m target -t 1 -I 192.168.230.203
[root@master-all ~]# tgtadm -L iscsi -o new -m lu -t 2 -l 1 -b /dev/md5
[root@master-all ~]# tgtadm -L iscsi -o bind -m target -t 2 -I 192.168.230.203
修改配置文件并重启
target名与客户端处显示一致
backing-store: 设备地址
initator-address: 授权地址
[root@master-all ~]# vim /etc/tgt/targets.conf
backing-store /dev/vgs/lvs
initator-address 192.168.230.203
backing-store /dev/md5
[root@master-all ~]# systemctl restart tgtd
[root@master-all ~]# systemctl enable tgtd
iSCSI客户端
[root@Node-1 ~]# yum -y install iscsi-initiator-utils lsscsi
[root@Node-1 ~]# systemctl start iscsi
[root@Node-1 ~]# systemctl enable iscsi
查找并连接iSCSI设备
[root@Node-1 ~]# iscsiadm -m discovery -t sendtargets -p 192.168.230.202
192.168.230.202:3260,1 2020-04.cc.ym68.store:lvm
192.168.230.202:3260,1 2020-04.cc.ym68.store:raid
[root@Node-1 ~]# iscsiadm -m node -T 2020-04.cc.ym68.store:lvm --login
Logging in to [iface: default, target: 2020-04.cc.ym68.store:lvm, portal: 192.168.230.202,3260] (multiple)
Login to [iface: default, target: 2020-04.cc.ym68.store:lvm, portal: 192.168.230.202,3260] successful.
[root@Node-1 ~]# iscsiadm -m node -T 2020-04.cc.ym68.store:raid --login
Logging in to [iface: default, target: 2020-04.cc.ym68.store:raid, portal: 192.168.230.202,3260] (multiple)
Login to [iface: default, target: 2020-04.cc.ym68.store:raid, portal: 192.168.230.202,3260] successful.
查看磁盘信息
/dev/sdb(lvm)及/dev/sdc(raid)为iSCSI设备磁盘
[root@Node-1 ~]# fdisk -l
Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 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: 0x000b9014
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 104857599 51379200 8e Linux LVM
Disk /dev/mapper/centos-root: 50.5 GB, 50457477120 bytes, 98549760 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 /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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 /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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 /dev/sdc: 4288 MB, 4288675840 bytes, 8376320 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
磁盘分区并格式化挂载
[root@Node-1 ~]# fdisk -l
Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 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: 0x000b9014
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 104857599 51379200 8e Linux LVM
Disk /dev/mapper/centos-root: 50.5 GB, 50457477120 bytes, 98549760 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 /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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 /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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 /dev/sdc: 6433 MB, 6433013760 bytes, 12564480 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
自动挂载
[root@Node-1 ~]# blkid /dev/sdb1
/dev/sdb1: UUID="109d8e10-b13a-4e9d-a43c-f812c9df462f" TYPE="ext4"
[root@Node-1 ~]# vim /etc/fstab
UUID=109d8e10-b13a-4e9d-a43c-f812c9df462f /datatmp1 ext4 defaults 0 0
文章来源于互联网:ISCSI环境部署配置