zoukankan      html  css  js  c++  java
  • iscsi共享分区测试

    要求:
    在服务器端Server0上创建一个分区/dev/sdb1(无需格式化),配置成iscsi target设备,块设备名称为sun1,iqn名称为iqn.2018-01.com.ultrapower:testserverdisk1,并配置acls仅允许desktop1访问。
    在客户端服务器desktop1上使用server0上的分区,将其格式化为500MB的xfs分区,并自动挂载到/mydisk目录下。

    一、服务端安装配置
    安装软件包
    # yum install targetcli

    配置防火墙策略
    firewall-cmd --permanent --add-port=3260/tcp
    firewall-cmd –reload

    创建共享设备

    [root@server0 ~]# targetcli 
    targetcli shell version 2.1.fb46
    Copyright 2011-2013 by Datera, Inc and others.
    For help on commands, type 'help'.
    /backstores/block> create san1 /dev/sdb1   --把新分区/dev/sdb1创建为一个块设备,名称为san1
    Created block storage object san1 using /dev/sdb1.
    /backstores/block> /iscsi create iqn.2018-01.com.ultrapower:testServerDisk1  --创建iscsi设备,并指定名称
    Created target iqn.2018-01.com.ultrapower:testserverdisk1.
    Created TPG 1.
    Global pref auto_add_default_portal=true
    Created default portal listening on all IPs (0.0.0.0), port 3260.
    
    /> ls
    o- / ......................................................................................................................... [...]
      o- backstores .............................................................................................................. [...]
      | o- block .................................................................................................. [Storage Objects: 1]
      | | o- san1 ......................................................................... [/dev/sdb1 (0 bytes) write-thru deactivated]
      | |   o- alua ................................................................................................... [ALUA Groups: 1]
      | |     o- default_tg_pt_gp ....................................................................... [ALUA state: Active/optimized]
      | o- fileio ................................................................................................. [Storage Objects: 0]
      | o- pscsi .................................................................................................. [Storage Objects: 0]
      | o- ramdisk ................................................................................................ [Storage Objects: 0]
      o- iscsi ............................................................................................................ [Targets: 1]
      | o- iqn.2018-01.com.ultrapower:testserverdisk1 ........................................................................ [TPGs: 1]
      |   o- tpg1 ............................................................................................... [no-gen-acls, no-auth]
      |     o- acls .......................................................................................................... [ACLs: 0]
      |     o- luns .......................................................................................................... [LUNs: 0]
      |     o- portals .................................................................................................... [Portals: 1]
      |       o- 0.0.0.0:3260 ..................................................................................................... [OK]
      o- loopback ......................................................................................................... [Targets: 0]
    /> 

    acls:允许谁访问
    lun设备:把iscsi设备和block设备sun1进行关联
    portals: 设备iqn监听的端口

    #设置acl参数,指明网络上“仅允许desktopX.example.com主机访问”主机可以访问该sicsi设备

    /> /iscsi/iqn.2018-01.com.ultrapower:testserverdisk1/tpg1/acls create iqn.2018-01.com.ultrapower:desktop1
    Created Node ACL for iqn.2018-01.com.ultrapower:desktop1 

    #设置lun参数,指明lun管理的iscsi设备(iqn.2018-01.com.ultrapower:testserverdisk1)对应的块设备为san1 。

    /> /iscsi/iqn.2018-01.com.ultrapower:testserverdisk1/tpg1/luns create /backstores/block/san1 
    Created LUN 0.
    Created LUN 0->0 mapping in node ACL iqn.2018-01.com.ultrapower:desktop1

    #设置portal参数,指明共享iscsi设备的IP和端口号,默认为“0.0.0.0 3260”,删除后,重新配置portal参数。

    /> /iscsi/iqn.2018-01.com.ultrapower:testserverdisk1/tpg1/portals create 192.168.100.200 3260
    Using default IP port 3260
    Could not create NetworkPortal in configFS
    /> ls
    o- / ......................................................................................................................... [...]
      o- backstores .............................................................................................................. [...]
      | o- block .................................................................................................. [Storage Objects: 1]
      | | o- san1 ........................................................................... [/dev/sdb1 (0 bytes) write-thru activated]
      | |   o- alua ................................................................................................... [ALUA Groups: 1]
      | |     o- default_tg_pt_gp ....................................................................... [ALUA state: Active/optimized]
      | o- fileio ................................................................................................. [Storage Objects: 0]
      | o- pscsi .................................................................................................. [Storage Objects: 0]
      | o- ramdisk ................................................................................................ [Storage Objects: 0]
      o- iscsi ............................................................................................................ [Targets: 1]
      | o- iqn.2018-01.com.ultrapower:testserverdisk1 ........................................................................ [TPGs: 1]
      |   o- tpg1 ............................................................................................... [no-gen-acls, no-auth]
      |     o- acls .......................................................................................................... [ACLs: 1]
      |     | o- iqn.2018-01.com.ultrapower:desktop1 .................................................................. [Mapped LUNs: 1]
      |     |   o- mapped_lun0 .................................................................................. [lun0 block/san1 (rw)]
      |     o- luns .......................................................................................................... [LUNs: 1]
      |     | o- lun0 ...................................................................... [block/san1 (/dev/sdb1) (default_tg_pt_gp)]
      |     o- portals .................................................................................................... [Portals: 1]
      |       o- 0.0.0.0:3260 ..................................................................................................... [OK]
      o- loopback ......................................................................................................... [Targets: 0]
    /> 
    /iscsi/iqn.20.../tpg1/portals> delete 0.0.0.0 3260   --把默认的删除。
    Deleted network portal 0.0.0.0:3260
    /iscsi/iqn.20.../tpg1/portals> cd /
    /> iscsi/iqn.2018-01.com.ultrapower:testserverdisk1/tpg1/portals create 192.168.100.200 3260
    Using default IP port 3260
    Created network portal 192.168.100.200:3260.
    /> saveconfig  --保存退出。
    Last 10 configs saved in /etc/target/backup.
    Configuration saved to /etc/target/saveconfig.json
    /> exit

    服务端配置完成。

    [root@server0 ~]# systemctl restart target  --重启target服务

    二、客户端安装配置
    Desktop服务器上安装iscsi-initiator-utils软件包,或者iscsi*

    [root@desktop1 home]# yum install -y iscsi-initiator-utils --安装软件包
    [root@desktop1 home]# vi /etc/iscsi/initiatorname.iscsi --修改配置文件
    InitiatorName=iqn.2018-01.com.ultrapower:desktop1

    [root@desktop1 home]# systemctl restart iscsi --重启并设置开机启动
    [root@desktop1 home]# systemctl enable iscsi
    [root@desktop1 home]# systemctl restart iscsid.service
    [root@desktop1 home]# systemctl enable iscsid.service

    发现并登入使用server端的iscsi设备(提示:查看man iscsiadm帮助文档中的EXAMPLE示例):

    [root@desktop1 ~]# iscsiadm --mode discoverydb --type sendtargets --portal 192.168.100.200 --discover 
    192.168.100.200:3260,1 iqn.2018-01.com.ultrapower:testserverdisk1
    [root@desktop1 ~]#  iscsiadm --mode node --targetname iqn.2018-01.com.ultrapower:testserverdisk1 --portal 192.168.100.200:3260 --login
    Logging in to [iface: default, target: iqn.2018-01.com.ultrapower:testserverdisk1, portal: 192.168.100.200,3260] (multiple)
    Login to [iface: default, target: iqn.2018-01.com.ultrapower:testserverdisk1, portal: 192.168.100.200,3260] successful.
    [root@desktop1 ~]# fdisk -l
    
    Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk label type: dos
    Disk identifier: 0x000d2b42
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048      411647      204800   83  Linux
    /dev/sda2          411648    62914559    31251456   8e  Linux LVM
    
    Disk /dev/mapper/ruskyVG-root: 29.9 GB, 29850861568 bytes, 58302464 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    
    
    Disk /dev/mapper/ruskyVG-swap: 2147 MB, 2147483648 bytes, 4194304 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    
    
    Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 sectors    --可以看到/dev/sdb磁盘了。
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 33550336 bytes
    
    将/dev/sdb磁盘分区500MB,并挂载使用。(题目中并未要求挂载)
    
    [root@desktop1 ~]# fdisk /dev/sdb 
    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 0xc17d77c4.
    
    Command (m for help): n
    Partition type:
       p   primary (0 primary, 0 extended, 4 free)
       e   extended
    Select (default p): p
    Partition number (1-4, default 1): 
    First sector (65528-2097151, default 65528): 
    Using default value 65528
    Last sector, +sectors or +size{K,M,G} (65528-2097151, default 2097151): +500M
    Partition 1 of type Linux and of size 512 MiB is set
    
    Command (m for help): w
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    Syncing disks.
    [root@desktop1 ~]# partprobe   --刷新分区
    Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.
    
    [root@desktop1 ~]# mkfs.xfs /dev/sdb1   --格式化分区
    meta-data=/dev/sdb1              isize=512    agcount=4, agsize=32764 blks
             =                       sectsz=512   attr=2, projid32bit=1
             =                       crc=1        finobt=0, sparse=0
    data     =                       bsize=4096   blocks=131056, imaxpct=25
             =                       sunit=0      swidth=0 blks
    naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
    log      =internal log           bsize=4096   blocks=855, version=2
             =                       sectsz=512   sunit=0 blks, lazy-count=1
    realtime =none                   extsz=4096   blocks=0, rtextents=0
    [root@desktop1 ~]# mkdir /mydisk   --创建挂载目录
    [root@desktop1 ~]# mount /dev/sdb1 /mydisk/    ---手动挂载测试
    [root@desktop1 ~]# df -h
    Filesystem                                  Size  Used Avail Use% Mounted on
    /dev/mapper/ruskyVG-root                     28G  3.6G   25G  13% /
    devtmpfs                                    715M     0  715M   0% /dev
    tmpfs                                       731M     0  731M   0% /dev/shm
    tmpfs                                       731M   36M  696M   5% /run
    tmpfs                                       731M     0  731M   0% /sys/fs/cgroup
    /dev/sda1                                   197M  138M   59M  71% /boot
    tmpfs                                       147M   12K  147M   1% /run/user/42
    tmpfs                                       147M     0  147M   0% /run/user/0
    192.168.100.200:/home/guests/testldapuser5   28G  3.7G   25G  14% /home/guests/testldapuser5
    192.168.100.200:/home/guests/testldapuser2   28G  3.7G   25G  14% /home/guests/testldapuser2
    /dev/sr0                                    3.8G  3.8G     0 100% /mnt/cdrom
    /dev/sdb1                                   509M   26M  483M   6% /mydisk    ---已经挂载成功了  
    [root@desktop1 ~]# blkid  /dev/sdb1  --查看/dev/sdb1的UUID,挂载网络设备一定要使用UUID.
    /dev/sdb1: UUID="d69a4140-4622-4dc1-823a-e7cfba80b9fa" TYPE="xfs" 
    [root@desktop1 ~]# vi /etc/fstab    --添加开机自动挂载,增加如下一行。一定要添加_netdev,否则开机会卡死。
    UUID=d69a4140-4622-4dc1-823a-e7cfba80b9fa /mydisk xfs     defaults,_netdev        0 0
  • 相关阅读:
    NYOJ 746---整数划分(四)(区间DP)
    2014 ICPC---Relief grain(树链剖分)
    51Node 1483----化学变换(暴力枚举)
    2016暑假多校联合---Rikka with Sequence (线段树)
    《程序员代码面试指南》第五章 字符串问题 字典树(前缀树)的实现
    《程序员代码面试指南》第五章 字符串问题 找到被指的新类型字符
    《程序员代码面试指南》第五章 字符串问题 公式字符串求值
    《程序员代码面试指南》第五章 字符串问题 数组中两个字符串的最小距离
    《程序员代码面试指南》第五章 字符串问题 翻转字符串
    《程序员代码面试指南》第五章 字符串问题 字符串的调整与替换
  • 原文地址:https://www.cnblogs.com/rusking/p/8313547.html
Copyright © 2011-2022 走看看