使用iscsi服务部署网络存储

iSCSI 技术在生产环境中的优势和劣势:

首先,iSCSI 存储技术非常便捷,在访问存储资源的形式上发生了很大变化,摆脱了物理环境的限制,同时还可以把存储资源分给
多个服务器共同使用,因此是一种非常推荐使用的存储技术。但是,iSCSI 存储技术受到了网速的制约。以往,硬盘设备直接通
过主板上的总线进行数据传输,现在则需要让互联网作为数据传输的载体和通道,因此传输速率和稳定性是 iSCSI 技术的瓶颈。
随着网络技术的持续发展,相信 iSCSI 技术也会随之得以改善。

共享设备:

在服务端(target):

[root@server ~]# yum install targetcli -y 安装策略共享编辑器

这里写图片描述

[root@server ~]# fdisk /dev/vdb  建立一个2G的分区
[root@server ~]# partprobe  同步分区
[root@server ~]# systemctl start target  开启服务

使用iscsi服务部署网络存储_第1张图片

[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]
/> /backstores/block create westos:storage1 /dev/vdb1创建共享的磁盘
Created block storage object westos:storage1 using /dev/vdb1.
/> /iscsi create iqn.2018-06.com.example:storage1 iqn域名反写,创建共享主机
Created target iqn.2018-06.com.example:storage1.
Created TPG 1.

使用iscsi服务部署网络存储_第2张图片

创建密钥:
/> /iscsi/iqn.2018-06.com.example:storage1/tpg1/acls create iqn.2018-06.com.example:westoskey 设置钥匙
Created Node ACL for iqn.2018-06.com.example:westoskey
/> /iscsi/iqn.2018-06.com.example:storage1/tpg1/luns create /backstores/block/westos:storage1 关联设备
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2018-06.com.example:westoskey
/> /iscsi/iqn.2018-06.com.example:storage1/tpg1/portals create 172.25.254.221开端口
Using default IP port 3260
Created network portal 172.25.254.221:3260.
/> exit  退出
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json

使用iscsi服务部署网络存储_第3张图片

[root@server ~]# systemctl stop firewalld  关闭防火墙
[root@server ~]# fdisk -l  查看硬件信息
   Device Boot      Start         End      Blocks   Id  System  建立的分区
/dev/vdb1         4194304     8388607     2097152   83  Linux

使用iscsi服务部署网络存储_第4张图片
在客户端(initiator):

[root@client ~]# yum search iscsi  查找安装包
[root@client ~]# yum install iscsi-initiator-utils.x86_64  安装软件

使用iscsi服务部署网络存储_第5张图片

[root@client ~]# iscsiadm -m discovery -t st -p 172.25.254.221   -m discovery 参数的目的是扫描并发
现可用的存储资源,-t st 参数为执行扫描操作的类型,-p 172.25.254.221 参数为 iSCSI 服务端的IP 地址
172.25.254.221:3260,1 iqn.2018-06.com.example:storage1
[root@client ~]# iscsiadm -m node -T iqn.2018-06.com.example:storage1 -p 172.25.254.221 -l   -m node 参数为将客户端所在主机作为一台节点服务器, -T iqn.2018-06.com.example:storage1 参数为要使用的存储资源,-p 172.25.254.221 参数依然为对方 iSCSI 服务端的 IP 地址。最后使用--login 或-l 参数进行登录验证
Logging in to [iface: default, target: iqn.2018-06.com.example:storage1, portal: 172.25.254.221,3260] (multiple)
iscsiadm: Could not login to [iface: default, target: iqn.2018-06.com.example:storage1, portal: 172.25.254.221,3260].
iscsiadm: initiator reported error (24 - iSCSI login failed due to authorization failure)报错是本地认证与服务端钥匙不匹配
iscsiadm: Could not log into all portals
[root@client ~]# cd /etc/iscsi/

使用iscsi服务部署网络存储_第6张图片

[root@client iscsi]# vim initiatorname.iscsi  编辑密钥文件
InitiatorName=iqn.2018-06.com.example:westoskey  更改为服务器提供的密钥

这里写图片描述

