环境准备:

主机:VMware VM (Linux :CentOS 7.5 )

网络:VM 可以访问公网 (NAT)

共享硬盘:/dev/sdb(宿主机准备一块硬盘提供iscsi容器使用,作为共享硬盘)

软件要求:安装docker;iscsi-initiator-utils(iscsi客户端软件)

Docker安装

1、 使用官方安装脚本自动安装

 #curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

2、启动 Docker 服务

 #systemctl start docker  

3、确认docker 组件已经启动

 # ps aux | grep docker
 root      11568  0.1  3.0 661408 56004 ?        Ssl  08:44   0:54 /usr/bin/dockerd -H fd:// -- 
 containerd=/run/containerd/containerd.sock

iSCSI简介

iSCSI(Internet Small Computer System Interface,Internet 小型计算机系统接口)是一种由IBM公司研究开发的IP SAN技术,该技术是将现有SCSI接口与以太网络(Ethernet)技术结合,基于 TCP/IP的协议连接iSCSI服务端(Target)和客户端(Initiator),使得封装后的SCSI数据包可以通用互联网传输,最终实现iSCSI服务端映射为一个存储空间(磁盘)提供给已连接认证后的客户端。

iSCSI服务端称为Target,访问的客户端应用称为Initiator。
在这里插入图片描述

下载iSCSI镜像

1、下载iSCSI docker 镜像

#docker pull wtnb75/stgt 

**2、确认 iSCSI docker 镜像存在于本地 **

#docker images 

[root@localhost ~]# docker images
REPOSITORY        TAG       IMAGE ID       CREATED        SIZE
ubuntu            14.04     13b66b487594   7 months ago   197MB
wtnb75/stgt       latest    acb56e1844e0   3 years ago    8.31MB
dreamcat4/iscsi   latest    99b5f61483ed   4 years ago    326MB
aosqe/iscsi       latest    1d1aa0a7ba73   5 years ago    386MB

启动iSCSI容器

docker run \
--detach \
--name stgt \
--restart=unless-stopped \
--net host \
--privileged \
--volume /etc/target:/etc/target \
--volume /run/lvm:/run/lvm \
--volume /lib/modules:/lib/modules \
--volume /sys/kernel/config:/sys/kernel/config \
--volume /dev:/dev \
-p 3260:3260 \
wtnb75/stgt 

查看iSCSI容器运行状态

**检查iSCSI docker 运行状态 **

 #docker ps 

[root@localhost ~]# docker ps 
CONTAINER ID   IMAGE         COMMAND     CREATED          STATUS          PORTS     NAMES
26e6d34ff4af   wtnb75/stgt   "tgtd -f"   30 minutes ago   Up 30 minutes             stgt

iSCSI容器创建共享硬盘

1、创建target

#docker exec stgt tgtadm --mode target --op new --tid 1 --targetname 		iqn.2017-04.com.comsys:iscsi.fcdisk

2、创建lun

#docker exec stgt tgtadm --mode logicalunit --op new --tid 1 --lun 1 --backing-store /dev/sdb1

3、授权

#docker exec stgt tgtadm --mode target --op bind --tid 1 --initiator-address 	192.168.234.0/24
#docker exec stgt tgtadm --mode target --op bind --tid 1 --initiator-address 172.17.0.0/24

4、查看已经定义的信息

#docker exec stgt tgtadm --mode target --op show

[root@localhost ~]# docker exec stgt tgtadm --mode target --op show
Target 1: iqn.2017-04.com.comsys:iscsi.fcdisk
System information:
    Driver: iscsi
    State: ready
I_T nexus information:
LUN information:
    LUN: 0
        Type: controller
        ............................
 LUN: 1
        Type: disk
        SCSI ID: IET     00010001
        SCSI SN: beaf11
        Size: 5368 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:
    192.168.234.0/24
    172.17.0.0/24

iSCSI客户端发现并登录存储

1、安装客户端软件

[root@localhost ~]# yum install iscsi-initiator-utils

2、启动iSCSI服务

[root@localhost ~]#service iscsi start;service iscsid start

3、发现iSCSI存储

[root@localhost ~]# iscsiadm -m discovery -t st -p 192.168.234.128
192.168.234.128:3260,1 iqn.2017-04.com.comsys:iscsi.fcdisk

4、登录iSCSI存储

[root@localhost ~]# iscsiadm -m node   -d -T   iqn.2017-04.com.comsys:iscsi.fcdisk   -p 192.168.234.128 -l
Logging in to [iface: default, target: iqn.2017-04.com.comsys:iscsi.fcdisk, portal: 192.168.234.128,3260] (multiple)
Login to [iface: default, target: iqn.2017-04.com.comsys:iscsi.fcdisk, portal: 192.168.234.128,3260] successful.

5、查看共享硬盘

[root@localhost ~]# fdisk -l
Disk /dev/sda: 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: 0x0000959b
Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      616447      307200   83  Linux
/dev/sda2          616448     2713599     1048576   82  Linux swap / Solaris
/dev/sda3         2713600    20971519     9128960   83  Linux

Disk /dev/sdb: 5368 MB, 5368709120 bytes, 10485760 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: 0xbdecb11b


Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    10485759     5241856   83  Linux

Disk /dev/sdc: 5367 MB, 5367660544 bytes, 10483712 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
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