linxu iSCSI设备共享

一、iscsI 概念
node

  SCSI 支持从客客户端经过IP向远程服务器上的iscsI 存储设备发送SCSI命令。默认状况下,网络通讯是至iSCSI目标上的端口3260/tcp的明文端口vim

二、软件安装bash

[root@server ~]# yum install targetcil -y
[root@server ~]# systemctl  start target
[root@server ~]# systemctl enable target

三、通常的磁盘共享
服务器

  在server上做以下操做网络

[root@server ~]# targetcli
/> /backstores/block create  feitian1:storage1 /dev/vdb1
Created block storage objectfeitian1:storage1 using /dev/vdb1.
#添加一个叫作feitian的共享磁盘
/> /iscsi  create iqn.2017-08.com.example:stroage1
Created target iqn.2017-08.com.example:stroage1.
Created TPG 1.
#建立一个iqn.2017-08.com.example的磁盘共享
/>/iscsi/iqn.2017-08.com.example:stroage1/tpg1/lunscreate /backstores/block/feitian1:storage1
Created LUN 0.
#将添加的磁盘共享和建立的磁盘共享关联起来
/>/iscsi/iqn.2017-08.com.example:stroage1/tpg1/acls createiqn.2017-08.com.example:stroage1key
Created Node ACL foriqn.2017-08.com.example:stroage1key
Created mapped LUN 0.
#建立共享的证书,他要写入客户端的的文件中/etc/iscsi/initiatorname.iscsi
/>/iscsi/iqn.2017-08.com.example:stroage1/tpg1/portals create 172.25.254.231
Using default IP port 3260
Created network portal 172.25.254.231:3260.
#开启172.25.254.3260的端口,能够共享
#若是写错了可使用下面的命令删除
#/>/iscsi/iqn.2017-08.com.example:storage1/tpg1/portals/ delete 172.25.254.2313260
#Deleted network portal 172.25.254.231:3260

  当你将这些步骤都完成就会看到下图的内容session

wKiom1mYNG-BSuUqAAHkklrlVM0859.png

  在客户端做以下步骤app

#首先安装客户端软件
[root@client ~]# yum install iscsi-initiator-utils.x86_64
[root@client ~]# iscsiadm  -m discovery -t st -p 172.25.254.231
172.25.254.231:3260,1iqn.2017-08.com.example:stroage1
[root@client ~]# vim/etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2017-08.com.example:stroage1
[root@client ~]# iscsiadm -m node -Tiqn.2017-08.com.example:stroage1 -P 172.25.254.231 -l

  fdisk -l 就会发现你多了一块磁盘/dev/sda3,格式化挂载就可使用。tcp

wKioL1mYNJqhMRXwAACHLf0n9pM424.png

  注意:在直接重启iscsi这个服务时,他会报错,这时你须要先从新启动iscsid在重起你的iscsi服务。ide

wKiom1mYNNGzFVk7AADBeflO0kU187.png

四、 清除磁盘共享
spa

4.1 client端的的清除

#先中止磁盘共享,而后进入/var/lib/iscsi
[root@client ~]# cd /var/lib/iscsi
[root@client iscsi]# systemctl stop iscsi
[root@client iscsi]# iscsiadm  -m node -T iqn.2017-08.com.example:stroage1-o delete

wKioL1mYNPXD9EH3AAEXR-e5Nhk189.png


4.2 server端的的清除

  server端登录targetcli以后,直接执行下面的命令,就删除完毕

[root@client iscsi]#targetcli
/> clearconfig confirm=TRUE
All configuration cleared

五、lvm 磁盘共享

  在server上作以下操做

  首先你须要fdisk分出两个分区,个人分出来的是/dev/vdb1/dev/vdb2,注意分区的同时要将分区的id改成8e,也就是LVM类型。

[root@server ~]# pvcreate /dev/vdb1
[root@server ~]# vgcreate vg0 /dev/vdb1
[root@server ~]# lvcreate -l 511 -n  lv0 vg0
#或者使用-L参数直接指定大小。
#这个511是用vgdisplay查询出一共有522个没有使用的PE
#接下来就是重复刚才的步骤,创建共享磁盘
/> /backstores/block create feitian:storage1/dev/vg0/lv0
Created block storage objectfeitian:storage1 using /dev/vg0/lv0.
/> /iscsi create  iqn.2017-08.com.example:storage1
Created targetiqn.2017-08.com.example:storage1.
Created TPG 1.
/>iscsi/iqn.2017-08.com.example:storage1/tpg1/luns create/backstores/block/feitian:storage1
Created LUN 0.
/>iscsi/iqn.2017-08.com.example:storage1/tpg1/acls  create iqn.2017-08.com.example:storage1key
Created Node ACL foriqn.2017-08.com.example:storage1key
Created mapped LUN 0.
/>iscsi/iqn.2017-08.com.example:storage1/tpg1/portals  create 172.25.254.231
Using default IP port 3260
Created network portal 172.25.254.231:3260.

  在客户端作以下操做

[root@client ~]# vim/etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2017-08.com.example:stroage1key
[root@client iscsi]# systemctl restartiscsid.service
[root@client iscsi]# systemctl restartiscsi
[root@client ~]# iscsiadm  -m discovery -t st -p 172.25.254.231
172.25.254.231:3260,1iqn.2017-08.com.example:storage1
#查看共享
[root@client iscsi]# iscsiadm -m node -Tiqn.2017-08.com.example:storage1 -P 172.25.254.231 -l
链接共享磁盘

  fdisk -l就会多出来一/dev/sda3,是2G的大小

wKioL1mYPxWRcyWYAACHLf0n9pM511.png

5.2扩大lvm共享磁盘

  在server上作以下操做     

[root@server ~]# pvcreate /dev/vdb2
 Physical volume "/dev/vdb2" successfully created
[root@server ~]# vgextend vg0  /dev/vdb2
 Volume group "vg0" successfully extended
[root@server ~]# lvextend -L 3G  /dev/vg0/lv0
 Extending logical volume lv0 to 3.00 GiB
 Logical volume lv0 successfully resized

  在客户端作以下操做

[root@client iscsi]# iscsiadm  -m node -T iqn.2017-08.com.example:storage1 -u
Logging out of session [sid: 9, target:iqn.2017-08.com.example:storage1, portal: 172.25.254.231,3260]
Logout of [sid: 9, target:iqn.2017-08.com.example:storage1, portal: 172.25.254.231,3260] successful.
[root@client iscsi]# systemctl restartiscsid
[root@client iscsi]# systemctl restartiscsi
[root@client iscsi]# iscsiadm -m node -Tiqn.2017-08.com.example:storage1 -P 172.25.254.231 -l
Logging in to [iface: default, target:iqn.2017-08.com.example:storage1, portal: 172.25.254.231,3260] (multiple)
Login to [iface: default, target:iqn.2017-08.com.example:storage1, portal: 172.25.254.231,3260] successful.

这时你用fdisk -l 查看时就会看到他有3G的大小

wKioL1mYP7_i5KueAACFXdHVVGU436.png

相关文章
相关标签/搜索