[root@client iscsi]# systemctl restart iscsid.service  重启服务
[root@client iscsi]# iscsiadm -m discovery -t st -p 172.25.254.221 客户端寻找找服务器提供的密钥
172.25.254.221:3260,1 iqn.2018-06.com.example:storage1
[root@client iscsi]# iscsiadm -m node -T iqn.2018-06.com.example:storage1 -p 172.25.254.221 -l   登录端口
Logging in to [iface: default, target: iqn.2018-06.com.example:storage1, portal: 172.25.254.221,3260] (multiple)
Login to [iface: default, target: iqn.2018-06.com.example:storage1, portal: 172.25.254.221,3260] successful.

这里写图片描述

[root@client iscsi]# fdisk -l   查看硬件信息出来服务端建立的分区
Disk /dev/sda: 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 / 4194304 bytes

使用iscsi服务部署网络存储_第7张图片
设备的使用以及开机自动挂载:

[root@client iscsi]# fdisk /dev/sda 建立一个2G分区
[root@client iscsi]# partprobe  同步分区

使用iscsi服务部署网络存储_第8张图片

[root@client iscsi]# mkfs.xfs /dev/sda1 格式化
meta-data=/dev/sda1              isize=256    agcount=8, agsize=65408 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0
data     =                       bsize=4096   blocks=523264, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@client iscsi]# mount /dev/sda1 /mnt/  挂载
[root@client iscsi]# df  挂载成功
Filesystem         1K-blocks    Used Available Use% Mounted on
/dev/vda1           10473900 3187380   7286520  31% /
devtmpfs              469344       0    469344   0% /dev
tmpfs                 484932      80    484852   1% /dev/shm
tmpfs                 484932   12788    472144   3% /run
tmpfs                 484932       0    484932   0% /sys/fs/cgroup
/dev/mapper/vg0-vo    483670    2355    451824   1% /home
/dev/sda1            2082816   33056   2049760   2% /mnt

使用iscsi服务部署网络存储_第9张图片

[root@client iscsi]# vim /etc/fstab 编辑文件开启自启动
/dev/sda1      /mnt   xfs    defaults,_netdev   0   0 加入,_netdev目的是先启动网络服务在挂载设备。

这里写图片描述

[root@client iscsi]# reboot
Connection to 172.25.254.121 closed by remote host.
Connection to 172.25.254.121 closed. 
[kiosk@foundation21 Desktop]$ rht-vmctl poweroff desktop 第一次一般起不来需要强行关闭
Powering off desktop..

使用iscsi服务部署网络存储_第10张图片

[kiosk@foundation21 Desktop]$ rht-vmctl start desktop  再次启动虚拟机
Starting desktop.
[kiosk@foundation21 Desktop]$ rht-vmctl view desktop  显示虚拟机,正常登陆
[kiosk@foundation21 Desktop]$ ssh [email protected]
[email protected]'s password: 
Last login: Sun Jun  3 01:45:41 2018

使用iscsi服务部署网络存储_第11张图片

[root@client ~]# df  查看挂载
Filesystem         1K-blocks    Used Available Use% Mounted on
/dev/vda1           10473900 3186724   7287176  31% /
devtmpfs              469344       0    469344   0% /dev
tmpfs                 484932      80    484852   1% /dev/shm
tmpfs                 484932   12776    472156   3% /run
tmpfs                 484932       0    484932   0% /sys/fs/cgroup
/dev/mapper/vg0-vo    483670    2355    451824   1% /home
/dev/sda1            2082816   33056   2049760   2% /mnt

使用iscsi服务部署网络存储_第12张图片
设备的删除:

[root@client ~]# yum install tree -y  安装树形显示工具

这里写图片描述

[root@client ~]# tree /var/lib/iscsi/  显示iscsi的信息
/var/lib/iscsi/
├── ifaces
├── isns
├── nodes
│   └── iqn.2018-06.com.example:storage1
│       └── 172.25.254.221,3260,1
│           └── default
├── send_targets
│   └── 172.25.254.221,3260
│       ├── iqn.2018-06.com.example:storage1,172.25.254.221,3260,1,default -> /var/lib/iscsi/nodes/iqn.2018-06.com.example:storage1/172.25.254.221,3260,1
│       └── st_config
├── slp
└── static

10 directories, 2 files

使用iscsi服务部署网络存储_第13张图片

