Redhat Linux 6 下实现ISCSI

来源:互联网 发布:和孩子一起学编程 官网 编辑:程序博客网 时间:2024/06/01 20:28

转载http://hi.baidu.com/ouleiq/item/25ecaad2b8beb614d80e445d

ISCSI 是利用ip进行远程磁盘访问模拟本地硬盘的一种方式。下面描述如何在一台redhat linux 6上通过模拟iscsi服务, 在客户端进行访问连接的过程。

1.服务器端
  a .安装scsi-target-utils 包

[root@weblogic2 ~]# yum install scsi-target-utils
Loaded plugins: refresh-packagekit, rhnplugin
This system is not registered with RHN.
RHN support will be disabled.
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package scsi-target-utils.i686 0:1.0.4-3.el6 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================================
 Package                              Arch                    Version                        Repository               Size
===========================================================================================================================
Installing:
 scsi-target-utils                    i686                    1.0.4-3.el6                    base                    134 k

Transaction Summary
===========================================================================================================================
Install       1 Package(s)
Upgrade       0 Package(s)

Total download size: 134 k
Installed size: 334 k
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : scsi-target-utils-1.0.4-3.el6.i686                                                                  1/1

Installed:
  scsi-target-utils.i686 0:1.0.4-3.el6                                                                                    

Complete!
 b. 准备好本地磁盘模拟存储系统提供远程访问.
    fdisk /dev/sdb
    不用格式化文件系统. linux 6 需要重启.
    

 c. 配置iscsi服务器端
[root@weblogic2 ~]# vi /etc/tgt/targets.conf
    186 <target iqn.2011-09.com.orcl:server.target6>
    187     backing-store /dev/sdb1
    188 </target>
    189

186行表示iqn号,可以随便取,但是要遵循这个格式.
187 行 表示提供iscsi服务的硬盘分区.

    150     # Only allow connections from 192.168.100.1 and 192.168.200.5
    151     initiator-address 192.168.16.200
    152     initiator-address 192.168.200.5

150 151行表示允许这两个ip的地址访问scsi磁盘.
  
   d. 把scsi服务器端的服务启动并置于自动启动
   [root@weblogic2 ~]# service tgtd start
   [root@weblogic2 ~]# chkconfig tgtd on
   [root@weblogic2 ~]# service tgtd status
   tgtd (pid 1566 1564) is running...
                
好, 服务器端配置好了, 现在配置客户端.

  e . 安装客户端软件 iscsi initiator
[root@host200 ~]# yum install -y iscsi-initiator-utils
Loaded plugins: refresh-packagekit, rhnplugin
Repository InstallMedia is listed more than once in the configuration
This system is not registered with RHN.
RHN support will be disabled.
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package iscsi-initiator-utils.i686 0:6.2.0.872-10.el6 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================================
 Package                             Arch               Version                           Repository                  Size
===========================================================================================================================
Installing:
 iscsi-initiator-utils               i686               6.2.0.872-10.el6                  InstallMedia               454 k

Transaction Summary
===========================================================================================================================
Install       1 Package(s)
Upgrade       0 Package(s)

Total download size: 454 k
Installed size: 1.6 M
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : iscsi-initiator-utils-6.2.0.872-10.el6.i686                                                         1/1

Installed:
  iscsi-initiator-utils.i686 0:6.2.0.872-10.el6                                                                           

Complete!
[root@host200 ~]#

f. 对服务器端进行扫描,发现目标
  ~]# iscsiadm -m discovery -t st -p 192.168.16.221 
192.168.16.221:3260,1 iqn.2011-09.com.orcl:server.target6
   
然后登录
[root@host200 ~]# iscsiadm -m node -T iqn.2011-09.com.orcl:server.target6 -l
Logging in to [iface: default, target: iqn.2011-09.com.orcl:server.target6, portal: 192.168.16.221,3260]
Login to [iface: default, target: iqn.2011-09.com.orcl:server.target6, portal: 192.168.16.221,3260] successful.

可以看到新加了一个200m的磁盘, 这里的sdd1就是服务器端对外提供的磁盘分区.
[root@host200 ~]# fdisk -l
Disk /dev/sdd: 213 MB, 213825024 bytes
7 heads, 59 sectors/track, 1011 cylinders
Units = cylinders of 413 * 512 = 211456 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x1bb6a108

   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1        1011      208742   83  Linux
 
格式化即可使用了
[root@host200 ~]# fdisk /dev/sdd1
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x0efac01f.
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/sdd1: 213 MB, 213751808 bytes
7 heads, 59 sectors/track, 1010 cylinders
Units = cylinders of 413 * 512 = 211456 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0efac01f

     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-1010, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1010, default 1010): 
Using default value 1010

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 22: Invalid argument.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@host200 ~]# mkfs.ext3 /dev/sdd1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
52208 inodes, 208740 blocks
10437 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
26 block groups
8192 blocks per group, 8192 fragments per group
2008 inodes per group
Superblock backups stored on blocks: 
        8193, 24577, 40961, 57345, 73729, 204801

