iscsi

1.
iscsi 是直接对设备进行共享的服务


2.启动iscsi共享设备
在server上
建立一个lvm设备
yum install targetcli
systemctl enable target


targetcli 
targetcli shell version 2.1.fb34
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.


/> ls
/> /backstores/block create serverlstorage /dev/vg0/iscsi_storge
/> /iscsi create iqn.2017-06.com.example:staragel
/> /iscsi/iqn.2017-06.com.example:staragel/tpg1/luns create /backstores/block/serverlstorage
/> /iscsi/iqn.2017-06.com.example:staragel/tpg1/acls create iqn.2017-06.com.example:serverlstoragekey
/> /iscsi/iqn.2017-06.com.example:staragel/tpg1/portals create 172.25.0.11
/> exit


在desktop
vim /etc/iscsi/initiatorname.iscsi





iscsiadm -m discovery -t st -p 172.25.0.11
iscsiadm -m node -T iqn.2017-06.com.example:stragel -p 172.25.0.11 -l
fdisk -l






3.挂载
vim /etc/fstab







4.删除
umount /mnt
vim /etc/fstab
iscsiadm -m node -T iqn.2017-06.com.example:stragel -p 172.25.0.11 -u
iscsiadm -m node -T iqn.2017-06.com.example:stragel -p 172.25.0.11 -o delete






在服务端
/> clearconfig confirm=Ture ##清除iscsi的所有配置信息
-----------------------------------------------------------------------------------------
server端


[root@server ~]# yum inatall targetcli
Loaded plugins: langpacks
No such command: inatall. Please use /usr/bin/yum --help
[root@server ~]# yum install targetcli -y
Loaded plugins: langpacks
Installed:
  targetcli.noarch 0:2.1.fb34-1.el7                                             


Dependency Installed:
  pyparsing.noarch 0:1.5.6-9.el7     python-configshell.noarch 1:1.1.fb11-3.el7 
  python-kmod.x86_64 0:0.9-4.el7     python-rtslib.noarch 0:2.1.fb46-1.el7      
  python-urwid.x86_64 0:1.1.1-3.el7 


Complete!
[root@server ~]# systemctl enable target
ln -s '/usr/lib/systemd/system/target.service' '/etc/systemd/system/multi-user.target.wants/target.service'
[root@server ~]# systemctl start target
[root@server ~]# systemctl stop firewalld
[root@server ~]# 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@server ~]# fdisk 
Usage:
 fdisk [options] <disk>    change partition table
 fdisk [options] -l <disk> list partition table(s)
 fdisk -s <partition>      give partition size(s) in blocks


Options:
 -b <size>             sector size (512, 1024, 2048 or 4096)
 -c[=<mode>]           compatible mode: 'dos' or 'nondos' (default)
 -h                    print this help text
 -u[=<unit>]           display units: 'cylinders' or 'sectors' (default)
 -v                    print program version
 -C <number>           specify the number of cylinders
 -H <number>           specify the number of heads
 -S <number>           specify the number of sectors per track


[root@server ~]# fdisk
Usage:
 fdisk [options] <disk>    change partition table
 fdisk [options] -l <disk> list partition table(s)
 fdisk -s <partition>      give partition size(s) in blocks


Options:
 -b <size>             sector size (512, 1024, 2048 or 4096)
 -c[=<mode>]           compatible mode: 'dos' or 'nondos' (default)
 -h                    print this help text
 -u[=<unit>]           display units: 'cylinders' or 'sectors' (default)
 -v                    print program version
 -C <number>           specify the number of cylinders
 -H <number>           specify the number of heads
 -S <number>           specify the number of sectors per track


[root@server ~]# 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@server ~]# 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 0x3a165126.


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): +2G
Partition 1 of type Linux and of size 2 GiB is set


Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 81
Changed type of partition 'Linux' to 'Minix / old Linux'


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


Calling ioctl() to re-read partition table.
Syncing disks.
[root@server ~]# partproble
bash: partproble: command not found...
[root@server ~]# partprob
bash: partprob: command not found...
[root@server ~]# partprobe 
Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.
Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.
Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.
[root@server ~]# pvcreate /dev/vdb1
  Physical volume "/dev/vdb1" successfully created
