文件共享之iscsi

1.
iscsi 是直接對設備進行共享的服務

2.啓動iscsi共享設備


****server端****
1.
建立一個lvm設備

[root@server40 ~]# fdisk /dev/vdb
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 0x0099d7b4.

Command (m for help): p       

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x0099d7b4

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n        
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (2048-20971519, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +1000M
Partition 1 of type Linux and of size 1000 MiB is set

Command (m for help): p

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x0099d7b4

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048     2050047     1024000   83  Linux

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x0099d7b4

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048     2050047     1024000   8e  Linux LVM

Command (m for help): q   

[root@server40 ~]# pvcreate /dev/vdb1
  Physical volume "/dev/vdb1" successfully created
[root@server40 ~]# vgcreate vg0 /dev/vdb1
  Volume group "vg0" successfully created
[root@server40 ~]# vgdisplay
  --- Volume group ---
  VG Name               vg0
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               996.00 MiB
  PE Size               4.00 MiB
  Total PE              249
  Alloc PE / Size       0 / 0   
  Free  PE / Size       249 / 996.00 MiB
  VG UUID               oEjeoF-I07m-UJOg-JJFX-4X3S-xNst-2k4bsD
   
[root@server40 ~]# lvcreate -l 249 -n iscsi_storage vg0
  Logical volume "iscsi_storage" created
[root@server40 ~]# lvs
  LV            VG   Attr       LSize   Pool Origin Data%  Move Log Cpy%Sync Convert
  iscsi_storage vg0  -wi-a----- 996.00m

2.下載並開啓客戶服務                                            
[root@server40 ~]# yum install targetcli -y
[root@server40 ~]# systemctl enable target
ln -s '/usr/lib/systemd/system/target.service' '/etc/systemd/system/multi-user.target.wants/target.service'
[root@server40 ~]# systemctl stop  firewalld.service
[root@server40 ~]# targetcli
Warning: Could not load preferences file /root/.targetcli/prefs.bin.
targetcli shell version 2.1.fb34
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]
/> /backstores/block create serverlstorage /dev/vg0/                       
/> /backstores/block create serverlstorage /dev/vg0/iscsi_storage   ##
提供硬盤,建立存儲設備

Created block storage object serverlstorage using /dev/vg0/iscsi_storage.
/> /iscsi create iqn.2017-06.com.example:strage1                            ##創建iqn
Created target iqn.2017-06.com.example:strage1.
Created TPG 1.
/> /iscsi/iqn.2017-06.com.example:strage1/tpg1/luns create /backstores/block/serverlstorage   ##創建目標地址
Created LUN 0.
/> /iscsi/iqn.2017-06.com.example:strage1/tpg1/acls create iqn.2017-06.com.example:serverlstorage  ##創建ian密匙,只用明文密碼
Created Node ACL for iqn.2017-06.com.example:serverlstorage
Created mapped LUN 0.
/> /iscsi/iqn.2017-06.com.example:strage1/tpg1/portals create 172.25.40.11   ##設置目標門戶,即服務器ip,打開3260端口
Using default IP port 3260
Created network portal 172.25.40.11:3260.
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
[root@server40 ~]# targetcli
targetcli shell version 2.1.fb34
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.

/> ls
o- / ..................................................................................... [...]
  o- backstores .......................................................................... [...]
  | o- block .............................................................. [Storage Objects: 1]
  | | o- serverlstorage ............... [/dev/vg0/iscsi_storage (996.0MiB) write-thru activated]
  | o- fileio ............................................................. [Storage Objects: 0]
  | o- pscsi .............................................................. [Storage Objects: 0]
  | o- ramdisk ............................................................ [Storage Objects: 0]
  o- iscsi ........................................................................ [Targets: 1]
  | o- iqn.2017-06.com.example:strage1 ............................................... [TPGs: 1]
  |   o- tpg1 ........................................................... [no-gen-acls, no-auth]
  |     o- acls ...................................................................... [ACLs: 1]
  |     | o- iqn.2017-06.com.example:serverlstorage ........................... [Mapped LUNs: 1]
  |     |   o- mapped_lun0 .................................... [lun0 block/serverlstorage (rw)]
  |     o- luns ...................................................................... [LUNs: 1]
  |     | o- lun0 .............................. [block/serverlstorage (/dev/vg0/iscsi_storage)]
  |     o- portals ................................................................ [Portals: 1]
  |       o- 172.25.40.11:3260 ............................................................ [OK]
  o- loopback ..................................................................... [Targets: 0]
