现在的位置: 首页 > 综合 > 正文

Software iSCSI Target / Initiator 操作備忘

2013年09月22日 ⁄ 综合 ⁄ 共 3443字 ⁄ 字号 评论关闭
  • 在 Fedora 9 建立 iSCSI Target (server)
  • Ubuntu 8.10 系統下的 iSCSI Initiator (client) 操作
  • iSCSI Target 權限設置
  • iSCSI Initiator: Ubuntu 開機自動掛載 iSCSI 硬碟
  • 附錄: WinXP iSCSI Software Initiator 操作備忘

建立 iSCSI Target (server)

環境:

  • Fedora 9 x86_64
  • Hostname: example
  • IP Address: 192.168.1.1

yum install scsi-target-utils

chkconfig tgtd on

/etc/init.d/tgtd start

建立 10GB 虛擬磁碟, 但不分配實際空間
dd if=/dev/zero of=/test.img bs=1 seek=10G count=0

將剛剛建立的 10GB 虛擬磁碟空間設置成為 test 這個 iSCSI target
tgt-setup-lun -d /test.img -n test

另一種設立方法 (正規)
tgtadm --mode target --op new --tid 1 -T iqn.2009-04.com.example-test
tgtadm --mode logicalunit --op new --tid 1 --lun 1 -b /test.img
tgtadm --mode target --op bind --tid 1 -I ALL

ref: Maarten Lippmann - dd examples
,
/usr/share/doc/scsi-target-utils-0.0/*

ps. 若要開機自動產生 iSCSI target, 將 tgt-setup-lun 或 tgtadm 步驟寫入 rc.local 即可

iSCSI Initiator (client) 基本操作

環境:

  • Ubuntu 8.10
  • open-iscsi 2.0-870.3 (source installation)

安裝 open-iscsi 套件

Download open-iscsi tar-ball source from
official site

sudo su -

cd /path/to/open-iscsi-src

make KSRC=/usr/src/linux-headers-$(uname -r)

make install

掛載 iSCSI 硬碟

/etc/init.d/open-iscsi start

iscsiadm -m discovery -t sendtargets -p 192.168.1.1

列出所有 target
iscsiadm -m node

登入所有 target
iscsiadm -m node -L all

登入指定 target
iscsiadm -m node -T iqn.2001-04.com.example-test -p 192.168.1.1
--login

查看目前 iSCSI target 連線狀態
iscsiadm -m session

tcp: [1] 192.168.1.1:3260,1 iqn.2001-04.com.example-test

查看硬碟代號
dmesg | tail

第一次使用 dd 建立的虛擬磁碟須進行格式化
fdisk /dev/sdb
mke2fs -j /dev/sdb1

mount /dev/sdb1 /mnt

卸載 iSCSI 硬碟

umount /mnt

登出所有 target
iscsiadm -m node -U all

登出指定 target
iscsiadm -m node -T iqn.2001-04.com.example-test -p 192.168.1.1
--logout

查看目前連線狀況
iscsiadm -m session

iscsiadm: No active sessions. (目前已沒有連線
iSCSI target)

刪除所有 node 資訊 (需重新 discovery)
iscsiadm -m node --op delete

iSCSI Target 權限設置

啟用 CHAP 帳號密碼驗證

建立帳號密碼
tgtadm --mode account --op new --user test --password your_secret

檢視 target 資訊
tgtadm --mode target --op show

Target 1:
iqn.2001-04.com.example-test (Target 1 == --tid
1)
    System information:
        Driver: iscsi
        State: ready
    I_T nexus information:
    LUN information:
        LUN: 0
            Type:
controller
            ...
        LUN: 1 (LUN 1 == --lun 1, disk 從 1 開始)
            Type: disk
            ...
            Backing
store: /path/to/disk.img
    Account information:
    ACL information:
        ALL

指定 target 1 的 login 帳號 (*註)
tgtadm --mode account --op bind --tid 1 --user test

*註:
scsi-target-utils-0.0-5.20080805snap.fc9.x86_64、scsi-target-utils-0.0-6.20080805snap.fc10.i386
實驗結果, 不管 target 綁定 (bind) 哪個帳號, initiator 都可以利用 tgtadm 所建立的任一個帳號來 login

設定 ACL information

限制只有 LAN IP 能使用 target 1 (最後一個參數是大寫的 i )
tgtadm --mode target --op bind --tid 1 -I 192.168.1.0/24

unbind 已存在的 ACL information
tgtadm --mode target --op unbind --tid 1 -I ALL

iSCSI Initiator: Ubuntu 開機自動掛載 iSCSI 硬碟

sudo su -

apt-get install sysv-rc-conf

sysv-rc-conf open-iscsi

sysv-rc-conf --level 2 open-iscsi on

vi /etc/iscsi/iscsid.conf

node.startup = automatic

#node.startup = manual

如果 target 有 CHAP auth 的話:

node.session.auth.authmethod = CHAP
node.session.auth.username = username
node.session.auth.password = password

vi /etc/fstab

/dev/sdb1    /mnt    ext3   
defaults,noatime    0 0

/etc/init.d/open-iscsi start

iscsiadm -m discovery -t sendtargets -p 192.168.1.1

iscsiadm -m node -L all

/etc/init.d/open-iscsi restart

ps. 移除 service: update-rc.d -f open-iscsi remove


附錄: WinXP iSCSI Software Initiator 操作備忘

(Vista、Windows 7 均已內建 iSCSI Software Initiator)

安裝 Microsoft iSCSI Software Initiator

執行桌面上 (或控制台) 的 Microsoft iSCSI Initiator

Discovery → Add → IP address or DNS name: 192.168.1.1 → OK

Targets → 選擇欲登入的 target → Log On...

若該 target 無 CHAP auth, 直接點選 OK

設定 CHAP: Advanced... → 勾選 CHAP logon information

User name: username

Target secret: password (密碼須 12 ~ 16 個字元)

確定 → OK

桌面 → 我的電腦 (右鍵) → 管理 (或控制台的 "系統管理工具" → "電腦管理")

磁碟管理 → 關閉 "初始化及轉換磁碟精靈" 視窗 → 磁碟 1 (Unknown) 未初始化 (右鍵) → 初始化磁碟

初始化後, 磁碟 1 的狀態會變成 "基本"、"連線", 於畫面右手邊的 "未配置" 條狀區按右鍵, 點選 "新增磁碟分割" 即可配置硬碟空間

抱歉!评论已关闭.