Iscsi NAS和SAN
如果你的系统需要大量的磁盘容量,但是身边却没有外接存储设备,仅有个人计算机时,那该怎么办?
此时,通过网络的SCSI磁盘(iSCSI)就能够提供帮助。这个iscsi是将来自网络的数据仿真成本机的SCSI 设备,因此可以进行诸如LVM等方面的操作,而不是单纯使用服务器端提供的文件系统而已,相当有帮 助。
作为服务器的系统,通常是需要存储设备的,而存储设备出来可以使用系统内置的磁盘之外,如果内置 的磁盘容量不够大,而且也没有额外的磁盘插槽可用时,那么常见的解决方案就是增加NAS:Network Attached Storage(网络附加存储服务器)或外接式存储设备。在高档一点的系统,可能就会用到 SAN:Storage Area Network(存储局域网) 不过,不论是哪一种架构,基本上,他们的内部硬盘通常是以磁盘阵列(RAID)作为基础的。那什么是 NAS 什么是SAN?这两者有什么不同,于我们本章讲的iscsi又有什么关系?
由于企业的数据量越来越大,而且重要性与保密性越来越重要,尤其类似数据库的内容,常常容量单位 是以TB、PB、EB进行计算的。所以磁盘阵列的应用就很重要了。那么磁盘阵列通常是在哪里呢?
主机内部有磁盘阵列控制卡,可以自行管理磁盘阵列,不过想要提供磁盘阵列的容量,需要通过额 外的网络服务才行; 外接式磁盘阵列设备,就是单纯的磁盘阵列设备,必须通过某些接口连接到主机上,主机也要安装 适当的驱动程序后才能捕捉到这个设备所提供的磁盘容量。
下载服务
[root@localhost ~]# systemctl start target
[root@localhost ~]# systemctl enable target
Created symlink from /etc/systemd/system/multi-user.target.wants/target.service to /usr/lib/systemd/system/target.service.
[root@localhost ~]# systemctl status target
● target.service - Restore LIO kernel target configuration
Loaded: loaded (/usr/lib/systemd/system/target.service; enabled; vendor preset: disabled)
Active: active (exited) since 五 2022-04-29 04:22:35 CST; 1min 21s ago
Main PID: 36214 (code=exited, status=0/SUCCESS)
4月 29 04:22:35 localhost.localdomain systemd[1]: Starting Restore LIO kernel target configuration...
4月 29 04:22:35 localhost.localdomain target[36214]: No saved config file at /etc/target/saveconfig.js...ing
4月 29 04:22:35 localhost.localdomain systemd[1]: Started Restore LIO kernel target configuration.
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost ~]#
设置防火墙
[root@localhost ~]# firewall-cmd --add-port=3260/tcp --permanent
success
[root@localhost ~]# firewall-cmd --reload
success
[root@localhost ~]# firewall-cmd --list-ports
514/tcp 514/udp 3260/tcp
[root@localhost ~]#
执行targetcli工具
[root@localhost ~]# 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'.
/>
client端
安装工具
[root@localhost ~]# yum -y install iscsi-initiator-utils
给initiator命名
[root@localhost ~]# vim /etc/iscsi/initatorname.iscsi
InitiatorName=iqn.2022-4.com.bdqn:client1
启动服务
[root@localhost ~]# systemctl start iscsi
[root@localhost ~]# systemctl enable iscsi
[root@localhost ~]# systemctl status iscsi
● iscsi.service - Login and scanning of iSCSI devices
Loaded: loaded (/usr/lib/systemd/system/iscsi.service; enabled; vendor preset: disabled)
Active: inactive (dead)
Condition: start condition failed at 五 2022-04-29 04:33:53 CST; 31s ago
Docs: man:iscsid(8)
man:iscsiadm(8)
4月 26 17:33:00 localhost.localdomain systemd[1]: Unit iscsi.service cannot be reloaded becaus...e.
4月 26 17:33:00 localhost.localdomain systemd[1]: Unit iscsi.service cannot be reloaded becaus...e.
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost ~]#
发现存储
[root@localhost ~]# iscsiadm -m discovery -t st -p 192.168.1.121
192.168.1.121 :3260,1 iqn.2020-05.com.bdqn:disk1
登陆存储/连接target
[root@localhost ~]# iscsiadm -m discovery -t st -p 192.168.1.121 -l 192.168.1.60:3260,1 iqn.2020-05.com.bdqn:disk1
Logging in to [iface: default, target: iqn.2020-05.com.bdqn:disk1, portal: 192.168.1.60,3260] (multiple)
Login to [iface: default, target: iqn.2020-05.com.bdqn:disk1, portal: 192.168.1.60,3260] successful.
验证iscsi连接,查看是否得到外界硬盘
[root@localhost ~]# lsscsi [0:0:0:0] disk VMware, VMware Virtual S 1.0 /dev/sda
[2:0:0:0] cd/dvd NECVMWar VMware IDE CDR10 1.00 /dev/sr0
[3:0:0:0] disk LIO-ORG server0.disk1 4.0 /dev/sdb
然后就可以像操作本地磁盘一样来操作iscsi磁盘 了。
[root@client ~]# gdisk /dev/sdb
... Number Start (sector) End (sector) Size Code Name
1 2048 10487807 5.0 GiB 8300 Linux filesystem
2 10487808 20971486 5.0 GiB 8300 Linux filesystem
[root@client ~]# partprobe /dev/sdb
[root@client ~]# partprobe /dev/sdb
[root@client ~]# partprobe /dev/sdb
[root@client ~]# cat /proc/partitions
major minor #blocks name
...
8 16 10485760 sdb
8 17 5242880 sdb1
8 18 5241839 sdb2
这里将/dev/sdb1分区挂载到/mnt/iscsi目录中使用。
[root@client ~]# mkdir /mnt/iscsi
[root@client ~]# mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1 isize=512 agcount=4, agsize=327680 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=1310720, 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
[root@client ~]# mount /dev/sdb1 /mnt/iscsi/
[root@client ~]# mount | tail -1 /dev/sdb1 on /mnt/iscsi type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
[root@client ~]# df -hT /mnt/iscsi/
Filesystem Type Size Used Avail Use% Mounted on
/dev/sdb1 xfs 5.0G 33M 5.0G 1% /mnt/iscsi
如果加入开机自动挂载,需要在挂载选项中添加_netdev 选项。
[root@client ~]# vim /etc/fstab
...
/dev/sdb1 /mnt/iscsi xfs defaults,_netdev 0 0
[root@client ~]# mount -a
再次提醒:iscsi,网络存储,经过网络,那么就必须要注意安全。这里注意是以防火墙来体现安全。 可以再开一台虚拟机。当做iscsi客户端,看看是否能够发现iscsi存储。
[root@work ~]# yum install iscsi*
[root@work ~]# systemctl start iscsi
[root@work ~]# iscsiadm -m discovery -t st -p 192.168.1.121
192.168.1.121:3260,1 iqn.2020-05.com.bdqn:disk1