CentOS连接iSCSI

配置思路

  1. 初始化配置
    • 主机初始化
      • 配置主机名
      • 配置IP地址
    • 存储初始化
      • 创建存储池
      • 配置IP地址
  2. 主机配置
    • 安装ISCSI软件
    • 连接存储
    • 安装多路径软件
  3. 存储配置
    • 创建LUN
    • 创建主机
    • 绑定主机与LUN
  4. 主机扫盘
    • 扫盘
    • 格式化磁盘
    • 挂载分区

初始化配置

  • 修改主机名
    方法1:hostnamectl set-hostname hostname
    方法2:nmcli general hostname hostname

    • 修改IP地址
      1. NMCLI命令行修改

        nmcli connect add type ethernet con-name eth2 ifname eth2 ipv4.addresses 192.168.20.150/24 ipv4.gateway 192.168.20.254 ipv4.method manual

        ipv4.gateway按需配置

      2. NMTUI图形化修改

  • 临时配置IP地址
    ip命令配置地址:ip addr add x.x.x.x/x dev ethx
    重启接口:ip link set dev ethx { up | down }
    ifconfig命令配置地址:ifconfig ethx x.x.x.x/x netmask x.x.x.x

  • 临时配置网关
    route add default gw x.x.x.x

配置ISCSI

初始化

  1. 检查iscsi软件是否安装
    rpm -qa | grep iscsi
  2. 安装iscsi软件
    yum install iscsi-initiator-utils
  3. 修改ISCSI的IQN
    vim /etc/iscsi/initiatorname.iscsi
  4. 修改完成后需要重启服务
    systemctl restart iscsi

连接服务器

  1. 发现服务器:
    方法1:iscsiadm -m discoverydb -t st -p 192.168.140.1 -D
    方法2:iscsiadm -m discovery -t st -p 192.168.140.1
  2. 登录服务器:iscsiadm -m node -T iqn.XXXX:XXXX -p 192.168.140.1 -l
  3. 设置开机自动登录:iscsiadm -m node -T iqn.XXXX:XXXX -p 192.168.140.1 -o update -n node.startup -v automatic

安装多路径软件(连接华为存储需要)

  1. 安装依赖:
    查询命令所属包:yum provides */lspci
    安装依赖:yum install pciutils
  2. 上传多路径软件到服务器,并使用unzip命令解压,如果没有unzip命令,则用yum install unzip命令安装
  3. 安装多路径软件:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
[root@localhost CentOS]# sh install.sh 
complete iscsi checking.
complete FC checking.
Verify the UltraPath existence.
The UltraPath is not installed.
If the operating system is installed on a local drive of the server, you are advised
to choose boot from local; if the operating system is installed on a SAN storage
system, you must choose boot from san. Please choose the boot type of your system:
<1>--boot-from-Local
<2>--boot-from-SAN
please input your select:1 #从本地启动
Preparing... ########################################
Updating / installing...
UltraPath-31.02.024-2 ########################################
User configuration is saved successfully.
The boot service is installed successfully.
The running service is installed successfully.
************************************Attention************************************
* UltraPath would modify some parameters of HBA cards for better performace. If *
* UltraPath is installed for the first time, you may need to update the initrd *
* image before system reboot to make the modification take effect. *
*********************************************************************************
*********************************************************************************
* UltraPath will use the system hostname for alarm generation and automatic host*
* registration. Make sure that the system hostname is correctly configured.. *
*********************************************************************************
The installation is complete. Whether to restart the system now?
<Y|N>:Y #Y之后服务器会重启,不重启则选N

扫盘

  • 多路径扫盘:hot_add ISCSI与FC通用命令,有多路径软件时推荐使用
  • iscsiadm工具扫盘:iscsiadm -m node --rescan 未安装多路径软件时推荐
  • 系统扫盘
    1. 查看iscsi驱动器属于哪个host:cat /proc/scsi/scsilsscsi
    2. echo "- - -" > /sys/class/scsi_host/$HOST/scan
  • 查看已连接的磁盘:lsblk

可选:卸载盘

  • 首先卸载挂载点:umount
  • 查看已连接的iscsi节点信息:iscsiadm -m node
  • 注销需要卸载的节点:iscsiadm -m node -T iqn.XXXX:XXXX --logout
  • 删除节点信息:iscsiadm -m node -o delete -T iqn.XXXX:XXXX 192.168.140.1
  • 最后通过iscsiadm -m node命令查看删除结果,No records found,说明是删除ISCSI设备干净了

配置fstab

配置重启自动连接iscsi磁盘,和普通磁盘有区别的地方是需要在defaults后面加_netdev选项,不添加会导致系统无法开机。

1
2
[root@localhost CentOS]# vim /etc/fstab
/dev/sdc1 /data ext4 defaults,_netdev 0 0

CentOS连接iSCSI
https://www.intx.work/posts/9c767552.html
发布于
2024年4月5日
更新于
2025年6月29日
许可协议