一、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
在客戶端做以下步驟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
注意:在直接重啓iscsi這個服務時,他會報錯,這時你須要先從新啓動iscsid在重起你的iscsi服務。ide
四、 清除磁盤共享
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
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的大小
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的大小