天天看點

x-sky ISCSI使用

一、用戶端安裝iscsi依賴包(所有iscsi用戶端上)

[root@localhost ~]#yum install -y binutils iscsi-initiator-utils  xfsprogs
[root@localhost ~]#systemctl restart iscsi
[root@localhost ~]# systemctl enable iscsi
[root@localhost ~]#cat /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.1994-05.com.redhat:3915324ae53  #檢視本機IQN号      

二、服務端建立ISCSI服務

1.建立塊存儲

 2.建立一次性組

===

 3.建立用戶端組

 4.建立通路路徑

 三、用戶端挂載

1.檢視服務端IP及IQN号

x-sky ISCSI使用
x-sky ISCSI使用

 2.檢視存儲伺服器的iscsi是否線上

[root@localhost ~]# iscsiadm -m discovery --type sendtargets --portal 172.16.149.73
172.16.149.73:3260,1 iqn.2020-06.com.xsky:qggcluster.iscsi.118.1f3ecd86026a3293  #确認是否和服務端IQN号一緻      

3.登入ISCSI伺服器并設定開機自動挂載

[root@localhost ~]# iscsiadm -m discovery --type sendtargets --portal 172.16.149.73  #發現ISCSI target 
172.16.149.73:3260,1 iqn.2020-06.com.xsky:qggcluster.iscsi.118.1f3ecd86026a3293
[root@localhost ~]# iscsiadm -m discovery --type sendtargets --portal 172.16.149.74
172.16.149.74:3260,1 iqn.2020-06.com.xsky:qggcluster.iscsi.118.1f3ecd86026a3293
[root@localhost ~]# iscsiadm -m node -T iqn.2020-06.com.xsky:qggcluster.iscsi.118.1f3ecd86026a3293 -p 172.16.149.73:3260 -l  #登入target,iscsiadm -m node -l all 指令可以一次登入是以發現的target
Logging in to [iface: default, target: iqn.2020-06.com.xsky:qggcluster.iscsi.118.1f3ecd86026a3293, portal: 172.16.149.73,3260] (multiple)
Login to [iface: default, target: iqn.2020-06.com.xsky:qggcluster.iscsi.118.1f3ecd86026a3293, portal: 172.16.149.73,3260] successful.  #確定出現successful
[root@localhost ~]# iscsiadm -m node -T iqn.2020-06.com.xsky:qggcluster.iscsi.118.1f3ecd86026a3293 -p 172.16.149.74:3260 -l
Logging in to [iface: default, target: iqn.2020-06.com.xsky:qggcluster.iscsi.118.1f3ecd86026a3293, portal: 172.16.149.74,3260] (multiple)
Login to [iface: default, target: iqn.2020-06.com.xsky:qggcluster.iscsi.118.1f3ecd86026a3293, portal: 172.16.149.74,3260] successful.
[root@localhost ~]# iscsiadm -m node -T iqn.2020-06.com.xsky:qggcluster.iscsi.118.1f3ecd86026a3293 -p 172.16.149.73:3260  --op update -n node.startup -v automatic #設定開機自動挂載
[root@localhost ~]# iscsiadm -m node -T iqn.2020-06.com.xsky:qggcluster.iscsi.118.1f3ecd86026a3293 -p 172.16.149.74:3260  --op update -n node.startup -v automatic
[root@localhost ~]# iscsiadm -m session  #顯示目前已經建立的連接配接
tcp: [1] 172.16.149.73:3260,1 iqn.2020-06.com.xsky:qggcluster.iscsi.118.1f3ecd86026a3293 (non-flash)
tcp: [2] 172.16.149.74:3260,1 iqn.2020-06.com.xsky:qggcluster.iscsi.118.1f3ecd86026a3293 (non-flash)      

4.分區格式化及挂載

檢視存儲空間是否已經顯示在磁盤清單中

x-sky ISCSI使用

 對其中任意一塊進行分區

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

The device presents a logical sector size that is smaller than
the physical sector size. Aligning to a physical sector (or optimal
I/O) size boundary is recommended, or performance may be impacted.

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-629145599, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-629145599, default 629145599): 
Using default value 629145599
Partition 1 of type Linux and of size 300 GiB is set

Command (m for help): w  #儲存
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# mkfs.xfs /dev/sda1  #對新分區格式化
meta-data=/dev/sda1              isize=512    agcount=4, agsize=19660736 blks
         =                       sectsz=4096  attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=78642944, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=38399, version=2
         =                       sectsz=4096  sunit=1 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@localhost ~]# mkdir /Data  #建立挂載目錄
[root@localhost ~]# mount /dev/sda1 /Data/ #挂載
[root@localhost ~]# df -h
Filesystem                   Size  Used Avail Use% Mounted on
/dev/mapper/qgg_vg1-lv_root  298G  2.4G  296G   1% /
devtmpfs                     7.8G     0  7.8G   0% /dev
tmpfs                        7.8G     0  7.8G   0% /dev/shm
tmpfs                        7.8G  8.7M  7.8G   1% /run
tmpfs                        7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/vda1                    283M  115M  150M  44% /boot
tmpfs                        1.6G     0  1.6G   0% /run/user/0
/dev/sda1                    300G   33M  300G   1% /Data      

5. 設定開機自動挂載

檢視挂載磁盤UUID

[root@localhost ~]# blkid /dev/sda1
/dev/sda1: UUID="897ef05d-cd7e-469e-9886-028a96ba05e1" TYPE="xfs" 
[root@localhost ~]# vim /etc/fstab 
UUID=897ef05d-cd7e-469e-9886-028a96ba05e1 /Data     xfs     defaults,_netdev        0 0   #注意:挂載的時候一定要加_netdev參數,否則重新開機會卡住
[root@localhost ~]# umount /Data #測試是否可以自動挂載
[root@localhost ~]# df -h
[root@localhost ~]# mount -a
[root@localhost ~]# df -h      

 參考文檔:https://blog.csdn.net/jiyiyun/article/details/103798730

"一勞永逸" 的話,有是有的,而 "一勞永逸" 的事卻極少