精华内容
下载资源
问答
  • 启动targetcli时遭遇ImportError: cannot import name ALUATargetPortGroup故障 targetcli是一个iSCSI配置管理工具,该工具简单易用,可以直接替换scsi-target-utils。满心欢喜的装上它,正准备一睹为快,就杯具了。...
  • targetcli-fb 用于管理Linux LIO内核目标的命令外壳 targetcli-fb是一个命令行界面,用于配置3.x Linux内核版本中的LIO通用SCSI目标。 使用python-six库与Python 2.7和3.x兼容。 targetcli-fb开发 targetcli-fb是...
  • targetcli

    千次阅读 2018-03-20 17:28:43
    targetcli which makes configuring a software iSCSI target quitedifferent. In earlier versions one had to edit the /etc/tgtd/targets.conf file and service tgtd restart . Here is an example ...

    Linux-IO (LIO) Target is an open-source implementation of the SCSI target thathas become the standard one included in the Linux kernel and the one present inRed Hat Enterprise Linux 7. The popular scsi-target-utils package is replacedby the newer targetcli which makes configuring a software iSCSI target quitedifferent.

    In earlier versions one had to edit the /etc/tgtd/targets.conf file andservice tgtd restart. Here is an example configuration:

    <target iqn.2008-09.com.example:server.target1>
        backing-store /dev/vg_iscsi/lv_lun1
        backing-store /dev/vg_iscsi/lv_lun2
    
        incominguser user2 secretpass23
        outgoinguser userA secretpassA
    </target>
    

    targetcli can be used either as an interactive shell or as stand alone commands.Here is an example shell session which creates a file-based disk image. Comments areprovided inline:

    # yum install -y targetcli
    # systemctl enable target
    
    # targetcli 
    
    # first create a disk image with the name of disk1. All files are sparsely created.
    
    /> backstores/fileio create disk1 /var/lib/libvirt/images/disk1.img 10G
    Created fileio disk1 with size 10737418240
    
    # create an iSCSI target. NB: this only defines the target
    
    /> iscsi/ create iqn.2015-04.com.example:target1
    Created target iqn.2015-04.com.example:target1.
    Created TPG 1.
    Global pref auto_add_default_portal=true
    Created default portal listening on all IPs (0.0.0.0), port 3260.
    
    # TPGs (Target Portal Groups) allow the iSCSI to support multiple complete
    # configurations within one target. This is useful for complex quality-of-service
    # configurations. targetcli will automatically create one TPG when the target
    # is created, and almost all setups only need one.
    
    # switch to TPG definition for our target
    
    /> cd iscsi/iqn.2015-04.com.example:target1/tpg1
    
    # list the contents
    
    /iscsi/iqn.20...:target1/tpg1> ls 
    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]
    
    # create a portal aka IP:port pairs which expose the target on the network
    
    /iscsi/iqn.20...:target1/tpg1> portals/ create
    Using default IP port 3260
    Binding to INADDR_ANY (0.0.0.0)
    This NetworkPortal already exists in configFS.
    
    # create logical units (LUNs) aka disks inside our target
    # in other words bind the target to its on-disk storage
    
    /iscsi/iqn.20...:target1/tpg1> luns/ create /backstores/fileio/disk1
    Created LUN 0.
    
    # disable authentication
    
    /iscsi/iqn.20...:target1/tpg1> set attribute authentication=0
    Parameter authentication is now '0'.
    
    # enable read/write mode
    
    /iscsi/iqn.20...:target1/tpg1> set attribute demo_mode_write_protect=0
    Parameter demo_mode_write_protect is now '0'.
    
    # Enable generate_node_acls mode. This can be thought of as 
    # "ignore ACLs mode" -- both  authentication and LUN mapping
    # will then use the TPG settings.
    
    /iscsi/iqn.20...:target1/tpg1> set attribute generate_node_acls=1
    Parameter generate_node_acls is now '1'.
    
    /iscsi/iqn.20...:target1/tpg1> ls
    o- tpg1 ........................................................................................................ [gen-acls, no-auth]
      o- acls ................................................................................................................ [ACLs: 0]
      o- luns ................................................................................................................ [LUNs: 1]
      | o- lun0 ..................................................................... [fileio/disk1 (/var/lib/libvirt/images/disk1.img)]
      o- portals .......................................................................................................... [Portals: 1]
        o- 0.0.0.0:3260 ........................................................................................................... [OK]
    
    # exit or Ctrl+D will save the configuration under /etc/target/saveconfig.json
    
    /iscsi/iqn.20...:target1/tpg1> exit
    Global pref auto_save_on_exit=true
    Last 10 configs saved in /etc/target/backup.
    Configuration saved to /etc/target/saveconfig.json
    
    # after creating a second target the layout looks like this
    
    /> ls
    o- / ......................................................................................................................... [...]
      o- backstores .............................................................................................................. [...]
      | o- block .................................................................................................. [Storage Objects: 0]
      | o- fileio ................................................................................................. [Storage Objects: 2]
      | | o- disk1 .................................................. [/var/lib/libvirt/images/disk1.img (10.0GiB) write-back activated]
      | | o- disk2 .................................................. [/var/lib/libvirt/images/disk2.img (10.0GiB) write-back activated]
      | o- pscsi .................................................................................................. [Storage Objects: 0]
      | o- ramdisk ................................................................................................ [Storage Objects: 0]
      o- iscsi ............................................................................................................ [Targets: 2]
      | o- iqn.2015-04.com.example:target1 ................................................................................... [TPGs: 1]
      | | o- tpg1 .................................................................................................. [gen-acls, no-auth]
      | |   o- acls .......................................................................................................... [ACLs: 0]
      | |   o- luns .......................................................................................................... [LUNs: 1]
      | |   | o- lun0 ............................................................... [fileio/disk1 (/var/lib/libvirt/images/disk1.img)]
      | |   o- portals .................................................................................................... [Portals: 1]
      | |     o- 0.0.0.0:3260 ..................................................................................................... [OK]
      | o- iqn.2015-04.com.example:target2 ................................................................................... [TPGs: 1]
      |   o- tpg1 .................................................................................................. [gen-acls, no-auth]
      |     o- acls .......................................................................................................... [ACLs: 0]
      |     o- luns .......................................................................................................... [LUNs: 1]
      |     | o- lun0 ............................................................... [fileio/disk2 (/var/lib/libvirt/images/disk2.img)]
      |     o- portals .................................................................................................... [Portals: 1]
      |       o- 0.0.0.0:3260 ..................................................................................................... [OK]
      o- loopback ......................................................................................................... [Targets: 0]
    
    
    # enable CHAP and Reverse CHAP (mutual) for both discovery and login authentication
    
    # discovery authentication is enabled under the global iscsi node
    
    /> cd /iscsi
    /iscsi> set discovery_auth enable=1
    /iscsi> set discovery_auth userid=IncomingUser
    /iscsi> set discovery_auth password=SomePassword1
    /iscsi> set discovery_auth mutual_userid=OutgoingUser
    /iscsi> set discovery_auth mutual_password=AnotherPassword2
    
    # login authentication is enabled either under the TPG node or under ACLs
    
    /iscsi> cd iqn.2015-04.com.example:target1/tpg1
    /iscsi/iqn.20...:target1/tpg1> set attribute authentication=1
    /iscsi/iqn.20...:target1/tpg1> set auth userid=IncomingUser2
    /iscsi/iqn.20...:target1/tpg1> set auth password=SomePassword3
    /iscsi/iqn.20...:target1/tpg1> set auth mutual_userid=OutgoingUser2
    /iscsi/iqn.20...:target1/tpg1> set auth mutual_password=AnotherPassword4
    /iscsi/iqn.20...:target1/tpg1> exit
    
    展开全文
  • iscsi-initiator-utils-6.2.0.874-19.el7.aarch64.rpm python-kmod-0.9-4.el7.aarch64.rpm iscsi-initiator-utils-iscsiuio-6.2.0.874-19.el7.aarch64.rpm python-rtslib-2.1.72-1.el7.noarch.rpm ...
  • ) 共享存储服务器检查安装targetcli工具 (CentOS7.1往前的貌似不是targetcli工具,可以自行对照系统配置,以防我的操作方式有一些区别;) 我的是已经安装了targetcli配置工具的: 查看targetcli [root@www ~]# ...

    说到今天的心情,也能用好也能用不好来形容。
    今天也不整这些影响心情的事情。我来粗略的配置一下target服务的共享存储配置,解决计算机磁盘空间不足的问题。

    两台计算机

    一台功能服务型计算机,一台用作共享存储的服务器。

    功能型主机:

    [root@localhost ~]# fdisk -l
    WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
    
    磁盘 /dev/sda:64.0 GB, 64023257088 字节,125045424 个扇区
    Units = 扇区 of 1 * 512 = 512 bytes
    扇区大小(逻辑/物理):512 字节 / 512 字节
    I/O 大小(最小/最佳):512 字节 / 512 字节
    磁盘标签类型:gpt
    Disk identifier: 6F22154B-F340-445A-9DD3-36035F0E1A86
    
    
    #         Start          End    Size  Type            Name
     1         2048       411647    200M  EFI System      EFI System Partition
     2       411648      2508799      1G  Microsoft basic
     3      2508800    125044735   58.4G  Linux LVM
    
    磁盘 /dev/mapper/centos-root:39.4 GB, 39355154432 字节,76865536 个扇区
    Units = 扇区 of 1 * 512 = 512 bytes
    扇区大小(逻辑/物理):512 字节 / 512 字节
    I/O 大小(最小/最佳):512 字节 / 512 字节
    
    
    磁盘 /dev/mapper/centos-swap:4160 MB, 4160749568 字节,8126464 个扇区
    Units = 扇区 of 1 * 512 = 512 bytes
    扇区大小(逻辑/物理):512 字节 / 512 字节
    I/O 大小(最小/最佳):512 字节 / 512 字节
    
    
    磁盘 /dev/mapper/centos-home:19.2 GB, 19214106624 字节,37527552 个扇区
    Units = 扇区 of 1 * 512 = 512 bytes
    扇区大小(逻辑/物理):512 字节 / 512 字节
    I/O 大小(最小/最佳):512 字节 / 512 字节
    
    
    磁盘 /dev/sdb:52.4 GB, 52437189120 字节,102416385 个扇区
    Units = 扇区 of 1 * 512 = 512 bytes
    扇区大小(逻辑/物理):512 字节 / 512 字节
    I/O 大小(最小/最佳):512 字节 / 33550336 字节
    
    [root@localhost ~]#
    

    可以看到服务型功能主机的硬盘空间不到60G,这个硬盘大小做服务的时候是不够用的。

    存储共享服务器

    存储共享服务器也就是多加了一块硬盘,但是可以用来模拟共享存储空间用。

    [root@www ~]# df -h
    文件系统                 容量  已用  可用 已用% 挂载点
    devtmpfs                 1.4G     0  1.4G    0% /dev
    tmpfs                    1.4G     0  1.4G    0% /dev/shm
    tmpfs                    1.4G  9.4M  1.4G    1% /run
    tmpfs                    1.4G     0  1.4G    0% /sys/fs/cgroup
    /dev/mapper/centos-root   90G   38G   53G   42% /
    /dev/sda1               1014M  240M  775M   24% /boot
    tmpfs                    284M   12K  284M    1% /run/user/42
    tmpfs                    284M     0  284M    0% /run/user/0
    [root@www ~]# fdisk -l
    
    磁盘 /dev/sda:320.1 GB, 320071851520 字节,625140335 个扇区
    Units = 扇区 of 1 * 512 = 512 bytes
    扇区大小(逻辑/物理):512 字节 / 512 字节
    I/O 大小(最小/最佳):512 字节 / 512 字节
    磁盘标签类型:dos
    磁盘标识符:0x00044653
    
       设备 Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048     2099199     1048576   83  Linux
    /dev/sda2         2099200   113262591    55581696   8e  Linux LVM
    /dev/sda3       113262592   625140334   255938871+  8e  Linux LVM
    
    磁盘 /dev/sdb:500.1 GB, 500106780160 字节,976771055 个扇区
    Units = 扇区 of 1 * 512 = 512 bytes
    扇区大小(逻辑/物理):512 字节 / 512 字节
    I/O 大小(最小/最佳):512 字节 / 512 字节
    磁盘标签类型:dos
    磁盘标识符:0x624aa2e0
    
       设备 Boot      Start         End      Blocks   Id  System
    /dev/sdb1            2048   102416383    51207168   8e  Linux LVM
    /dev/sdb2       102416384   204832768    51208192+  8e  Linux LVM
    /dev/sdb3       204834816   512086016   153625600+  8e  Linux LVM
    /dev/sdb4       512088064   976771054   232341495+  8e  Linux LVM
    
    磁盘 /dev/mapper/centos-root:96.6 GB, 96636764160 字节,188743680 个扇区
    Units = 扇区 of 1 * 512 = 512 bytes
    扇区大小(逻辑/物理):512 字节 / 512 字节
    I/O 大小(最小/最佳):512 字节 / 512 字节
    
    
    磁盘 /dev/mapper/centos-swap:3221 MB, 3221225472 字节,6291456 个扇区
    Units = 扇区 of 1 * 512 = 512 bytes
    扇区大小(逻辑/物理):512 字节 / 512 字节
    I/O 大小(最小/最佳):512 字节 / 512 字节
    
    [root@www ~]#
    

    可以看到,我的共享存储服务器在sdb下划分了4个分区用作后面的共享存储配置。(fdisk 磁盘分区的操作方式可以自行查找文章进行配置,这里不具体阐述了;)

    共享存储服务器检查安装targetcli工具

    (CentOS7.1往前的貌似不是targetcli工具,可以自行对照系统配置,以防我的操作方式有一些区别;)
    我的是已经安装了targetcli配置工具的:
    查看targetcli

    [root@www ~]# rpm -q targetcli
    targetcli-2.1.fb49-1.el7.noarch
    

    如果你的系统内没有安装,可以执行yum源安装此工具:

    [root@www ~]# yum install targetcli -y
    

    也可以更新此工具为最新版本:
    没有相关更新,我这就是个演示。

    [root@www ~]# yum update targetcli
    
    已加载插件:fastestmirror, langpacks
    Repository base is listed more than once in the configuration
    Repository updates is listed more than once in the configuration
    Repository extras is listed more than once in the configuration
    Repository centosplus is listed more than once in the configuration
    Loading mirror speeds from cached hostfile
     * base: mirror.bit.edu.cn
     * extras: mirrors.bfsu.edu.cn
     * updates: mirrors.bfsu.edu.cn
    base                                                                                                                                             | 3.6 kB  00:00:00
    extras                                                                                                                                           | 2.9 kB  00:00:00
    updates                                                                                                                                          | 2.9 kB  00:00:00
    No packages marked for update
    [root@www ~]#
    

    进入服务端targetcli工具

    直接输入targetcli就行:

    [root@www ~]# targetc
    targetcli  targetctl
    [root@www ~]# targetcli
    targetcli shell version 2.1.fb49
    Copyright 2011-2013 by Datera, Inc and others.
    For help on commands, type 'help'.
    
    /> -h
    /> help
    
    GENERALITIES
    ============
    This is a shell in which you can create, delete and configure
    configuration objects.
    
    The available commands depend on the current path or target
    path you want to run a command in: different path have
    different sets of available commands, i.e. a path pointing at
    an iscsi target will not have the same availaible commands as,
    say, a path pointing at a storage object.
    
    The prompt that starts each command line indicates your
    current path. Alternatively (useful if the prompt displays
    an abbreviated path to save space), you can run the
    pwd command to display the complete current path.
    
    Navigating the tree is done using the cd command. Without
    any argument, cd will present you with the full objects
    tree. Just use arrows to select the destination path, and
    enter will get you there. Please try help cd for navigation
    tips.
    
    COMMAND SYNTAX
    ==============
    Commands are built using the following syntax:
    
    [TARGET_PATH] COMMAND_NAME [OPTIONS]
    
    The TARGET_PATH indicates the path to run the command from.
    If ommited, the command will be run from your current path.
    
    The OPTIONS depend on the command. Please use help
    COMMAND to get more information.
    
    
    AVAILABLE COMMANDS
    ==================
    The following commands are available in the
    current path:
    
      - bookmarks action [bookmark]
      - cd [path]
      - clearconfig [confirm]
      - exit
      - get [group] [parameter...]
      - help [topic]
      - ls [path] [depth]
      - pwd
      - refresh
      - restoreconfig [savefile] [clear_existing]
      - saveconfig [savefile]
      - sessions [action] [sid]
      - set [group] [parameter=value...]
      - status
      - version
    />
    

    help可以获取帮助,双击Tab键可以显示在当前路径下使用的targetcli命令:

    current path:
    
      - bookmarks action [bookmark]
      - cd [path]
      - clearconfig [confirm]
      - exit
      - get [group] [parameter...]
      - help [topic]
      - ls [path] [depth]
      - pwd
      - refresh
      - restoreconfig [savefile] [clear_existing]
      - saveconfig [savefile]
      - sessions [action] [sid]
      - set [group] [parameter=value...]
      - status
      - version
    />
    *              /              @last          backstores/    iscsi/         loopback/      bookmarks      cd
    clearconfig    exit           get            help           ls             pwd            refresh        restoreconfig
    saveconfig     sessions       set            status         version
    />
    

    目前是在根路径下,直接敲ls(和linux的ls一样)命令来查看所有路径及路径下的配置,敲pwd命令可以显示当前所在的路径(和linux的pwd一样)。

    />
    *              /              @last          backstores/    iscsi/         loopback/      bookmarks      cd
    clearconfig    exit           get            help           ls             pwd            refresh        restoreconfig
    saveconfig     sessions       set            status         version
    /> ls
    o- / ......................................................................................................................... [...]
      o- backstores .............................................................................................................. [...]
      | o- block .................................................................................................. [Storage Objects: 2]
      | | o- block_sd2 ...................................................................... [/dev/sdb2 (48.8GiB) write-thru activated]
      | | | o- alua ................................................................................................... [ALUA Groups: 1]
      | | |   o- default_tg_pt_gp ....................................................................... [ALUA state: Active/optimized]
      | | o- block_sd3 ..................................................................... [/dev/sdb3 (146.5GiB) 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.2020-08.sd2.liyi.com:test ..................................................................................... [TPGs: 1]
      |   o- tpg1 ............................................................................................... [no-gen-acls, no-auth]
      |     o- acls .......................................................................................................... [ACLs: 1]
      |     | o- iqn.1994-05.com.redhat:be46bf1b1f5c .................................................................. [Mapped LUNs: 2]
      |     |   o- mapped_lun0 ............................................................................. [lun0 block/block_sd2 (rw)]
      |     |   o- mapped_lun1 ............................................................................. [lun1 block/block_sd3 (rw)]
      |     o- luns .......................................................................................................... [LUNs: 2]
      |     | o- lun0 ................................................................. [block/block_sd2 (/dev/sdb2) (default_tg_pt_gp)]
      |     | o- lun1 ................................................................. [block/block_sd3 (/dev/sdb3) (default_tg_pt_gp)]
      |     o- portals .................................................................................................... [Portals: 1]
      |       o- 192.168.0.104:3260 ............................................................................................... [OK]
      o- loopback ......................................................................................................... [Targets: 0]
    /> pwd
    /
    />
    

    完成共享存储服务的空间配置:

    创建block块

    创建一个block块关联我需要共享的分区:
    需要在backstores/block路径下创建关联block块

    /> ls
    o- / ......................................................................................................................... [...]
      o- backstores .............................................................................................................. [...]
      | o- block .................................................................................................. [Storage Objects: 2]
      | | o- block_sd2 ...................................................................... [/dev/sdb2 (48.8GiB) write-thru activated]
      | | | o- alua ................................................................................................... [ALUA Groups: 1]
      | | |   o- default_tg_pt_gp ....................................................................... [ALUA state: Active/optimized]
      | | o- block_sd3 ..................................................................... [/dev/sdb3 (146.5GiB) 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]
    

    可以看到我目前已经共享了两个block块,一个是sd2、一个是sd3,这两个名称我是根据sdb分区名称来配置的。
    在sd2这个block块的右边可以看到sd2关联的是/dev/sdb2,sdb2的分区空间为48.8G的空间。sd3也和sd2相同,关联的是sdb3,sdb3有146.5的大小。

    创建一个新的block关联块

    切换路径到block下,创建一个sd4的关联block:

    /> cd backstores/block/
    /backstores/block> ls
    o- block ...................................................................................................... [Storage Objects: 2]
      o- block_sd2 .......................................................................... [/dev/sdb2 (48.8GiB) write-thru activated]
      | o- alua ....................................................................................................... [ALUA Groups: 1]
      |   o- default_tg_pt_gp ........................................................................... [ALUA state: Active/optimized]
      o- block_sd3 ......................................................................... [/dev/sdb3 (146.5GiB) write-thru activated]
        o- alua ....................................................................................................... [ALUA Groups: 1]
          o- default_tg_pt_gp ........................................................................... [ALUA state: Active/optimized]
    /backstores/block> create
    dev=       name=      readonly=  wwn=
    /backstores/block> create name=sd4 dev=
    Desktop/         TeamViewer/      下载/          公共/          图片/          文档/          模板/
    视频/          音乐/
    /backstores/block> create name=sd4 dev=/dev/sdb
    /dev/sdb       /dev/sdb1      /dev/sdb2      /dev/sdb3      /dev/sdb4
    /backstores/block> create name=sd4 dev=/dev/sdb4
    Created block storage object sd4 using /dev/sdb4.
    /backstores/block> ls
    o- block ...................................................................................................... [Storage Objects: 3]
      o- block_sd2 .......................................................................... [/dev/sdb2 (48.8GiB) write-thru activated]
      | o- alua ....................................................................................................... [ALUA Groups: 1]
      |   o- default_tg_pt_gp ........................................................................... [ALUA state: Active/optimized]
      o- block_sd3 ......................................................................... [/dev/sdb3 (146.5GiB) write-thru activated]
      | o- alua ....................................................................................................... [ALUA Groups: 1]
      |   o- default_tg_pt_gp ........................................................................... [ALUA state: Active/optimized]
      o- sd4 ............................................................................. [/dev/sdb4 (221.6GiB) write-thru deactivated]
        o- alua ....................................................................................................... [ALUA Groups: 1]
          o- default_tg_pt_gp ........................................................................... [ALUA state: Active/optimized]
    /backstores/block>
    

    可以看见新增了一个sd4的block块,关联的是sdb4,sdb4有221.6G大小。

    进入ISCSI路径下配置共享存储对象和共享存储连接

    创建一个iscsi共享存储名称:

    /iscsi> create wwn=iqn.2020-08.sd2.liyi.com:test
    

    查看共享存储显示的iscsi名称:

     o- iscsi ............................................................................................................ [Targets: 1]
      | o- iqn.2020-08.sd2.liyi.com:test ..................................................................................... [TPGs: 1]
      |   o- tpg1 ............................................................................................... [no-gen-acls, no-auth]
      |     o- acls .......................................................................................................... [ACLs: 1]
      |     | o- iqn.1994-05.com.redhat:be46bf1b1f5c .................................................................. [Mapped LUNs: 2]
      |     |   o- mapped_lun0 ............................................................................. [lun0 block/block_sd2 (rw)]
      |     |   o- mapped_lun1 ............................................................................. [lun1 block/block_sd3 (rw)]
      |     o- luns .......................................................................................................... [LUNs: 2]
      |     | o- lun0 ................................................................. [block/block_sd2 (/dev/sdb2) (default_tg_pt_gp)]
      |     | o- lun1 ................................................................. [block/block_sd3 (/dev/sdb3) (default_tg_pt_gp)]
      |     o- portals .................................................................................................... [Portals: 1]
      |       o- 192.168.0.104:3260 ............................................................................................... [OK]
      o- loopback ......................................................................................................... [Targets: 0]
    

    里面有一些名称是我已经创建完成的共享。
    创建完成iscsi名称后,下面会默认创建一个tpg1的路径,在tpg1路径下有三个路径为主要的:
    1.acls(客户端访问名称,免认证配置)
    2.luns(共享lun存储池,调用block共享块)
    3.portals(共享存储地址和端口)

    创建luns共享池

    创建一个共享lun,将需要共享的block块配置进lun池:

    /iscsi> cd iqn.2020-08.sd2.liyi.com:test/tpg1/luns/
    /iscsi/iqn.20...est/tpg1/luns> ls
    o- luns .................................................................................................................. [LUNs: 2]
      o- lun0 ......................................................................... [block/block_sd2 (/dev/sdb2) (default_tg_pt_gp)]
      o- lun1 ......................................................................... [block/block_sd3 (/dev/sdb3) (default_tg_pt_gp)]
    /iscsi/iqn.20...est/tpg1/luns> create
    /backstores/block/block_sd2  /backstores/block/block_sd3  /backstores/block/sd4        Desktop/
    TeamViewer/                  anaconda-ks.cfg              help                         info.txt
    initial-setup-ks.cfg         newtest01.txt                下载/                      公共/
    图片/                      文档/                      模板/                      视频/
    音乐/                      add_mapped_luns=             lun=                         storage_object=
    /iscsi/iqn.20...est/tpg1/luns>
    *          /          @last      lun0/      lun1/      bookmarks  cd         create     delete     exit       get        help
    ls         pwd        refresh    set        status
    /iscsi/iqn.20...est/tpg1/luns> create
    /backstores/block/block_sd2  /backstores/block/block_sd3  /backstores/block/sd4        Desktop/
    TeamViewer/                  anaconda-ks.cfg              help                         info.txt
    initial-setup-ks.cfg         newtest01.txt                下载/                      公共/
    图片/                      文档/                      模板/                      视频/
    音乐/                      add_mapped_luns=             lun=                         storage_object=
    /iscsi/iqn.20...est/tpg1/luns> create lun=lun2 storage_object=
    /backstores/block/block_sd2                 /backstores/block/block_sd3                 /backstores/block/sd4
    Desktop/                                    TeamViewer/                                 anaconda-ks.cfg
    help                                        info.txt                                    initial-setup-ks.cfg
    newtest01.txt                               下载/                                     公共/
    图片/                                     文档/                                     模板/
    视频/                                     音乐/
    /iscsi/iqn.20...est/tpg1/luns> create lun=lun2 storage_object=/backstores/block/
    /backstores/block/block_sd2                 /backstores/block/block_sd3                 /backstores/block/sd4
    /iscsi/iqn.20...est/tpg1/luns> create lun=lun2 storage_object=/backstores/block/sd4
    Created LUN 2.
    Created LUN 2->2 mapping in node ACL iqn.1994-05.com.redhat:be46bf1b1f5c
    /iscsi/iqn.20...est/tpg1/luns> ls
    o- luns .................................................................................................................. [LUNs: 3]
      o- lun0 ......................................................................... [block/block_sd2 (/dev/sdb2) (default_tg_pt_gp)]
      o- lun1 ......................................................................... [block/block_sd3 (/dev/sdb3) (default_tg_pt_gp)]
      o- lun2 ............................................................................... [block/sd4 (/dev/sdb4) (default_tg_pt_gp)]
    /iscsi/iqn.20...est/tpg1/luns>
    

    创建了一个新lun2,调用的是block块中的sd4,这个lun2的大小就是sd4的block大小。

    创建acls免认证访问

    在这里我们需要先打开那个没有多大磁盘空间的主机(我的就是功能型客户端),在功能型客户端中查看是否有iscsi这个工具:
    客户端默认是自带iscsi功能的,先查看一下需要免认证的客户端的iscsi名称。
    查看客户端iscsi名称:
    默认路径是在/etc/iscsi/initiatorname.iscsi中

    [root@localhost ~]# cat /etc/iscsi/initiatorname.iscsi
    InitiatorName=iqn.1994-05.com.redhat:be46bf1b1f5c
    [root@localhost ~]#
    

    我的客户端iscsi名称是这个,我把这个名称写入共享存储服务器的acls配置内:

    /iscsi/iqn.20...est/tpg1/luns> cd ../acls/
    /iscsi/iqn.20...est/tpg1/acls> ls
    o- acls .................................................................................................................. [ACLs: 1]
      o- iqn.1994-05.com.redhat:be46bf1b1f5c .......................................................................... [Mapped LUNs: 3]
        o- mapped_lun0 ..................................................................................... [lun0 block/block_sd2 (rw)]
        o- mapped_lun1 ..................................................................................... [lun1 block/block_sd3 (rw)]
        o- mapped_lun2 ........................................................................................... [lun2 block/sd4 (rw)]
    /iscsi/iqn.20...est/tpg1/acls>
    /                                     @last                                 iqn.1994-05.com.redhat:be46bf1b1f5c/
    bookmarks                             cd                                    create
    delete                                exit                                  get
    help                                  ls                                    pwd
    refresh                               set                                   status
    tag                                   untag
    /iscsi/iqn.20...est/tpg1/acls> create
    add_mapped_luns=  wwn=
    /iscsi/iqn.20...est/tpg1/acls> create wwn=iqn.1994-05.com.redhat:be46bf1b1f5c
    

    因为我这个已经添加了,就不再重新添加了,按两下Tab键可以查看当前路径下可用的命令,可以用delete命令再删除添加的客户端iscsi名称。

    将共享存储服务器的地址和端口配置进portals中

    /> ls
    o- / ......................................................................................................................... [...]
      o- backstores .............................................................................................................. [...]
      | o- block .................................................................................................. [Storage Objects: 3]
      | | o- block_sd2 ...................................................................... [/dev/sdb2 (48.8GiB) write-thru activated]
      | | | o- alua ................................................................................................... [ALUA Groups: 1]
      | | |   o- default_tg_pt_gp ....................................................................... [ALUA state: Active/optimized]
      | | o- block_sd3 ..................................................................... [/dev/sdb3 (146.5GiB) write-thru activated]
      | | | o- alua ................................................................................................... [ALUA Groups: 1]
      | | |   o- default_tg_pt_gp ....................................................................... [ALUA state: Active/optimized]
      | | o- sd4 ........................................................................... [/dev/sdb4 (221.6GiB) 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.2020-08.sd2.liyi.com:test ..................................................................................... [TPGs: 1]
      |   o- tpg1 ............................................................................................... [no-gen-acls, no-auth]
      |     o- acls .......................................................................................................... [ACLs: 1]
      |     | o- iqn.1994-05.com.redhat:be46bf1b1f5c .................................................................. [Mapped LUNs: 3]
      |     |   o- mapped_lun0 ............................................................................. [lun0 block/block_sd2 (rw)]
      |     |   o- mapped_lun1 ............................................................................. [lun1 block/block_sd3 (rw)]
      |     |   o- mapped_lun2 ................................................................................... [lun2 block/sd4 (rw)]
      |     o- luns .......................................................................................................... [LUNs: 3]
      |     | o- lun0 ................................................................. [block/block_sd2 (/dev/sdb2) (default_tg_pt_gp)]
      |     | o- lun1 ................................................................. [block/block_sd3 (/dev/sdb3) (default_tg_pt_gp)]
      |     | o- lun2 ....................................................................... [block/sd4 (/dev/sdb4) (default_tg_pt_gp)]
      |     o- portals .................................................................................................... [Portals: 1]
      |       o- 192.168.0.104:3260 ............................................................................................... [OK]
      o- loopback ......................................................................................................... [Targets: 0]
    /> cd iscsi/iqn.2020-08.sd2.liyi.com:test/tpg1/portals/
    /iscsi/iqn.20.../tpg1/portals> ls
    o- portals ............................................................................................................ [Portals: 1]
      o- 192.168.0.104:3260 ....................................................................................................... [OK]
    /iscsi/iqn.20.../tpg1/portals>
    /                    192.168.0.104:3260/  @last                bookmarks            cd                   create
    delete               exit                 get                  help                 ls                   pwd
    refresh              set                  status
    /iscsi/iqn.20.../tpg1/portals> delete
    192.168.0.104   ip_address=     ip_port=
    /iscsi/iqn.20.../tpg1/portals> delete ip_
    ip_address=  ip_port=
    /iscsi/iqn.20.../tpg1/portals> delete ip_address=192.168.0.104 ip_port=3260
    

    我这个是删除掉里面的IP地址和端口。
    下面是创建IP和端口(共享服务器的IP地址)

    /iscsi/iqn.20.../tpg1/portals> create ip_address=192.168.0.104 ip_port=3260
    

    记住这个端口,等下需要在服务器上放行这个端口,现在已经配置完成了服务器的共享存储targetcli。

    放行服务器端的3260端口

    我用的是firewall防火墙,所以需要使用firewall-cmd新加3260端口:

    [root@www ~]# firewall-cmd --add-
    --add-forward-port=                --add-lockdown-whitelist-command=  --add-masquerade                   --add-service=
    --add-icmp-block=                  --add-lockdown-whitelist-context=  --add-port=                        --add-source=
    --add-icmp-block-inversion         --add-lockdown-whitelist-uid=      --add-protocol=                    --add-source-port=
    --add-interface=                   --add-lockdown-whitelist-user=     --add-rich-rule=
    [root@www ~]# firewall-cmd --add-port=3260/tcp
    

    查看firewall开启的3260端口:

    [root@www ~]# firewall-cmd --list-ports
    80/tcp 3306/tcp 21/tcp 3260/tcp
    [root@www ~]# netstat -an | grep 3260
    tcp        0      0 192.168.0.104:3260      0.0.0.0:*               LISTEN
    tcp        0      0 192.168.0.104:3260      192.168.0.175:51998     ESTABLISHED
    [root@www ~]#
    

    下面的192.168.0.175这个是我已经建立了客户端调用共享存储后列出的记录。

    客户端配置iSCSI

    iscsi查看服务器共享的存储名称

    [root@localhost ~]# iscsiadm -h
    iscsiadm -m discoverydb [ -hV ] [ -d debug_level ] [-P printlevel] [ -t type -p ip:port -I ifaceN ... [ -Dl ] ] | [ [ -p ip:port -t type] [ -o operation ] [ -n name ] [ -v value ] [ -lD ] ]
    iscsiadm -m discovery [ -hV ] [ -d debug_level ] [-P printlevel] [ -t type -p ip:port -I ifaceN ... [ -l ] ] | [ [ -p ip:port ] [ -l | -D ] ]
    iscsiadm -m node [ -hV ] [ -d debug_level ] [ -P printlevel ] [ -L all,manual,automatic ] [ -U all,manual,automatic ] [ -S ] [ [ -T targetname -p ip:port -I ifaceN ] [ -l | -u | -R | -s] ] [ [ -o  operation  ] [ -n name ] [ -v value ] ]
    iscsiadm -m session [ -hV ] [ -d debug_level ] [ -P  printlevel] [ -r sessionid | sysfsdir [ -R | -u | -s ] [ -o operation ] [ -n name ] [ -v value ] ]
    iscsiadm -m iface [ -hV ] [ -d debug_level ] [ -P printlevel ] [ -I ifacename | -H hostno|MAC ] [ [ -o  operation  ] [ -n name ] [ -v value ] ] [ -C ping [ -a ip ] [ -b packetsize ] [ -c count ] [ -i interval ] ]
    iscsiadm -m fw [ -d debug_level ] [ -l ]
    iscsiadm -m host [ -P printlevel ] [ -H hostno|MAC ] [ [ -C chap [ -x chap_tbl_idx ] ] | [ -C flashnode [ -A portal_type ] [ -x flashnode_idx ] ] | [ -C stats ] ] [ [ -o operation ] [ -n name ] [ -v value ] ]
    iscsiadm -k priority
    [root@localhost ~]# iscsiadm -m discovery -t st -p 192.168.0.104 
    192.168.0.104:3260,1 iqn.2020-08.sd2.liyi.com:test
    [root@localhost ~]#
    

    可以看到客户端查到了服务器的iscsi名称。
    客户端登陆服务端iscsi共享
    这里有三条命令来使用iscsiadm,分别为查看、连接、断开连接:
    查看:iscsiadm -m discovery -t st -p 【服务器IP地址】
    登陆:iscsiadm -m node -T 【服务器iscsi名称】 -p 【服务器IP地址】 -l
    断开连接:iscsiadm -m node -T 【服务器iscsi名称】 -u

    [root@localhost ~]# lsblk
    NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sda               8:0    0 59.6G  0 disk
    ├─sda1            8:1    0  200M  0 part /boot/efi
    ├─sda2            8:2    0    1G  0 part /boot
    └─sda3            8:3    0 58.4G  0 part
      ├─centos-root 253:0    0 36.7G  0 lvm  /
      ├─centos-swap 253:1    0  3.9G  0 lvm  [SWAP]
      └─centos-home 253:2    0 17.9G  0 lvm  /home
    sdb               8:16   0 48.9G  0 disk
    [root@localhost ~]# iscsiadm -m node -T iqn.2020-08.sd2.liyi.com:test -u
    Logging out of session [sid: 3, target: iqn.2020-08.sd2.liyi.com:test, portal: 192.168.0.104,3260]
    Logout of [sid: 3, target: iqn.2020-08.sd2.liyi.com:test, portal: 192.168.0.104,3260] successful.
    [root@localhost ~]# lsblk
    NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sda               8:0    0 59.6G  0 disk
    ├─sda1            8:1    0  200M  0 part /boot/efi
    ├─sda2            8:2    0    1G  0 part /boot
    └─sda3            8:3    0 58.4G  0 part
      ├─centos-root 253:0    0 36.7G  0 lvm  /
      ├─centos-swap 253:1    0  3.9G  0 lvm  [SWAP]
      └─centos-home 253:2    0 17.9G  0 lvm  /home
    [root@localhost ~]#
    

    可以看到,我的客户端断开了sdb这个iscsi共享空间了。
    使用登陆命令访问iscsi共享空间:

    [root@localhost ~]# lsblk
    NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sda               8:0    0 59.6G  0 disk
    ├─sda1            8:1    0  200M  0 part /boot/efi
    ├─sda2            8:2    0    1G  0 part /boot
    └─sda3            8:3    0 58.4G  0 part
      ├─centos-root 253:0    0 36.7G  0 lvm  /
      ├─centos-swap 253:1    0  3.9G  0 lvm  [SWAP]
      └─centos-home 253:2    0 17.9G  0 lvm  /home
    [root@localhost ~]# iscsiadm -m node -T iqn.2020-08.sd2.liyi.com:test -p 192.168.0.104 -l
    Logging in to [iface: default, target: iqn.2020-08.sd2.liyi.com:test, portal: 192.168.0.104,3260] (multiple)
    Login to [iface: default, target: iqn.2020-08.sd2.liyi.com:test, portal: 192.168.0.104,3260] successful.
    [root@localhost ~]# lsblk
    NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
    sda               8:0    0  59.6G  0 disk
    ├─sda1            8:1    0   200M  0 part /boot/efi
    ├─sda2            8:2    0     1G  0 part /boot
    └─sda3            8:3    0  58.4G  0 part
      ├─centos-root 253:0    0  36.7G  0 lvm  /
      ├─centos-swap 253:1    0   3.9G  0 lvm  [SWAP]
      └─centos-home 253:2    0  17.9G  0 lvm  /home
    sdb               8:16   0  48.9G  0 disk
    sdc               8:32   0 221.6G  0 disk
    sdd               8:48   0 146.5G  0 disk
    [root@localhost ~]#
    

    可以看见,现在列出了三个新的共享iscsi分区,这个就是targetcli服务器内的三个lun池。可以直接用mount命令挂载共享存储空间来直接使用了。

    客户端挂载共享存储空间

    可以看到客户端多了三个共享分区:sdb,sdc,sdd。
    需要使用共享分区可以直接将此分区挂载到某个目录下即可:

    [root@localhost ~]# lsblk
    NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
    sda               8:0    0  59.6G  0 disk
    ├─sda1            8:1    0   200M  0 part /boot/efi
    ├─sda2            8:2    0     1G  0 part /boot
    └─sda3            8:3    0  58.4G  0 part
      ├─centos-root 253:0    0  36.7G  0 lvm  /
      ├─centos-swap 253:1    0   3.9G  0 lvm  [SWAP]
      └─centos-home 253:2    0  17.9G  0 lvm  /home
    sdb               8:16   0  48.9G  0 disk
    sdc               8:32   0 221.6G  0 disk
    sdd               8:48   0 146.5G  0 disk
    [root@localhost ~]# df -h
    文件系统                 容量  已用  可用 已用% 挂载点
    /dev/mapper/centos-root   37G  8.5G   29G   23% /
    devtmpfs                 1.8G     0  1.8G    0% /dev
    tmpfs                    1.9G     0  1.9G    0% /dev/shm
    tmpfs                    1.9G   56M  1.8G    3% /run
    tmpfs                    1.9G     0  1.9G    0% /sys/fs/cgroup
    /dev/sda2               1014M  172M  843M   17% /boot
    /dev/sda1                200M  9.8M  191M    5% /boot/efi
    /dev/mapper/centos-home   18G   40M   18G    1% /home
    tmpfs                    371M   40K  371M    1% /run/user/1000
    tmpfs                    371M     0  371M    0% /run/user/0
    [root@localhost ~]# ll /
    总用量 28
    drwxr-xr-x.   2 root root    42 8月  24 17:20 Application
    lrwxrwxrwx.   1 root root     7 7月   8 09:53 bin -> usr/bin
    dr-xr-xr-x.   6 root root  4096 8月  14 13:34 boot
    drwxr-xr-x.  20 root root  3400 8月  27 11:24 dev
    drwxr-xr-x. 135 root root 12288 8月  17 14:39 etc
    drwxr-xr-x.   3 root root    18 7月   8 10:07 home
    lrwxrwxrwx.   1 root root     7 7月   8 09:53 lib -> usr/lib
    lrwxrwxrwx.   1 root root     9 7月   8 09:53 lib64 -> usr/lib64
    drwxr-xr-x.   4 root root    29 8月  18 11:34 media
    drwxr-xr-x.   2 root root     6 11月  5 2016 mnt
    drwxr-xr-x.   3 root root    16 7月   8 09:59 opt
    dr-xr-xr-x. 224 root root     0 8月  17 15:31 proc
    dr-xr-x---.  16 root root  4096 8月  26 15:13 root
    drwxr-xr-x.  37 root root  1220 8月  27 06:57 run
    lrwxrwxrwx.   1 root root     8 7月   8 09:53 sbin -> usr/sbin
    drwxr-xr-x.   2 root root     6 11月  5 2016 srv
    dr-xr-xr-x.  13 root root     0 8月  17 15:31 sys
    drwxrwxrwt.  14 root root  4096 8月  27 11:21 tmp
    drwxr-xr-x.  13 root root   155 7月   8 09:53 usr
    drwxr-xr-x.  20 root root   282 7月   8 10:05 var
    drwxr-xr-x.   2 root root     6 8月  25 12:19 virtual_kvm
    [root@localhost ~]# df -h /virtual_kvm/
    文件系统                 容量  已用  可用 已用% 挂载点
    /dev/mapper/centos-root   37G  8.5G   29G   23% /
    [root@localhost ~]# mou
    mount        mount.fuse   mount.nfs    mount.nfs4   mountpoint   mountstats   mousetweaks
    [root@localhost ~]# mount /dev/sd
    sda   sda1  sda2  sda3  sdb   sdc   sdd
    [root@localhost ~]# mount /dev/sdb /virtual_kvm/
    [root@localhost ~]# df -h /virtual_kvm/
    文件系统        容量  已用  可用 已用% 挂载点
    /dev/sdb         48G   53M   46G    1% /virtual_kvm
    [root@localhost ~]# df -h
    文件系统                 容量  已用  可用 已用% 挂载点
    /dev/mapper/centos-root   37G  8.5G   29G   23% /
    devtmpfs                 1.8G     0  1.8G    0% /dev
    tmpfs                    1.9G     0  1.9G    0% /dev/shm
    tmpfs                    1.9G   56M  1.8G    3% /run
    tmpfs                    1.9G     0  1.9G    0% /sys/fs/cgroup
    /dev/sda2               1014M  172M  843M   17% /boot
    /dev/sda1                200M  9.8M  191M    5% /boot/efi
    /dev/mapper/centos-home   18G   40M   18G    1% /home
    tmpfs                    371M   40K  371M    1% /run/user/1000
    tmpfs                    371M     0  371M    0% /run/user/0
    /dev/sdb                  48G   53M   46G    1% /virtual_kvm
    [root@localhost ~]#
    

    可以看到,我将sdb的共享空间挂载给了/virtual_kvm文件夹,现在这个文件夹的空间是48G。

    服务器避免意外操作保存配置

    在服务器targetcli中使用save命令来保存当前的iscsi配置信息:

    /> ls
    o- / ......................................................................................................................... [...]
      o- backstores .............................................................................................................. [...]
      | o- block .................................................................................................. [Storage Objects: 3]
      | | o- block_sd2 ...................................................................... [/dev/sdb2 (48.8GiB) write-thru activated]
      | | | o- alua ................................................................................................... [ALUA Groups: 1]
      | | |   o- default_tg_pt_gp ....................................................................... [ALUA state: Active/optimized]
      | | o- block_sd3 ..................................................................... [/dev/sdb3 (146.5GiB) write-thru activated]
      | | | o- alua ................................................................................................... [ALUA Groups: 1]
      | | |   o- default_tg_pt_gp ....................................................................... [ALUA state: Active/optimized]
      | | o- sd4 ........................................................................... [/dev/sdb4 (221.6GiB) 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.2020-08.sd2.liyi.com:test ..................................................................................... [TPGs: 1]
      |   o- tpg1 ............................................................................................... [no-gen-acls, no-auth]
      |     o- acls .......................................................................................................... [ACLs: 1]
      |     | o- iqn.1994-05.com.redhat:be46bf1b1f5c .................................................................. [Mapped LUNs: 3]
      |     |   o- mapped_lun0 ............................................................................. [lun0 block/block_sd2 (rw)]
      |     |   o- mapped_lun1 ............................................................................. [lun1 block/block_sd3 (rw)]
      |     |   o- mapped_lun2 ................................................................................... [lun2 block/sd4 (rw)]
      |     o- luns .......................................................................................................... [LUNs: 3]
      |     | o- lun0 ................................................................. [block/block_sd2 (/dev/sdb2) (default_tg_pt_gp)]
      |     | o- lun1 ................................................................. [block/block_sd3 (/dev/sdb3) (default_tg_pt_gp)]
      |     | o- lun2 ....................................................................... [block/sd4 (/dev/sdb4) (default_tg_pt_gp)]
      |     o- portals .................................................................................................... [Portals: 1]
      |       o- 192.168.0.104:3260 ............................................................................................... [OK]
      o- loopback ......................................................................................................... [Targets: 0]
    /> saveconfig
    Configuration saved to /etc/target/saveconfig.json
    /> exit
    Global pref auto_save_on_exit=true
    Last 10 configs saved in /etc/target/backup/.
    Configuration saved to /etc/target/saveconfig.json
    [root@www ~]# ll /etc/target/
    总用量 16
    drwxr-xr-x. 2 root root  252 8月  27 11:33 backup
    -rw-r--r--. 1 root root 8980 8月  27 11:33 saveconfig.json
    -rw-r--r--. 1 root root  581 8月   4 2017 targetd.yaml
    [root@www ~]# ll /etc/target/backup/
    总用量 48
    -rw-r--r--. 1 root root 3694 8月  26 10:12 saveconfig-20200826-10:12:53.json
    -rw-r--r--. 1 root root 4644 8月  26 15:15 saveconfig-20200826-15:15:03.json
    -rw-r--r--. 1 root root 4650 8月  26 15:15 saveconfig-20200826-15:15:12.json
    -rw-r--r--. 1 root root 6422 8月  27 10:22 saveconfig-20200827-10:22:02.json
    -rw-r--r--. 1 root root 6821 8月  27 10:25 saveconfig-20200827-10:25:40.json
    -rw-r--r--. 1 root root 8980 8月  27 11:33 saveconfig-20200827-11:33:10.json
    [root@www ~]#
    

    这下就完美搞成了!别忘了点赞哦。

    展开全文
  • targetcli RTSLibError

    2019-10-02 13:03:08
    [root@server223 common_software]# targetcli targetcli shell version 2.1.fb41 Copyright 2011-2013 by Datera, Inc and others. For help on commands, type 'help'. /> exit Global pref auto...
    [root@server223 common_software]# targetcli
    targetcli shell version 2.1.fb41
    Copyright 2011-2013 by Datera, Inc and others.
    For help on commands, type 'help'.
    
    /> exit
    Global pref auto_save_on_exit=true
    Last 10 configs saved in /etc/target/backup.
    Traceback (most recent call last):
      File "/bin/targetcli", line 121, in <module>
        main()
      File "/bin/targetcli", line 117, in main
        root_node.ui_command_saveconfig()
      File "/usr/lib/python2.7/site-packages/targetcli/ui_root.py", line 86, in ui_command_saveconfig
        self.rtsroot.save_to_file(savefile)
      File "/usr/lib/python2.7/site-packages/rtslib_fb/root.py", line 250, in save_to_file
        f.write(json.dumps(self.dump(), sort_keys=True, indent=2))
      File "/usr/lib/python2.7/site-packages/rtslib_fb/root.py", line 146, in dump
        d['storage_objects'] = [so.dump() for so in self.storage_objects]
      File "/usr/lib/python2.7/site-packages/rtslib_fb/tcm.py", line 734, in dump
        d['wwn'] = self.wwn
      File "/usr/lib/python2.7/site-packages/rtslib_fb/tcm.py", line 124, in _get_wwn
        + "an unconfigured StorageObject")
    rtslib_fb.utils.RTSLibError: Cannot read a T10 WWN Unit Serial from an unconfigured StorageObject
    

     

    Linux server223 3.10.0-229.el7.x86_64

    pyparsing-1.5.6-9.el7.noarch.rpm

    python-configshell-1.1.fb18-1.el7.noarch.rpm

    python-ethtool-0.8-5.el7.x86_64.rpm

    python-kmod-0.9-4.el7.x86_64.rpm

    python-rtslib-2.1.fb57-5.el7.noarch.rpm

    python-six-1.9.0-1.el7.noarch.rpm

    python-urwid-1.1.1-3.el7.x86_64.rpm

    targetcli-2.1.fb41-3.el7.noarch.rpm

    安装好上面的包后还是报上面的错误时,执行下面命令可解决问题。

    targetctl clear

    targetcli saveconfig

    转载于:https://www.cnblogs.com/longchang/p/11608144.html

    展开全文
  • targetcli配置iSCSI

    2018-10-25 17:12:00
    概述:这篇文章来介绍LIO下的用户态工具targetcli来配置iSCSI服务 虚拟机环境:centos7.x(内核版本3.10.0-862.el7.x86_64) IP分别为192.168.1.200/201 targetcli安装 centos一般都自带了此工具,没有的话去...

    概述:这篇文章来介绍LIO下的用户态工具targetcli来配置iSCSI服务

    虚拟机环境:centos7.x(内核版本3.10.0-862.el7.x86_64)

    IP分别为192.168.1.200/201

     

    targetcli安装

    centos一般都自带了此工具,没有的话去官网下载,这里就不再介绍

     

    快速创建IP-SAN

    1.命令行输入targetcli进入交互界面,在交互界面可以使用ls,cd等命令灵活简单的操作,如图所示,最上层目录包括backstores、iscsi等,如果有FC或Infiniband的话,还会有其余的一些子模块如qla2xxx等

     

     

    2.创建卷资源

    使用cd进入/backstores/block目录,

    cd backstores/block

    然后创建卷资源,使用块设备/dev/sdb

    create dev=/dev/sdb name=sdb

    提示sdb设备正在被使用,重新选择/dev/sdc来创建卷资源,提示创建成功(readonly属性表示读写权限,wwn号为卷资源的唯一标号)

     

     

    3.创建iSCSI

    快速创建一个iSCSI服务的步骤如下:

    a.首先创建一个iqn

    b.在iqn下添加提供服务的IP以及需要映射的卷

    c.设置认证

     操作如下:

    这里介绍一个技巧,在交互界面输入cd,可以进入下图界面,可以灵活快速地跳到指定目录

     

    接下来在iscsi目录下创建iqn

     

    然后在iqn的对应目录下添加服务IP,映射卷和权限设置

     

     

    initiator端发现:可以看到已经可以发现登录过来的逻辑卷

    发现命令:iscsiadm -m discovery -t st -p IP

    登录命令:在发现命令后面加入-l或者iscsiadm -m node -T IQN -l

    登出命令:iscsiadm -m node -T IQN -u 如 iscsiadm -m node -T iqn.2018-10.hzhrinet.com:test -u

     

     iSCSI认证

    iSCSI认证分为发现认证和登录认证,其中每种认证又分为单向认证和双向认证

    发现认证和登录认证的意思就和名字一样

    单向认证是指initiator端在发现target端的时候,要提供正确的认证才能发现在target端的iSCSI服务

    双向认证是指在单向认证的基础上,target端需要正确设置initiator端设置的认证才能被initiator端发现

    发现认证:

    1.首先我们来看发现认证的默认属性,这是一个全局的设置

     

    2.设置单向认证

    首先在target端执行命令,设置单向认证

    此时initiator端登录会出现认证错误,无法发现

    这时我们需要设置initiator端的配置文件/etc/iscsi/iscsid.conf

    此时再在initiator端发现,发现成功

     

    3.设置双向认证(必须建立在单向认证的基础上)

    首先在initiator端设置认证

     

    然后在target端设置initiator的认证

     

     

    登录认证:

    登录认证和发现认证类似,也是分为单向认证和双向认证,设置的方法和发现认证几乎一样

    这里有几个注意的地方

    1.generate_node_acls属性表示是否开启ACL,当为no-gen-acls的是否,initiator端的iqn号(/etc/iscsi/initiatorname.iscsi下)必须加入acl才能登陆

    2.在tpg目录下打开认证set attribute authentication=1,作用类似发现认证的enable

    在acl的iqn目录下设置用户和密码,操作类似发现认证

     

    initiator端修改这些选项就可以了,和发现认证类似

     

     

    参考:http://blog.51cto.com/zhuxu91313/2154819

    转载于:https://www.cnblogs.com/luxiaodai/p/9851214.html

    展开全文
  • CentOS7.1下targetcli的使用

    千次阅读 2018-02-24 14:10:08
    以前使用tgtadm工具,但是在CentOS7.1下无法安装该工具,网上查询后发现targetcli工具,于是将target及initiator的配置方法记录于下:target端 1.yum -y install targetcli 2.#targetcli 创建一个块设备 3.&...
  • Targetcli man page

    2018-01-29 11:32:33
    targetcli支持一般大小的缩写,如“M”、“G”和“T”。       除了文件支持卷的fileio backstore之外,其他的backstore类型包括块用于块设备支持的卷,     以及由本地SCSI设备支持的卷的pscsi。ramdisk ...
  • 测试环境说明: 测试环境一共使用4台服务器,两台Linux、两台Windows,一台Linux做为iSCSIServer,用Targetcli以iSCSI的方式提供存储共享服务,另外三台使用iSCSIServer上的存储资源,各自访问各自的资源,相互之间...
  • 1:在服务端下载targetcli 关闭防火墙并开启targetcli 2:创建一个分区,大小为2G fdisk /dev/vdb 3:执行targetcli ls /backstores/block create westos:storage1 /dev/vdb1 /iscsi create iqn.2018-06....
  • 1.修改主机名称  node1 和node2 2.配置IP 3.关闭selinux 和firewall ...4.安装targetcli 5.建立逻辑卷 6.targetcli   backstore/block/ create iscsiname /dev/vg/lv /建立一个存储块  /iscsi ...
  • targetcli搭建Fibre Channel(FC) target

    万次阅读 2015-04-23 21:40:54
    如果利用targetcli创建Fibre Channel (FC) targets
  • targetcli是建立起LIO用来把后台的存储资源映射给initiator的重要工具,它下面通过python rtslib实现和iscsi(linux下对应iscsi_target_mod.ko驱动)和HBA卡(linux下对应tcm_qlax2xxx.ko驱动)等介质的交互,进而向...
  • targetcli是一个iSCSI配置管理工具,该工具简单易用,可以直接替换scsi-target-utils。满心欢喜的装上它,正准备一睹为快,就杯具了。报错ImportError: cannot import name ALUATargetPortGroup。
  • targetcli 的配置都需要用到configFS, 因此configFS模块必须被加载到内核中。把configFS挂载到/sys/kernel/config: mount -t configfs configfs /sys/kernel/config   (3)设置HBA卡为target mode vi /etc/...
  • 组建iscsi 网络三种target工具,分别为tgt,iscsi_tgt,和targetcli ; initiator 端均使用open-iscsi即可; a. tgt  使用tgtadm命令创建iscsi target;  首先,创建target  tgtadm --lld iscsi --mode ...
  • FC targetcli 光纤HBA卡直连

    千次阅读 2018-12-29 18:26:42
    推荐用fedora,Ubuntu15.10版可以,后来的版本不可以,没全试,centos不可以。 mount -t configfs configfs /sys/kernel/config  设置HBA卡为target modevi /etc/modprobe.d/qla2xxx.conf options qla2xxx qlini_...
  • 于CentOS7.2配置ISCSI-targetcli---Linux

    万次阅读 2017-06-01 10:20:43
    yum -y install targetcli 启动target服务 # systemctl start target 设置开机启动服务 # systemctl enable target 新建分区 注意:(/dev/sdb1)第二块硬盘(可自定义任何磁盘),fdisk -l查看...
  • 离线安装包,亲测可用
  • ceph1326:rbd的ceph 13.2.6和iscsi targetcli
  • rhel7中,targetcli使用两位数的分区后缀名字(比如sda10)而导致的问题
  • CentOS7.2配置ISCSI-targetcli---Linux

    千次阅读 2018-03-22 14:48:28
    CentOS7.2配置ISCSI-targetcli---Linux一、准备工作1.1、(服务端和客户端都需要设置)系统使用的是CentOS7.2禁用防火墙:查看状态:# systemctl status firewalld或者 firewall-cmd--state停止:# systemctl stop ...
  • targetcli save error

    2019-05-24 12:09:00
    File "/usr/lib/python2.7/site-packages/targetcli/ui_root.py", line 90, in ui_command_saveconfig self.rtsroot.save_to_file(savefile) File "/usr/lib/python2.7/site-packages/rtslib_fb/root.py", line ...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 2,202
精华内容 880
关键字:

targetcli