「iSCSI」- Initiator Configuration @20210224

本文档介绍了在Linux环境下,如何安装、配置和挂载iSCSI发起端(Initiator),包括使用yum或apt-get安装iscsi-initiator-utils,发现目标,修改配置以实现自动登录和CHAP认证,以及检查连接状态。内容适用于CentOS和Debian系统,详细步骤便于系统管理员进行存储网络的设置。

系统环境

# 操作系统
不做具体限制,实验环境是CentOS Linux release 7.4.1708 (Core)发行版。

但是,任何一个系统都可以,这是在细节或者某些文件的位置上存在差异。

安装软件包

#!/bin/sh

################################################################################
# CentOS
################################################################################
yum install -y iscsi-initiator-utils.x86_64

################################################################################
# Debain
################################################################################
apt-get update
apt-get install open-iscsi

发现目标

执行如下命令,来发现主机上的目标:

#!/bin/sh

# 单纯的发现目标
iscsiadm --mode discovery --type sendtargets --op nonpersistent --portal 10.10.50.11

# 不建议:将全部目标写入数据库(iSCSI自带的数据库)
# 该命令同时会:
# 	在Debian中,在/etc/iscsi/nodes/下生成配置文件;
# 	在CentOS中,在/var/lib/iscsi/nodes/下生成配置文件;
# 每个「LUN」都有对应的配置文件。
# !!!每次执行这个命令,原有配置就会被覆盖。
iscsiadm --mode discovery --type sendtargets --op update --portal 10.10.50.11

# 将特定的LUN写入数据库
# 该命令将创建特定的数据库文件
# 这是要登录的LUN,如果不写入后面无法登录。
iscsiadm --mode node --op new -T iqn.2002-10.com.infortrend:eonnas.eonnas:pro:510.dfwsnas.test-mysql-master-02.e1000g0 \
    --portal 10.10.50.11

修改配置

修改配置文件,比如自动登录、认证等等信息:

################################################################################
# 配置自动挂载
################################################################################
node.startup = automatic

################################################################################
# 认证方式一:单向认证
################################################################################
# Enable CHAP Authentication
node.session.auth.authmethod = CHAP

# 连接Target所使用的密码
node.session.auth.username = tecmint-iscsi-user
node.session.auth.password = password

################################################################################
# 认证方式二:双向认证
################################################################################
# Enable CHAP Authentication
node.session.auth.authmethod = CHAP

# 连接Target所使用的密码
node.session.auth.username = tecmint-iscsi-user
node.session.auth.password = password

# 为Target准备的密码
node.session.auth.username_in = debian-iscsi-target
node.session.auth.password_in = secretpass

正常将应该通过命令操作。下面是一个简单的示例:

#!/bin/sh

iscsiadm --mode node -T iqn.2002-10.com.infortrend:eonnas.eonnas:pro:510.dfwsnas.test-mysql-master-02.e1000g0 \
    --op update -n node.startup -v automatic

iscsiadm --mode node -T iqn.2002-10.com.infortrend:eonnas.eonnas:pro:510.dfwsnas.test-mysql-master-02.e1000g0 \
    --op update -n node.session.auth.authmethod -v CHAP

iscsiadm --mode node -T iqn.2002-10.com.infortrend:eonnas.eonnas:pro:510.dfwsnas.test-mysql-master-02.e1000g0 \
    --op update -n node.session.auth.username -v tecmint-iscsi-user

iscsiadm --mode node -T iqn.2002-10.com.infortrend:eonnas.eonnas:pro:510.dfwsnas.test-mysql-master-02.e1000g0 \
    --op update -n node.session.auth.password -v password

挂载目标

修改配置后,需要重新启动服务以加载新的配置:

#!/bin/sh

# 实际上由两种方式:服务;命令;
#    命令:直接挂载;
#    服务:自动登录,为系统的管理上提供了便利;

# 命令
iscsiadm -m node -T <target-iqn> -l

# 服务
systemctl restart iscsid.service
# 重启服务应该没有关系:我把iSCSI相关的服务都停掉了,但是依旧能访问(格式化)挂载的块设备

检查连接

# 在Initiator端

两种方法检查设备的挂载情况:

#!/bin/sh

lsblk

iscsiadm -m session -P 3

# 在Target端

在Target端,可以使用如下命令检查连接信息:

#!/bin/sh

tgtadm --mode conn --op show --tid 1

附加说明

如果设备中包含了重要的文件系统,那在/etc/fstab中需要指定_netdev参数。

常用命令

#!/bin/sh

# 退出所有的会话
iscsiadm --mode node --logoutall=all

# 删除所有的NODE
iscsiadm --mode node --op delete

# 如果不指定Target(-T)就是更新所有

参考文献

How to Setup iSCSI Server (Target) and Client (Initiator) on Debian 9
Configuring manual or automatic node login with iSCSI
How to configure iSCSI Initiator (client) in CentOS / RHEL 7
Linux (openSuSe) iSCSI Initiator: How to pass a CHAP user name and password?

### iSCSI Initiator Name Configuration File Location and Content For Red Hat Enterprise Linux (RHEL), the iSCSI initiator name is configured within a specific file that allows customization of how the system identifies itself when connecting to targets. The primary configuration file for setting up or modifying the iSCSI initiator name resides at `/etc/iscsi/initiatorname.iscsi`[^2]. This file contains entries related specifically to identifying the host as an initiator. The contents typically include: ```ini InitiatorName=iqn.yyyy-mm.<reversed domain name>:<identifier> ``` Here `iqn` stands for "iSCSI Qualified Name," followed by a date (`yyyy-mm`) indicating when the naming authority took control over this format, then comes the reversed DNS domain owned by the entity assigning names, ending with any unique identifier chosen for differentiation among multiple initiators from the same organization. In addition to configuring the initiator name through `/etc/iscsi/initiatorname.iscsi`, settings associated with individual nodes are stored under directories like `/etc/iscsi/nodes/<target-name>/<IP-address>/`. These configurations might involve parameters affecting session establishment but do not directly relate to changing the global initiator identity used across all connections initiated by the server[^3]. To ensure proper operation post-reconfiguration, restarting services such as `iscsid` service becomes necessary so changes take effect immediately without requiring a full reboot unless specified otherwise based on distribution-specific documentation provided by vendors like Red Hat.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值