Linux操作文档——iSCSI 架构

iSCSI 架构

文章目录

    • iSCSI 架构
      • 一、相关概念
      • 二、配置
        • 1、Target的配置
        • 2、initiator的配置
        • 3、部分命令解释


一、相关概念

1、Internet Small Computer System Interface:Internet小型计算机系统接口,是一个基于 TCP/IP 的协议,主要用于通过IP网络仿真 SCSI,从而为远程块存储设备提供数据传输和管理。
2、iSCSI target:储存设备端,存放磁盘或RAID的设备,目前也能够将Linux主机仿真成iSCSI target。目的在于提供其他主机使用的“磁盘”;
3、iSCSI initiator:能够使用target的客户端,通常是服务器。也就是说,想要连接到iSCSI target的服务器,也必须要安装iSCSI initiator的相关功能后才能够使用iSCSI target提供的磁盘。

二、配置

在SAN中,主机一般都是Initiator,存储设备则是Target。

1、Target的配置

[root@target ~]# yum -y install targetd targetcli          //下载相关软件
[root@target ~]# systemctl start target          //启动target
[root@target ~]# systemctl enable target          //开机自启动target
Created symlink from /etc/systemd/system/multi-user.target.wants/target.service to /usr/lib/systemd/system/target.service.
[root@target ~]# systemctl status target          //查看target状态
● target.service - Restore LIO kernel target configuration
   Loaded: loaded (/usr/lib/systemd/system/target.service; enabled; vendor preset: disabled)
   Active: active (exited) since Sat 2020-05-09 23:45:30 CST; 15s ago
 Main PID: 8155 (code=exited, status=0/SUCCESS)

May 09 23:45:30 target systemd[1]: Starting Restore LIO kernel target configuration...
May 09 23:45:30 target target[8155]: No saved config file at /etc/target/saveconfig.json, ok, exiting
May 09 23:45:30 target systemd[1]: Started Restore LIO kernel target configuration.
[root@target ~]# systemctl start firewalld.service           //开启防火墙
[root@target ~]# firewall-cmd --add-port=3260/tcp --permanent           //防火墙永久开启tcp:3260端口(Target默认采用TCP:3260端口)
success
[root@target ~]# firewall-cmd --reload           //重新载入配置
success
[root@target ~]# firewall-cmd --list-ports           //查看开启的端口
3260/tcp
[root@target ~]# targetcli          //执行targetcli工具(如果报错,可以执行yum -y install python-rtslib命令安装所缺包)
Warning: Could not load preferences file /root/.targetcli/prefs.bin.
targetcli shell version 2.1.fb49
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.

/> /backstores/block create server0.disk1 /dev/sdc          //指定要发布的磁盘,(server0.disk1是给/dev/sdc转化成块的名字)
Created block storage object server0.disk1 using /dev/sdc.
/> /iscsi create iqn.2020-05.com.admin:disk1          //创建iqn名字即创建ISCSI对象
Created target iqn.2020-05.com.admin:disk1.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/> /iscsi/iqn.2020-05.com.admin:disk1/tpg1/acls create iqn.2020-05.com.admin:client1          //设置ACL即将ISCSI对象与客户端IP或主机名绑定(iqn.2020-05.com.admin:client1是initiator的名字,需要在客户端中设置)
Created Node ACL for iqn.2020-05.com.admin:client1
/> /iscsi/iqn.2020-05.com.admin:disk1/tpg1/luns create /backstores/block/server0.disk1           //创建LUN并绑定块
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2020-05.com.admin:client1

2、initiator的配置

[root@initiator ~]# yum -y install iscsi-initiator-utils          //安装工具
[root@initiator ~]# vim /etc/iscsi/initiatorname.iscsi           //给initiator命名
InitiatorName=iqn.2020-05.com.admin:client1
[root@initiator ~]# systemctl start iscsi          //启动服务
[root@initiator ~]# systemctl enable iscsi          //开机自启动服务
[root@initiator ~]# systemctl status iscsi          //查看状态
● iscsi.service - Login and scanning of iSCSI devices
   Loaded: loaded (/usr/lib/systemd/system/iscsi.service; enabled; vendor preset: disabled)
   Active: inactive (dead)
