案例说明:
在CentOS 7环境下,配置iscsi共享存储。
操作系统版本:
[root@node201 KingbaseHA]# cat /etc/centos-release
CentOS Linux release 7.9.2009 (Core)
集群架构:
如下所示,node1和node2为集群节点:
节点信息:
[root@node201 KingbaseHA]# vi /etc/hosts
192.168.1.201 node201
192.168.1.202 node202
192.168.1.203 node203 iscsi_Srv
集群软件:
[root@node201 data]# rpm -qa |egrep 'corosync|pacemaker'
corosynclib-2.4.5-7.el7_9.2.x86_64
pacemaker-1.1.23-1.el7_9.1.x86_64
pacemaker-libs-1.1.23-1.el7_9.1.x86_64
pacemaker-doc-1.1.23-1.el7_9.1.x86_64
corosync-qdevice-2.4.5-7.el7_9.2.x86_64
pacemaker-cluster-libs-1.1.23-1.el7_9.1.x86_64
pacemaker-cli-1.1.23-1.el7_9.1.x86_64
corosync-2.4.5-7.el7_9.2.x86_64
iSCSI简介:
iSCSI(Internet Small Computer System Interface)是一种在IP网络上传输SCSI(Small Computer System Interface)命令和数据的存储协议。它允许将远程存储设备映射到本地主机,提供了一种基于网络的存储解决方案。
iSCSI服务架构涉及以下组件:
- iSCSI Initiator(客户端):iSCSI发起器是指主机或计算机系统,它通过iSCSI协议与远程存储设备进行通信。发起器通过网络发送iSCSI命令和数据来访问远程存储。
- iSCSI Target(服务端):iSCSI目标是远程存储设备或存储服务器,它通过iSCSI协议接受发起器的请求。目标将接收到的iSCSI命令转换为对存储设备的本地SCSI命令,并将数据传输回发起器。
- iSCSI Initiator 和 Target 之间的网络连接:iSCSI Initiator 和 Target 之间的通信是通过TCP/IP网络实现的。通常使用以太网作为传输介质,并使用标准的IP协议栈进行通信。
- iSCSI Initiator 驱动程序(iscsid):iSCSI Initiator 驱动程序是在主机操作系统上运行的软件组件,负责将iSCSI命令和数据传递给网络,并处理从网络接收到的响应。
- iSCSI Target 软件(target.service,targetcli):iSCSI Target 软件是在远程存储设备上运行的软件组件,用于接受和处理来自发起器的iSCSI请求,并将其转换为本地存储设备的操作。
- 存储设备:存储设备可以是磁盘阵列、磁盘存储系统或其他支持SCSI协议的存储设备,LVM 等。iSCSI目标通过本地存储设备提供存储服务。
一、配置ISCSI共享
1、server端安装软件
[root@node201 ~]# yum install targetd targetcli -y
2、启动target服务
[root@node201 ~]# systemctl start targetd
[root@node201 ~]# systemctl enable targetd
Created symlink from /etc/systemd/system/multi-user.target.wants/targetd.service to /usr/lib/systemd/system/targetd.service.
3、配置iscsi共享
如下所示,通过targetli工具配置iscsi的共享:
1)targetli帮助信息
[root@node203 ~]# targetcli
AVAILABLE COMMANDS
==================
The following commands are available in the
current path:
- bookmarks action [bookmark]
- cd [path]
- clearconfig [confirm]
- exit
- get [group] [parameter...]
- help [topic]
- ls [path] [depth]
- pwd
- refresh
- restoreconfig [savefile] [clear_existing] [target] [storage_object]
- saveconfig [savefile]
- sessions [action] [sid]
- set [group] [parameter=value...]
- status
- version
/> exit
Global pref auto_save_on_exit=true
Configuration saved to /etc/target/saveconfig.json
2)创建iscsi磁盘
/> /backstores/block create idisk1 /dev/sdb
Created block storage object idisk1 using /dev/sdb.
/> /backstores/block create idisk2 /dev/sdc
Created block storage object idisk2 using /dev/sdc.
/> ls
o- / ........................................................................................... [...]
o- backstores ................................................................................ [...]
| o- block .................................................................... [Storage Objects: 2]
| | o- idisk1 .......................................... [/dev/sdb (10.7GiB) write-thru deactivated]
| | | o- alua ..................................................................... [ALUA Groups: 1]
| | | o- default_tg_pt_gp ......................................... [ALUA state: Active/optimized]
| | o- idisk2 ......................................... [/dev/sdc (512.0MiB) 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 支持下面四种后端存储类型:
block:它允许将块设备作为iSCSI后端存储使用,例如硬盘驱动器或逻辑卷。
fileio:它允许使用文件作为iSCSI后端存储使用,即将文件作为虚拟磁盘提供给iSCSI客户端。
pscsi:pscsi代表"pass-through SCSI",允许将SCSI设备直接公开给iSCSI客户端,以便客户端可以直接访问SCSI命令。
ramdisk:它允许将RAM磁盘作为iSCSI后端存储使用,即将内存中的一部分作为虚拟磁盘提供给iSCSI客户端。
3)创建iSCSI服务端
/> iscsi/ create iqn.2024-08.pip.cc:server
Created target iqn.2024-08.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: 2]
| | o- idisk1 .......................................... [/dev/sdb (10.7GiB) write-thru deactivated]
| | | o- alua ..................................................................... [ALUA Groups: 1]
| | | o- default_tg_pt_gp ......................................... [ALUA state: Active/optimized]
| | o- idisk2 ......................................... [/dev/sdc (512.0MiB) 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.2024-08.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]
关于为 Target 创建 IQN,有以下几点需要进行说明:
在为 Target 创建 IQN 时会在此 IQN 下面创建一个默认的 TPG。
IQN 即 iSCSI 限定名称,一个全球唯一名称,用于以强制命名格式来识别启动器(initiator)和目标(target)。
通用格式:iqn.YYYY-MM.com.reversed.domain[:optional_string];
iqn:表示此名称将使用域作为其标识符;
YYYY-MM:拥有域名的第一个月;
com.reversed.domain:此 iSCSI 名称的创建组织的逆向域名;
optional_string:以冒号为前缀的可选字符串。
管理员如果不指定要创建的 IQN,系统会自动生成一个 IQN。
4)创建lun(共享卷)
/> cd iscsi/iqn.2024-08.pip.cc:server/tpg1/
/iscsi/iqn.20...c:server/tpg1> luns/ create /backstores/block/idisk1
Created LUN 0.
/iscsi/iqn.20...c:server/tpg1> luns/ create /backstores/block/idisk2
Created LUN 1.
/iscsi/iqn.20...c:server/tpg1> ls
o- tpg1 ....................................................................... [no-gen-acls, no-auth]
o- acls .................................................................................. [ACLs: 0]
o- luns .................................................................................. [LUNs: 2]
| o- lun0 ............................................. [block/idisk1 (/dev/sdb) (default_tg_pt_gp)]
| o- lun1 ............................................. [block/idisk2 (/dev/sdc) (default_tg_pt_gp)]
o- portals ............................................................................ [Portals: 1]
o- 0.0.0.0:3260 ............................................................................. [OK]
5)创建客户端认证(chap)
/iscsi/iqn.20...c:server/tpg1> acls/ create iqn.2024-08.pip.cc:client
Created Node ACL for iqn.2024-08.pip.cc:client
Created mapped LUN 1.
Created mapped LUN 0.
/iscsi/iqn.20...c:server/tpg1> cd acls/iqn.2024-08.pip.cc:client/
/iscsi/iqn.20...pip.cc:client> set auth userid=root
Parameter userid is now 'root'.
/iscsi/iqn.20...pip.cc:client> set auth password=123456
Parameter password is now '123456'.
/iscsi/iqn.20...pip.cc:client> info
chap_password: 123456
chap_userid: root
wwns:
iqn.2024-08.pip.cc:client
6)创建portal
管理员需要创建一个门户配置以指定监听 IP 地址和端口;如果未指定 IP 则默认使用 0.0.0.0 地址;如果未指定端口号则默认使用 3260 端口。
/> cd iscsi/iqn.2024-08.pip.cc:server/tpg1/
/iscsi/iqn.20...c:server/tpg1> ls
o- tpg1 ....................................................................... [no-gen-acls, no-auth]
o- acls .................................................................................. [ACLs: 1]
| o- iqn.2024-08.pip.cc:client .................................................... [Mapped LUNs: 2]
| o- mapped_lun0 ........................................................ [lun0 block/idisk1 (rw)]
| o- mapped_lun1 ........................................................ [lun1 block/idisk2 (rw)]
o- luns .................................................................................. [LUNs: 2]
| o- lun0 ............................................. [block/idisk1 (/dev/sdb) (default_tg_pt_gp)]
| o- lun1 ............................................. [block/idisk2 (/dev/sdc) (default_tg_pt_gp)]
o- portals ............................................................................ [Portals: 1]
o- 0.0.0.0:3260 ............................................................................. [OK]
/iscsi/iqn.20...c:server/tpg1> cd portals
/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.1.203 3260
Using default IP port 3260
Created network portal 192.168.1.203:3260.
/iscsi/iqn.20.../tpg1/portals> ls
o- portals .............................................................................. [Portals: 1]
o- 192.168.1.203:3260 ......................................................................... [OK]
7)查看iscsi server配置
/iscsi/iqn.20...pip.cc:client> cd /
/> ls
o- / ........................................................................................... [...]
o- backstores ................................................................................ [...]
| o- block .................................................................... [Storage Objects: 2]
| | o- idisk1 ............................................ [/dev/sdb (10.7GiB) write-thru activated]
| | | o- alua ..................................................................... [ALUA Groups: 1]
| | | o- default_tg_pt_gp ......................................... [ALUA state: Active/optimized]
| | o- idisk2 ........................................... [/dev/sdc (512.0MiB) 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.2024-08.pip.cc:server ........................................................... [TPGs: 1]
| o- tpg1 ................................................................. [no-gen-acls, no-auth]
| o- acls ............................................................................ [ACLs: 1]
| | o- iqn.2024-08.pip.cc:client .............................................. [Mapped LUNs: 2]
| | o- mapped_lun0 .................................................. [lun0 block/idisk1 (rw)]
| | o- mapped_lun1 .................................................. [lun1 block/idisk2 (rw)]
| o- luns ............................................................................ [LUNs: 2]
| | o- lun0 ....................................... [block/idisk1 (/dev/sdb) (default_tg_pt_gp)]
| | o- lun1 ....................................... [block/idisk2 (/dev/sdc) (default_tg_pt_gp)]
| o- portals ...................................................................... [Portals: 1]
| o- 192.168.1.203:3260 ................................................................. [OK]
o- loopback ........................................................................... [Targets: 0]
/> saveconfig
Last 10 configs saved in /etc/target/backup/.
Configuration saved to /etc/target/saveconfig.json
/> exit
Global pref auto_save_on_exit=true
Configuration saved to /etc/target/saveconfig.json
4、重启target服务
[root@node203 ~]# systemctl restart target
[root@node203 ~]# systemctl status target
● target.service - Restore LIO kernel target configuration
Loaded: loaded (/usr/lib/systemd/system/target.service; disabled; vendor preset: disabled)
Active: active (exited) since Fri 2024-08-02 10:50:45 CST; 4s ago
Process: 18476 ExecStop=/usr/bin/targetctl clear (code=exited, status=0/SUCCESS)
.......
5、配置客户端访问iscsi共享(all nodes)
iscsi-initiator-utils 提供了 iSCSI 客户端的工具和服务,用于管理和配置 iSCSI 连接。它包含了 iscsiadm 命令行工具和其他与 iSCSI 相关的组件。
主要功能和组件包括:
- iscsiadm 命令行工具:iscsi-initiator-utils 包含了 iscsiadm 命令行工具,用于管理和配置 iSCSI 连接。您可以使用该工具来发现 iSCSI 目标、建立会话、断开连接、管理目标列表等。
- iSCSI 服务:iscsi-initiator-utils 包含了 iSCSI 服务(通常是 iscsid 守护进程),它在后台运行并处理与 iSCSI 存储目标的通信。该服务负责管理 iSCSI 会话和设备,并提供与 iSCSI 目标的交互接口。
- iSCSI 配置文件:iscsi-initiator-utils 提供了用于配置 iSCSI 客户端的配置文件。这些配置文件包含了 iSCSI 目标的信息、认证设置、会话选项等。您可以编辑这些配置文件来自定义 iSCSI 连接的行为。
1)客户端安装软件
[root@node201 ~]# yum install iscsi-initiator-utils-iscsiuio -y
2)配置iscsi配置文件
如下所示,在客户端配置访问server端认证文件:
[root@node201 ~]# cat /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2024-08.pip.cc:client
node.session.auth.authmethod = CHAP
node.session.auth.username = root
node.session.auth.password = 123456
启动服务:
[root@node201 ~]# systemctl restart iscsid
[root@node201 ~]# systemctl enable iscsid
3)客户端访问iscsi共享
# 查看iscsi共享
[root@node201 ~]# iscsiadm -m discovery -t st -p 192.168.1.203
192.168.1.203:3260,1 iqn.2024-08.pip.cc:server
# 建立到iscsi server的共享访问
[root@node201 ~]# iscsiadm -m node -T iqn.2024-08.pip.cc:server -p 192.168.1.203 --login
Logging in to [iface: default, target: iqn.2024-08.pip.cc:server, portal: 192.168.1.203,3260] (multiple)
Login to [iface: default, target: iqn.2024-08.pip.cc:server, portal: 192.168.1.203,3260] successful.
# 查看共享存储信息
[root@node201 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 102.9G 0 disk
├─sda1 8:1 0 500M 0 part /boot
└─sda2 8:2 0 102.4G 0 part
├─centos-root 253:0 0 50G 0 lvm /
├─centos-swap 253:1 0 3G 0 lvm [SWAP]
└─centos-home 253:2 0 49.3G 0 lvm /home
sdb 8:16 0 10.7G 0 disk
sdc 8:32 0 512M 0 disk
sr0 11:0 1 1024M 0 rom
# 如下所示,在客户端可以看到共享存储已作为本地磁盘访问
[root@node202 iscsi]# fdisk -l
Disk /dev/sdb: 11.5 GB, 11499421696 bytes, 22459808 sectors
......
Disk /dev/sdc: 536 MB, 536870912 bytes, 1048576 sectors
......
# 至此,共享存储配置完成。
标签:...,CentOS,cc,iSCSI,server,共享,root,iscsi
From: https://www.cnblogs.com/tiany1224/p/18394130