使用ISCSI服务部署网络储存

创建RAID 5 磁盘阵列

[root@localhost ~]# mdadm -Cv /dev/md0 -n 3 -l 5 -x 1 /dev/nvme0n2 /dev/nvme0n3 /dev/nvme0n4 /dev/nvme0n5
mdadm: layout defaults to left-symmetric
mdadm: layout defaults to left-symmetric
mdadm: chunk size defaults to 512K
mdadm: size set to 20954112K
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.

[root@localhost ~]# mdadm -D /dev/md0
/dev/md0:
           Version : 1.2
     Creation Time : Wed Jun 21 01:03:14 2023
        Raid Level : raid5
        Array Size : 41908224 (39.97 GiB 42.91 GB)
     Used Dev Size : 20954112 (19.98 GiB 21.46 GB)
      Raid Devices : 3
     Total Devices : 4
       Persistence : Superblock is persistent

       Update Time : Wed Jun 21 01:05:00 2023
             State : clean
    Active Devices : 3
   Working Devices : 4
    Failed Devices : 0
     Spare Devices : 1

            Layout : left-symmetric
        Chunk Size : 512K

Consistency Policy : resync

              Name : localhost.localdomain:0  (local to host localhost.localdomain)
              UUID : 5692f526:17ee2012:9361508d:ebb9c842
            Events : 18

    Number   Major   Minor   RaidDevice State
       0     259        4        0      active sync   /dev/nvme0n2
       1     259        5        1      active sync   /dev/nvme0n3
       4     259        6        2      active sync   /dev/nvme0n4

       3     259        7        -      spare   /dev/nvme0n5

配置ISCSI客户端

[root@localhost ~]# targetcli
Warning: Could not load preferences file /root/.targetcli/prefs.bin.
targetcli shell version 2.1.53
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]
/>

//使用targetcli命令后就能进入到交互式页面,可以通过ls查看目录参数的结构,/backstores/block是ISCSI服务端配置共享设备的位置。需要把RAID5磁盘阵列md0文件加入到配置共享设备的"资源池中",并将该文件重新命名为disk0
/> cd /backstores/block
/backstores/block> create disk0 /dev/md0
Created block storage object disk0 using /dev/md0.
/backstores/block> cd /
/> ls
o- / ......................................................................................................................... [...]
  o- backstores .............................................................................................................. [...]
  | o- block .................................................................................................. [Storage Objects: 1]
  | | o- disk0 ......................................................................... [/dev/md0 (40.0GiB) write-thru deactivated]
  | |   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: 0]
  o- loopback ......................................................................................................... [Targets: 0]
/>

//创建ISCSI target名称及配置共享资源。ISCSI名 target名称是由系统自动生成的,用于描述共享资源的唯一字符串
/> cd iscsi
/iscsi> create
Created target iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.f4e1883b8030.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/iscsi> ls
o- iscsi .............................................................................................................. [Targets: 1]
  o- iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.f4e1883b8030 ......................................................... [TPGs: 1]
    o- tpg1 ................................................................................................. [no-gen-acls, no-auth]
      o- acls ............................................................................................................ [ACLs: 0]
      o- luns ............................................................................................................ [LUNs: 0]
      o- portals ...................................................................................................... [Portals: 1]
        o- 0.0.0.0:3260 ....................................................................................................... [OK]


/iscsi> cd iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.f4e1883b8030/
/iscsi/iqn.20....f4e1883b8030> cd tpg1/luns
/iscsi/iqn.20...030/tpg1/luns> create /backstores/block/disk0
Created LUN 0.

//设置访问控制列表(ACL),ISCSI协议是通过客户端名称进行验证的,用户在访问存储共享资源时不需要输入密码,只要ISCSI客户端的名称与服务端中设置的访问控制列表中某一名称条目一致即可,因此需要在ISCSI服务端的配置文件中写入一串能够验证用户信息的名称
/iscsi/iqn.20...030/tpg1/luns> cd ..
/iscsi/iqn.20...883b8030/tpg1> cd acls
/iscsi/iqn.20...030/tpg1/acls> create iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.f4e1883b8030:client
Created Node ACL for iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.f4e1883b8030:client
Created mapped LUN 0.

//设置ISCSI服务端的监听IP地址和端口号。位于生产环境中的服务器可能由多块网卡
/iscsi/iqn.20...030/tpg1/acls> cd ../portals/
/iscsi/iqn.20.../tpg1/portals> ls
o- portals ............................................................................................................ [Portals: 1]
  o- 0.0.0.0:3260 ............................................................................................................. [OK]
