設置環境
Server: server1.itken.local
IP Address: 192.168.3.30
OS: CentOS Linux release 3.10.0-693.el7.x86_64
Windows Client: node1.itken.local
IP Address: 192.168.3.31
OS: Windows 10 64位元
Linux Client: node2.itken.local
IP Address: 192.168.3.32
OS: CentOS Linux release 7.4.1708 (Core)
設置儲存區
在這裡,我們將在目標伺服器上創建 5GB 的 LVM 磁區,作為用戶端的共用存儲。讓我們使用下面的命令列出附加到目標伺服器的可用磁區。如果要將整個磁區用於 LVM,請跳過磁碟分割步驟。
[root@server1 ~]# fdisk -l | grep -i sd
Disk /dev/sda: 17.2 GB, 17179869184 bytes, 33554432 sectors
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 33554431 15727616 8e Linux LVM
Disk /dev/sdb: 17.2 GB, 17179869184 bytes, 33554432 sectors
從上面的輸出中,您可以看到我的系統有一個 16GB 的磁片 (/dev/sdb)。我們將在上述磁片上創建一個 10GB 分區,並將其用於 LVM。
[root@server1 ~]# 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 0xcaf0f1af.
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): 1 --> 分割號碼
First sector (2048-33554431, default 2048): --> 直接按下Enter
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-33554431, default 33554431): +10G --> 輸入大小
Partition 1 of type Linux and of size 10 GiB is set
Command (m for help): w --> 儲存
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
使用 /dev/sdb1 分區創建 LVM(用磁q區名稱替換 /dev/sdb1)
[root@server1 ~]# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created.
[root@server1 ~]# vgcreate vg_iscsi /dev/sdb1
Volume group "vg_iscsi" successfully created
[root@server1 ~]# lvcreate -l 100%FREE -n lv_iscsi vg_iscsi
Logical volume "lv_iscsi" created.
設定iSCSI target
現在可以選擇創建帶或不帶身份驗證的目標。在本文中可以找到這兩種方案的步驟。由你決定哪一個適合你的環境。
在這裡將配置 iSCSI 目標,而無需 CHAP 身份驗證。在伺服器上安裝targetcli 包。
[root@server1 ~]# yum install targetcli -y
安裝後,在下面輸入命令以獲取 iSCSI CLI 的互動式提示。
[root@server1 ~]# targetcli Warning: Could not load preferences file /root/.targetcli/prefs.bin. targetcli shell version 2.1.fb46 Copyright 2011-2013 by Datera, Inc and others. For help on commands, type 'help'. />
現在使用現有邏輯卷 (/dev/vg_iscsi/lv_iscsi) 作為存儲物件 scsi_disk1_server 的塊類型後備存儲。
/> cd backstores/block
/backstores/block> create scsi_disk1_server /dev/vg_iscsi/lv_iscsi
Created block storage object scsi_disk1_server using /dev/vg_iscsi/lv_iscsi.
建立一個 target
/backstores/block> cd /iscsi
/iscsi> create iqn.2019-07.local.itken.server1:disk1
Created target iqn.2016-02.local.itzgeek.server:disk1.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/iscsi>
為用戶端電腦創建 ACL(用戶端用於連接的 IQN)
/iscsi> cd /iscsi/iqn.2019-07.local.itken.server1:disk1/tpg1/acls
/iscsi/iqn.20...sk1/tpg1/acls> create iqn.2019-07.local.itken.server1:node1node2
Created Node ACL for iqn.2016-02.local.itzgeek.server:node1node2
在目標下創建 LUN。LUN 應使用前面提到的名為"scsi_disk1_server"的後備存儲物件
/iscsi/iqn.20...er:disk1/tpg1> cd /iscsi/iqn.2019-07.local.itken.server1:disk1/tpg1/luns
/iscsi/iqn.20...sk1/tpg1/luns> create /backstores/block/scsi_disk1_server
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2016-02.local.itzgeek.server:node1node2
驗證目標伺服器配置
/iscsi/iqn.20...sk1/tpg1/luns> cd / /> ls o- / ............................................... [...] o- backstores .................................... [...] | o- block ........................ [Storage Objects: 1] | | o- scsi_disk1_server [/dev/vg_iscsi/lv_iscsi (10.0GiB) write-thru activated] | | o- alua ......................... [ALUA Groups: 1] | | o- default_tg_pt_gp [ALUA state: Active/optimized] | o- fileio ....................... [Storage Objects: 0] | o- pscsi ........................ [Storage Objects: 0] | o- ramdisk ...................... [Storage Objects: 0] o- iscsi .................................. [Targets: 1] | o- iqn.2019-07.local.itken.server1:disk1 ... [TPGs: 1] | o- tpg1 ..................... [no-gen-acls, no-auth] | o- acls ................................ [ACLs: 1] | | o- iqn.2019-07.local.itken.server1:node1node2 [Mapped LUNs: 1] | | o- mapped_lun0 [lun0 block/scsi_disk1_server (rw)] | o- luns ................................ [LUNs: 1] | | o- lun0 [block/scsi_disk1_server (/dev/vg_iscsi/lv_iscsi) (default_tg_pt_gp)] | o- portals .......................... [Portals: 1] | o- 0.0.0.0:3260 ........................... [OK] o- loopback ............................... [Targets: 0] /> saveconfig Configuration saved to /etc/target/saveconfig.json /> exit Global pref auto_save_on_exit=true Last 10 configs saved in /etc/target/backup/. Configuration saved to /etc/target/saveconfig.json
啟用並重新啟動目標服務.
[root@server1 ~]# systemctl enable target.service Created symlink from /etc/systemd/system/multi-user.target.wants/target.service to /usr/lib/systemd/system/target.service. [root@server1 ~]# systemctl restart target.service
配置防火牆以允許 iSCSI 流量.
[root@server1 ~]# firewall-cmd --permanent --add-port=3260/tcp success [root@server1 ~]# firewall-cmd --reload success
設置Linux啟動器
現在,是時候將用戶端電腦配置為將創建的目標用作存儲了。在用戶端電腦上安裝以下套裝軟體 (node1).
[root@node1 ~]# yum install iscsi-initiator-utils -y
編輯活動名稱.iscsi 檔.
[root@node1 ~]# vi /etc/iscsi/initiatorname.iscsi
刪除上行及添加 iSCSI 活動程式名稱.
InitiatorName=iqn.2019-07.local.itken.server1:node1node2
使用以下命令發現目標.
[root@node1 ~]# iscsiadm -m discovery -t st -p 192.168.3.30 192.168.3.30:3260,1 iqn.2019-07.local.itken.server1:disk1
重新開機並啟用開始器服務.
[root@node1 ~]# systemctl restart iscsid.service [root@node1 ~]# systemctl enable iscsid.service Created symlink from /etc/systemd/system/multi-user.target.wants/iscsid.service to /usr/lib/systemd/system/iscsid.service.
登錄到發現的目標.
[root@node1 ~]# iscsiadm -m node -T iqn.2019-07.local.itken.server1:disk1 -p 192.168.3.30 -l Logging in to [iface: default, target: iqn.2019-07.local.itken.server1:disk1, portal: 192.168.3.30,3260] (multiple) Login to [iface: default, target: iqn.2019-07.local.itken.server1:disk1, portal: 192.168.3.30,3260] successful.
在ISCSI 磁區建立檔案系統
列出附加的磁區.
[root@node1 ~]# cat /proc/partitions major minor #blocks name 8 0 16777216 sda 8 1 1048576 sda1 8 2 15727616 sda2 11 0 1048575 sr0 253 0 14045184 dm-0 253 1 1679360 dm-1 8 16 10481664 sdb
格式化新磁區(已經格式化了整個磁區,而不是創建分區)
[root@node1 ~]# mkfs.xfs /dev/sdb meta-data=/dev/sdb isize=512 agcount=4, agsize=655104 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=2620416, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0
掛載disk.
[root@node1 ~]# mount /dev/sdb /mnt
使用以下命令驗證磁片是否裝載.
[root@node1 ~]# df -hT Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/centos-root xfs 14G 1017M 13G 8% / devtmpfs devtmpfs 910M 0 910M 0% /dev tmpfs tmpfs 920M 0 920M 0% /dev/shm tmpfs tmpfs 920M 8.6M 912M 1% /run tmpfs tmpfs 920M 0 920M 0% /sys/fs/cgroup /dev/sda1 xfs 1014M 143M 872M 15% /boot tmpfs tmpfs 184M 0 184M 0% /run/user/0
輸出:
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 50G 955M 50G 2% /
devtmpfs devtmpfs 908M 0 908M 0% /dev
tmpfs tmpfs 914M 54M 861M 6% /dev/shm
tmpfs tmpfs 914M 8.5M 905M 1% /run
tmpfs tmpfs 914M 0 914M 0% /sys/fs/cgroup
/dev/mapper/centos-home xfs 48G 33M 48G 1% /home
/dev/sda1 xfs 497M 97M 401M 20% /boot
/dev/sdb xfs 5.0G 33M 5.0G 1% /mnt
自動掛載iSCSI 儲存區
要在每次重新開機期間自動安裝 iSCSI 存儲,您需要在 /etc/fstab 檔中輸入.
在更新 /etc/fstab 檔之前,請使用以下命令獲取 iSCSI 磁片的 UUID。將 /dev/sdb 替換為 iSCSI 磁片名稱.
blkid /dev/sdb
/dev/sdb: LABEL="/" UUID="9df472f4-1b0f-41c0-a6eb-89574d2caee3" TYPE="xfs"
現在,編輯 /etc/fstab 檔.
vi /etc/fstab
編輯 fstab 檔內容如下
#
# /etc/fstab
# Created by anaconda on Tue Jan 30 02:14:21 2018
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=9df472f4-1b0f-41c0-a6eb-89574d2caee3 / xfs defaults 0 0
UUID=c7469f92-75ec-48ac-b42d-d5b89ab75b39 /mnt xfs _netdev 0 0
設置Windows啟動器
按下Winkey+S, 搜索 iscsi initiator出現下面視窗
1.切換欄位到設置, 2.更改啟動器名稱
回到Taget欄位,1.輸入Target IP, 2.按快速連線
連線成功
選擇我的電腦,右鍵選擇管理
按下磁碟管理,會出現初始化磁碟視窗,按OK
新增簡單磁區
磁碟設置成功
完成
移除Linux iSCSI 儲存區
如果要取消附加添加的磁區,請按照該過程(卸載和登出)).
[root@node1 ~]# umount /mnt
[root@node1 ~]# iscsiadm -m node -T iqn.2019-07.local.itken.server1:disk1 -p 192.168.3.30 -u
Logging out of session [sid: 6, target: iqn.2019-07.local.itken.server1:disk1, portal: 192.168.3.30,3260]
Logout of [sid: 6, target: iqn.2019-07.local.itken.server1:disk1, portal: 192.168.3.30,3260] successful.
完成
移除Windows iSCSI 儲存區
刪除磁區
中斷連線
完成
留言列表