slave-147作为服务端

需要安装的软件

[root@slave-147 ~]# yum install -y scsi-target-utils

slave-148和slave-149作为客户端

需要安装的软件

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

创建共享分区

[root@slave-147 ~]# fdisk /dev/sdb

Command (m for help): p

Disk /dev/sdb: 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: 0xba211077

Device Boot      Start         End      Blocks   Id  System

Command (m for help): n

Command action
    e   extended
    p   primary partition (1-4)

p

Partition number (1-4): 1

First cylinder (1-2610, default 1):

Using default value 1

Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +5G

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

同样步骤再创建sdb2.

格式化为ext4文件系统:

[root@slave-147 ~]# mkfs.ext4 /dev/sdb1

[root@slave-147 ~]# mkfs.ext4 /dev/sdb2

因为我在安装系统时,磁盘创建成了LVM,可能是这个原因,导致在这里直接改/etc/tgt/targets.conf文件不生效。

所以这里我也将新建的sdb1和sdb2创建成了LVM格式:

[root@slave-147 ~]# pvcreate /dev/sdb{1,2}
   Physical volume "/dev/sdb1" successfully created
   Physical volume "/dev/sdb2" successfully created

[root@slave-147 ~]# pvscan
   PV /dev/sdb1                      lvm2 [5.01 GiB]
   PV /dev/sdb2                      lvm2 [5.01 GiB]
   Total: 2 [10.02 GiB] / in use: 0 [0   ] / in no VG: 2 [10.02 GiB]

[root@slave-147 ~]# vgcreate vg_01 /dev/sdb{1,2}
   Volume group "vg_01" successfully created

[root@slave-147 ~]# lvcreate -L 10G vg_01
   Logical volume "lvol0" created

[root@slave-147 ~]# lvscan
   ACTIVE            '/dev/vg_01/lvol0' [10.00 GiB] inherit

[root@slave-147 ~]# lvdisplay
   --- Logical volume ---
   LV Path                /dev/vg_01/lvol0                    //地址要记住,修改targets.conf时用                                      
   LV Name                lvol0
   VG Name                vg_01
   LV UUID                BAnblY-DKHO-89bT-SoRS-daCR-E76l-XeW94v
   LV Write Access        read/write
   LV Creation host, time slave-147, 2018-03-29 13:38:44 +0800
   LV Status              available
   # open                 0
   LV Size                10.00 GiB
   Current LE             2560
   Segments               2
   Allocation             inherit
   Read ahead sectors     auto
   - currently set to     256
   Block device           253:0

[root@slave-147 ~]# vim /etc/tgt/targets.conf

#<target iqn.2008-09.com.example:server.target4>              //在此段下面添加如下内容

#    direct-store /dev/sdb      # Becomes LUN 1

#    direct-store /dev/sdc      # Becomes LUN 2

#    direct-store /dev/sdd      # Becomes LUN 3

#    write-cache off

#    vendor_id MyCompany Inc.

#</target>

<target iqn.2018-01.cn.xueji.www:target_san1>

backing-store /dev/vg_01/lvol0

initiator-address 192.168.75.148

vendor_id xueji

product_id target1

</target>

重启tgtd服务

[root@slave-147 ~]# /etc/init.d/tgtd restart

查看:

[root@slave-147 ~]# tgt-admin --show

Target 1: iqn.2018-01.cn.xueji.www:target_san1
     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: 10737 MB, Block size: 512
             Online: Yes
             Removable media: No
             Prevent removal: No
             Readonly: No
             Backing store type: rdwr
             Backing store path: /dev/vg_01/lvol0
             Backing store flags:
     Account information:
     ACL information:
         192.168.75.148

客户端:

安装ISCSI

[root@slave-148 ~]# yum install -y iscsi-initiator-utils

[root@slave-148 ~]# /etc/init.d/iscsi start                               //没有任何输出,这里需要我们发现target存储,再启动客户端服务,才会生效

[root@slave-148 ~]# iscsiadm -m discovery -t sendtargets -p 192.168.75.147:3260

Starting iscsid:                                        [  OK  ]                                                 [  OK  ]

192.168.75.147:3260,1 iqn.2018-01.cn.xueji.www:target_san1

[root@slave-148 ~]# /etc/init.d/iscsid status

iscsid (pid  2801) is running...

[root@slave-148 ~]# yum install -y tree    //用于查询目录树

[root@slave-148 ~]# tree /var/lib/iscsi/     //发现target后,会在该目录下生成树结构

/var/lib/iscsi/

├── ifaces

├── isns

├── nodes

