iscsi

来源:互联网 发布:美国海关数据查询 编辑:程序博客网 时间:2024/05/20 00:13

iscsi

iSCSI的概念:
iSCSI(Internet SCSI)支持从客户端(发起端)通过IP向远程服务器上的SCSI存储设备(目标)发送SCSI命令。iSCSI限定名称用于确定发起端和目标,并采用iqn.yyyy-mm.{reverse domain}:label的格式。默认情况下,网络通信是至iSCSI目标上的端口3260/tcp的明文。
(1)iSCSI发起端:需要访问原始SAN存储的客户端。
(2)iSCSI目标:从iSCSI服务器提供的远程硬盘磁盘,或“目标门户”
(3)iSCSI目标门户:通过网络向发起端提供目标的服务器。
(4)IQN:“iSCSI限定名称”。每个发起端和目标需要唯一名称进行标识,最好的做法是使用一个在Internet上可能独一无二的名称。

1.

iscsi是直接对设备进行共享的服务

2.
启动iscsi共享设备
在server上

先建立一个lvm设备

yum install targetcli -y                                         ##安装iSCSI目标软件包
systemctl start target                                          ##启动服务
systemctl enable target                                      ##设定服务开机自动开启
systemctl stop firewalld                                     ##关闭防火墙
systemctl disable firewalld                                ##设定防火墙开机不会自动开启

                     
[root@server80 ~]# targetcli                               ##进入iSCSI目标交互式配置模式
targetcli shell version 2.1.fb34
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.

/> ls
/> /backstores/block create server1storage /dev/vg0/iscsi_storage
/> /iscsi create iqn.2017-06.com.example:strage1
/> /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.1.11
/> exit

在desktop上
[root@desktop80 ~]# vim /etc/iscsi/initiatorname.iscsi   ##在/etc/iscsi/initiatorname.iscsi中设置发起端的IQN
InitiatorName=iqn.2017-06.com.example.server1storagekey

[root@desktop80 ~]# iscsiadm -m discovery -t st -p 172.25.80.11                    ##查找iSCSI服务器所提供的iSCSI目标(目标门户
[root@desktop80 ~]# iscsiadm -m node -T iqn.2017-06.com.example:strage1 -p 172.25.80.11 -l           ##登录服务器上的一个或多个iscsi目标
[root@desktop80 ~]# fdisk -l                                             ##查看分区情况

Disk /dev/sda: 1044 MB, 1044381696 bytes, 2039808 sectors


此时,可以使用iSCSI磁盘,就好像它是本地连接硬盘驱动器。可以挂载现有文件系统。如果磁盘未格式化,可以通过fdisk进行分区,例如,通过文件系统格式化分区或作为LVM物理卷。
在/etc/fstab中永久挂载文件系统
(1)使用blkid确定文件系统UUID并使用UUID挂载,而不是/dev/sd*设备名称。(每次引导时显示的设备名称都不同,具体取决于iSCSI设备通过网络进行响应的顺序。如果按设备名称挂载,这会导致使用错误的设备。)
(2)在/etc/fstab中使用_netdev作为挂载选项。(这将确保客户端不会尝试挂载文件系统,直至启用联网。否则,在引导时系统将出错。)
(3)确保iscsi服务在引导时启动。


3.挂载(在desktop)
[root@desktop80 ~]# blkid                                                  ##查看UUID
[root@desktop80 ~]# vim /etc/fstab                                   ##编辑配置文件,并写入内容
UUID=""        /mnt    xfs    defaults,_netdev    0 0
[root@desktop80 ~]# mount -a

4.删除(在desktop)
umount /mnt                                         ##卸载
vim /etc/fstab                                        ##将之前写入的内容全都删掉

确保没有使用目标所提供的任何设备。
确保从/etc/fstab等位置中删除使用目标的所有永久挂载


iscsiadm -m node -T iqn.2017-06.com.example:strage1 -p 172.25.80.11 -u                ##登出iSCSI目标,以暂时断开连接

iscsiadm -m node -T iqn.2017-06.com.example:strage1 -p 172.25.80.11 -o delete    ##删除iSCSI目标的本地记录,以永久断开连接
tree -C /var/lib/iscsi/systemctl start target                              ##查看是否删去
systemctl enable target
systemctl stop firewalld
systemctl disable firewalld
原创粉丝点击