34补3-2 Linux系统上IP SAN的实现

02Linux系统上IP SAN的实现

配置环境

node1:192.168.1.151CentOS6.5

node2:192.168.1.152CentOS6.5

node3:192.168.1.153CentOS6.5#服务端:node3添加两块20G磁盘

配置iSCSI target(服务端)

1、准备硬盘

在node3上添加两块20磁盘

2、安装程序包,启动服务

[[email protected] ~]# yum -y install scsi-target-utils

[[email protected] ~]# service tgtd start

[[email protected] ~]# chkconfig tgtd on

3、创建target

方法1:命令行

创建iscsi target

[[email protected] ~]# tgtadm --lld iscsi --mode target --op new --tid 1 --targetname iqn.2015-06.com.magedu:s1.t1

查看当前主机上的iscsi target

[[email protected] ~]# tgtadm --lld iscsi --mode target --op show

Target 1: iqn.2015-06.com.magedu:s1.t1

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:配置文件方式

[[email protected] ~]# cd /etc/tgt/

[[email protected] tgt]# cp targets.conf{,.bak}

[[email protected] tgt]# vim targets.conf

添加

<target iqn.2015-06.com.magedu:s2.t1>

backing-store /dev/sdb

backing-store /dev/sdc

initiator-address 192.168.1.0/24

</target>

[[email protected] tgt]# service tgtd restart

[[email protected] tgt]# tgtadm -L iscsi -m target -o show

Target 1: iqn.2015-06.com.magedu:s2.t1

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: 21475 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: 

LUN: 2

Type: disk

SCSI ID: IET     00010002

SCSI SN: beaf12

Size: 21475 MB, Block size: 512

Online: Yes

Removable media: No

Prevent removal: No

Readonly: No

Backing store type: rdwr

Backing store path: /dev/sdc

Backing store flags: 

Account information:

ACL information:

192.168.1.0/24

4、创建lun

[[email protected] ~]# tgtadm --lld iscsi --mode logicalunit --op new --tid 1 --lun 1 --backing-store /dev/sdb

[[email protected] ~]# tgtadm --lld iscsi --mode target --op show

Target 1: iqn.2015-06.com.magedu:s1.t1

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: 21475 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:

[[email protected] ~]# tgtadm --lld iscsi --mode logicalunit --op new --tid 1 --lun 2 --backing-store /dev/sdc

[[email protected] ~]# tgtadm --lld iscsi --mode target --op show

Target 1: iqn.2015-06.com.magedu:s1.t1

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: 21475 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: 

LUN: 2

Type: disk

SCSI ID: IET     00010002

SCSI SN: beaf12

Size: 21475 MB, Block size: 512

Online: Yes

Removable media: No

Prevent removal: No

Readonly: No

Backing store type: rdwr

Backing store path: /dev/sdc

Backing store flags: 

Account information:

ACL information:

删除lun

[[email protected] ~]# tgtadm --lld iscsi --mode logicalunit --op delete --tid 1 --lun 2

[[email protected] ~]# tgtadm --lld iscsi --mode target --op show                       

Target 1: iqn.2015-06.com.magedu:s1.t1

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: 21475 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:

[[email protected] ~]# tgtadm --lld iscsi --mode logicalunit --op new --tid 1 --lun 2 --backing-store /dev/sdc

5、授权

(1)通常IP地址认证

[[email protected] ~]# tgtadm --lld iscsi --mode target --op bind --tid 1 --initiator-address 192.168.1.0/24

(2)通过账号认证

#创建用户账号

[[email protected] ~]# tgtadm -L iscsi -m account -o new --user obama --password obama

#绑定用户账号

[[email protected] ~]# tgtadm -L iscsi -m account -o bind --tid 1 --user obama

#解绑用户账号

[[email protected] ~]# tgtadm -L iscsi -m account -o unbind --tid 1 --user obama

#查看用户账号

[[email protected] ~]# tgtadm -L iscsi -m account -o show

[[email protected] ~]# vim /etc/iscsi/iscsid.conf 

去掉

60 #node.session.auth.username = username

61 #node.session.auth.password = password

74 #discovery.sendtargets.auth.username = username

75 #discovery.sendtargets.auth.password = password

行首的#号

配置iSCSI initiator(客户端)

1、安装程序包,配置initiator的名字,并启动服务

[[email protected] ~]# yum -y install iscsi-initiator-utils

[[email protected] ~]# service iscsi start

[[email protected] ~]# service iscsid start

