測試環境說明:
測試環境一共使用4臺服務器,兩臺Linux、兩臺Windows,一臺Linux做爲iSCSIServer,用Targetcli以iSCSI的方式提供存儲共享服務,另外三臺使用iSCSIServer上的存儲資源,各自訪問各自的資源,相互之間不能看到對方的存儲資源,做到資源訪問控制。
iSCSI Server
OS: Red Hat Enterprise Linux Server release 7.0
IP:10.20.1.100
Client
OS:Windows Server 2008 R2
IP:10.20.1.55
OS:NeoKylin Linux 6.5
IP:10.20.1.56
OS: Windows Server 2008 R2
IP:10.20.1.57
三臺Client已經把基礎環境配置完畢。
iSCSI Server配置過程
1、一些基礎配置,目的以能安裝使用targetcli,主要配置IP,關閉防火牆、yum源,安裝targetcli需要python環境,在進行系統安裝時要把python包選上。:
[root@localhost /]# vi /etc/sysconfig/network-scripts/ifcfg-ens192 TYPE=Ethernet BOOTPROTO=none IPADDR=10.20.1.100 NETMASK=255.255.255.0 GATEWAY=10.20.1.254 NAME=ens192 ONBOOT=yes [root@localhost /]#systemctl stop firewalld
2、yum源配置。
[root@localhost /]# cd /mnt [root@localhost /]# mkdir rehl7 [root@localhost /]# mount /dev/sr0 /mnt/rehl7/ //虛擬光驅,提前做好的 [root@localhost /]# vim /etc/yum.repos.d/base.repo [base] name=base baseurl=file:///mnt/rehl7 enable=1 gpgcheck=0 [root@localhost /]# yum clean all //清除緩存 [root@localhost /]# yum makecache //重載緩存
3、磁盤分區,分區時最好使用LVM格式,以便後期對共享盤空間進行調整。
[root@localhost /]# fdisk -l Disk /dev/sdb: 536.9 GB, 536870912000 bytes, 1048576000 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
系統區分完後還剩餘500G空間,使用fdisk進行分區,將以上的設備/dev/sdb建立分區,並改變格式爲LVM。
[root@localhost ~]# fdisk /dev/sdb 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 0x8fa166b8. 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 (2048-1048575999, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-1048575999, default 1048575999): Using default value 1048575999 Partition 1 of type Linux and of size 500 GiB is set 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/sdb: 536.9 GB, 536870912000 bytes, 1048576000 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: 0x8fa166b8 Device Boot Start End Blocks Id System /dev/sdb1 2048 1048575999 524286976 8e Linux LVM Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@localhost /]# partprobe /dev/sdb1 //重載分區表
4、創建LVM。在/dev/sdb1上分別創建PV、VG,並按照分區規劃創建LV。
分區規劃:
IP pv name lv name size
10.20.1.57 /dev/sdb1 iscsi_57 150G
10.20.1.56 /dev/sdb1 iscsi_56 150G
10.20.1.55 /dev/sdb1 iscsi_55 150G
LVM操作步驟:
[root@localhost /]# pvcreate /dev/sdb1 Physical volume "/dev/sdb1" successfully created [root@localhost /]# vgcreate iSCSI /dev/sdb1 Volume group "iSCSI" successfully created [root@localhost /]# lvcreate -L 150G -n iscsi_56 iSCSI Logical volume "iscsi_56" created [root@localhost /]# lvcreate -L 150G -n iscsi_57 iSCSI Logical volume "iscsi_57" created [root@localhost /]# lvcreate -L 150G -n iscsi_55 iSCSI Logical volume "iscsi_55" created [root@localhost /]# vgs VG #PV #LV #SN Attr VSize VFree iSCSI 1 3 0 wz--n- 500.00g 50.00g rhel 1 2 0 wz--n- 83.80g 0 [root@localhost /]# lvs LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert iscsi_55 iSCSI -wi-a----- 150.00g iscsi_56 iSCSI -wi-a----- 150.00g iscsi_57 iSCSI -wi-a----- 150.00g home rhel -wi-ao---- 4.88g root rhel -wi-ao---- 78.92g
5、targetcli安裝及iSCSI配置。配置本地服務器時爲了好區分,需要提前修改iqn名,最好在後綴加上server的方式命名,以和Client區分
[root@localhost /]# yum install targetcli –y //安裝iscsi 服務管理器 [root@localhost /]# systemctl start target //啓動target服務 [root@localhost /]# systemctl enable target //將服務設置爲開機自動啓動 [root@localhost /]# yum install iscsi-initiator-utils //安裝iscsi Initiator [root@localhost /]# vim /etc/iscsi/initiatorname.iscsi //修改iqn name InitiatorName=iqn.1994-05.com.redhat:iSCSIserver
運行iSCSI配置命令
[root@localhost etc]# 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 iscsi55_data /dev/iSCSI/iscsi_55 //分別使用LV創建存儲塊。 Created block storage object iscsi55_data using /dev/iSCSI/iscsi_55. /> /backstores/block create iscsi56_data /dev/iSCSI/iscsi_56 //創建iscsi56-data Created block storage object iscsi56_data using /dev/iSCSI/iscsi_56. /> /backstores/block create iscsi57_data /dev/iSCSI/iscsi_57 //創建iscsi57-data Created block storage object iscsi57_data using /dev/iSCSI/iscsi_57. /> iscsi/ create iqn.1994-05.com.redhat:iSCSIserver //配置服務端iSCSITarget名,該名稱已經在前面寫入到文件裏。 Created target iqn.1994-05.com.redhat:iSCSIserver. Created TPG 1. /> iscsi/iqn.1994-05.com.redhat:server/tpg1/portals create 10.20.1.100 //配置服務端IP及端口,端口默認爲3260 Using default IP port 3260 Created network portal 10.20.1.100:3260. />ls //查看配置情況
配置Client 啓動器,3臺客戶端的啓動器名已以提前修改爲統一格式,粘貼複製文本文件。由於在targetcli中使用一些配置路徑名太長,可以使用cd命令進入該項下,如果對命令不熟悉可以使用help查看幫助。在acls下使用carete命令分別創建57、56、55的啓動器。
> cd iscsi/iqn.1994-05.com.redhat:iscsiserver/tpg1/acls /iscsi/iqn.19...ver/tpg1/acls> create iqn.1991-05.com.microsoft:mq57master Created Node ACL for iqn.1991-05.com.microsoft:mq57master
創建LUN,有兩種方式,一種是在luns下創建,一種是在啓動器下直接建。
首先測試在luns下創建,在luns項下每建好一個LUN,程序會自動將該LUN掛在所有acls下,所以要根據需求在acls下將多餘的LUN刪除。在luns下使用create創建LUN。
能看到acls下每個啓動器上都有3個LUN。
將多餘的LUN刪除。
在啓動器下創建,這種方式比較直接,在acls項下直接按需新建LUN,直接映射到對應啓動器,一次到位,就是命令比較長。
先把原來的3個LUN刪除,在acls下使用create創建。
iSCSI配置完畢,看看整體效果:
6、客戶端配置
windows配置,這種windows掛iSCSI的配置網上教程比較多,這裏就只寫步驟不配圖了。
在管理工具打開iSCSI發起程序,以下步驟:
1) 在目標中輸入IP,點快速連接;
2) 彈出快速連接登陸成功報告,點擊確定;
3) 在發現和收藏的目標裏會有相應的內容;
4) 在卷和設備點擊自動配置,會自己獲得設備;
5) 點開服務管理器—存儲—磁盤管理—在新加硬盤上右鍵點聯機;
6) 初始化爲MBR,然後格式化磁盤。
Linux操作系統配置方法,linux按步驟配圖
1) 使用命令發現資源
[root@FTPServer ~]# iscsiadm -m discovery -t sendtargets -p 10.20.1.100
2)使用命令登陸資源
[root@FTPServer ~]# iscsiadm -m node T iqn.1994-05.com.redhat:iscsiserver -p 10.20.1.100
3)使用fdisk檢查並分區
[root@FTPServer ~]# fdisk –l
檢測到一塊161G的設備,進行分區,因爲以後可能對磁盤有擴容或縮減的操操作,最好將磁盤格式改爲LVM。
[root@FTPServer ~]# fdisk /dev/sdc [root@FTPServer ~]# partprobe /dev/sdc1 //重讀分區表
4)創建LVM並進行格式化
[root@FTPServer ~]# pvcreate /dev/sdc1 //創建PV Physical volume "/dev/sdc1" successfully created [root@FTPServer ~]# vgcreate FtpDataGroup /dev/sdc1 //創建VG Volume group "FtpDataGroup" successfully created [root@FTPServer ~]# lvcreate -l 38398 -n FtpData FtpDataGroup //創建LV Logical volume "FtpData" created [root@FTPServer ~]# mkfs.xfs /dev/FtpDataGroup/FtpData //格式化爲xfs
5)掛載新分區
由於是網絡磁盤,使用自動掛載方式時最好使用UUID來掛載,先查看UUID
磁盤掛載,注意千萬不要忘記netdev前面的下劃線。小心萬劫不復。。。。
[root@FTPServer ~]# vim /etc/fstab
mount –a 一下 df –h查看分區掛載,完成。
配置完成後重啓系統,確定能正常識別新加盤配置完成。