iSCSI远程块存储
#########################
#######iscsi#############
#########################
1.iscsi是直接对设备进行共享的服务
iSCSI(Internet SCSI)支持从客户端(发起端)通过IP向远程服务器上的
SCSI存储设备(目标)发送SCSI命令。iSCSI限定名称用于确定发起端和目
标,并采用iqn.yyyy-mm.{reverse domain}:label的格式。默认情况下,网络
通信是至iSCSI目标上的端口3260/tcp的明文。
iSCSI发起端:需要访问原始SAN存储的客户端。
iSCSI目标:从iSCSI服务器提供的远程硬盘磁盘,或“目标门户”
iSCSI目标门户:通过网络向发起端提供目标的服务器。
IQN:“iSCSI限定名称”。每个发起端和目标需要唯一名称进行标识,
最好的做法是使用一个在Internet上可能独一无二的名称。
2.启动iscsi共享设备
1>在server上
建立一个lvm设备
[[email protected] ~]# fdisk /dev/vdb
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-20971519, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +1000M
Partition 1 of type Linux and of size 1000 MiB is set
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): p
Changed type of partition 'Linux' to 'unknown'
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Empty' 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: 0xfee851aa
Device Boot Start End Blocks Id System
/dev/vdb1 2048 2050047 1024000 8e Linux LVM
[[email protected] ~]# partprobe
[[email protected] ~]# pvcreate /dev/vdb1
Physical volume "/dev/vdb1" successfully created
[[email protected] ~]# vgcreate vg0 /dev/vdb1
Volume group "vg0" successfully created
[[email protected] ~]# lvcreate -l 249 -n iscsi_storage vg0
Logical volume "iscsi_storage" created
[[email protected] ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
iscsi_storage vg0 -wi-a----- 996.00m
安装 yum install targetcli -y
[[email protected] ~]# systemctl enable target
[[email protected] ~]# systemctl stop firewalld
[[email protected] ~]# targetcli
/> ls
/> /backstores/block create server1storage /dev/vg0/iscsi_storage ##将/dev/vg0重新命名
/> /iscsi create iqn.2017-06.com.example:strage1
/> ls
/> /iscsi/iqn.2017-06.com.example:strage1/tpg1/luns create /backstores/block/server1storage ##钥匙和设备匹配
/> /iscsi/iqn.2017-06.com.example:strage1/tpg1/acls create iqn.2017-06.com.example:server1storagekey ##创建钥匙
/> /iscsi/iqn.2017-06.com.example:strage1/tpg1/portals create 172.25.2.11 ##开启设备端口
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json ##退出后所做的设定保存在此
2>在deskotp上
[[email protected] ~]# vim /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2017-06.com.example:server1storagekey ##添加钥匙
[[email protected] ~]# systemctl restart iscsi
[[email protected] ~]# fdisk -l
[[email protected] ~]# iscsiadm -m discovery -t st -p 172.25.2.11 ##查找
172.25.2.11:3260,1 iqn.2017-06.com.example:strage1
[[email protected] ~]# iscsiadm -m node -T iqn.2017-06.com.example:strage1 -p 172.25.2.11 -l ##登陆
Logging in to [iface: default, target: iqn.2017-06.com.example:strage1, portal: 172.25.2.11,3260] (multiple)
Login to [iface: default, target: iqn.2017-06.com.example:strage1, portal: 172.25.2.11,3260] successful.
[[email protected] ~]# fdisk -l
Disk /dev/sda: 1044 MB, 1044381696 bytes, 2039808 sectors
[[email protected] ~]# fdisk /dev/sda
[[email protected] ~]# partprobe
[[email protected] ~]# mkfs.xfs /dev/sda1
[[email protected] ~]# mount /dev/sda1 /mnt ##实现直接访问服务器存储器
[[email protected] ~]# df
[[email protected] ~]# yum install tree.x86_64 -y
[[email protected] ~]# tree -C /var/lib/iscsi/ ##查看存储信息
3.挂载
[[email protected] ~]# blkid
/dev/sda1: UUID="a90b98d2-4ee9-4b49-ab82-b4bf4b3cd673" TYPE="xfs"
[[email protected] ~]# vim /etc/fstab
UUID="a90b98d2-4ee9-4b49-ab82-b4bf4b3cd673" /mnt xfs defaults 0 0
[[email protected] ~]# mount -a
[[email protected] ~]# df
[[email protected] ~]# reboot^C
4.删除
[[email protected] ~]# umount /mnt
[[email protected] ~]# vim /etc/fstab
[[email protected] ~]# iscsiadm -m node -T iqn.2017-06.com.example:strage1 -p 172.25.2.11 -u ##登出
[[email protected] ~]# iscsiadm -m node -T iqn.2017-06.com.example:strage1 -p 172.25.2.11 -o delete ##删除
[[email protected] ~]# targetcli
/> clearconfig confirm=True
All configuration cleared
/> ls