│   └── iqn.2018-01.cn.xueji.www:target_san1

│       └── 192.168.75.147,3260,1

│           └── default

├── send_targets

│   └── 192.168.75.147,3260

│       ├── iqn.2018-01.cn.xueji.www:target_san1,192.168.75.147,3260,1,default -> /var/lib/iscsi/nodes/iqn.2018-01.cn.xueji.www:target_san1/192.168.75.147,3260,1

│       └── st_config

├── slp

└── static

10 directories, 2 files

重启服务,查看是否发现硬盘

[root@slave-148 ~]# /etc/init.d/iscsid restart

Stopping iscsid:

Starting iscsid:                                           [  OK  ]

[root@slave-148 ~]# /etc/init.d/iscsi  restart

Stopping iscsi:                                            [  OK  ]

Starting iscsi:                                            [  OK  ]

[root@slave-148 ~]# lsblk

NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT

sda      8:0    0   20G  0 disk

├─sda1   8:1    0  200M  0 part /boot

├─sda2   8:2    0    4G  0 part [SWAP]

└─sda3   8:3    0 15.8G  0 part /

sr0     11:0    1  3.6G  0 rom  /mnt/cdrom

sdb      8:16   0   10G  0 disk

使用ISCSI

[root@slave-148 ~]# fdisk /dev/sdb

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel with disk identifier 0x48b9f524.

Changes will remain in memory only, until you decide to write them.

After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
          switch off the mode (command 'c') and change display units to
          sectors (command 'u').

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes

64 heads, 32 sectors/track, 10240 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x48b9f524

Device Boot      Start         End      Blocks   Id  System

Command (m for help): n

Command action
    e   extended
    p   primary partition (1-4)

p

Partition number (1-4): 1

First cylinder (1-10240, default 1):

Using default value 1

Last cylinder, +cylinders or +size{K,M,G} (1-10240, default 10240): +1G

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

[root@slave-148 ~]# mkfs.ext4 /dev/sdb1

[root@slave-148 ~]# mkdir /sdb1

[root@slave-148 ~]# lsblk

NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT

sda      8:0    0   20G  0 disk

├─sda1   8:1    0  200M  0 part /boot

├─sda2   8:2    0    4G  0 part [SWAP]

└─sda3   8:3    0 15.8G  0 part /

sr0     11:0    1  3.6G  0 rom  /mnt/cdrom

sdb      8:16   0   10G  0 disk

└─sdb1   8:17   0    1G  0 part

[root@slave-148 ~]# mount /dev/sb1 /sdb1/

[root@slave-148 ~]# df -h

Filesystem      Size  Used Avail Use% Mounted on

/dev/sda3        16G  4.1G   11G  28% /

tmpfs           996M   72K  996M   1% /dev/shm

/dev/sda1       194M   34M  151M  19% /boot

/dev/sr0        3.6G  3.6G     0 100% /mnt/cdrom

[root@slave-148 sdb1]# touch slave-148.txt

[root@slave-148 sdb1]# ll

total 16

drwx------ 2 root root 16384 Mar 29 14:22 lost+found

-rw-r--r-- 1 root root     0 Mar 29 14:25 slave-148.txt

为了验证,我们再以同样的方式添加一台客户端

首先将slave-148上的iscsi停掉,这里要注意,必须先停掉,再去添加,否则会出错。具体原因还有待研究。

[root@slave-148 ~]# /etc/init.d/iscsi stop

Stopping iscsi:                                            [  OK  ]

在master-147上:

<target iqn.2018-01.cn.xueji.www:target_san1>

backing-store /dev/vg_01/lvol0

initiator-address 192.168.75.148

initiator-address 192.168.75.149                                                  //在原有的基础上加上这行  

vendor_id xueji

product_id target1

</target>

[root@slave-147 ~]# /etc/init.d/tgtd restart

Stopping SCSI target daemon:                               [  OK  ]

Starting SCSI target daemon:                               [  OK  ]

[root@slave-147 ~]# tgt-admin --show

Target 1: iqn.2018-01.cn.xueji.www:target_san1
     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: 10737 MB, Block size: 512
             Online: Yes
             Removable media: No
             Prevent removal: No
             Readonly: No
             Backing store type: rdwr
             Backing store path: /dev/vg_01/lvol0
             Backing store flags:
     Account information:
     ACL information:
         192.168.75.148
         192.168.75.149

在slave-149上

[root@slave-149 ~]# /etc/init.d/iscsi start

[root@slave-149 ~]# /etc/init.d/iscsid start