/>

****desktop端****
[root@desktop40 ~]# yum whatprovides */genkey
Loaded plugins: langpacks
rhel_dvd/filelists_db                                                    | 3.0 MB  00:00:00     
crypto-utils-2.4.1-42.el7.x86_64 : SSL certificate and key management utilities
Repo        : rhel_dvd
Matched from:
Filename    : /usr/bin/genkey



[root@desktop40 ~]# vim /etc/iscsi/initiatorname.iscsi    ##設置發起端iqn

                                    =後爲iqn密匙
[root@desktop40 ~]# iscsiadm -m discovery -t st -p 172.25.40.11           ##登陸服務器
172.25.40.11:3260,1 iqn.2017-06.com.example:strage1
[root@desktop40 ~]# fdisk -l

Disk /dev/vda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x00013f3e

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    20970332    10484142+  83  Linux

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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

[root@desktop40 ~]# iscsiadm -m node -T iqn.2017-06.com.example:strage1 -p 172.25.40.11 -l
Logging in to [iface: default, target: iqn.2017-06.com.example:strage1, portal: 172.25.40.11,3260] (multiple)
Login to [iface: default, target: iqn.2017-06.com.example:strage1, portal: 172.25.40.11,3260] successful.
[root@desktop40 ~]# fdisk -l

Disk /dev/vda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x00013f3e

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    20970332    10484142+  83  Linux

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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/sda: 1044 MB, 1044381696 bytes, 2039808 sectors    ##iscsi磁盤
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 4194304 bytes

[root@desktop40 ~]# systemctl restart iscsi
[root@desktop40 ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xea14d41e.

Command (m for help):
Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (8192-2039807, default 8192):
Using default value 8192
Last sector, +sectors or +size{K,M,G} (8192-2039807, default 2039807):
Using default value 2039807
Partition 1 of type Linux and of size 992 MiB is set

Command (m for help): p

Disk /dev/sda: 1044 MB, 1044381696 bytes, 2039808 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 4194304 bytes
Disk label type: dos
Disk identifier: 0xea14d41e

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            8192     2039807     1015808   83  Linux

Command (m for help): wq
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@desktop40 ~]# mkfs.xfs /dev/sda
sda   sda1  
[root@desktop40 ~]# mkfs.xfs /dev/sda1
meta-data=/dev/sda1              isize=256    agcount=8, agsize=31744 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0
data     =                       bsize=4096   blocks=253952, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=853, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@desktop40 ~]# mount /dev/sda1 /mnt                       ##掛載iscsi設備
[root@desktop40 ~]# df
Filesystem           1K-blocks    Used Available Use% Mounted on
/dev/vda1             10473900 3209332   7264568  31% /
devtmpfs                927072       0    927072   0% /dev
tmpfs                   942660     124    942536   1% /dev/shm
tmpfs                   942660   17048    925612   2% /run
tmpfs                   942660       0    942660   0% /sys/fs/cgroup
/dev/sr0               3654720 3654720         0 100% /run/media/root/RHEL-7.0 Server.x86_64
172.25.40.11:/public   1012396   33056    979340   4% /mnt
[root@desktop40 ~]# yum install tree.x86_64 -y         ##下載樹形菜單控件
[root@desktop40 ~]# tree -C /var/lib/iscsi/                  ##查看iscsi目標
/var/lib/iscsi/
|-- ifaces
|-- isns
|-- nodes
|   `-- iqn.2017-06.com.example:strage1
|       `-- 172.25.40.11,3260,1
|           `-- default
|-- send_targets
|   `-- 172.25.40.11,3260
|       |-- iqn.2017-06.com.example:strage1,172.25.40.11,3260,1,default -> /var/lib/iscsi/nodes/iqn.2017-06.com.example:strage1/172.25.40.11,3260,1
|       `-- st_config
|-- slp
`-- static

10 directories, 2 files


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章