概念
iscsi 就是现在自己的磁盘上分出一片区域,在此通过下载 targetcli 实现磁盘存储共享技术
做法
服务端
1:分盘
[root@server ~]# fdisk /dev/vdb
2:下载 targetcli
[
root@server ~]# yum install targetcli -y
[root@server ~]# systemctl start target
[root@server ~]# systemctl status target
target.service - Restore LIO kernel target configuration
Loaded: loaded (/usr/lib/systemd/system/target.service; disabled)
Active: active (exited) since Tue 2017-08-22 21:27:37 EDT; 1s ago
Process: 4450 ExecStart=/usr/bin/targetctl restore (code=exited, status=0/SUCCESS)
Main PID: 4450 (code=exited, status=0/SUCCESS)
Aug 22 21:27:37 server.example.com target[4450]: No saved config file at /etc/targ...g
Aug 22 21:27:37 server.example.com systemd[1]: Started Restore LIO kernel target c....
Hint: Some lines were ellipsized, use -l to show in full.
3:进入 targetcli
[root@server ~]# targetcli
Warning: Could not load preferences file /root/.targetcli/prefs.bin.
targetcli shell version 2.1.fb34
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.
/> ls
o- / ........................................................................... [...]
o- backstores ................................................................ [...]
| o- block .................................................... [Storage Objects: 0]
| o- fileio ................................................... [Storage Objects: 0]
| o- pscsi .................................................... [Storage Objects: 0]
| o- ramdisk .................................................. [Storage Objects: 0]
o- iscsi .............................................................. [Targets: 0]
o- loopback ........................................................... [Targets: 0]
4:创建要共享的磁盘
/> /backstores/block create westos:storagel /dev/vdb1
5:创建共享主机
/> /iscsi create iqn.2017-09.com.example:storagel
Created target iqn.2017-09.com.example:storagel.
Created TPG 1.
/> /iscsi/iqn.2017-09.com.example:storagel/tpg1/portals create 172.25.254.111
Using default IP port 3260
Created network portal 172.25.254.111:3260.
6:创建密码
/> /iscsi/iqn.2017-09.com.example:storagel/tpg1/acls create iqn.2017-09.com.example:storagelkey
Created Node ACL for iqn.2017-09.com.example:storagelkey
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
7:清除
/> clearconfig confirm=True
All configuration cleared
客户端
1:下载iscsi-initiator-utils.x86_64
[root@custom ~]# yum install iscsi-initiator-utils.x86_64 -y
Loaded plugins: langpacks
Package iscsi-initiator-utils-6.2.0.873-21.el7.x86_64 already installed and latest version
Nothing to do
2:编辑文件 /etc/iscsi/initiatorname.iscsi
[root@custom ~]# vim /etc/iscsi/initiatorname.iscsi
############################################
InitiatorName=iqn.2017-08.com.example:storagelkey
#############################################
[root@custom mnt]# systemctl restart iscsid.service
[root@custom mnt]# systemctl restart iscsi
3:进入共享区并分盘配置文件系统
[root@custom iscsi]# iscsiadm -m node -T iqn.2017-09.com.example:storagel -p 172.25.254.111 -l
[root@custom ~]# fdisk /dev/sda
[root@custom ~]# partprobe
[root@custom ~]# mkfs.xfs /dev/sda1
[root@custom ~]# mount /dev/sda1 /mnt
4:下载 tree
[root@custom ~]# yum install tree.x86_64 -y
5:学会使用 tree
[root@custom ~]# tree -C /var/lib/iscsi/
/var/lib/iscsi/
├── ifaces
├── isns
├── nodes
│ └── iqn.2017-09.com.example:storagel
│ └── 172.25.254.111,3260,1
│ └── default
├── send_targets
│ └── 172.25.254.111,3260
│ ├── iqn.2017-09.com.example:storagel,172.25.254.111,3260,1,default -> /var/lib/iscsi/nodes/iqn.2017-09.com.example:storagel/172.25.254.111,3260,1
│ └── st_config
├── slp
└── static
10 directories, 2 files
6:清除
[root@custom ~]# iscsiadm -m node -T iqn.2017-09.com.example:storagel -u
Logging out of session [sid: 9, target: iqn.2017-09.com.example:storagel, portal: 172.25.254.111,3260]
Logout of [sid: 9, target: iqn.2017-09.com.example:storagel, portal: 172.25.254.111,3260] successful.
lvm 可扩充磁盘的共享
服务端
1:创建 lvm
[root@server ~]# fdisk /dev/vdb
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/vdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x5e76d22e
Device Boot Start End Blocks Id System
/dev/vdb1 2048 10487807 5242880 83 Linux
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p
Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x5e76d22e
Device Boot Start End Blocks Id System
/dev/vdb1 2048 10487807 5242880 8e Linux LVM
Command (m for help): wq
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@server ~]# partprobe
[root@server ~]# pvcreate /dev/vdb1
WARNING: dos signature detected on /dev/vdb1 at offset 510. Wipe it? [y/n] y
Wiping dos signature on /dev/vdb1.
Physical volume "/dev/vdb1" successfully created
[root@server ~]# vgcreate iscsivg /dev/vdb1
Volume group "iscsivg" successfully created
[root@server ~]# vgdisplay
--- Volume group ---
VG Name iscsivg
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size 5.00 GiB
PE Size 4.00 MiB
Total PE 1279
Alloc PE / Size 0 / 0
Free PE / Size 1279 / 5.00 GiB
VG UUID L7MBEZ-gOBH-KlDe-SQjn-b2uu-CAuA-PeLv1s
[root@server ~]# lvcreate -l 1279 -n iscsilv0 iscsivg
Logical volume "iscsilv0" created
[root@server ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
iscsilv0 iscsivg -wi-a----- 5.00g
[root@server ~]# ll /dev/iscsivg/iscsilv0
lrwxrwxrwx. 1 root root 7 Aug 22 23:20 /dev/iscsivg/iscsilv0 -> ../dm-0
2:进入 targetcli
3:创建共享 lvm 和密码登录
[root@server ~]# targetcli
targetcli shell version 2.1.fb34
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.
/> ls
o- / ....................................................................... [...]
o- backstores ............................................................ [...]
| o- block ................................................ [Storage Objects: 0]
| o- fileio ............................................... [Storage Objects: 0]
| o- pscsi ................................................ [Storage Objects: 0]
| o- ramdisk .............................................. [Storage Objects: 0]
o- iscsi .......................................................... [Targets: 0]
o- loopback ....................................................... [Targets: 0]
/> /backstores/block create westos:storagel /dev/iscsivg/iscsilv0
Created block storage object westos:storagel using /dev/iscsivg/iscsilv0.
/> /iscsi create iqn.2017-08.com.example:storagel
Created target iqn.2017-08.com.example:storagel.
Created TPG 1.
/>
/> /iscsi/iqn.2017-08.com.example:storagel/tpg1/luns create /backstores/block/westos:storagel
Created LUN 0.
/> /iscsi/iqn.2017-08.com.example:storagel/tpg1/acls create iqn.2017-08.com.example:storagelkey
Created Node ACL for iqn.2017-08.com.example:storagelkey
Created mapped LUN 0.
/> iscsi/iqn.2017-08.com.example:storagel/tpg1/portals create 172.25.254.111
Using default IP port 3260
Created network portal 172.25.254.111:3260.
/> ls
o- / ....................................................................... [...]
o- backstores ............................................................ [...]
| o- block ................................................ [Storage Objects: 1]
| | o- westos:storagel ... [/dev/iscsivg/iscsilv0 (5.0GiB) write-thru activated]
| o- fileio ............................................... [Storage Objects: 0]
| o- pscsi ................................................ [Storage Objects: 0]
| o- ramdisk .............................................. [Storage Objects: 0]
o- iscsi .......................................................... [Targets: 1]
| o- iqn.2017-08.com.example:storagel ................................ [TPGs: 1]
| o- tpg1 ............................................. [no-gen-acls, no-auth]
| o- acls ........................................................ [ACLs: 1]
| | o- iqn.2017-08.com.example:storagelkey ................ [Mapped LUNs: 1]
| | o- mapped_lun0 ..................... [lun0 block/westos:storagel (rw)]
| o- luns ........................................................ [LUNs: 1]
| | o- lun0 ................ [block/westos:storagel (/dev/iscsivg/iscsilv0)]
| o- portals .................................................. [Portals: 1]
| o- 172.25.254.111:3260 ............................................ [OK]
o- loopback ....................................................... [Targets: 0]
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
[root@server ~]# fdisk /dev/vdb
4:扩充磁盘
[root@server ~]# fdisk /dev/vdb
[root@server ~]# partprobe
[root@server ~]# pvc
pvchange pvck pvcreate
[root@server ~]# pvcreate /dev/vdb1
Can't initialize physical volume "/dev/vdb1" of volume group "iscsivg" without -ff
[root@server ~]# pvcreate /dev/vdb2
Physical volume "/dev/vdb2" successfully created
[root@server ~]# vgextend iscsivg /dev/vdb2
Volume group "iscsivg" successfully extended
[root@server ~]# vgdisplay
--- Volume group ---
VG Name iscsivg
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 2
Act PV 2
VG Size 5.97 GiB
PE Size 4.00 MiB
Total PE 1528
Alloc PE / Size 1279 / 5.00 GiB
Free PE / Size 249 / 996.00 MiB
VG UUID L7MBEZ-gOBH-KlDe-SQjn-b2uu-CAuA-PeLv1s
[root@server ~]# lvextend -L 5500M /dev/iscsivg/iscsilv0
Extending logical volume iscsilv0 to 5.37 GiB
Logical volume iscsilv0 successfully resized
客户端
1:编写文件,配置密码
2:刷新
[root@custom ~]# vim /etc/iscsi/initiatorname.iscsi
[root@custom ~]# iscsiadm -m discovery -t st -p 172.25.254.111
172.25.254.111:3260,1 iqn.2017-08.com.example:storagel
[root@custom mnt]# systemctl restart iscsid.service
[root@custom mnt]# systemctl restart iscsi
[root@custom mnt]# iscsiadm -m node -T iqn.2017-08.com.example:storagel -p 172.25.254.111 -l
3:取消挂载,重新挂载,查看磁盘是否扩充
[root@custom mnt]# fdisk -l
[root@custom mnt]# iscsiadm -m node -T iqn.2017-08.com.example:storagel -u
Logging out of session [sid: 15, target: iqn.2017-08.com.example:storagel, portal: 172.25.254.111,3260]
Logout of [sid: 15, target: iqn.2017-08.com.example:storagel, portal: 172.25.254.111,3260] successful.
[root@custom mnt]# iscsiadm -m node -T iqn.2017-08.com.example:storagel -p 172.25.254.111 -l
Logging in to [iface: default, target: iqn.2017-08.com.example:storagel, portal: 172.25.254.111,3260] (multiple)
Login to [iface: default, target: iqn.2017-08.com.example:storagel, portal: 172.25.254.111,3260] successful.
[root@custom mnt]# fdisk -l