[root@slave-149 ~]# iscsiadm -m discovery -t sendtargets -p 192.168.75.147:3260Starting iscsid:                                           [  OK  ]

192.168.75.147:3260,1 iqn.2018-01.cn.xueji.www:target_san1

[root@slave-149 ~]# lsblk

NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT

sda      8:0    0   20G  0 disk

├─sda1   8:1    0  200M  0 part /boot

├─sda2   8:2    0    4G  0 part [SWAP]

└─sda3   8:3    0 15.8G  0 part /

sr0     11:0    1  3.6G  0 rom  /mnt/cdrom

sdb      8:16   0   10G  0 disk

└─sdb1   8:17   0    1G  0 part

使用

[root@slave-149 ~]# mkdir /sdb1

[root@slave-149 ~]# fdisk /dev/sdb

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
          switch off the mode (command 'c') and change display units to
          sectors (command 'u').

Command (m for help): n

Command action
    e   extended
    p   primary partition (1-4)

p

Partition number (1-4): 2

First cylinder (1026-10240, default 1026):

Using default value 1026

Last cylinder, +cylinders or +size{K,M,G} (1026-10240, default 10240): +1G

Command (m for help): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes

64 heads, 32 sectors/track, 10240 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x48b9f524

Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               1        1025     1049584   83  Linux

/dev/sdb2            1026        2050     1049600   83  Linux

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

[root@slave-149 ~]# mkfs.ext4 /dev/sdb2

[root@slave-149 ~]# mount /dev/sdb2 /sdb2

[root@slave-149 ~]# df -h

Filesystem      Size  Used Avail Use% Mounted on

/dev/sda3        16G  3.9G   11G  26% /

tmpfs           996M   72K  996M   1% /dev/shm

/dev/sda1       194M   34M  151M  19% /boot

/dev/sr0        3.6G  3.6G     0 100% /mnt/cdrom

/dev/sdb1      1008M   34M  924M   4% /sdb1

/dev/sdb2      1008M   34M  924M   4% /sdb2

进入到sdb1中查看

[root@slave-149 sdb1]# ll

total 16

drwx------ 2 root root 16384 Mar 29 14:57 lost+found

-rw-r--r-- 1 root root     0 Mar 29 15:02 slave-148.txt

在slave-148上面查看

[root@slave-148 ~]# iscsiadm -m discovery -t sendtargets -p 192.168.75.147:3260192.168.75.147:3260,1 iqn.2018-03.cn.xueji.www:target_san1

[root@slave-148 ~]# /etc/init.d/iscsid restart

Stopping iscsid:

Starting iscsid:                                           [  OK  ]

[root@slave-148 ~]# /etc/init.d/iscsi restart

Stopping iscsi:                                            [  OK  ]

Starting iscsi:                                            [  OK  ]

[root@slave-148 ~]# lsblk

NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT

sda      8:0    0   20G  0 disk

├─sda1   8:1    0  200M  0 part /boot

├─sda2   8:2    0    4G  0 part [SWAP]

└─sda3   8:3    0 15.8G  0 part /

sr0     11:0    1  3.6G  0 rom  /mnt/cdrom

sdb      8:16   0   10G  0 disk

├─sdb1   8:17   0    1G  0 part

└─sdb2   8:18   0    1G  0 part

到sdb1中查看

[root@slave-148 sdb1]# ll

total 16

drwx------ 2 root root 16384 Mar 29 14:57 lost+found

-rw-r--r-- 1 root root     0 Mar 29 15:02 slave-148.txt

-rw-r--r-- 1 root root     0 Mar 29 15:03 slave-149.tx

同步这块,还不是很清楚,在slave-148上创建了测试数据后,不能立刻在slave-149上查到相关数据,要重新发现,重启slave-149上的服务才可以,这点可能是我做的有问题,后面在折腾下。今天先记录到这里~