[[email protected] ~]# echo "InitiatorName=$(iscsi-iname -p iqn.2015-06.com.magedu)" > /etc/iscsi/initiatorname.iscsi

[[email protected] ~]# for i in iscsi iscsid;do service $i restart;done

2、使用iscsiadm实现target的发现,注册等

(1)发现模式:discovery

[[email protected] ~]# iscsiadm -m discovery -d 3 -t st -p 192.168.1.153:3260

iscsiadm: ip 192.168.1.153, port 3260, tgpt -1

iscsiadm: Max file limits 1024 4096

Starting iscsid:                                           [  OK  ]

iscsiadm: Could not open /var/lib/iscsi/send_targets/192.168.1.153,3260: No such file or directory

iscsiadm: starting sendtargets discovery, address 192.168.1.153:3260, 

iscsiadm: connecting to 192.168.1.153:3260

iscsiadm: connected local port 58181 to 192.168.1.153:3260

iscsiadm: connected to discovery address 192.168.1.153

iscsiadm: login response status 0000

iscsiadm: discovery process to 192.168.1.153:3260 exiting

iscsiadm: disconnecting conn 0xd87ce8, fd 3

192.168.1.153:3260,1 iqn.2015-06.com.magedu:s1.t1

[[email protected] ~]# ls /var/lib/iscsi/send_targets/

192.168.1.153,3260

[[email protected] ~]# ls /var/lib/iscsi/send_targets/192.168.1.153,3260/

iqn.2015-06.com.magedu:s1.t1,192.168.1.153,3260,1,default  st_config

(2)节点模式:node#登录

登录target

[[email protected] ~]# iscsiadm -m node -d 1 -T iqn.2015-06.com.magedu:s1.t1 -p 192.168.1.153:3260 -l

Logging in to [iface: default, target: iqn.2015-06.com.magedu:s1.t1, portal: 192.168.1.153,3260] (multiple)

Login to [iface: default, target: iqn.2015-06.com.magedu:s1.t1, portal: 192.168.1.153,3260] successful.

登出target

[[email protected] ~]# iscsiadm -m node -d 1 -T iqn.2015-06.com.magedu:s1.t1 -p 192.168.1.153:3260 -u

Logging out of session [sid: 1, target: iqn.2015-06.com.magedu:s1.t1, portal: 192.168.1.153,3260]

Logout of [sid: 1, target: iqn.2015-06.com.magedu:s1.t1, portal: 192.168.1.153,3260] successful.

删除target

[[email protected] ~]# iscsiadm -m node -d 1 -T iqn.2015-06.com.magedu:s1.t1 -p 192.168.1.153:3260 -o delete#需要先登出target

[[email protected] ~]# ls /var/lib/iscsi/send_targets/192.168.1.153,3260/

st_config

[[email protected] ~]# iscsiadm -m discovery -d 3 -t st -p 192.168.1.153:3260  

[[email protected] ~]# iscsiadm -m node -d 1 -T iqn.2015-06.com.magedu:s1.t1 -p 192.168.1.153:3260 -l

[[email protected] ~]# fdisk -l /dev/sd[a-z]

Disk /dev/sda: 214.7 GB, 214748364800 bytes

255 heads, 63 sectors/track, 26108 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: 0x000284a7

  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        5248    41943040   83  Linux

/dev/sda3            5248        5509     2097152   82  Linux swap / Solaris

Disk /dev/sdb: 21.5 GB, 21474836480 bytes

64 heads, 32 sectors/track, 20480 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: 0x00000000

Disk /dev/sdc: 21.5 GB, 21474836480 bytes

64 heads, 32 sectors/track, 20480 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: 0x00000000

[[email protected] ~]# 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 0x27fc8101.

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): n

Command action

  e   extended

  p   primary partition (1-4)

p

Partition number (1-4): 1

First cylinder (1-20480, default 1): 

Using default value 1

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

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

[[email protected] ~]# mke2fs -t ext4 /dev/sdb1

[[email protected] ~]# mount /dev/sdb1 /mnt

[[email protected] ~]# cd /mnt/

[[email protected] ~]# fdisk -l /dev/sd[a-z]

Disk /dev/sda: 214.7 GB, 214748364800 bytes

255 heads, 63 sectors/track, 26108 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: 0x000284a7

  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        5248    41943040   83  Linux

/dev/sda3            5248        5509     2097152   82  Linux swap / Solaris

Disk /dev/sdb: 21.5 GB, 21474836480 bytes

64 heads, 32 sectors/track, 20480 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: 0x27fc8101

  Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               1        5121     5243888   83  Linux

Disk /dev/sdc: 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: 0x00000000