[root@server ~]# vgcreate vg0 /dev/vdb1
  Volume group "vg0" successfully created
[root@server ~]# 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               2.00 GiB
  PE Size               4.00 MiB
  Total PE              511
  Alloc PE / Size       0 / 0   
  Free  PE / Size       511 / 2.00 GiB
  VG UUID               k1HtYU-uuKd-PZ2Z-0p3j-TgxL-SxEd-rkMxZZ
   
[root@server ~]# lvcreate -l 249 -n iscsi_storage vg0
  Logical volume "iscsi_storage" created
[root@server ~]# lvs
  LV            VG   Attr       LSize   Pool Origin Data%  Move Log Cpy%Sync Convert
  iscsi_storage vg0  -wi-a----- 996.00m                                             
[root@server ~]# yum install targetcli -y
Loaded plugins: langpacks
Package targetcli-2.1.fb34-1.el7.noarch already installed and latest version
Nothing to do
[root@server ~]# tartgetcli 
bash: tartgetcli: command not found...
[root@server ~]# 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/iscsi_storage 
Created block storage object serverlstorage using /dev/vg0/iscsi_storage.
/> /iscsi create iqn.2017-06.com.example:stragel
Created target iqn.2017-06.com.example:stragel.
Created TPG 1.
/> ls
o- / ......................................................................... [...]
  o- backstores .............................................................. [...]
  | o- block .................................................. [Storage Objects: 1]
  | | o- serverlstorage . [/dev/vg0/iscsi_storage (996.0MiB) write-thru deactivated]
  | 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:stragel ................................... [TPGs: 1]
  |   o- tpg1 ............................................... [no-gen-acls, no-auth]
  |     o- acls .......................................................... [ACLs: 0]
  |     o- luns .......................................................... [LUNs: 0]
  |     o- portals .................................................... [Portals: 0]
  o- loopback ......................................................... [Targets: 0]
/> /iscsi/iqn.2017-06.com.example:stragel/tpg1/luns create /backstores/block/serverlstorage 
Created LUN 0.
/> iscsi/iqn.2017-06.com.example:stragel/tpg1/acls create iqn.2017-06.com.example:serverlstoragekey
Created Node ACL for iqn.2017-06.com.example:serverlstoragekey
Created mapped LUN 0.
/> /iscsi/iqn.2017-06.com.example:stragel/tpg1/portals create 172.25.5.11
Using default IP port 3260
Created network portal 172.25.5.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@server ~]# 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:stragel ................................... [TPGs: 1]
  |   o- tpg1 ............................................... [no-gen-acls, no-auth]
  |     o- acls .......................................................... [ACLs: 1]
  |     | o- iqn.2017-06.com.example:serverlstoragekey ............ [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.5.11:3260 ................................................. [OK]
  o- loopback ......................................................... [Targets: 0]
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
[root@server ~]# systemctl status firewalld.service 
firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled)
   Active: inactive (dead) since Sun 2017-06-04 00:01:16 EDT; 2h 24min ago
 Main PID: 6572 (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/firewalld.service


Jun 03 22:14:34 server systemd[1]: Started firewalld - dynamic firewall daemon.
Jun 04 00:01:15 server systemd[1]: Stopping firewalld - dynamic firewall daemon...
Jun 04 00:01:16 server systemd[1]: Stopped firewalld - dynamic firewall daemon.
Jun 04 02:06:17 server systemd[1]: Stopped firewalld - dynamic firewall daemon.
[root@server ~]# 






desktop端


[root@desktop ~]# vim /etc/iscsi/initiatorname.iscsi 
[root@desktop ~]# cat /etc/iscsi/initiatorname.iscsi InitiatorName=iqn.2017-06.com.example:serverlstoragekey
[root@desktop ~]# systemctl restart iscsi
[root@desktop ~]# iscsiadm -m discovery -t st -p 172.25.5.11
172.25.5.11:3260,1 iqn.2017-06.com.example:stragel
[root@desktop ~]# 关闭server端防火墙^C
[root@desktop ~]# iscsiadm -m node -T iqn.2017-06.com.example:stragel -p 172.25.5.11 -l
Logging in to [iface: default, target: iqn.2017-06.com.example:stragel, portal: 172.25.5.11,3260] (multiple)
Login to [iface: default, target: iqn.2017-06.com.example:stragel, portal: 172.25.5.11,3260] successful.
[root@desktop ~]# 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
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@desktop ~]# 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 0x6cc3320c.


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 (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): wq
The partition table has been altered!


