ISCSI
转载
环境准备
1 1、服务器添加硬盘,并做Raid
2 [root@iscsi-server ~]# lsblk
3 #查看磁盘挂载情况
4 NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
5 sda 8:0 0 8G 0 disk
6 ├─sda1 8:1 0 1G 0 part /boot
7 └─sda2 8:2 0 7G 0 part
8 ├─centos-root 253:0 0 6.2G 0 lvm /
9 └─centos-swap 253:1 0 820M 0 lvm [SWAP]
10 sdb 8:16 0 2G 0 disk
11 sdc 8:32 0 2G 0 disk
12 sdd 8:48 0 2G 0 disk
13 sde 8:64 0 2G 0 disk
14 sdf 8:80 0 2G 0 disk
15 sr0 11:0 1 1024M 0 rom
16 [root@iscsi-server ~]# yum install mdadm -y >> /etc/null
17 [root@iscsi-server ~]# mdadm -C /dev/md0 -l5 -n4 -x1 /dev/sd{b,c,d,e,f}
18 #新建Raid,设备/dev/md0,Raid5,4块数据盘,一块热备盘
19 mdadm: Defaulting to version 1.2 metadata
20 mdadm: array /dev/md0 started.
21 [root@iscsi-server ~]# lsblk
22 #验证
23 NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
24 sda 8:0 0 8G 0 disk
25 ├─sda1 8:1 0 1G 0 part /boot
26 └─sda2 8:2 0 7G 0 part
27 ├─centos-root 253:0 0 6.2G 0 lvm /
28 └─centos-swap 253:1 0 820M 0 lvm [SWAP]
29 sdb 8:16 0 2G 0 disk
30 └─md0 9:0 0 6G 0 raid5
31 sdc 8:32 0 2G 0 disk
32 └─md0 9:0 0 6G 0 raid5
33 sdd 8:48 0 2G 0 disk
34 └─md0 9:0 0 6G 0 raid5
35 sde 8:64 0 2G 0 disk
36 └─md0 9:0 0 6G 0 raid5
37 sdf 8:80 0 2G 0 disk
38 └─md0 9:0 0 6G 0 raid5
39 sr0 11:0 1 1024M 0 rom
40 [root@iscsi-server ~]#
ISCSI服务器
1 [root@iscsi-server ~]# yum install targetcli -y >> /dev/null
2 [root@iscsi-server ~]# targetcli
3 Warning: Could not load preferences file /root/.targetcli/prefs.bin.
4 targetcli shell version 2.1.51
5 Copyright 2011-2013 by Datera, Inc and others.
6 For help on commands, type 'help'.
7
8 /> ls
9 o- / .......................................................................... [...]
10 o- backstores ............................................................... [...]
11 | o- block ................................................... [Storage Objects: 0]
12 | o- fileio .................................................. [Storage Objects: 0]
13 | o- pscsi ................................................... [Storage Objects: 0]
14 | o- ramdisk ................................................. [Storage Objects: 0]
15 o- iscsi ............................................................. [Targets: 0]
16 o- loopback .......................................................... [Targets: 0]
17 /> /backstores/block create iscsi_test /dev/md0
18 Created block storage object iscsi_test using /dev/md0.
19 /> /iscsi create iqn.2020-12.com.test
20 Created target iqn.2020-12.com.test.
21 Created TPG 1.
22 Global pref auto_add_default_portal=true
23 Created default portal listening on all IPs (0.0.0.0), port 3260.
24 /> cd /iscsi/iqn.2020-12.com.test/tpg1/
25 /iscsi/iqn.20...com.test/tpg1> ls
26 o- tpg1 ...................................................... [no-gen-acls, no-auth]
27 o- acls ................................................................. [ACLs: 0]
28 o- luns ................................................................. [LUNs: 0]
29 o- portals ........................................................... [Portals: 1]
30 o- 0.0.0.0:3260 ............................................................ [OK]
31 /iscsi/iqn.20...com.test/tpg1> acls/ create iqn.2020-12.com.test:192.168.1.92
32 Created Node ACL for iqn.2020-12.com.test:192.168.1.92
33 /iscsi/iqn.20...com.test/tpg1> luns/ create /backstores/block/iscsi_test
34 Created LUN 0.
35 Created LUN 0->0 mapping in node ACL iqn.2020-12.com.test:192.168.1.92
36 /iscsi/iqn.20...com.test/tpg1> portals/ delete ip_address=0.0.0.0 ip_port=3260
37 Deleted network portal 0.0.0.0:3260
38 /iscsi/iqn.20...com.test/tpg1> portals/ create ip_address=192.168.1.91 ip_port=3260
39 Using default IP port 3260
40 Created network portal 192.168.1.91:3260.
41 /iscsi/iqn.20...com.test/tpg1> cd /
42 /> ls
43 o- / .............................................................................. [...]
44 o- backstores ................................................................... [...]
45 | o- block ....................................................... [Storage Objects: 1]
46 | | o- iscsi_test ............................ [/dev/md0 (6.0GiB) write-thru activated]
47 | | o- alua ........................................................ [ALUA Groups: 1]
48 | | o- default_tg_pt_gp ............................ [ALUA state: Active/optimized]
49 | o- fileio ...................................................... [Storage Objects: 0]
50 | o- pscsi ....................................................... [Storage Objects: 0]
51 | o- ramdisk ..................................................... [Storage Objects: 0]
52 o- iscsi ................................................................. [Targets: 1]
53 | o- iqn.2020-12.com.test ................................................... [TPGs: 1]
54 | o- tpg1 .................................................... [no-gen-acls, no-auth]
55 | o- acls ............................................................... [ACLs: 1]
56 | | o- iqn.2020-12.com.test:192.168.1.92 ......................... [Mapped LUNs: 1]
57 | | o- mapped_lun0 ................................. [lun0 block/iscsi_test (rw)]
58 | o- luns ............................................................... [LUNs: 1]
59 | | o- lun0 ...................... [block/iscsi_test (/dev/md0) (default_tg_pt_gp)]
60 | o- portals ......................................................... [Portals: 1]
61 | o- 192.168.1.91:3260 ..................................................... [OK]
62 o- loopback .............................................................. [Targets: 0]
63 /> exit
64 Global pref auto_save_on_exit=true
65 Last 10 configs saved in /etc/target/backup/.
66 Configuration saved to /etc/target/saveconfig.json
67 [root@iscsi-server ~]# firewall-cmd --add-port=3260/tcp
68 success
69 [root@iscsi-server ~]# firewall-cmd --add-port=3260/tcp --permanent
70 success
71 [root@iscsi-server ~]# systemctl restart target
72 [root@iscsi-server ~]# systemctl enable target
ISCSI客户端
[root@iscsi-client ~]# yum install iscsi* -y >> /dev/null
[root@iscsi-client ~]# vim /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2020-12.com.test:192.168.1.92
[root@iscsi-client ~]# systemctl start iscsid
[root@iscsi-client ~]# iscsiadm -m discovery -t st -p 192.168.1.91
192.168.1.91:3260,1 iqn.2020-12.com.test
[root@iscsi-client ~]# iscsiadm -m node -T iqn.2020-12.com.test -p 192.168.1.91 -l
Logging in to [iface: default, target: iqn.2020-12.com.test, portal: 192.168.1.91,32multiple)
Login to [iface: default, target: iqn.2020-12.com.test, portal: 192.168.1.91,3260] ssful.
[root@iscsi-client ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 8G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 7G 0 part
├─centos-root 253:0 0 6.2G 0 lvm /
└─centos-swap 253:1 0 820M 0 lvm [SWAP]
sdb 8:16 0 6G 0 disk
sr0 11:0 1 1024M 0 rom
[root@iscsi-client ~]#
退出登录:iscsiadm -m node -T iscsi名称 -p 服务器ip -u(如果有多组,退出指定组)
iscsiadm -m node --logoutall=all / iscsiadm -m node -u ALL(两个均为注销所有链接)
如本测验:iscsiadm -m node -T iqn.2020-12.com.disk -p 192.168.1.103 -u
注销只是相当于退出登录,重启后共享存储又存在了,所以需要删除存储硬盘:
删除所有:iscsiadm -m node -o delete
删除指定组:iscsiadm -m node -T iscsi名称 -p 服务器ip -o delete
本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。