[[email protected] mnt]# cp /etc/issue /mnt/

[[email protected] mnt]# vim /mnt/issue

new line

node2安装配置iSCSI initiator

[[email protected] ~]# yum -y install iscsi-initiator-utils

[[email protected] ~]# echo "InitiatorName=$(iscsi-iname -p iqn.2015-06.com.magedu.com)" > /etc/iscsi/initiatorname.iscsi

[[email protected] ~]# service iscsi start

[[email protected] ~]# service iscsid start

[[email protected] ~]# iscsiadm -m discovery -t st -p 192.168.1.153:3260

Starting iscsid:                                           [  OK  ]

192.168.1.153:3260,1 iqn.2015-06.com.magedu:s1.t1

[[email protected] ~]# iscsiadm -m node -T iqn.2015-06.com.magedu:s1.t1 -p 192.168.1.153:3260 -l

[[email protected] ~]# fdisk -l /dev/sd[a-z]

Disk /dev/sda: 214.7 GB, 214748364800 bytes

255 heads, 63 sectors/track, 26108 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: 0x000284a7

  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        5248    41943040   83  Linux

/dev/sda3            5248        5509     2097152   82  Linux swap / Solaris

Disk /dev/sdb: 21.5 GB, 21474836480 bytes

64 heads, 32 sectors/track, 20480 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: 0x27fc8101

  Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               1        5121     5243888   83  Linux

Disk /dev/sdc: 21.5 GB, 21474836480 bytes

64 heads, 32 sectors/track, 20480 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: 0x00000000

[[email protected] ~]# mount /dev/sdb1 /mnt/

[[email protected] ~]# ls /mnt/

issue  lost+found

issue  lost+found

[[email protected] ~]# cat /mnt/issue 

CentOS release 6.5 (Final)

Kernel \r on an \m

new line

#和node1上添加后的内容一致

[[email protected] ~]# vim /mnt/issue

删除node1添加的new line行

[[email protected] mnt]# cat /mnt/issue 

CentOS release 6.5 (Final)

Kernel \r on an \m

new line

#node1上issue显示的还是原来的结果

[[email protected] ~]# umount /mnt

[[email protected] ~]# umount /mnt

解除绑定

1、客户端

#登出

[[email protected] ~]# iscsiadm -m node -d 1 -T iqn.2015-06.com.magedu:s1.t1 -p 192.168.1.153:3260 -uLogging out of session [sid: 3, target: iqn.2015-06.com.magedu:s1.t1, portal: 192.168.1.153,3260]

Logout of [sid: 3, target: iqn.2015-06.com.magedu:s1.t1, portal: 192.168.1.153,3260] successful.

#删除

[[email protected] ~]# iscsiadm -m node -d 1 -T iqn.2015-06.com.magedu:s1.t1 -p 192.168.1.153:3260 -o delete

[[email protected] ~]# iscsiadm -m node -d 1 -T iqn.2015-06.com.magedu:s1.t1 -p 192.168.1.153:3260 -u

Logging out of session [sid: 1, target: iqn.2015-06.com.magedu:s1.t1, portal: 192.168.1.153,3260]

Logout of [sid: 1, target: iqn.2015-06.com.magedu:s1.t1, portal: 192.168.1.153,3260] successful.

[[email protected] ~]# iscsiadm -m node -d 1 -T iqn.2015-06.com.magedu:s1.t1 -p 192.168.1.153:3260 -o delete

2、服务端

#删除lun

[[email protected] ~]# tgtadm -L iscsi -m logicalunit -o delete -t 1 -l 2

[[email protected] ~]# tgtadm -L iscsi -m logicalunit -o delete -t 1 -l 1

删除target

[[email protected] ~]# tgtadm -L iscsi -m target -o delete -t 1

[[email protected] ~]# tgtadm -L iscsi -m target -o show

[[email protected] ~]# iscsiadm -m discovery -t st -p 192.168.1.153:3260

[[email protected] ~]# iscsiadm -m node -T iqn.2015-06.com.magedu:s2.t1 -p 192.168.1.153:3260 -l

[[email protected] ~]# fdisk -l /dev/sd[a-z]

时间: 2024-11-04 12:05:11

34补3-2 Linux系统上IP SAN的实现的相关文章

linux系统上IP SAN的实现