[root@client ~]# df  查看挂载
Filesystem         1K-blocks    Used Available Use% Mounted on
/dev/vda1           10473900 3188508   7285392  31% /
devtmpfs              469344       0    469344   0% /dev
tmpfs                 484932      80    484852   1% /dev/shm
tmpfs                 484932   12776    472156   3% /run
tmpfs                 484932       0    484932   0% /sys/fs/cgroup
/dev/mapper/vg0-vo    483670    2355    451824   1% /home
/dev/sda1            2082816   33056   2049760   2% /mnt
[root@client ~]# umount /mnt/  解除挂载
[root@client ~]# vim /etc/fstab 删除开机自启动行

使用iscsi服务部署网络存储_第14张图片

[root@client ~]# iscsiadm -m node -T iqn.2018-06.com.example:storage1 -p 172.25.254.221 -u  登出
Logging out of session [sid: 1, target: iqn.2018-06.com.example:storage1, portal: 172.25.254.221,3260]
Logout of [sid: 1, target: iqn.2018-06.com.example:storage1, portal: 172.25.254.221,3260] successful.
[root@client ~]# tree /var/lib/iscsi/  查看iscsi信息还在
/var/lib/iscsi/
├── ifaces
├── isns
├── nodes
│   └── iqn.2018-06.com.example:storage1
│       └── 172.25.254.221,3260,1
│           └── default
├── send_targets
│   └── 172.25.254.221,3260
│       ├── iqn.2018-06.com.example:storage1,172.25.254.221,3260,1,default -> /var/lib/iscsi/nodes/iqn.2018-06.com.example:storage1/172.25.254.221,3260,1
│       └── st_config
├── slp
└── static

10 directories, 2 files

使用iscsi服务部署网络存储_第15张图片

[root@client ~]# fdisk -l  看不到硬件信息

Disk /dev/vda: 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: 0x00013f3e

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    20970332    10484142+  83  Linux

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: 0x09ee18d7

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048     1026047      512000   8e  Linux LVM

Disk /dev/mapper/vg0-vo: 520 MB, 520093696 bytes, 1015808 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

使用iscsi服务部署网络存储_第16张图片

[root@client ~]# systemctl restart iscsi  重启服务之后
[root@client ~]# fdisk -l  又会从文件中加载出来

Disk /dev/vda: 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: 0x00013f3e

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    20970332    10484142+  83  Linux

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: 0x09ee18d7

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048     1026047      512000   8e  Linux LVM

Disk /dev/mapper/vg0-vo: 520 MB, 520093696 bytes, 1015808 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/sda: 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 / 4194304 bytes
Disk label type: dos
Disk identifier: 0xd38703a8

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            8192     4194303     2093056   83  Linux

使用iscsi服务部署网络存储_第17张图片

[root@client ~]# iscsiadm -m node -T iqn.2018-06.com.example:storage1 -p 172.25.254.221 -u登出
Logging out of session [sid: 2, target: iqn.2018-06.com.example:storage1, portal: 172.25.254.221,3260]
Logout of [sid: 2, target: iqn.2018-06.com.example:storage1, portal: 172.25.254.221,3260] successful.
[root@client ~]# iscsiadm -m node -T iqn.2018-06.com.example:storage1 -p 172.25.254.221 -o delete 删除文件
[root@client ~]# tree /var/lib/iscsi/ 树形信息消失
/var/lib/iscsi/
├── ifaces
├── isns
├── nodes
├── send_targets
│   └── 172.25.254.221,3260
│       └── st_config
├── slp
└── static

7 directories, 1 file

使用iscsi服务部署网络存储_第18张图片

[root@client ~]# fdisk -l  硬件信息显示设备删除

Disk /dev/vda: 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: 0x00013f3e

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    20970332    10484142+  83  Linux

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: 0x09ee18d7

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048     1026047      512000   8e  Linux LVM

Disk /dev/mapper/vg0-vo: 520 MB, 520093696 bytes, 1015808 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

使用iscsi服务部署网络存储_第19张图片

[root@client ~]# systemctl restart iscsi 重启服务
[root@client ~]# fdisk -l 硬件信息显示设备已经删除

Disk /dev/vda: 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: 0x00013f3e

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    20970332    10484142+  83  Linux

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: 0x09ee18d7

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048     1026047      512000   8e  Linux LVM

Disk /dev/mapper/vg0-vo: 520 MB, 520093696 bytes, 1015808 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

使用iscsi服务部署网络存储_第20张图片

你可能感兴趣的:(使用iscsi服务部署网络存储)