Writing inode tables: done                            
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 35 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@host200 ~]# mount /dev/sdd1 /tt/
[root@host200 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       18G   11G  5.6G  67% /
tmpfs                 504M  260K  504M   1% /dev/shm
/dev/sda1             485M   29M  431M   7% /boot
/dev/md127p1         1004M   20M  934M   3% /acct
/dev/sr0              2.8G  2.8G     0 100% /media/RHEL_6.0 i386 Disc 1
/dev/sdd1             198M  5.8M  182M   4% /tt
[root@host200 ~]#


最后,需要把iscsi服务置于自动启动.
~]# chkconfig iscsi on
[root@host200 ~]# 
并把挂载目录写入fstab中,此时可使用先使用blkid /dev/sdd1 查到uuid号. 因为系统启动后根据挂载顺序可能使得iscsi盘不固定,可能是sdd也可能是sde. 用uuid绝对定位到该盘. 
vi /etc/fstab 添加
 UUID="e73e2954-a06a-4ba0-8742-0fb5dbaf7ca1"              /tt                     ext3     defaults       0 0

重启即可自动挂载了.

可以用service iscsci查看挂载状态.

~]# service iscsi status
iSCSI Transport Class version 2.0-870
version 2.0-872
Target: iqn.2011-09.com.orcl:server.target6
        Current Portal: 192.168.16.221:3260,1
        Persistent Portal: 192.168.16.221:3260,1
                **********
                Interface:
                **********
                Iface Name: default
                Iface Transport: tcp
                Iface Initiatorname: iqn.2011-09.com.redhat:603ce6521b60
                Iface IPaddress: 192.168.16.200
                Iface HWaddress: <empty>
                Iface Netdev: <empty>
                SID: 1
                iSCSI Connection State: LOGGED IN
                iSCSI Session State: LOGGED_IN
                Internal iscsid Session State: NO CHANGE
                ************************
                Negotiated iSCSI params:
                ************************
                HeaderDigest: None
                DataDigest: None
                MaxRecvDataSegmentLength: 262144
                MaxXmitDataSegmentLength: 8192
                FirstBurstLength: 65536
                MaxBurstLength: 262144
                ImmediateData: Yes
                InitialR2T: Yes
                MaxOutstandingR2T: 1
                ************************
                Attached SCSI devices:
                ************************
                Host Number: 2  State: running
                scsi2 Channel 00 Id 0 Lun: 0
                scsi2 Channel 00 Id 0 Lun: 1
                        Attached scsi disk sdd          State: running

 

查看iscsi 目标

[root@host200 ~]# more /var/lib/iscsi/nodes/iqn.2011-09.com.orcl\:server.target6/192.168.16.221\,3260\,1/default 
# BEGIN RECORD 2.0-872
node.name = iqn.2011-09.com.orcl:server.target6
node.tpgt = 1
node.startup = automatic
iface.iscsi_ifacename = default
iface.transport_name = tcp
node.discovery_address = 192.168.16.221
node.discovery_port = 3260
node.discovery_type = send_targets
node.session.initial_cmdsn = 0
node.session.initial_login_retry_max = 8
node.session.xmit_thread_priority = -20
node.session.cmds_max = 128
node.session.queue_depth = 32
node.session.auth.authmethod = None
node.session.timeo.replacement_timeout = 120
node.session.err_timeo.abort_timeout = 15
node.session.err_timeo.lu_reset_timeout = 30
node.session.err_timeo.tgt_reset_timeout = 30
node.session.err_timeo.host_reset_timeout = 60
node.session.iscsi.FastAbort = Yes
node.session.iscsi.InitialR2T = No
node.session.iscsi.ImmediateData = Yes
node.session.iscsi.FirstBurstLength = 262144
node.session.iscsi.MaxBurstLength = 16776192
node.session.iscsi.DefaultTime2Retain = 0
node.session.iscsi.DefaultTime2Wait = 2
node.session.iscsi.MaxConnections = 1
node.session.iscsi.MaxOutstandingR2T = 1
node.session.iscsi.ERL = 0
node.conn[0].address = 192.168.16.221
node.conn[0].port = 3260
node.conn[0].startup = manual
node.conn[0].tcp.window_size = 524288
node.conn[0].tcp.type_of_service = 0
node.conn[0].timeo.logout_timeout = 15
node.conn[0].timeo.login_timeout = 15
node.conn[0].timeo.auth_timeout = 45
node.conn[0].timeo.noop_out_interval = 5
node.conn[0].timeo.noop_out_timeout = 5
node.conn[0].iscsi.MaxXmitDataSegmentLength = 0
node.conn[0].iscsi.MaxRecvDataSegmentLength = 262144
node.conn[0].iscsi.HeaderDigest = None
node.conn[0].iscsi.IFMarker = No
node.conn[0].iscsi.OFMarker = No
# END RECORD

#oracle_unix
原创粉丝点击