ISCSI存储的更多相关文章

  1. 有了iscsi存储怎么让主机识别以及使用创建lvm

    1.查找安装包:rpm -ivh iscsi-initiator-utils去sf.net下载iscsitarget包make kernel,usr,install开启服务 (0)查看iscsi发现记 ...

  2. 通过SCVMM分配iSCSI存储

    除了使用基于SMB3.0应用程序的文件共享外,还可以使用iSCSI目标服务器的SAN存储,然后在SCVMM控制台中添加基于SMI-S类型的存储,步骤如下: 1.将一台安装了 iSCSI目标 功能的Wi ...

  3. linux杂谈(十七):iscsi存储分离技术

    1.iscsi简单介绍 ​ ​iSCSI利用了TCP/IP的port 860 和 3260 作为沟通的渠道.透过两部计算机之间利用iSCSI的协议来交换SCSI命令,让计算机能够透过快速的局域网集线来 ...

  4. 通过Windows Server 2008 R2建立iSCSI存储

    名词解释:iSCSI技术是一种由IBM公司研究开发的,是一个供硬件设备使用的可以在IP协议的上层运行的SCSI指令集,这种指令集合可以实现在IP网络上运行 SCSI协议,使其能够在诸如高速千兆以太网上 ...

  5. iSCSI存储的3种连接方式

    我们分析了iSCSI存储的系统结构,下面来看iSCSI是如何与服务器.工作站等主机设备来连接的,也就是我们如何建立一个iSCSI网络存储系统. iSCSI设备的主机接口一般默认都是IP接口,可以直接与 ...

  6. vSphere ESXi主机配置iSCSI存储

    vSphere ESXi主机配置iSCSI存储 vSphere ESXi主机一般连接的存储类型有光纤存储.iSCSI存储两类.本次案例为iSCSI存储连接ESXi主机的配置. 案例环境:ESXi主机通 ...

  7. linux下挂载ISCSI存储设备

    安装 首先要在存储设备上做好RAID,设置好iSCSI 目标方(target). 这里主要说明iSCSI initiator的安装. 不同的操作系统对应各自的iSCSI initiator,以Redh ...

  8. Linux FC/iSCSI存储设备管理系列(一):Linux系统设备驱动入门

    Linux FC/iSCSI存储设备管理系列(一):Linux系统设备驱动入门 转载请在文首保留原文出处:EMC中文支持论坛 - https://community.emc.com/go/chines ...

  9. 基于使用ISCSI存储的ibmmq通过heartbeat实现HA方案以及碰到的问题总结

    一.背景 ibmmq是一种传统架构的mq产品,运行稳定,有其自身优点,但在高可用(HA)这一块需要使用公司根据自身需求选用高可用(HA)产品,但由于市面HA商业产品较贵,所以使用linux操作系统级的 ...

  10. 配置软ISCSI存储

    说明:这里是Linux服务综合搭建文章的一部分,本文可以作为单独使用RedHat Enterprise Linux 7搭建软ISCSI的参考. 注意:这里所有的标题都是根据主要的文章(Linux基础服 ...

随机推荐

  1. svgo

    SVG精简压缩工具svgo简介和初体验 SVG精简压缩工具svgo简介和初体验 « 张鑫旭-鑫空间-鑫生活 https://www.zhangxinxu.com/wordpress/2016/02/s ...

  2. jquery 选择器(selector)和事件(events)

    页面加载完成后开始运行do stuff when DOM is ready 中的语句! $(document).ready(function() {       // do stuff when DO ...

  3. navcat for mysql 连接远程数据库 教程

    1.首先进入数据库: mysql -uroot -p 2.然后打开数据库设置远程连接权限: mysql>GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%'ID ...

  4. HDU 5178 pairs —— 思维 + 二分

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5178 pairs Time Limit: 2000/1000 MS (Java/Others)     ...

  5. 启动vmware中的虚拟机的时候,提示Failed to lock the file

    http://www.vixual.net/blog/archives/842 VMware Server 當掉後重新啟動 Guest OS 時,出現 cannot open the disk '*. ...

  6. node安装与升级

    node安装与升级 1.安装 sudo apt-get install nodejs sudo apt-get install npm 2.升级 如果node不是最新的,node有一个模块叫n,是专门 ...

  7. JQuery树形插件Dynatree的包装对象

    这是JQuery Dynatree插件的包装对象,做了些改进和增强,增加了右键菜单,以及相应事件等扩展1. [代码]MagicDTree的基本使用 <SCRIPT type=text/javas ...

  8. solr安装-tomcat+solrCloud构建稳健solr集群

    solrCloud的搭建可以有两种方式:使用solr内嵌的jetty来搭建:使用外部web容器tomcat来搭建.对于使用jett来搭建参考solr官方的手册照着做肯定ok,下面我主要讲的是如何使用t ...

  9. codeforces 673D D. Bear and Two Paths(构造)

    题目链接: D. Bear and Two Paths time limit per test 2 seconds memory limit per test 256 megabytes input ...

  10. Dijkstra堆优化

    Dijkstra是一个非常不错的最短路算法,它使用两层循环进行枚举,通过每次更新蓝白点的方式更新最短路,时间复杂度为O(n^2),优于floyd的O(n^3),不过只能用于计算单源最短路,而且无法处理 ...