CentOS 7部署网络存储ISCSI
部署网络存储ISCSI
1、什么是ISCSI
Internet Small Computer System Interface 互联网小型计算机接口技术,是一种将SCS存储与以太网技术相结合,可以用来在互联网中传输SCSI接口的数据与命令。
2、当前硬盘接口类型有IDE、SATA、SAS(服务器用的较多)SCSI、四种
3、ISCSI技术优势与劣势
优势:摆脱了物理环境的限制,同时还能将存储资源分配给多个服务器使用
劣势:受到网速的限制,传输速率与稳定性是ISCSI技术的瓶颈
实验1:用虚拟机创建RAID阵列,四块5G磁盘,3块raid5,一块备份盘。配置ISCSI服务端与linux客户端、windows客户端
实验一:创建RAID5
先给主机添加4块5G磁盘
[root@localhost ~]# ls /dev/sd?
/dev/sda /dev/sdb /dev/sdc /dev/sdd /dev/sde
创建raid阵列
[root@localhost ~]# mdadm -Cv /dev/md0 -n 3 -l 5 -x 1 /dev/sd[b-e]
mdadm: layout defaults to left-symmetric
mdadm: layout defaults to left-symmetric
mdadm: chunk size defaults to 512K
mdadm: size set to 5238272K
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
shell
查看raid
```shell
[root@localhost ~]# mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Thu Mar 7 12:21:24 2019
Raid Level : raid5
Array Size : 10476544 (9.99 GiB 10.73 GB)
Used Dev Size : 5238272 (5.00 GiB 5.36 GB)
Raid Devices : 3
Total Devices : 4
Persistence : Superblock is persistent
配置ISCSI服务器端
安装
[root@localhost ~]# yum install -y targetd targetcli
[root@localhost ~]# systemctl start target
[root@localhost ~]# systemctl enable target
ln -s '/usr/lib/systemd/system/target.service' '/etc/systemd/system/multi-user.target.wants/target.service'
配置ISCSI服务端共享资源
[root@localhost ~]# targetcli
/> 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]
/> cd backstores/block
/backstores/block> create disk0 /dev/md0
Created block storage object disk0 using /dev/md0.
创建ISCSI target名称并配置共享资源
/backstores/block> cd /iscsi
/iscsi> create
Created target iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.45784430da82.
Created TPG 1.
/iscsi> ls
o- iscsi .............................................................. [Targets: 1]
o- iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.45784430da82 ......... [TPGs: 1]
o- tpg1 ................................................. [no-gen-acls, no-auth]
o- acls ............................................................ [ACLs: 0]
o- luns ............................................................ [LUNs: 0]
o- portals ...................................................... [Portals: 0]
/iscsi> cd iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.45784430da82/tpg1/luns
/iscsi/iqn.20...a82/tpg1/luns> create /backstores/block/disk0
Created LUN 0.
设置访问控制列表(ACL)
/iscsi/iqn.20...a82/tpg1/luns> cd ..
/iscsi/iqn.20...4430da82/tpg1> cd acls
/iscsi/iqn.20...a82/tpg1/acls> create iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.45784430da82:client
Created Node ACL for iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.45784430da82:client
Created mapped LUN 0.
设置ISCSI服务端监听的IP地址与端口
/iscsi/iqn.20...a82/tpg1/acls> cd ..
/iscsi/iqn.20...4430da82/tpg1> cd portals
/iscsi/iqn.20.../tpg1/portals> create 192.168.10.10
Using default IP port 3260
Created network portal 192.168.10.10:3260.
重启服务,清空iptables 防火墙策略并打开防火墙3260/TCP端口
[root@localhost ~]# systemctl restart targetd
[root@localhost ~]# iptables -F
[root@localhost ~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ OK ]
[root@localhost ~]# firewall-cmd --permanent --add-port=3260/tcp
success
[root@localhost ~]# firewall-cmd --reload
success
配置linux客户端(RHEL默认已安装客户端)
[root@localhost ~]# yum install iscsi-initiator-utils -y
配置ISCSI客户端中initiator名称文件
[root@localhost ~]# vim /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.45784430da82:client
重启ISCSI客户端服务
[root@localhost ~]# systemctl restart iscsid
[root@localhost ~]# systemctl enable iscsid
ln -s '/usr/lib/systemd/system/iscsid.service' '/etc/systemd/system/multi-user.target.wants/iscsid.service'
扫描并发现192.168.10.10主机的ISCSI共享资源
[root@localhost ~]# iscsiadm -m discovery -t st -p 192.168.10.10
192.168.10.10:3260,1 iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.45784430da82
登录ISCSI服务器端
[root@localhost ~]# iscsiadm -m node -T iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.45784430da82 -P 192.168.10.10 --login
Logging in to [iface: default, target: iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.45784430da82, portal: 192.168.10.10,3260] (multiple)
Login to [iface: default, target: iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.45784430da82, portal: 192.168.10.10,3260] successful.
此时会发现客户端主机多出sdb的磁盘
[root@localhost ~]# ls /dev/sd?
/dev/sda /dev/sdb
[root@localhost ~]# file /dev/sdb
/dev/sdb: block special
格式化并挂载
[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=256 agcount=16, agsize=163712 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=2619136, imaxpct=25
= sunit=128 swidth=256 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=8 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@localhost ~]# mkdir /iscsi
[root@localhost ~]# vim /etc/fstab
[root@localhost ~]# blkid /dev/sdb
/dev/sdb: UUID="5e0c1f4a-1e65-4691-8be6-598203f9041b" TYPE="xfs"
[root@localhost ~]# vim /etc/fstab
UUID=5e0c1f4a-1e65-4691-8be6-598203f9041b /iscsi xfs defaults,_netdev 0 0
成功挂载
[root@localhost ~]# mount -a
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 18G 3.0G 15G 17% /
devtmpfs 905M 0 905M 0% /dev
tmpfs 914M 176K 914M 1% /dev/shm
tmpfs 914M 8.9M 905M 1% /run
tmpfs 914M 0 914M 0% /sys/fs/cgroup
/dev/sr0 3.5G 3.5G 0 100% /mnt
/dev/sda1 497M 119M 379M 24% /boot
/dev/sdb 10G 33M 10G 1% /iscsi
1.简述iSCSI存储技术在生产环境中的作用。
2.在Linux系统中,iSCSI服务端和iSCSI客户端所使用的服务程序分别叫什么?
3.在使用targetcli命令配置iSCSI服务端配置文件时,acls与portals参数目录中分别存放什么内容?
4.iSCSI协议占用了服务器哪个协议和端口号?
5、用户在填写fstab设备挂载配置文件时,一般会把远程存储资源的UUID(而非设备的名称)填写到配置文件中。这是为什么?
6.在使用Windows系统来访问iSCSI共享存储资源时,它有两个步骤与Linux系统一样。请说明是哪两个步骤。
作者:一毛
本博客所有文章仅用于学习、研究和交流目的,欢迎非商业性质转载。
不管遇到了什么烦心事,都不要自己为难自己;无论今天发生多么糟糕的事,都不应该感到悲伤。记住一句话:越努力,越幸运。