ISCSI用法及简单配置

数字漫游
• 阅读 3175

ISCSI(Internet Small Computer System Interface) 是一种 SAN(Storage Area network) 的实现

环境:

OS: CentOS6.7
node1: 10.11.8.187 (target)
node2: 10.11.8.186 (initiator)
node3: 10.11.8.200 (initiator)

安装:

target(即服务端, 提供存储): scsi-target-utils

initiator(即使用端): iscsi-initiator-utils

target 端:

服务脚本: /etc/init.d/tgtd

管理命令: tgtadm

tgtadm模式化的命令
-m, --mode [target、logicalunit、account]

  • target --op [new、delete、show、update、bind、unbind]

  • logicalunit --op [new、delete]

  • account --op [new、delete、bind、unbind]

-L, --lld <driver>
-t, --tid
-l, --lun
-b, --backing-store <path>
-I, --initiator-address <address>
-T, --targetname <targetname>

initiator 端:

服务脚本: /etc/init.d/iscsid

管理命令: iscsiadm

iscsiadm模式化的命令
-m {discovery|node|session|iface}

  • discovery: 发现某服务器是否有target输出,以及输出了哪些target;

  • node: 管理跟某target的关联关系;

  • session: 会话管理

  • iface: 接口管理

iscsiadm -m discovery [ -d debug_level ] [ -P printlevel ] [ -I iface -t type -p ip:port [ -l ] ]

  • -d: 0-8

  • -I: Network interface

  • -t type: SendTargets(st), SLP, and iSNS

  • -p: IP:port

对所有的操作
iscsiadm -m node [ -d debug_level ] [ -L all,manual,automatic ] | [ -U all,manual,automatic ]
对单个的操作
iscsiadm -m node [ -d debug_level ] [ [ -T targetname -p ip:port -I ifaceN ] [ -l | -u ] ] [ [ -o operation ] [ -n name ] [ -v value ] ]

iscsi-initiator-utils:
不支持discovery认证;
如果使用基于用户的认证,必须首先开放基于IP的认证;

node1 配置 target 服务:

1.创建一个控制器

[root@node1 ~]# tgtadm --lld iscsi --mode target --op new --targetname iqn.2016.com.shiina:storage.disk1 --tid 1
[root@node1 ~]# tgtadm --lld iscsi --mode target --op show
Target 1: iqn.2016.com.shiina:storage.disk1
    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
            Backing store type: null
            Backing store path: None
            Backing store flags:
    Account information:
    ACL information:

2.创建一块存储设备

[root@node1 ~]# tgtadm --lld iscsi --mode logicalunit --op new --tid 1 --lun 1 --backing-store /dev/sdb
[root@node1 ~]# tgtadm --lld iscsi --mode target --op show
Target 1: iqn.2016.com.shiina:storage.disk1
    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
            Backing store type: null
            Backing store path: None
            Backing store flags:
        LUN: 1
            Type: disk
            SCSI ID: IET     00010001
            SCSI SN: beaf11
            Size: 8590 MB, Block size: 512
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: rdwr
            Backing store path: /dev/sdb
            Backing store flags:
    Account information:
    ACL information:

3.添加访问控制

[root@node1 ~]# tgtadm --lld iscsi --mode target --op bind --tid 1 --initiator-address 10.11.0.0/16
[root@node1 ~]# tgtadm --lld iscsi --mode target --op show
Target 1: iqn.2016.com.shiina:storage.disk1
    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
            Backing store type: null
            Backing store path: None
            Backing store flags:
        LUN: 1
            Type: disk
            SCSI ID: IET     00010001
            SCSI SN: beaf11
            Size: 8590 MB, Block size: 512
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: rdwr
            Backing store path: /dev/sdb
            Backing store flags:
    Account information:
    ACL information:
        10.11.0.0/16

tgtadm 所做的修改全都是在内核中保存的, 重启服务器后所有记录将会消失, 若想自动生效, 需要将配置写在 /etc/tgt/target.conf中, 以上的简单配置在文件中可以这样定义:

<target iqn.2016.com.shiina:storage.disk1>
    backing-store /dev/sdb
    initiator-address 10.11.0.0/16
</target>

详细配置文件内有事例

node2 配置 initiator:

iscsi-iname 命令: 生成initiator-name

-p: 指定名前缀

1.生成InitiatorName

[root@node2 ~]# echo "InitiatorName=`iscsi-iname -p iqn.2016.com.shiina`" > /etc/iscsi/initiatorname.iscsi
[root@node2 ~]# cat /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2016.com.shiina:60362cc811e4

2.搜索发现 target:

[root@node2 ~]# iscsiadm -m discovery -t sendtargets -p 10.11.8.187
10.11.8.187:3260,1 iqn.2016.com.shiina:storage.disk1
[root@node2 ~]# ll /var/lib/iscsi/send_targets/10.11.8.187,3260/
total 8
lrwxrwxrwx 1 root root  73 May 28 20:44 iqn.2016.com.shiina:storage.disk1,10.11.8.187,3260,1,default -> /var/lib/iscsi/nodes/iqn.2016.com.shiina:storage.disk1/10.11.8.187,3260,1
-rw------- 1 root root 554 May 28 20:44 st_config

