ISCSI共享存储-2017-2-23
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ISCSI共享存储-2017-2-23相关的知识,希望对你有一定的参考价值。
这个实验比较有成就感,毕竟不是为我做的,而是给班上的其他人和老师,凭这个赢得了老师的信任(以及更多的任务),当然毕业实习也拿了优秀。个人收获上,也有收获,但是理论方面,没有深究很多,我相信以后会有机会的,因为这是openstack云计算有可能需要的东西
1、在192.168.1.21部署target ,最好在VM workstation单独加一块硬盘用来测试,默认添加后就是/dev/sdb
[[email protected] ~]# ifconfig eth0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.21 netmask 255.255.255.0 broadcast 192.168.1.255
2、网卡配置
[[email protected] ~]# ping www.163.com ##如果网络不通,编辑如下网卡配置即可,具体的IP网段由实际情况决定。
# vim /etc/sysconfig/network-scripts/ifcfg-eth0
------------------------------
DEVICE=eth0
BOOTPROTO="static"
NM_CONTROLLED="no"
ONBOOT="yes"
TYPE="Ethernet"
IPADDR=192.168.1.27
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
--------------------------------
[[email protected] ~]# service network restart
3、yum源的配置。
[[email protected] ~]# cd /etc/yum.repos.d
[[email protected] yum.repos.d]# vim centos7.repo ##如果系统自带的Yum源不好使,把下面的配置文件拷贝进去
---------------------------------------------
#centOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
---------------------------------------------
[[email protected] ~]# yum install epel-release -y ##必须安装这个yum源,不然无法下载target软件
[[email protected] ~]# yum install scsi-target-utils -y
4、磁盘分区
[[email protected] ~]# fdisk /dev/sdb ##写入一个500M的分区,这一步也可以不做,比较麻烦,测试有一个disk1.img已经够了
Command (m for help): p
Partition number (1-4, default 1): 1
First sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +500M
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0x5dc1ecee
Device Boot Start End Blocks Id System
/dev/sdb1 2048 1026047 512000 83 Linux
Command (m for help): w
The partition table has been altered!
[[email protected] ~]# partprobe
##注意此硬盘只能格式化,但是不能挂载,否则无法共享。
[[email protected] ~]# mkfs.ext4 /dev/sdb1
[[email protected] tgt]# fdisk -l /dev/sdb1
Disk /dev/sdb1: 524 MB, 524288000 bytes, 1024000 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
[[email protected] ~]# vim /etc/tgt/targets.conf
=============================================================
<target iqn.2017-02.dev.iscsi-target:iscsidisk>
backint-store /dev/sdb1
</target>
=============================================================
iqn = iSCSI Qualified Name
iSCSI target的名称规则如下:
iqn.2014-07.dev.iscsi-target:iscsidisk
iqn.年份-月份.域名反写.设备识别
每个在同一个target上的backing-store 称为逻辑单元号(Logical Unit Number,LUN)
当开启此次服务以后,再次写入配置文件时,共享新的设备,需要设置新的target
<target iqn.2017-02.yhc.iscsi-target.sdb1>
backing-store /dev/sdb1
</target>
[[email protected] ~]# service tgtd start ##运行该服务
Redirecting to /bin/systemctl start tgtd.service
[[email protected] ~]# systemctl enable tgtd ##开机自启
Created symlink from /etc/systemd/system/multi-user.target.wants/tgtd.service to /usr/lib/systemd/system/tgtd.service.
[[email protected] ~]# netstat -tulnp|grep tgt
tcp 0 0 0.0.0.0:3260 0.0.0.0:* LISTEN 2654/tgtd
tcp6 0 0 :::3260 :::* LISTEN 2654/tgtd
[[email protected] ~]# tgt-admin --show ##查看测试镜像disk1.img是否暴露在网络中
Target 1: iqn.2017-2-23.dev.iscsi-target:iscsidisk
System information:
Driver: iscsi
State: ready
I_T nexus information:
LUN information:
LUN: 0
Type: controller
SCSI ID: IET 00010000
SCSI SN: beaf10
Size: 0 MB, Block size: 1
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
SWP: No
Thin-provisioning: No
Backing store type: null
Backing store path: None
Backing store flags:
LUN: 1
Type: disk
SCSI ID: IET 00010001
SCSI SN: beaf11
Size: 210 MB, Block size: 512
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
SWP: No
Thin-provisioning: No
Backing store type: rdwr
Backing store path: /dev/sdb1
Backing store flags:
Account information:
ACL information:
ALL
##很简单的target部署完成
二、windows打开initator,只用保证虚拟机和物理机同一网段便可共享,当然一般都是连通的。
参考文档:http://jingyan.baidu.com/article/a65957f4909da624e67f9b90.html
位置: 控制面板\所有控制面板项\管理工具--打开ISCSI发起程序
目标: 【192.168.1.21】 ##填入虚拟机的IP地址
发现门户-目标,把共享硬盘由不活动改为连接,之后会进行一段时间的驱动程序安装
计算机管理会发现添加了一个磁盘,右击该硬盘进行创建简单卷即可使用。
再次回到linux上
[[email protected] ~]# tgt-admin --show ##显示已连接,192.168.1.102是windows的IP
Target 1: iqn.2017-2-23.dev.iscsi-target:iscsidisk
System information:
Driver: iscsi
State: ready
I_T nexus information:
I_T nexus: 1
Initiator: iqn.1991-05.com.microsoft:xb-20160403hplc alias: none
Connection: 1
IP Address: 192.168.1.102
三、Linux创建initator,开启另一台虚拟机192.168.1.23
[[email protected] ~]# yum -y install iscsi-initiator-utils
[[email protected] ~]# vim /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2017-02.yhc.iscsi-target.sdb1
[[email protected] ~]# iscsiadm -m discovery -t sendtargets -p 192.168.1.21
192.168.1.21:3260,1 iqn.2017-02.yhc.iscsi-target.sdb1
## -m discovery //侦测target
-t sendtargets //通过iscsi协议
-p IP:port //指定target的IP和port,不写port的话,默认为3260
[[email protected] ~]# ll /var/lib/iscsi/nodes/ ##iscsiadm 侦测到的结果会写入/var/lib/iscsi/nodes/ 中,因此只需启动/etc/init.d/iscsi 就能够在下次开机时,自动连接到正确的target了
total 0
drw------- 3 root root 32 Feb 23 17:42 iqn.2017-02.yhc.iscsi-target.sdb1
[[email protected] 192.168.1.21,3260,1]# iscsiadm -m node ##查看目前系统上面所有的target
192.168.1.21:3260,1 iqn.2017-02.yhc.iscsi-target.sdb1
[[email protected] ~]# iscsiadm -m node -T iqn.2017-02.yhc.iscsi-target.sdb --login ##登录到ISCSI的target服务器
Logging in to [iface: default, target: iqn.2017-02.yhc.iscsi-target.sdb1, portal: 192.168.1.21,3260] (multiple)
Login to [iface: default, target: iqn.2017-02.yhc.iscsi-target.sdb1, portal: 192.168.1.21,3260] successful.
[[email protected] ~]# fdisk -l /dev/sdb ##查看共享硬盘,本来是没有该硬盘的
Disk /dev/sdb: 524 MB, 524288000 bytes, 1024000 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
[[email protected] ~]# mount /dev/sdb /mnt
[[email protected] ~]# cd /mnt
[[email protected] mnt]# echo "这是iSCSI实验,目标Target服务器的IP是192.168.100.21,于2017-2-24" >test.txt
[[email protected] mnt]# ls
lost+found test.txt
[[email protected] ~]# systemctl enable iscsid
Created symlink from /etc/systemd/system/multi-user.target.wants/iscsid.service to /usr/lib/systemd/system/iscsid.service.
[[email protected] ~]# service iscsid status ##安装该软件包之后就会自启
Redirecting to /bin/systemctl status iscsid.service
● iscsid.service - Open-iSCSI
Loaded: loaded (/usr/lib/systemd/system/iscsid.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2017-02-23 17:38:43 CST; 20min ago
报错:奇了怪了,明明已经到target,居然fdisk -l /dev/sdb没有东西,可是明明ll /dev/sdb存在。重启系统估计会报错,果然重启不成功,把电源,日了狗!
[[email protected] ~]# mount /dev/sdb /mnt ##这种问题多半是没有格式化
mount: /dev/sdb is write-protected, mounting read-only
mount: unknown filesystem type ‘(null)‘
注意:关机的时候先把target停掉,再关机。
以上是关于ISCSI共享存储-2017-2-23的主要内容,如果未能解决你的问题,请参考以下文章