rhel6.3搭建iscsi-target伺服器實戰

來源:互聯網
上載者:User

 iSCSI技術是一種由IBM公司研究開發的,是一個供硬體裝置使用的可以在IP協議的上層啟動並執行SCSI指令集,這種指令集合可以實現在IP網路上運行SCSI協議,使其能夠在諸如高速千兆乙太網路上進行路由選擇。iSCSI的最大好處是能提供快速的網路環境,雖然其效能和頻寬跟光纖網路還有一些差距,但能節省企業約30-40%的成本。

  下面我們來看一下在RHEL6.3上如何搭建iscsi-target伺服器和用戶端如何掛載.

 一、服務端操作

服務端版本:

[root@racscsi home]# uname  -r

2.6.32-279.el6.x86_64

[root@racscsi home]# cat /etc/redhat-release

Red Hat Enterprise Linux Server release 6.3 (Santiago)

安裝iscsi server軟體包。

用RPM的方式安裝。

[root@racscsi home]# rpm -ivh scsi-target-utils-1.0.24-2.el6.x86_64.rpm

warning: scsi-target-utils-1.0.24-2.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY

Preparing...                ########################################### [100%]

package scsi-target-utils-1.0.24-2.el6.x86_64 is already installed

用yum命令安裝需自己配置YUM源)

[root@racscsi home]#yum -y install scsi-target-utils

啟動服務並且添加到開機自啟動。

[root@racscsi home]# /etc/init.d/tgtd start

Starting SCSI target daemon: [ OK ]

[root@racscsi home]# chkconfig tgtd on


使用fdisk命令建立幾個分區,或者通過外部儲存映射共用分區。

現在這台伺服器已劃分好/dev/sdb、 /dev/sdc、 /dev/sdd、 /dev/sde、 /dev/sdf、 /dev/sdg 、/dev/sdh、/dev/sdi分區,用於用戶端的掛載

下面我們需要編輯設定檔/etc/tgt/targets.conf,並設定下iSCSI Qualified Name (IQN).

[root@racscsi home]#vim /etc/tgt/ targets.conf

在檔案末尾添加如下內容

<target iqn.2008-09.com.example:asm>  #iqn名字可任意

   backing-store /dev/sdb                

   backing-store /dev/sdc

   backing-store /dev/sdd

   backing-store /dev/sde

   backing-store /dev/sdf    

   backing-store /dev/sdg

   backing-store /dev/sdh

   backing-store /dev/sdi  

   initiator-address 192.168.10.0/24   #限定允許訪問的用戶端位址區段或具體IP

   write-cache off                     #是否開啟或關閉快取

</target>

重啟服務,使修改後的配置生效。

[root@racscsi home]#/etc/init.d/tgtd restart

確定iscsi server是否成功。如果顯示如下說明配置iscsi server已經成功。

[root@racscsi home]# tgt-admin --show

Target 1: iqn.2008-09.com.example:asm

   System information:

       Driver: iscsi

       State: ready

   I_T nexus information:

       I_T nexus: 1

           Initiator: iqn.1994-05.com.redhat:b363811441a

           Connection: 0

               IP Address: 192.168.10.212

   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: 2147 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: 8

           Type: disk

           SCSI ID: IET     00010008

           SCSI SN: beaf18

           Size: 5369 MB, Block size: 512

           Online: Yes

           Removable media: No

           Prevent removal: No

           Readonly: No

           Backing store type: rdwr

           Backing store path: /dev/sdi

           Backing store flags:

   Account information:

   ACL information:

       192.168.10.0/24

注意:關閉服務端的IPTABLES,以免用戶端無法正常訪問


二、用戶端掛載

用戶端需安裝的包iscsi-initiator-utils

[root@rac2 home]# rpm -ivh iscsi-initiator-utils-6.2.0.872-41.el6.x86_64.rpm

warning: iscsi-initiator-utils-6.2.0.872-41.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY

Preparing...                ########################################### [100%]

  1:iscsi-initiator-utils  ########################################### [100%]

用yum命令安裝需自己配置YUM源)

[root@rac2 home]#yum -y install iscsi-initiator-utils


啟動服務並且添加到開機啟動。

[root@rac2 Desktop]# /etc/init.d/iscsid start

[root@rac2 Desktop]# chkconfig iscsid on


探索服務器端iscsi server的共用分區。

[root@rac2 Desktop]# iscsiadm --mode discovery --type sendtargets --portal 192.168.10.220

192.168.10.220:3260,1 iqn.2008-09.com.example:asm

已發現


登陸到iscsi server共用的分區。

[root@rac2 Desktop]# iscsiadm -m node -T iqn.2008-09.com.example:asm -p 192.168.10.220 -l

Logging in to [iface: default, target: iqn.2008-09.com.example:asm, portal: 192.168.10.220,3260] (multiple)

Login to [iface: default, target: iqn.2008-09.com.example:asm, portal: 192.168.10.220,3260] successful.


再使用fdisk -l命令查看分區,發現共用出來的分區都已經掛過來了。

[root@rac2 Desktop]# 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: 0x000586f0


  Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          39      307200   83  Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2              39         549     4096000   82  Linux swap / Solaris

Partition 2 does not end on cylinder boundary.

/dev/sda3             549        2611    16567296   83  Linux


Disk /dev/sdb: 2147 MB, 2147483648 bytes

67 heads, 62 sectors/track, 1009 cylinders

Units = cylinders of 4154 * 512 = 2126848 bytes

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

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

Disk identifier: 0x00000000



Disk /dev/sdc: 2147 MB, 2147483648 bytes

67 heads, 62 sectors/track, 1009 cylinders

Units = cylinders of 4154 * 512 = 2126848 bytes

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

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

Disk identifier: 0x00000000



Disk /dev/sdd: 2147 MB, 2147483648 bytes

67 heads, 62 sectors/track, 1009 cylinders

Units = cylinders of 4154 * 512 = 2126848 bytes

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

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

Disk identifier: 0x00000000



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



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



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



Disk /dev/sdh: 5368 MB, 5368709120 bytes

166 heads, 62 sectors/track, 1018 cylinders

Units = cylinders of 10292 * 512 = 5269504 bytes

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

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

Disk identifier: 0x00000000



Disk /dev/sdi: 5368 MB, 5368709120 bytes

166 heads, 62 sectors/track, 1018 cylinders

Units = cylinders of 10292 * 512 = 5269504 bytes

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

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

Disk identifier: 0x00000000


最後你可以格式化分區,掛載在本地相應目錄。如果要實現開機自動掛載,要在fstab檔案添加記錄。

注意添加_netdev參數,要不你在重啟iscsi server後,啟動時會報錯。

樣本: /dev/sdb /crs  ext4  default,_netdev 0 0


補充:

如果在服務端/etc/tgt/targets.conf檔案配置了使用者名稱密碼,比如

<target iqn.2008-09.com.example:server.target3>

     backing-store  /dev/sdb

     initiator-address 192.168.10.0/24    

     incoming grid  123@passwd          

     write-cacheoff              

</target>


則在用戶端/etc/iscsi/iscsid.conf設定檔

需要添加相應的帳號和密碼

node.session.auth.username = grid

node.session.auth.password = 123@passwd

discovery.sendtargets.auth.username = grid

discovery.sendtargets.auth.password = 123@passwd


本文出自 “滴水穿石” 部落格,請務必保留此出處http://xjsunjie.blog.51cto.com/999372/1280283

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.