Calling ioctl() to re-read partition table.
Syncing disks.
[root@desktop ~]# partprobe 
[root@desktop ~]# mkfs.xfs /dev/sda
mkfs.xfs: /dev/sda appears to contain a partition table (dos).
mkfs.xfs: Use the -f option to force overwrite.
[root@desktop ~]# mkfs.xfs -f /dev/sda
meta-data=/dev/sda               isize=256    agcount=8, agsize=31872 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0
data     =                       bsize=4096   blocks=254976, 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@desktop ~]# 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
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@desktop ~]# mkfs.xfs /dev/sda
mkfs.xfs: /dev/sda appears to contain an existing filesystem (xfs).
mkfs.xfs: Use the -f option to force overwrite.
[root@desktop ~]# mkfs.xfs /dev/sda -f
meta-data=/dev/sda               isize=256    agcount=8, agsize=31872 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0
data     =                       bsize=4096   blocks=254976, 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@desktop ~]# 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@desktop ~]# mount /dev/sda1 /mnt/
[root@desktop ~]# df
Filesystem          1K-blocks    Used Available Use% Mounted on
/dev/vda1            10473900 3188176   7285724  31% /
devtmpfs               481120       0    481120   0% /dev
tmpfs                  496708     124    496584   1% /dev/shm
tmpfs                  496708   13080    483628   3% /run
tmpfs                  496708       0    496708   0% /sys/fs/cgroup
172.25.5.11:/public   1012396   33056    979340   4% /mnt
[root@desktop ~]# umount /mnt
[root@desktop ~]# df
Filesystem          1K-blocks    Used Available Use% Mounted on
/dev/vda1            10473900 3188176   7285724  31% /
devtmpfs               481120       0    481120   0% /dev
tmpfs                  496708     124    496584   1% /dev/shm
tmpfs                  496708   13076    483632   3% /run
tmpfs                  496708       0    496708   0% /sys/fs/cgroup
172.25.5.11:/public  10473984 3195648   7278336  31% /mnt
[root@desktop ~]# umount /mnt
[root@desktop ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/vda1       10473900 3188176   7285724  31% /
devtmpfs          481120       0    481120   0% /dev
tmpfs             496708     124    496584   1% /dev/shm
tmpfs             496708   13076    483632   3% /run
tmpfs             496708       0    496708   0% /sys/fs/cgroup
[root@desktop ~]# mount /dev/sda1 /mnt/
[root@desktop ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/vda1       10473900 3188176   7285724  31% /
devtmpfs          481120       0    481120   0% /dev
tmpfs             496708     124    496584   1% /dev/shm
tmpfs             496708   13076    483632   3% /run
tmpfs             496708       0    496708   0% /sys/fs/cgroup
/dev/sda1        1012396   33056    979340   4% /mnt
[root@desktop ~]# yum install tree.x86_64 -y
Loaded plugins: langpacks
Installed:
  tree.x86_64 0:1.6.0-10.el7                                                        


Complete!
[root@desktop ~]# tree -C /var/lib/iscsi/
/var/lib/iscsi/
├── ifaces
├── isns
├── nodes
│   └── iqn.2017-06.com.example:stragel
│       └── 172.25.5.11,3260,1
│           └── default
├── send_targets
│   └── 172.25.5.11,3260
│       ├── iqn.2017-06.com.example:stragel,172.25.5.11,3260,1,default -> /var/lib/iscsi/nodes/iqn.2017-06.com.example:stragel/172.25.5.11,3260,1
│       └── st_config
├── slp
└── static


10 directories, 2 files
[root@desktop ~]# 
----------------------------------------------------------------------------------------
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值