一.几种流行的存储技术 1.NAS(Network Attached Storage,网络附加存储)基于标准网络协议实现数据传输,为网络中的各种不同操作系统的计算机提供文件共享和数据备份,NAS采用的是File Protocal存取方式:实现方案如nfs: 2.DAS(Direct Attached Storage,直接附加存储)是指将存储设备通过总线(SCSI.PCI.IDE等)接口直接连接到一台服务器上使用,是最流行的存储方式. 缺点: 服务器本身容易成为系统瓶颈: 服务器发生故障,数据不可

用shell脚本实现linux系统上wifi模式(STA和soft AP)的转换

转载请注明出处:http://blog.csdn.net/hellomxj1/ 功能:在linux系统上实现wifi STA与AP功能的转换 实现成果:1.添加wifi密码账户add_wifi_account: 2.wifi两种模式启动的脚本wifi_start: 3.帮助信息README_WIFI_START: 具体实现过程如下: 添加wifi密码账户add_wifi_account 1 #!/bin/sh 2 3 echo "Add Wifi Account ..." 4 5 if

Linux系统上命令的使用格式

简述: 在学习Linux系统时,必不可少的要接触命令的使用方法和格式,下面通过详细介绍ifconfig.echo.tty.startx.export.pwd.history.shutdown.poweroff.reboot.hwclock.date等Linux常用命令的使用方法,来了解Linux系统上命令的使用格式. 正文: Linux系统命令使用格式: #COMMAND  [OPTIONS...]  [ARGUMENTS...] COMMAND :命令:一个可执行的二进制程序文件 OPTION

Linux系统上的特殊权限SUID,SGID,STICKY以及额外权限管理工具facl命令

Linux系统上的特殊权限 特殊权限:SUID, SGID, STICKY 安全上下文: 1.进程以某用户的身份运行:进程是发起此进程用户的代理,因此以此用户的身份和权限完成所有操作: 2.权限匹配模型: (1) 判断进程的属主,是否为被访问的文件属主:如果是,则应用属主的权限:否则进入第2步: (2) 判断进程的属主,是否属于被访问的文件属组:如果是,则应用属组的权限:否则进入第3步: (3) 应用other的权限: SUID: 默认情况下:用户发起的进程,进程的属主是其发起者:因此,其以发起

[翻译]现代Linux系统上的栈溢出攻击【转】

转自:http://www.codeweblog.com/%E7%BF%BB%E8%AF%91-%E7%8E%B0%E4%BB%A3linux%E7%B3%BB%E7%BB%9F%E4%B8%8A%E7%9A%84%E6%A0%88%E6%BA%A2%E5%87%BA%E6%94%BB%E5%87%BB/ 现代Linux系统上的栈溢出攻击 2012.12.21 - 06:56 — jip 预备知识: 对C语言和 X86_64 汇编语言有基本的了解 ++++++++++++++++++++++++

Linux系统上的网络配置

本篇我们介绍一下Linux的网络配置命令,既然学习Linux网络配置是我们必须学习,而且还要学习好的一项技能,下面我会大致介绍一下ifcg命令家族,ip命令家族,nmcli命令以及配置文件等方式进行简单概述. ifcg: ifconfig命令:此钟命令是最简单也是入门容易的命令 ifconfig查看所有网络接口信息,也可以指明单独看哪个设备 添加格式: ifconfig INTERFACE IP/MASK [up|down] 演示: 我们只有一块网卡接口为eth0,可以看到ip地址为10.0.0

Linux系统上静态配置路由表

手动指定路由出口,指向特定的下一路由或网关,静态路由是指由用户或网络管理员手工配置的路由信息.当网络的拓扑结构或链路的状态发生变化时,网络管理员需要手工去修改路由表中相关的静态路由信息.静态路由信息在缺省情况下是私有的,不会传递给其他的路由器.当然,网管员也可以通过对路由器进行设置使之成为共享的.静态路由一般适用于比较简单的网络环境,在这样的环境中,网络管理员易于清楚地了解网络的拓扑结构,便于设置正确的路由信息. 下面我们来做一个小实验,简单演示一下在Linux系统上如何静态配置路由表 实验开始

在linux系统上安装python,django,xftp

在Linux系统上安装python,django,xftp安装Python3.5.6详细文档!!!! 1.安装相关依赖库(工具包) yum install gcc patch libffi-devel python-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel -y 2

linux系统上安装paramiko模块

Linux系统上安装paramiko模块要求python要是2.7以上的,所以在安装模块之前应该安装python2.7(这里的安装过程略去) 在安装setuptools的时候突然报错了,RuntimeError:Compression requires the (missing) zlib module原因是因为没有安装zilb和zlib-devel包. yum install zlib yum installzlib-devel 安装完成后,重新编译 python2.7[不需要删除,只需要重新