next up previous contents
Next: Client Initiator 除錯 Up: iSCSI Storage Previous: Server Target 架設   Contents

Client Initiator 設定

  1. Client kvm7.deyu.wang 先安裝 iscsi-initiator 工具。
    [root@kvm7 ~]# yum install iscsi-initiator-utils -y
    
  2. 設定開機啟動 iscsi 及 iscsid 服務。
    [root@kvm7 ~]# systemctl enable iscsid.service iscsi.service 
    ln -s '/usr/lib/systemd/system/iscsid.service' '/etc/systemd/system/multi-user.target.wants/iscsid.service'
    
  3. 設定 iSCSI client initiator 名稱, 此名稱為 server targetcli acls 產生的 iqn.2015-08.wang.deyu:kvm7,一定要相同才能存取。
    [root@kvm7 ~]# vim /etc/iscsi/initiatorname.iscsi
    [root@kvm7 ~]# cat /etc/iscsi/initiatorname.iscsi
    InitiatorName=iqn.2015-08.wang.deyu:kvm7
    
  4. 重新啟動 iscsi 及 iscsid 服務。
    [root@kvm7 ~]# systemctl restart iscsi.service iscsid.service
    
  5. 未發現 iscsi target 前 /var/lib/iscsi/nodes 目錄中是空的。
    [root@kvm7 ~]# ll /var/lib/iscsi/nodes/
    total 0
    
  6. 使用 iscsi 管理命令 iscsiadm 發現 server kvm5.deyu.wang 可用的 target,名稱為 iqn.2015-08.wang.deyu:kvm5。
    [root@kvm7 ~]# iscsiadm -m discovery -t st -p 192.168.122.5
    192.168.122.5:3260,1 iqn.2015-08.wang.deyu:kvm5
    
  7. 使用 iscsiadm -m discovery 發現 iscsi target 後 /var/lib/iscsi/nodes 目錄中出現發的 target iqn 目錄,目錄中有 default 檔記錄各個參數。
    [root@kvm7 ~]# ll /var/lib/iscsi/nodes/
    total 4
    drw-------. 3 root root 4096 Jul 10 15:26 iqn.2015-08.wang.deyu:kvm5
    
    [root@kvm7 ~]# cat /var/lib/iscsi/nodes/iqn.2015-08.wang.deyu\:kvm5/192.168.122.5\,3260\,1/default 
    # BEGIN RECORD 6.2.0.874-7
    node.name = iqn.2015-08.wang.deyu:kvm5
    node.tpgt = 1
    node.startup = automatic
    node.leading_login = No
    iface.iscsi_ifacename = default
    iface.transport_name = tcp
    iface.vlan_id = 0
    iface.vlan_priority = 0
    iface.iface_num = 0
    iface.mtu = 0
    iface.port = 0
    iface.tos = 0
    iface.ttl = 0
    iface.tcp_wsf = 0
    iface.tcp_timer_scale = 0
    iface.def_task_mgmt_timeout = 0
    iface.erl = 0
    iface.max_receive_data_len = 0
    iface.first_burst_len = 0
    iface.max_outstanding_r2t = 0
    iface.max_burst_len = 0
    node.discovery_address = 192.168.122.5
    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.nr_sessions = 1
    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.session.scan = auto
    node.conn[0].address = 192.168.122.5
    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
    
  8. 登入 iqn.2015-08.wang.deyu:kvm5。
    [root@kvm7 ~]# iscsiadm -m node -T iqn.2015-08.wang.deyu:kvm5 -p 192.168.122.5 -l
    Logging in to [iface: default, target: iqn.2015-08.wang.deyu:kvm5, portal: 192.168.122.5,3260] (multiple)
    Login to [iface: default, target: iqn.2015-08.wang.deyu:kvm5, portal: 192.168.122.5,3260] successful.
    
  9. 查看硬碟,多出一顆 sda。
    [root@kvm7 ~]# lsblk 
    NAME                MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sda                   8:0    0   12M  0 disk 
    vda                 252:0    0    8G  0 disk 
    ├─vda1              252:1    0   96M  0 part /boot
    ├─vda2              252:2    0  3.1G  0 part 
    │ ├─vg_kvm7usb-swap 253:0    0  124M  0 lvm  [SWAP]
    │ └─vg_kvm7usb-root 253:1    0  2.8G  0 lvm  /
    └─vda3              252:3    0  130M  0 part 
      └─vg_kvm7home-vo  253:2    0  120M  0 lvm  /home
    
  10. 在 /dev/sda 分割一個 10M 的分割區,type 為 Linux。
    [root@kvm7 ~]# fdisk /dev/sda
    Welcome to fdisk (util-linux 2.23.2).
    
    Changes will remain in memory only, until you decide to write them.
    Be careful before using the write command.
    
    Device does not contain a recognized partition table
    Building a new DOS disklabel with disk identifier 0xc497bbc1.
    
    Command (m for help): p
    
    Disk /dev/sda: 12 MB, 12582912 bytes, 24576 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 4194304 bytes
    Disk label type: dos
    Disk identifier: 0xc497bbc1
    
       Device Boot      Start         End      Blocks   Id  System
    
    Command (m for help): n
    Partition type:
       p   primary (0 primary, 0 extended, 4 free)
       e   extended
    Select (default p):  
    Using default response p
    Partition number (1-4, default 1): 
    First sector (1-24575, default 1): 
    Using default value 1
    Last sector, +sectors or +size{K,M,G} (1-24575, default 24575): +10M
    Partition 1 of type Linux and of size 10 MiB is set
    
    Command (m for help): p
    
    Disk /dev/sda: 12 MB, 12582912 bytes, 24576 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 4194304 bytes
    Disk label type: dos
    Disk identifier: 0xc497bbc1
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1               1       20481       10240+  83  Linux
    
    Command (m for help): w
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    Syncing disks.
    
  11. 使用 partprobe 偵測 /dev/sda 新的分割區。
    [root@kvm7 ~]# partprobe /dev/sda
    
  12. 格式化 /dev/sda1 為 ext4。
    [root@kvm7 ~]# mkfs.ext4 /dev/sda1
    
  13. 建立掛載目錄 /mnt/data。
    [root@kvm7 ~]# mkdir /mnt/data
    
  14. 編輯開機掛載表 /etc/fstab,設定開機自動掛載 /dev/sda1 在 /mnt/data,注意掛載參數是 _netdev,且 dump 及 fsck 都不執行,也就是設成 0。
    [root@kvm7 ~]# vim /etc/fstab
    [root@kvm7 ~]# tail -1 /etc/fstab 
    /dev/sda1		/mnt/data        ext4    _netdev        0 0
    
  15. 依照開機掛載表 /etc/fstab 掛載,成功掛載才可以重開機。
    [root@kvm7 ~]# mount -a
    [root@kvm7 ~]# df -Th | grep data
    /dev/sda1                   ext4      8.7M  172K  7.9M   3% /mnt/data
    



De-Yu Wang 2018-09-07