iscsi--internet small computer system interface互聯小型計算機系統接口,將數據包封裝在TCP/IP協議中傳輸,使用普通網線和網絡設備便可實現,相對於FC-SAN存儲來講更廉價。node
iscsi通常分爲服務器端和客戶端,服務器端負責管理本地磁盤或磁盤陳列,客戶端則是用來發現並鏈接服務器端得到訪問iscsi共享盤。linux
centos7 | 軟件包 |
---|---|
服務端 | targetcli, targetd,scsi-target-utils |
客戶端 | iscsi-initiator-utils |
角色 | 主機名 | IP |
---|---|---|
服務端 | master | 192.168.138.200 |
客戶端 | slave | 192.168.138.201 |
# targetcli targetcli shell version 2.1.fb46 Copyright 2011-2013 by Datera, Inc and others. For help on commands, type 'help'. /> ls o- / ........................................................... [...] o- backstores ................................................ [...] | o- block .................................... [Storage Objects: 0] | o- fileio ................................... [Storage Objects: 0] | o- pscsi .................................... [Storage Objects: 0] | o- ramdisk .................................. [Storage Objects: 0] o- iscsi .............................................. [Targets: 0] o- loopback ........................................... [Targets: 0] /> cd /backstores/block /backstores/block> create slave /dev/sdb Created block storage object slave using /dev/sdb.
/backstores/block> cd /iscsi /iscsi> create iqn.2018-02.com.frank.master:slave Created target iqn.2018-02.com.frank.master:slave. Created TPG 1. Default portal not created, TPGs within a target cannot share ip:port.
/iscsi> cd iqn.2018-02.com.frank.master:slave/tpg1/acls /iscsi/iqn.20...ave/tpg1/acls> create iqn.2018-02.com.frank.master:slave Created Node ACL for iqn.2018-02.com.frank.master:slave /iscsi/iqn.20...ave/tpg1/acls> ls o- acls .................................................... [ACLs: 1] o- iqn.2018-02.com.frank.master:slave ............. [Mapped LUNs: 0]
/iscsi> cd iqn.2018-02.com.frank.master:slave/tpg1/luns /iscsi/iqn.20...ave/tpg1/luns> create /backstores/block/slave Created LUN 0. Created LUN 0->0 mapping in node ACL iqn.2018-02.com.frank.master:slave /iscsi/iqn.20...ave/tpg1/luns> ls o- luns .................................................... [LUNs: 1] o- lun0 ................ [block/slave (/dev/sdb) (default_tg_pt_gp)]
/iscsi/iqn.20.../tpg1/portals> create 192.168.138.200 ip_port=3260 Using default IP port 3260 Created network portal 192.168.138.200:3260.
這裏要注意的是,使用ls查看一下是否是已經有0.0.0.0 3260這個條目,若是有刪除掉再建立,否則會報錯,還有一點的是若是 tgtd服務正在開啓的狀況下也沒法建立,必須先停掉tgtd這個服務。shell
/iscsi/iqn.20....master:slave> set auth userid=test Parameter userid is now 'test'. /iscsi/iqn.20....master:slave> set auth password=test Parameter password is now 'test'.
到這裏服務器的配置就算完成了,最後看一下配置完成的狀態centos
/> ls o- / ........................................................................... [...] o- backstores ................................................................ [...] | o- block .................................................... [Storage Objects: 1] | | o- slave ............................. [/dev/sdb (20.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.2018-02.com.frank.master:slave .................................. [TPGs: 1] | o- tpg1 ................................................. [no-gen-acls, no-auth] | o- acls ............................................................ [ACLs: 1] | | o- iqn.2018-02.com.frank.master:slave ..................... [Mapped LUNs: 1] | | o- mapped_lun0 ................................... [lun0 block/slave (rw)] | o- luns ............................................................ [LUNs: 1] | | o- lun0 ........................ [block/slave (/dev/sdb) (default_tg_pt_gp)] | o- portals ...................................................... [Portals: 1] | o- 192.168.138.200:3260 ............................................... [OK] o- loopback ........................................................... [Targets: 0] />
# systemctl start tgtd.service
# iscsiadm -m discovery -t sendtargets -p 192.168.138.200 iscsiadm: This command will remove the record [iface: default, target: iqn.2018-04.com.frank.www:iscsi1, portal: 192.168.138.200,3260], but a session is using it. Logout session then rerun command to remove record. 192.168.138.200:3260,1 iqn.2018-02.com.frank.master:slave
# iscsiadm -m node -T iqn.2018-02.com.frank.master:slave -p 192.168.138.200 --login Logging in to [iface: default, target: iqn.2018-02.com.frank.master:slave, portal: 192.168.138.200,3260] (multiple) Login to [iface: default, target: iqn.2018-02.com.frank.master:slave, portal: 192.168.138.200,3260] successful.
fdsik -l WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion. Disk /dev/sdc: 21.5 GB, 21474836480 bytes, 41943040 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: gpt # Start End Size Type Name # fdisk /dev/sdc Command (m for help): n Partition number (1-128, default 1): First sector (34-41943006, default 8192): Last sector, +sectors or +size{K,M,G,T,P} (8192-41943006, default 41943006): +10G Created partition 1 Command (m for help): n Partition number (2-128, default 2): First sector (34-41943006, default 20979712): Last sector, +sectors or +size{K,M,G,T,P} (20979712-41943006, default 41943006): Created partition 2 Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@slave ~]# fdisk /dev/sdc WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion. 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. Command (m for help): p Disk /dev/sdc: 21.5 GB, 21474836480 bytes, 41943040 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: gpt # Start End Size Type Name 1 8192 20979711 10G Linux filesyste 2 20979712 41943006 10G Linux filesyste
# mkfs.xfs /dev/sdc1 meta-data=/dev/sdc1 isize=512 agcount=4, agsize=610351 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=2441402, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 [root@slave ~]# mkfs.xfs /dev/sdc2 meta-data=/dev/sdc2 isize=512 agcount=4, agsize=610291 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=2441162, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 # mount /dev/sdc1 /iscsi/ # df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/cl-root xfs 37G 11G 27G 28% / devtmpfs devtmpfs 712M 0 712M 0% /dev tmpfs tmpfs 723M 12K 723M 1% /dev/shm tmpfs tmpfs 723M 72M 651M 10% /run tmpfs tmpfs 723M 0 723M 0% /sys/fs/cgroup /dev/sda1 xfs 1014M 184M 831M 19% /boot tmpfs tmpfs 145M 0 145M 0% /run/user/0 /dev/sdc1 xfs 9.4G 33M 9.3G 1% /iscsi