1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
| [root@centos77 tmp]# targetcli /> backstores/block create dev=/dev/loop0 name=shareddisk /> iscsi/ create iqn.2020-02.com.baidu:shareddisk /> iscsi/iqn.2020-02.com.baidu:shareddisk/tpg1/acls create iqn.2020-02.com.baidu:client /> /iscsi/iqn.2020-02.com.baidu:shareddisk/tpg1/luns create /backstores/block/shareddisk /> saveconfig /> exit Global pref auto_save_on_exit=true Configuration saved to /etc/target/saveconfig.json
[root@centos77 ~]# targetcli targetcli shell version 2.1.fb49 Copyright 2011-2013 by Datera, Inc and others. For help on commands, type 'help'.
/> ls o- / ................................................................................................... [...] o- backstores ........................................................................................ [...] | o- block ............................................................................ [Storage Objects: 1] | | o- shared_disk .............................................. [/dev/loop0 (2.0GiB) 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-02.com.baidu:shareddisk ............................................................ [TPGs: 1] | o- tpg1 ......................................................................... [no-gen-acls, no-auth] | o- acls .................................................................................... [ACLs: 1] | | o- iqn.2020-02.com.baidu:client ................................................... [Mapped LUNs: 1] | | o- mapped_lun0 ..................................................... [lun0 block/shared_disk (rw)] | o- luns .................................................................................... [LUNs: 1] | | o- lun0 ........................................ [block/shared_disk (/dev/loop0) (default_tg_pt_gp)] | o- portals .............................................................................. [Portals: 1] | o- 0.0.0.0:3260 ............................................................................... [OK] o- loopback ................................................................................... [Targets: 0] /> [root@centos77 tmp]# systemctl restart target [root@centos77 tmp]# systemctl status target [root@centos77 tmp]# systemctl status iscsid [root@centos77 ~]# iscsiadm -m discoverydb -t st -p 192.168.1.10 --discover iscsiadm: Could not bind connection 0 to ens33:0 iscsiadm: cannot make connection to 192.168.1.10: No such device iscsiadm: Could not bind connection 0 to ens33:0 iscsiadm: cannot make connection to 192.168.1.10: No such device iscsiadm: Could not bind connection 0 to ens33:0 iscsiadm: cannot make connection to 192.168.1.10: No such device iscsiadm: Could not bind connection 0 to ens33:0 iscsiadm: cannot make connection to 192.168.1.10: No such device iscsiadm: Could not bind connection 0 to ens33:0 iscsiadm: cannot make connection to 192.168.1.10: No such device iscsiadm: Could not bind connection 0 to ens33:0 iscsiadm: cannot make connection to 192.168.1.10: No such device iscsiadm: connection login retries (reopen_max) 5 exceeded 192.168.1.10:3260,1 iqn.2020-02.com.baidu:shareddisk [root@centos77 ~]# iscsiadm -m discoverydb -t st -p 192.168.1.11 --discover iscsiadm: Could not bind connection 0 to ens33:0 iscsiadm: cannot make connection to 192.168.1.11: No such device iscsiadm: Could not bind connection 0 to ens33:0 iscsiadm: cannot make connection to 192.168.1.11: No such device iscsiadm: Could not bind connection 0 to ens33:0 iscsiadm: cannot make connection to 192.168.1.11: No such device iscsiadm: Could not bind connection 0 to ens33:0 iscsiadm: cannot make connection to 192.168.1.11: No such device iscsiadm: Could not bind connection 0 to ens33:0 iscsiadm: cannot make connection to 192.168.1.11: No such device iscsiadm: Could not bind connection 0 to ens33:0 iscsiadm: cannot make connection to 192.168.1.11: No such device iscsiadm: connection login retries (reopen_max) 5 exceeded 192.168.1.11:3260,1 iqn.2020-02.com.baidu:shareddisk [root@centos77 ~]# iscsiadm -m node 192.168.1.10:3260,1 iqn.2020-02.com.baidu:shareddisk 192.168.1.11:3260,1 iqn.2020-02.com.baidu:shareddisk [root@centos77 tmp]# iscsiadm -m iface -I iface0 --op=new //删除iface为:iscsiadm -m iface -I iface0 --op=delete New interface iface0 added [root@centos77 tmp]# iscsiadm -m iface -I iface1 --op=new //删除iface为:iscsiadm -m iface -I iface1 --op=delete New interface iface1 added [root@centos77 tmp]# ls -l /var/lib/iscsi/ifaces/ total 8 -rw-------. 1 root root 419 Feb 15 10:01 iface0 -rw-------. 1 root root 419 Feb 15 10:01 iface1 [root@centos77 tmp]# iscsiadm -m iface -I iface0 --op=update -n iface.net_ifacename -v ens33 iface0 updated. [root@centos77 tmp]# iscsiadm -m iface -I iface1 --op=update -n iface.net_ifacename -v ens33:0 iface0 updated. [root@centos77 ~]# iscsiadm -m iface default tcp,<empty>,<empty>,<empty>,<empty> iser iser,<empty>,<empty>,<empty>,<empty> iface0 tcp,<empty>,<empty>,ens33,<empty> iface1 tcp,<empty>,<empty>,ens33:0,<empty> [root@centos77 tmp]# iscsiadm -m discoverydb -t st -p 192.168.1.10 -I iface0 -I iface1 # BEGIN RECORD 6.2.0.874-10 discovery.startup = manual discovery.type = sendtargets discovery.sendtargets.address = 192.168.1.10 discovery.sendtargets.port = 3260 discovery.sendtargets.auth.authmethod = None discovery.sendtargets.auth.username = <empty> discovery.sendtargets.auth.password = <empty> discovery.sendtargets.auth.username_in = <empty> discovery.sendtargets.auth.password_in = <empty> discovery.sendtargets.timeo.login_timeout = 15 discovery.sendtargets.use_discoveryd = No discovery.sendtargets.discoveryd_poll_inval = 30 discovery.sendtargets.reopen_max = 5 discovery.sendtargets.timeo.auth_timeout = 45 discovery.sendtargets.timeo.active_timeout = 30 discovery.sendtargets.iscsi.MaxRecvDataSegmentLength = 32768 # END RECORD [root@centos77 ~]# iscsiadm --mode node --targetname iqn.2020-02.com.baidu:shareddisk --portal 192.168.1.10:3260 --login [root@centos77 ~]# iscsiadm --mode node --targetname iqn.2020-02.com.baidu:shareddisk --portal 192.168.1.11:3260 --login 或者[root@centos77 ~]# iscsiadm -m node -l //登出为:iscsiadm -m node -u [root@centos77 ~]# iscsiadm -m node 192.168.1.10:3260,1 iqn.2020-02.com.baidu:shareddisk 192.168.1.11:3260,1 iqn.2020-02.com.baidu:shareddisk [root@centos77 ~]# iscsiadm -m session //查看登录会话 tcp: [5] 192.168.1.10:3260,1 iqn.2020-02.com.baidu:shareddisk (non-flash) tcp: [6] 192.168.1.11:3260,1 iqn.2020-02.com.baidu:shareddisk (non-flash) //也可以查看登录会话 [root@centos77 ~]# netstat -anp | grep 3260 tcp 0 0 0.0.0.0:3260 0.0.0.0:* LISTEN - tcp 0 0 192.168.1.10:57166 192.168.1.11:3260 ESTABLISHED 1727/iscsid tcp 0 0 192.168.1.11:3260 192.168.1.10:57166 ESTABLISHED - tcp 0 0 192.168.1.10:41850 192.168.1.10:3260 ESTABLISHED 1727/iscsid tcp 0 0 192.168.1.10:3260 192.168.1.10:41850 ESTABLISHED -
[root@centos77 tmp]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 7G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 6G 0 part ├─centos-root 253:0 0 5.3G 0 lvm / └─centos-swap 253:1 0 716M 0 lvm [SWAP] sdb 8:16 0 2G 0 disk sdc 8:32 0 2G 0 disk sr0 11:0 1 1024M 0 rom loop0 7:0 0 2G 0 loop //其中loop0是dd出来的作为共享的挂载在/dev/loop0上的/tmp/images.iso //sdb,sdc是通过initiator登录target识别出来的2块硬盘(其实就是一个loop0共享出来的target) //所以说,target,initiator,multipath同在一台机器上 [root@centos77 tmp]# netstat -anp | grep 3260 tcp 0 0 0.0.0.0:3260 0.0.0.0:* LISTEN - tcp 0 0 192.168.1.10:3260 192.168.1.10:46320 ESTABLISHED - tcp 0 0 192.168.1.10:45494 192.168.1.11:3260 ESTABLISHED 2290/iscsid tcp 0 0 192.168.1.10:46320 192.168.1.10:3260 ESTABLISHED 2290/iscsid tcp 0 0 192.168.1.11:3260 192.168.1.10:45494 ESTABLISHED - //如上输出也能证明,所以说,target,initiator,multipath同在一台机器上
[root@centos77 ~]# cat /proc/scsi/scsi Attached devices: Host: scsi0 Channel: 00 Id: 00 Lun: 00 Vendor: VMware, Model: VMware Virtual S Rev: 1.0 Type: Direct-Access ANSI SCSI revision: 02 Host: scsi2 Channel: 00 Id: 00 Lun: 00 Vendor: NECVMWar Model: VMware IDE CDR10 Rev: 1.00 Type: CD-ROM ANSI SCSI revision: 05 Host: scsi15 Channel: 00 Id: 00 Lun: 00 Vendor: LIO-ORG Model: shared_disk Rev: 4.0 Type: Direct-Access ANSI SCSI revision: 05 Host: scsi16 Channel: 00 Id: 00 Lun: 00 Vendor: LIO-ORG Model: shared_disk Rev: 4.0 Type: Direct-Access ANSI SCSI revision: 05 [root@centos77 ~]# grep -v "zZzZ" -H /sys/class/scsi_host/host{0,1,2,15,16}/state /sys/class/scsi_host/host0/state:running /sys/class/scsi_host/host1/state:running /sys/class/scsi_host/host2/state:running /sys/class/scsi_host/host15/state:running /sys/class/scsi_host/host16/state:running
|