Centos6.4系统存储服务器之ISCSI

     iSCSI技术是一种由IBM公司研究开发的,是一个供硬件设备使用的可以在IP协议的上层运行的SCSI指令集,这种指令集合可以实现在IP网络上运行SCSI协议,使其能够在诸如高速千兆以太网上进行路由选择。iSCSI技术是一种新储存技术,该技术是将现有SCSI接口与以太网络(Ethernet)技术结合,使服务器可与使用IP网络的储存装置互相交换资料。

 

1.安装iscsi服务软件和添加一块共享硬盘

[[email protected] ~]# yum install scsi-target-utils    --安装软件
[[email protected] ~]# sfdisk -l /dev/sdb   --新添加的磁盘
Disk /dev/sdb: 66 cylinders, 255 heads, 63 sectors/track
[[email protected] ~]#

 

2.服务器端修改配置文件

[[email protected] ~]# vim /etc/tgt/targets.conf    --修改配置文件,添加以下行
<target iqn.2014-01.node1:server.target4>  --2014-01是日期,node1是计算机名,server.target4随意写
direct-store /dev/sdb    --要共享的硬盘,也可以是分区,块设备
write-cache off   --不写入缓存
initiator-address 2.2.2.0/24   --允许哪个网段访问
</target>
[[email protected] ~]# /etc/init.d/tgtd  restart
Stopping SCSI target daemon:                               [  OK  ]
Starting SCSI target daemon:                               [  OK  ]
[[email protected] ~]# netstat -lutnp |grep 3260
tcp        0      0 0.0.0.0:3260                0.0.0.0:*                   LISTEN      1962/tgtd
tcp        0      0 :::3260                     :::*                        LISTEN      1962/tgtd
[[email protected] ~]# tgt-admin --show | grep Target    --查看到共享有一个存储
Target 1: iqn.2014-01.node1:server.target4
[[email protected] ~]# iptables -I INPUT -p tcp -s 2.2.2.0/24 --dport 3260 -j ACCEPT   --放行包过滤

 

3.客户端是Windows系统

(1)下载windows系统iSCSI客户端工具,并安装

http://zj.ouyaoxiazai.com:89/xiazaidian/MicrosoftweiruaniSCSIkehuduangongju.exe

(2)安装完后打开界面添

Centos6.4系统存储服务器之ISCSI

(3)写入服务器的IP地址

Centos6.4系统存储服务器之ISCSI

(4)查看服务器共享的磁盘,如果没有请检查其它地方是否有错

Centos6.4系统存储服务器之ISCSI

(5)登陆服务器的scsi服务

Centos6.4系统存储服务器之ISCSI

(6)在windows系统中可以看到新的磁盘了,在中途需要安装驱动就下一步安装,也要格式化新的磁盘

Centos6.4系统存储服务器之ISCSI

(7)在我的电脑中可以看到分区了

Centos6.4系统存储服务器之ISCSI

 

4.客户端是Linux系统

[[email protected] ~]# yum install iscsi-target-utils    --安装客户端软件
[[email protected] ~]# /etc/init.d/iscsid start   --启动服务
[[email protected] ~]# /etc/init.d/iscsi start    --启动服务
[[email protected] ~]# iscsiadm -m discovery -t sendtargets -p 2.2.2.27:3260   --查找服务器的共享磁盘
2.2.2.27:3260,1 iqn.2014-01.node1:server.target4
[[email protected] ~]# iscsiadm -m node -T iqn.2014-01.node1:server.target4 --login  --登陆服务器
Logging in to [iface: default, target: iqn.2014-01.node1:server.target4, portal: 2.2.2.27,3260] (multiple)
Login to [iface: default, target: iqn.2014-01.node1:server.target4, portal: 2.2.2.27,3260] successful.
[[email protected] ~]# fdisk -l /dev/sdb      --查看磁盘
Disk /dev/sdb: 546 MB, 546308096 bytes
255 heads, 63 sectors/track, 66 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: 0x5ce268ef
Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               2          66      522112+   5  Extended
/dev/sdb5               2          66      522081    7  HPFS/NTFS
[[email protected] ~]# mkfs.ext4 /dev/sdb    --格式化磁盘
mke2fs 1.41.12 (17-May-2010)
/dev/sdb is entire device, not just one partition!
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
33360 inodes, 133376 blocks
6668 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=138412032
5 block groups
32768 blocks per group, 32768 fragments per group
6672 inodes per group
Superblock backups stored on blocks:
32768, 98304
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 37 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[[email protected] ~]# mount /dev/sdb /mnt/     --挂载目录
[[email protected] ~]# df -TH
Filesystem    Type     Size   Used  Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
ext4      20G   833M    19G   5% /
tmpfs        tmpfs     262M      0   262M   0% /dev/shm
/dev/sda1     ext4     508M    32M   451M   7% /boot
/dev/sr0   iso9660     538M    18M   494M   4% /mnt
/dev/sdb      ext4     538M    18M   494M   4% /mnt
[[email protected] ~]# ll /mnt/     --查看文件
total 16
drwx------. 2 root root 16384 Jan 16 13:55 lost+found
[[email protected] ~]#

 

5.注销iscsi连接和退出

[[email protected] ~]# iscsiadm -m node -o delete -T iqn.2014-01.node1:server.target4    --注销连接
iscsiadm: This command will remove the record [iface: default, target: iqn.2014-01.node1:server.target4, portal: 2.2.2.27,3260], but a session is using it. Logout session then rerun command to remove record.
iscsiadm: Could not execute operation on all records: session exists
[[email protected] ~]# iscsiadm -m node -U all   --断开所有连接
Logging out of session [sid: 1, target: iqn.2014-01.node1:server.target4, portal: 2.2.2.27,3260]
Logout of [sid: 1, target: iqn.2014-01.node1:server.target4, portal: 2.2.2.27,3260] successful.
[[email protected] ~]# sfdisk -l     --没有那个磁盘了
Disk /dev/sda: 2652 cylinders, 255 heads, 63 sectors/track
Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0
Device Boot Start     End   #cyls    #blocks   Id  System
/dev/sda1   *      0+     63-     64-    512000   83  Linux
/dev/sda2         63+   2652-   2589-  20794368   8e  Linux LVM
/dev/sda3          0       -       0          0    0  Empty
/dev/sda4          0       -       0          0    0  Empty
Disk /dev/mapper/VolGroup-lv_root: 2457 cylinders, 255 heads, 63 sectors/track
Disk /dev/mapper/VolGroup-lv_swap: 130 cylinders, 255 heads, 63 sectors/track
[[email protected] ~]#










本文转自 z597011036 51CTO博客,原文链接:http://blog.51cto.com/tongcheng/1352211,如需转载请自行联系原作者