/iscsi/iqn.20.../tpg1/portals> delete 0.0.0.0 3260
Deleted network portal 0.0.0.0:3260
/iscsi/iqn.20.../tpg1/portals> create 192.168.95.128
Using default IP port 3260
Created network portal 192.168.95.128:3260.

//检查配置文件
/iscsi/iqn.20.../tpg1/portals> cd /
/> ls
o- / ......................................................................................................................... [...]
  o- backstores .............................................................................................................. [...]
  | o- block .................................................................................................. [Storage Objects: 1]
  | | o- disk0 ........................................................................... [/dev/md0 (40.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.2003-01.org.linux-iscsi.localhost.x8664:sn.f4e1883b8030 ....................................................... [TPGs: 1]
  |   o- tpg1 ............................................................................................... [no-gen-acls, no-auth]
  |     o- acls .......................................................................................................... [ACLs: 1]
  |     | o- iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.f4e1883b8030:client ................................... [Mapped LUNs: 1]
  |     |   o- mapped_lun0 ................................................................................. [lun0 block/disk0 (rw)]
  |     o- luns .......................................................................................................... [LUNs: 1]
  |     | o- lun0 ...................................................................... [block/disk0 (/dev/md0) (default_tg_pt_gp)]
  |     o- portals .................................................................................................... [Portals: 1]
  |       o- 192.168.95.128:3260 .............................................................................................. [OK]
  o- loopback ......................................................................................................... [Targets: 0]


[root@localhost ~]# firewall-cmd --permanent --zone=public --add-port=3260/tcp
success
[root@localhost ~]# firewall-cmd --reload
success


//客户端配置
//ISCSI协议是通过客户端的名称来进行验证的,而该名称也是ISCSI客户端的唯一标识,而且必须与服务端配置文件中访问控制列表的中的信息一致
[root@localhost iscsi]# yum -y install iscsi-initiator-utils
[root@localhost iscsi]# vim /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.f4e1883b8030:client
[root@localhost iscsi]# systemctl restart iscsid
[root@localhost iscsi]# systemctl enable iscsid
Created symlink /etc/systemd/system/multi-user.target.wants/iscsid.service → /usr/lib/systemd/system/iscsid.service.
//先发现,在登陆,最后挂载并使用。iscsiadm是用来管理、查询、插入、更新或删除ISCSI数据库配置文件的命令行工具,先进行扫描ISCSI服务端。其中-m discovery参数目的是扫描并发现可用资源,-t st参数韦执行扫描操作的类型,-p IP参数为ISCSI服务端的IP地址
[root@localhost ~]# iscsiadm -m discovery -t st -p 192.168.95.130
192.168.95.130:3260,1 iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.e787270a21b6
//-m node参数将客户端所在主机作为一台节点服务器,-T参数为要使用的存储资源,-p IP是服务端地址,--login进行登陆验证
[root@localhost ~]# iscsiadm -m node -T iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.e787270a21b6 -p 192.168.95.130 --login
Logging in to [iface: default, target: iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.e787270a21b6, portal: 192.168.95.130,3260]
Login to [iface: default, target: iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.e787270a21b6, portal: 192.168.95.130,3260] successful.
[root@localhost ~]# ls -d /dev/sdb
/dev/sdb
[root@localhost ~]# mkfs.xfs /dev/sdb
log stripe unit (524288 bytes) is too large (maximum is 256KiB)
log stripe unit adjusted to 32KiB
meta-data=/dev/sdb               isize=512    agcount=16, agsize=654720 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
data     =                       bsize=4096   blocks=10475520, imaxpct=25
         =                       sunit=128    swidth=256 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=5120, version=2
         =                       sectsz=512   sunit=8 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@localhost ~]# mkdir /iscsi
[root@localhost ~]# mount /dev/sdb /iscsi/
[root@localhost ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        885M     0  885M   0% /dev
tmpfs           901M     0  901M   0% /dev/shm
tmpfs           901M  9.5M  891M   2% /run
tmpfs           901M     0  901M   0% /sys/fs/cgroup
/dev/sda3        98G  5.8G   92G   6% /
/dev/sda1       295M  211M   85M  72% /boot
tmpfs           181M   24K  181M   1% /run/user/0
/dev/sdb         40G  319M   40G   1% /iscsi
//写入/etc/fstab中时,请使用UUID进行挂载,查看UUID命令blkid | grep /dev/sdb

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值