Linux挂载iscsi网络存储
iscsi网络存储简介
-
iSCSI
,即Internet SCSI,是IETF制订的一项标准,用于将SCSI数据块映射为以太网数据包。从根本上说,它是一种基于IP Storage理论的新型存储技术,该技术将存储行业广泛应用的SCSI接口技术与IP网络技术相结合,可以在IP网络上构建SAN。简单地说,iSCSI就是在IP网络上运行SCSI协议的一种网络存储技术
iscsi的组成
- iSCSI IniTIator或者iSCSI HBA iSCSI Target 以太网交换机 一台或者多台服务器
主机规划
名称 | IP地址 | 硬件配置 |
---|---|---|
iscsi服务端 | 192.168.100.20 | 1核2G |
iscsi客户端 | 192.168.100.19 | 1核2G |
配置iscsi网络存储挂载
iscsi服务端配置
# 安装iscsi服务端
yum install targetd targetcli -y
# 调用targetcli进行设置
[root@server ~]# 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]
# 创建iscsi磁盘
/> /backstores/block create idisk1 /dev/sdb # idisk1 自定义共享磁盘名称
Created block storage object idisk1 using /dev/sdb.
/> ls
o- / ........................................................................... [...]
o- backstores ................................................................ [...]
| o- block .................................................... [Storage Objects: 1]
| | o- idisk1 .......................... [/dev/sdb (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/ create iqn.2021-11.pip.cc:server
Created target iqn.2021-11.pip.cc:server.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/> ls
o- / ......................................................................................................................... [...]
o- backstores .............................................................................................................. [...]
| o- block .................................................................................................. [Storage Objects: 1]
| | o- idisk1 ........................................................................ [/dev/sdb (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: 1]
| o- iqn.2021-11.pip.cc:server ......................................................................................... [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]
o- loopback ......................................................................................................... [Targets: 0]
# 创建服务卷,<才能被客户端识别>
/> cd iscsi/iqn.2021-11.pip.cc:server/tpg1/
/iscsi/iqn.20...c:server/tpg1> luns/ create /backstores/block/idisk1 # 创建服务卷
Created LUN 0.
/iscsi/iqn.20...c:server/tpg1> ls
o- tpg1 ..................................................................................................... [no-gen-acls, no-auth]
o- acls ................................................................................................................ [ACLs: 0]
o- luns ................................................................................................................ [LUNs: 1]
| o- lun0 ........................................................................... [block/idisk1 (/dev/sdb) (default_tg_pt_gp)]
o- portals .......................................................................................................... [Portals: 1]
o- 0.0.0.0:3260 ........................................................................................................... [OK]
/iscsi/iqn.20...c:server/tpg1>
# 创建客户端连接器,启用(chap认证)
/iscsi/iqn.20...c:server/tpg1> acls/ create iqn.2021-11.pip.cc:client
Created Node ACL for iqn.2021-11.pip.cc:client
Created mapped LUN 0.
/iscsi/iqn.20...c:server/tpg1> ls
o- tpg1 ..................................................................................................... [no-gen-acls, no-auth]
o- acls ................................................................................................................ [ACLs: 1]
| o- iqn.2021-11.pip.cc:client .................................................................................. [Mapped LUNs: 1]
| o- mapped_lun0 ...................................................................................... [lun0 block/idisk1 (rw)]
o- luns ................................................................................................................ [LUNs: 1]
| o- lun0 ........................................................................... [block/idisk1 (/dev/sdb) (default_tg_pt_gp)]
o- portals .......................................................................................................... [Portals: 1]
o- 0.0.0.0:3260 ........................................................................................................... [OK]
# 设置验证密码
/iscsi/iqn.20...c:server/tpg1> cd acls/iqn.2021-11.pip.cc:client/
/iscsi/iqn.20...pip.cc:client> set auth userid=modern
Parameter userid is now 'modern'.
/iscsi/iqn.20...pip.cc:client> set auth password=chinano1
Parameter password is now 'chinano1'.
# 启动targetd服务
systemctl enable targetd && systemctl start targetd
# 暴露3260端口
ss -lntp | grep 3260
iscsi客户端配置
# 安装iscsi的客户端程序
yum install iscsi-initiator-utils -y
# 修改iscsi的配置文件
# initiatorname.iscsi: 定义客户端连接器的名称
# iscsid.conf:启用chap认证
vim /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2021-11.pip.cc:client
vim /etc/iscsi/iscsid.conf
57 node.session.auth.authmethod = CHAP # 启用chap认证
68 node.session.auth.username = modern # 认证用户名
69 node.session.auth.password = chinano1 # 如果需要让windows访问 password需要 12位以上
# 启动iscsid服务
systemctl enable iscsid && systemctl start iscsid
# 发现存储服务器资源
# -t 显示输出结果 -p:iscsi服务器地址
iscsiadm -m discovery --type sendtargets --portal 192.168.100.20
192.168.100.20:3260,1 iqn.2021-11.pip.cc:server
# 登录存储服务器
# -T:服务器发现的名称 -p:服务器地址
[root@localhost ~]# iscsiadm -m node -T iqn.2021-11.pip.cc:server -p 192.168.100.20 --login
Logging in to [iface: default, target: iqn.2021-11.pip.cc:server, portal: 192.168.100.20,3260] (multiple)
Login to [iface: default, target: iqn.2021-11.pip.cc:server, portal: 192.168.100.20,3260] successful.
# 查看iscsi是否存在
lsblk | grep sdb && fdisk -l | grep sdb
sdb 8:16 0 40G 0 disk
Disk /dev/sdb: 42.9 GB, 42949672960 bytes, 83886080 sectors
客户端配置方面
# 安装相关软件,其中kmod-xfs,xfsprogs为xfs文件系统的组件
yum install binutils iscsi-initiator-utils kmod-xfs xfsprogs -y
iscsiadm -m node
192.168.100.20:3260,1 iqn.2021-11.pip.cc:server
# 查看存储服务器的iscsi是否在线
iscsiadm -m discovery --type sendtargets --portal 192.168.100.20
192.168.100.20:3260,1 iqn.2021-11.pip.cc:server
# 设置开机自动登陆iscsi
iscsiadm -m node -T iqn.2021-11.pip.cc:server -p 192.168.100.20:3260 --op update -n node.startup -v automatic
# 显示当前的连接
iscsiadm -m session
tcp: [1] 192.168.100.20:3260,1 iqn.2021-11.pip.cc:server (non-flash)
# 查看存储空间是否已经显示在磁盘列表中
fdisk -l | grep sdb
Disk /dev/sdb: 42.9 GB, 42949672960 bytes, 83886080 sectors
# 注销所有连接
# iscsiadm -m node --logoutall=all
# 格式化为xfs文件系统
[root@localhost ~]# mkfs.xfs /dev/sdb
meta-data=/dev/sdb isize=512 agcount=4, agsize=2621440 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=10485760, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=5120, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
# 创建挂载点并挂载
mkdir /iscsi
mount -t xfs /dev/sdb /iscsi/
# 查看是否挂载成功
df -hT | grep sdb
/dev/sdb xfs 40G 33M 40G 1% /iscsi
# 永久挂载
vim /etc/fstab
# 一定要加_netdev不然系统会无法启动, _netdev的意思是等有了网络之后再挂载
/dev/sdb /iscsi xfs defaults,_netdev 0 0
关于
_netdev
参数
# 重启后查看挂载情况
reboot
df -hT | grep sdb
/dev/sdb xfs 40G 33M 40G 1% /iscsi
版权声明:本文为sixeleven611原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。