3.登录: 表示将远程主机target对应的lun关联到本机

[root@node2 ~]# iscsiadm -m node -T iqn.2016.com.shiina:storage.disk1 -p 10.11.8.187 -l
Logging in to [iface: default, target: iqn.2016.com.shiina:storage.disk1, portal: 10.11.8.187,3260] (multiple)
Login to [iface: default, target: iqn.2016.com.shiina:storage.disk1, portal: 10.11.8.187,3260] successful.
[root@node2 ~]# fdisk -l
 
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0000bfe1
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          26      204800   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              26         157     1048576   82  Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3             157        2611    19717120   8e  Linux LVM
 
Disk /dev/mapper/vol0-root: 5242 MB, 5242880000 bytes
255 heads, 63 sectors/track, 637 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
 
 
Disk /dev/mapper/vol0-usr: 14.9 GB, 14944305152 bytes
255 heads, 63 sectors/track, 1816 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
 
 
Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xfa870733
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1044     8385898+  83  Linux
PS: sdb1 是 node1 上一个尚未格式化的分区

4.格式化并写入数据

[root@node2 ~]# mke2fs -j /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
524288 inodes, 2096474 blocks
104823 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2147483648
64 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
 
Writing inode tables: done                          
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
 
This filesystem will be automatically checked every 22 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@node2 ~]# mount /dev/sdb1 /mnt
[root@node2 ~]# cp /etc/fstab /mnt/

node3 配置initiator并登录:

[root@node3 ~]# iscsiadm -m discovery -t sendtargets -p 10.11.8.187
Starting iscsid:                                           [  OK  ]
10.11.8.187:3260,1 iqn.2016.com.shiina:storage.disk1
[root@node3 ~]# iscsiadm -m node -T iqn.2016.com.shiina:storage.disk1 -p 10.11.8.187 -l
Logging in to [iface: default, target: iqn.2016.com.shiina:storage.disk1, portal: 10.11.8.187,3260] (multiple)
Login to [iface: default, target: iqn.2016.com.shiina:storage.disk1, portal: 10.11.8.187,3260] successful.
[root@node3 ~]# mount /dev/sdb1 /mnt
[root@node3 ~]# ls /mnt/
fstab  lost+found # 此时fatab文件存在

在 node2 和 node3 同时挂载的情况下,在 node3 写入数据:

[root@node3 ~]# cp /etc/inittab /mnt/
[root@node3 ~]# ls /mnt/
fstab  inittab  lost+found
[root@node2 ~]# ls /mnt/
fstab  lost+found

此时查看 node2 却发现并无 inittab 文件, 说明 node3 的数据写入依然停留在内存中, 尚未同步到硬盘

此种情况下容易造成文件系统崩溃, 因此只允许一台设备挂载, 若希望同时挂载, 则需安装集群文件系统

点赞
收藏
评论区
推荐文章
blmius blmius
3年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
Stella981 Stella981
3年前
Opencv中Mat矩阵相乘——点乘、dot、mul运算详解
Opencv中Mat矩阵相乘——点乘、dot、mul运算详解2016年09月02日00:00:36 \牧野(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fme.csdn.net%2Fdcrmg) 阅读数:59593
Wesley13 Wesley13
3年前
FLV文件格式
1.        FLV文件对齐方式FLV文件以大端对齐方式存放多字节整型。如存放数字无符号16位的数字300(0x012C),那么在FLV文件中存放的顺序是:|0x01|0x2C|。如果是无符号32位数字300(0x0000012C),那么在FLV文件中的存放顺序是:|0x00|0x00|0x00|0x01|0x2C。2.  
Easter79 Easter79
3年前
Twitter的分布式自增ID算法snowflake (Java版)
概述分布式系统中,有一些需要使用全局唯一ID的场景,这种时候为了防止ID冲突可以使用36位的UUID,但是UUID有一些缺点,首先他相对比较长,另外UUID一般是无序的。有些时候我们希望能使用一种简单一些的ID,并且希望ID能够按照时间有序生成。而twitter的snowflake解决了这种需求,最初Twitter把存储系统从MySQL迁移
Wesley13 Wesley13
3年前
mysql设置时区
mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0
Wesley13 Wesley13
3年前
PHP创建多级树型结构
<!lang:php<?php$areaarray(array('id'1,'pid'0,'name''中国'),array('id'5,'pid'0,'name''美国'),array('id'2,'pid'1,'name''吉林'),array('id'4,'pid'2,'n
Wesley13 Wesley13
3年前
00:Java简单了解
浅谈Java之概述Java是SUN(StanfordUniversityNetwork),斯坦福大学网络公司)1995年推出的一门高级编程语言。Java是一种面向Internet的编程语言。随着Java技术在web方面的不断成熟,已经成为Web应用程序的首选开发语言。Java是简单易学,完全面向对象,安全可靠,与平台无关的编程语言。
Wesley13 Wesley13
3年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Python进阶者 Python进阶者
1年前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这
美凌格栋栋酱 美凌格栋栋酱
5个月前
Oracle 分组与拼接字符串同时使用
SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(
数字漫游
数字漫游
Lv1
可怜夜半虚前席,不问苍生问鬼神。
文章
4
粉丝
0
获赞
0