iSCSI远程块存储配置实验
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iSCSI远程块存储配置实验相关的知识,希望对你有一定的参考价值。
实验环境:RHEL7.0
服务器端 server1.example.com 172.25.254.1
客户端1 server2.example.com 172.25.254.2
客户端2 server3.example.com 172.25.254.3
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》服务器端配置
2.1添加硬盘新硬盘,不用格式化分区,用于做远程磁盘。
我已经添加了一块磁盘vda
[[email protected] ~]# fdisk -l
Disk /dev/vda: 8589 MB, 8589934592 bytes, 16777216 sectors
分区不用格式化
[[email protected] ~]# fdisk /dev/vda
[[email protected] ~]# cat /proc/partitions
2.2安装iSCSI目标软件包:
# yum install -y targetcli
启动服务:
# systemctl enable target; systemctl start target
2.3 进入iSCSI目标交互式配置模式:
[[email protected] ~]# 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 server:disk /dev/vda1
Created block storage object server:disk using /dev/vda1.
/> /iscsi create iqn.2016-09.com.example.com:storage1
Created target iqn.2016-09.com.example.com:storage1.
Created TPG 1.
/> /iscsi/iqn.2016-09.com.example.com:storage1/tpg1/luns create /backstores/block/server:disk
/> /iscsi/iqn.2016-06.com.example:storage1/tpg1/acls create iqn.2016-06.com.example:key
Created Node ACL for iqn.2016-06.com.example:key
Created mapped LUN 0.
Created LUN 0.
/> /iscsi/iqn.2016-09.com.example.com:storage1/tpg1/portals create 172.25.254.1
Using default IP port 3260
Created network portal 172.25.254.1:3260.
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
[[email protected] ~]#
[[email protected] ~]# netstat -antple|grep 3260 ###查看端口
tcp 0 0 172.25.254.1:3260 0.0.0.0:* LISTEN 0 35120
[[email protected] ~]# firewall-cmd --permanent --add-port=3260/tcp ##添加防火墙策略
[[email protected] ~]# firewall-cmd --reload
《2》客户端1访问ISCSI存储
2.1 安装iSCSI发起端软件包:
[[email protected] ~]# yum install iscsi-initiator-utils -y
2.2 在/etc/iscsi/initiatorname.iscsi中设置发起端的IQN:
[[email protected] ~]# vim /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2016-09.com.example:storage
2.3 查找iSCSI服务器所提供的iSCSI目标(目标门户)
[[email protected] ~]# iscsiadm -m discovery -t st -p 172.25.254.1
172.25.254.1:3260,1 iqn.2016-09.com.example.com:key
2.4 登录服务器上的一个或多个iscsi目标
[[email protected] ~]# systemctl restart iscsid
[[email protected] ~]# iscsiadm -m node -T iqn.2016-06.com.example:storage1 -p 172.25.254.1 -l
Logging in to [iface: default, target: iqn.2016-06.com.example:storage1, portal: 172.25.254.1,3260] (multiple)
Login to [iface: default, target: iqn.2016-06.com.example:storage1, portal: 172.25.254.1,3260] successful.
[[email protected] ~]# fdisk -l ###查看,多了一块磁盘
Disk /dev/sdb: 4294 MB, 4294967296 bytes, 8388608 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
2.5 挂载使用
[[email protected] ~]# fdisk /dev/sdb
[[email protected] ~]# partprobe
[[email protected] ~]# mkfs.xfs /dev/sdb1
[[email protected] ~]# mount /dev/sdb1 /mnt/
[[email protected] ~]# cd /mnt/
[[email protected] mnt]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 8.5G 3.0G 5.6G 35% /
devtmpfs 488M 0 488M 0% /dev
tmpfs 498M 92K 497M 1% /dev/shm
tmpfs 498M 7.0M 491M 2% /run
tmpfs 498M 0 498M 0% /sys/fs/cgroup
/dev/sda1 497M 119M 379M 24% /boot
/dev/sdb1 4.0G 33M 4.0G 1% /mnt
[[email protected] mnt]# ls
file1 file10 file2 file3 file4 file5 file6 file7 file8 file9
[[email protected] mnt]# iscsiadm -m node -T iqn.2016-06.com.example:storage1 -p 172.25.254.1 -u #登出iSCSI目标,以暂时断开连接。
Logging out of session [sid: 3, target: iqn.2016-06.com.example:storage1, portal: 172.25.254.1,3260]
Logout of [sid: 3, targ
[[email protected] mnt]# iscsiadm -m node -T iqn.2016-06.com.example:storage1 -p 172.25.254.1 -o delete ##彻底断开连接
《3》客户端2访问ISCSI存储
[[email protected] ~]# yum install iscsi-initiator-utils.x86_64 -y
[[email protected] ~]# vim /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2016-06.com.example:key
[[email protected] ~]# iscsiadm -m discovery -t st -p 172.25.254.1
172.25.254.1:3260,1 iqn.2016-06.com.example:storage1
[[email protected] ~]# iscsiadm -m node -T iqn.2016-06.com.example:storage1 -p 172.25.254.1 -l
Logging in to [iface: default, target: iqn.2016-06.com.example:storage1, portal: 172.25.254.1,3260] (multiple)
Login to [iface: default, target: iqn.2016-06.com.example:storage1, portal: 172.25.254.1,3260] successful.
[[email protected] ~]# fdisk -l ###得到的磁盘已经是被分区格式化好的,可直接挂载使用
Disk /dev/sdb: 4294 MB, 4294967296 bytes, 8388608 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: 0x231cc8fa
Device Boot Start End Blocks Id System
/dev/sdb1 8192 8388607 4190208 83 Linux
[[email protected] ~]# mount /dev/sdb1 /mnt/
[[email protected] ~]# cd /mnt/
[[email protected] mnt]# ls ###可以看到我们在客户大端1上创建的文件
file1 file10 file2 file3 file4 file5 file6 file7 file8 file9
本文出自 “技术人生,简单不简单” 博客,请务必保留此出处http://willis.blog.51cto.com/11907152/1855554
以上是关于iSCSI远程块存储配置实验的主要内容,如果未能解决你的问题,请参考以下文章