Condition: start condition failed at Sat 2020-05-09 23:58:31 CST; 11s ago
     Docs: man:iscsiadm(8)
           man:iscsid(8)
[root@initiator ~]# iscsiadm -m discovery -t st -p 192.168.1.60          //发现存储
192.168.1.60:3260,1 iqn.2020-05.com.admin:disk1
[root@initiator ~]# iscsiadm -m discovery -t st -p 192.168.1.60 -l          //登录存储/连接target
192.168.1.60:3260,1 iqn.2020-05.com.admin:disk1
Logging in to [iface: default, target: iqn.2020-05.com.admin:disk1, portal: 192.168.1.60,3260] (multiple)
Login to [iface: default, target: iqn.2020-05.com.admin:disk1, portal: 192.168.1.60,3260] successful.
[root@initiator ~]# lsscsi          //验证iscsi连接,查看是否得到外界硬盘
[0:0:0:0]    disk    VMware,  VMware Virtual S 1.0   /dev/sda 
[2:0:0:0]    cd/dvd  NECVMWar VMware IDE CDR10 1.00  /dev/sr0 
[3:0:0:0]    disk    LIO-ORG  server0.disk1    4.0   /dev/sdb 
[root@initiator ~]# yum -y install gdisk          //下载gdisk分区工具
[root@initiator ~]# gdisk /dev/sdb          //给外界硬盘分区
GPT fdisk (gdisk) version 0.8.10

Partition table scan:
  MBR: not present
  BSD: not present
  APM: not present
  GPT: not present

Creating new GPT entries.

Command (? for help): n
Partition number (1-128, default 1): 
First sector (34-41943006, default = 2048) or {
     +-}size{
     KMGTP}: 
Last sector (2048-41943006, default = 41943006) or {
     +-}size{
     KMGTP}: 
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): 
Changed type of partition to 'Linux filesystem'

Command (? for help): w

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sdb.
The operation has completed successfully.
[root@initiator ~]# mkfs.xfs /dev/sdb1          //格式化分区
meta-data=/dev/sdb1              isize=512    agcount=4, agsize=1310655 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=5242619, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

[root@initiator ~]# mkdir /mnt/iscsi          //创建挂载目录
[root@initiator ~]# mount /dev/sdb1 /mnt/iscsi/          //临时挂载
[root@initiator ~]# df -hT /mnt/iscsi/          //查看存储
Filesystem     Type  Size  Used Avail Use% Mounted on
/dev/sdb1      xfs    20G   33M   20G   1% /mnt/iscsi
[root@initiator ~]# vim /etc/fstab           //永久挂载
/dev/sdb1               /mnt/iscsi           xfs     defaults,_netdev  0  0  
[root@initiator ~]# mount -a          //刷新配置

3、部分命令解释

iqn.2020-05.com.admin:disk1

iqn:表示此名称将使用域作为其标识符,
yyyy-mm:拥有域名的第一个月
com.xxx :逆向域名
optional_string:以冒号为前缀的可选字符串,根据需要分配

iscsiadm -m discovery -t st -p 192.168.1.60 -l

iscsiadm是基于命令行的iscsi管理工具,提供了对iSCSI节点、会话、连接以及发现记录的操作。
-m {discovery|node|session|iface} :发现某服务器是否有target输出,以及输出了哪些target|管理跟某target的关联关系|会话管理|接口管理
-d{0-8}:打印调试信息,有0到8这9个等级
-t:这里可以使用的类型为sendtargets(可简写为st)、slp、fw和isns,此选项仅用于discovery模式,且目前仅支持st、fw和isns;其中st表示允许每个iSCSI target发送一个可用target列表给initiator
-T:用于指定target的名字
-p:指定target服务的IP和端口,-p 192.168.1.60:3260
-o:指定针对discoverydb数据库的操作,其仅能为new、delete、update、show和nonpersistent其中之一
-I:指定执行操作的iSCSI接口,这些接口定义在/var/lib/iscsi/ifaces中
-l:登录节点
-u:登出节点(服务器)

你可能感兴趣的:(linux,iscsi)