VMvare
在
CentOS7.4
安装
iscsi
共享盘
1.
在节点
1
上添加一个
20g
的存储并
reboot
1.1
查看新添加的磁盘
[root@xmc1 ~]# fdisk -l
Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 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: 0x000b28d9
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 411647 204800 83 Linux
/dev/sda2 411648 62914559 31251456 8e Linux LVM
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
从上面看出是
sdb
1.2
将
sdb
分为
8G+12G
两个盘(
ocr+data
)
[root@xmc1 iscsi]# 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 0xfa692b5c.
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
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): +8G
Partition 1 of type Linux and of size 8 GiB is set
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (2-4, default 2):
First sector (16779264-41943039, default 16779264):
Using default value 16779264
Last sector, +sectors or +size{K,M,G} (16779264-41943039, default 41943039):
Using default value 41943039
Partition 2 of type Linux and of size 12 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
2.
检查安装
iscsi
相关软件
2.1
安装
iscsi
客户端软件
#yum -y install iscsi-initiator-utils
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Package iscsi-initiator-utils-6.2.0.874-4.el7.x86_64 already installed and latest version
Nothing to do
[root@xmc1 ~]# systemctl restart iscsi
[root@xmc1 ~]# systemctl enable iscsi
2.2
修改主机识别号
# cd /etc/iscsi/
[root@xmc1 iscsi]# cp initiatorname.iscsi initiatorname.iscsi.bak
root@xmc1 iscsi]# vi initiatorname.iscsi
[root@xmc1 iscsi]# more initiatorname.iscsi
InitiatorName=iqn.1994-05.com.redhat:xmc1
[root@xmc2 iscsi]# cp initiatorname.iscsi initiatorname.iscsi.bak
[root@xmc2 iscsi]# vi initiatorname.iscsi
[root@xmc2 iscsi]# more initiatorname.iscsi
InitiatorName=iqn.1994-05.com.redhat:xmc2
2.3
安装
iscsi
软件并启动
# yum install targetcli*
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Package targetcli-2.1.fb46-1.el7.noarch already installed and latest version
Nothing to do
[root@xmc1 ~]# systemctl status target
●
target.service - Restore LIO kernel target configuration
Loaded: loaded (/usr/lib/systemd/system/target.service; disabled; vendor preset: disabled)
Active: inactive (dead)
[root@xmc1 ~]# systemctl start target
[root@xmc1 ~]# systemctl enable target
[root@xmc1 ~]# 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 Thu 2020-10-08 22:39:38 CST; 3s ago
Process: 2885 ExecStart=/usr/bin/targetctl restore (code=exited, status=0/SUCCESS)
Main PID: 2885 (code=exited, status=0/SUCCESS)
Oct 08 22:39:38 xmc1 systemd[1]: Starting Restore LIO kernel target configuration...
Oct 08 22:39:38 xmc1 systemd[1]: Started Restore LIO kernel target configuration.
[root@xmc1 ~]# systemctl enable target
Created symlink from /etc/systemd/system/multi-user.target.wants/target.service to /usr/lib/systemd/system/target.service.
2.4
建立两个块存储
ocr_server,data_server,
使用新添加的硬盘
/dev/sdb1
和
/dev/sdb2
[root@xmc1 /]# targetcli
targetcli shell version 2.1.fb46
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.
/> /backstores/block
/backstores/block> create ocr_server /dev/sdb1
Created block storage object ocr_server using /dev/sdb1.
/backstores/block> create data_server /dev/sdb2
Created block storage object data_server using /dev/sdb2.
2.5
建立
target
的
ID
注意
iqn
的名称一定要与
initiatorname.iscsi
里的一样如下
/backstores/block> cd /iscsi
/iscsi> create iqn.1994-05.com.redhat:xmc1
Created target iqn.1994-05.com.redhat:xmc1.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
2.6
配置连接到此
iqn
上的设备
/iscsi> ls
o- iscsi ................................................................................ [Targets: 1]
o- iqn.1994-05.com.redhat:xmc1 ........................................................... [TPGs: 1]
o- tpg1 ................................................................... [no-gen-acls, no-auth]
o- acls .............................................................................. [ACLs: 0]
o- luns .............................................................................. [LUNs: 0]
o- portals ........................................................................ [Portals: 1]
o- 0.0.0.0:3260 ......................................................................... [OK]
/iscsi> cd iqn.1994-05.com.redhat:xmc1/tpg1/acls
/iscsi/iqn.19...mc1/tpg1/acls> create iqn.1994-05.com.redhat:xmc2
Created Node ACL for iqn.1994-05.com.redhat:xmc2
/iscsi/iqn.19...mc1/tpg1/acls> create iqn.1994-05.com.redhat:xmc1
Created Node ACL for iqn.1994-05.com.redhat:xmc1
2.7
设置具体的磁盘和
LUN
联系在一起
/iscsi/iqn.19...hat:xmc1/tpg1> cd luns
/iscsi/iqn.19...mc1/tpg1/luns> pwd
/iscsi/iqn.1994-05.com.redhat:xmc1/tpg1/luns
/iscsi/iqn.19...mc1/tpg1/luns> create /backstores/block/ocr_server
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.1994-05.com.redhat:xmc1
Created LUN 0->0 mapping in node ACL iqn.1994-05.com.redhat:xmc2
/iscsi/iqn.19...mc1/tpg1/luns> create /backstores/block/data_server
Created LUN 1.
Created LUN 1->1 mapping in node ACL iqn.1994-05.com.redhat:xmc1
Created LUN 1->1 mapping in node ACL iqn.1994-05.com.redhat:xmc2
2.8
配置
target
监听
ip
和端口并保存所有配置
/iscsi/iqn.19...mc1/tpg1/luns> cd /iscsi/iqn.1994-05.com.redhat:xmc1/tpg1/portals/
/iscsi/iqn.19.../tpg1/portals> ls
o- portals .............................................................................. [Portals: 1]
o- 0.0.0.0:3260 ............................................................................... [OK]
/iscsi/iqn.19.../tpg1/portals> delete 0.0.0.0 3260
Deleted network portal 0.0.0.0:3260
/iscsi/iqn.19.../tpg1/portals> create 192.168.5.10
Using default IP port 3260
Created network portal 192.168.5.10:3260.
/iscsi/iqn.19.../tpg1/portals> create 192.168.5.20
Using default IP port 3260
Created network portal 192.168.5.20:3260.
/iscsi/iqn.19.../tpg1/portals> ls
o- portals .............................................................................. [Portals: 2]
o- 192.168.5.10:3260 .......................................................................... [OK]
o- 192.168.5.20:3260 .......................................................................... [OK]
保存
/iscsi/iqn.19.../tpg1/portals> cd /
/> saveconfig
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
[root@
xmc1
/]# iscsiadm -m discovery -t st -p 192.168.5.10
192.168.5.20:3260,1 iqn.1994-05.com.redhat:xmc1
192.168.5.10:3260,1 iqn.1994-05.com.redhat:xmc1
[root@
xmc2 i
scsi]# iscsiadm -m discovery -t st -p 192.168.5.10
192.168.5.20:3260,1 iqn.1994-05.com.redhat:xmc1
192.168.5.10:3260,1 iqn.1994-05.com.redhat:xmc1
3.
客户端登录服务验证
[root@xmc1 /]# iscsiadm -m node -T iqn.1994-05.com.redhat:xmc1 -p 192.168.5.10:3260 -l
Logging in to [iface: default, target: iqn.1994-05.com.redhat:xmc1, portal: 192.168.5.10,3260] (multiple)
Login to [iface: default, target: iqn.1994-05.com.redhat:xmc1, portal: 192.168.5.10,3260] successful.
[root@xmc2 iscsi]# iscsiadm -m node -T iqn.1994-05.com.redhat:xmc1 -p 192.168.5.10:3260 -l
Logging in to [iface: default, target: iqn.1994-05.com.redhat:xmc1, portal: 192.168.5.10,3260] (multiple)
Login to [iface: default, target: iqn.1994-05.com.redhat:xmc1, portal: 192.168.5.10,3260] successful.
注意要查看
iscsi
和
target
的状态是否正常:
systemctl status iscsi/target
[root@xmc1 ~]# fdisk -l
Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 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: 0x000b28d9
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 411647 204800 83 Linux
/dev/sda2 411648 62914559 31251456 8e Linux LVM
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: 0xfa692b5c
Device Boot Start End Blocks Id System
/dev/sdb1 2048 16779263 8388608 83 Linux
/dev/sdb2 16779264 41943039 12581888 83 Linux
Disk /dev/mapper/centos-root: 29.9 GB, 29850861568 bytes, 58302464 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/sdc: 8589 MB, 8589934592 bytes, 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 4194304 bytes
Disk /dev/sdd: 12.9 GB, 12883853312 bytes, 25163776 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 4194304 bytes
如上
/dev/sdc
即为共享的
/dev/sdb1
,在节点
2
如下
[root@xmc2 ~]# fdisk -l
Disk /dev/sdb: 8589 MB, 8589934592 bytes, 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 4194304 bytes
Disk /dev/sdc: 12.9 GB, 12883853312 bytes, 25163776 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 4194304 bytes
4.
设置开机自启动
#vi iscsi.sql
添加如下命令
#!/bin/bash
iscsiadm -m node -T iqn.1994-05.com.redhat:xmc1 -p 192.168.5.10:3260 -l
#chmod +x iscsi.sql
#cd /etc/rc.d
# chmod +x rc.local
#vi rc.local
添加脚本
/root/iscsi.sql
至此,安装rac的共享盘问题解决。