Linux学习笔记--iSCSI

一 、简介

小型计算机系统接口(SCSI),一种用于计算机和智能设备之间(硬盘、光驱、打印机等)系统级接口的独立处理器标准SCSI是一种只能的通用接口标准。
SCSI即可具有应用范围广、多任务、宽带大、cpu占用率低,以及热插拔等优点。
ISCSI(互联网小型计算机系统接口)是一种在tcp/ip上进行数据块传输的标准。ISCSI可以实现在ip网络上运行SCSI协议,使其能够在诸如高速千兆以太网上进行快速的数据存取备份操作。

二 、概念

TPG共享存储组,咋特定iSCSI目标要侦听的接口ip地址和tcp端口的集合,可以将目标配置添加到TPG以协调多个LUN的配置
ACL访问权限控制列表,一种使用节点IQN(通常是启动器名称)来验证启动器的访问权限的访问限制
IQNiSCSI限定名称,全球唯一名称,用以强制命名格式来是被启动器和目标
LUN逻辑单元号,带有编号的块设备,连接到目标且通过目标来使用,可以有一个或多个LUN练级到单个目标,但通常一个目标提供一个LUN
portals入口目标或启动器上用于建立的ip地址和端口

IQN格式:iqn.年份-月份.com|cn|net|org.域名:自定义标识 字母要小写,即使大写系统默认改为小写

三 、服务端配置

1 服务端创建一个空的分区

[root@localhost /]# fdisk /dev/sdb
Command (m for help): n
All primary partitions are in use
Adding logical partition 5
First sector (46551040-83886079, default 46551040): 
Using default value 46551040
Last sector, +sectors or +size{K,M,G} (46551040-83886079, default 83886079): +3G
Partition 5 of type Linux and of size 3 GiB is set

Command (m for help): w

[root@localhost /]# partprobe 

2 安装包

[root@localhost /]# yum install -y targetcli

3创建新的 iSCSI Target,添加已创建的磁盘分区作为 Backstore

1、进入 targetcli 管理界面并列出现有项目

[root@localhost /]# targetcli
targetcli shell version 2.1.fb41
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]

2 将新建分区添加到Backstores 项下

/> /backstores/block create disk1 /dev/sda5
Created block storage object disk1 using /dev/sda5.

3 创建新的 Target

/> /iscsi create iqn.2019-04.com.Test:server
Created target iqn.2019-04.com.test:server.
Created TPG 1.

4 添加 Backstores 磁盘到 LUN 项下

/> /iscsi/iqn.2019-04.com.test:server/tpg1/luns create /backstores/block/disk1 
Created LUN 0.

5 创建portal窗口
必须先删除系统默认的 0.0.0.0:3260 这个设置,否则无法添加新的 IP 和端口

/> iscsi/iqn.2019-04.com.test:server/tpg1/portals delete 0.0.0.0 3260
Deleted network portal 0.0.0.0:3260
/> iscsi/iqn.2019-04.com.test:server/tpg1/portals create 172.24.8.138 3260
Using default IP port 3260
Created network portal 172.24.8.138:3260.

6 退出即自动保存

/> ls
o- / ........................................................... [...]
  o- backstores ................................................ [...]
  | o- block .................................... [Storage Objects: 1]
  | | o- disk1 ............. [/dev/sda5 (3.0GiB) write-thru activated]
  | o- fileio ................................... [Storage Objects: 0]
  | o- pscsi .................................... [Storage Objects: 0]
  | o- ramdisk .................................. [Storage Objects: 0]
  o- iscsi .............................................. [Targets: 1]
  | o- iqn.2019-04.com.test:server ......................... [TPGs: 1]
  |   o- tpg1 ................................. [no-gen-acls, no-auth]
  |     o- acls ............................................ [ACLs: 0]
  |     o- luns ............................................ [LUNs: 1]
  |     | o- lun0 .......................... [block/disk1 (/dev/sda5)]
  |     o- portals ...................................... [Portals: 1]
  |       o- 172.24.8.138:3260 .................................. [OK]
  o- loopback ........................................... [Targets: 0]
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json

4 停止防火墙服务,selinux调制允许模式**

[root@localhost /]# systemctl stop firewalld
[root@localhost /]# setenforce 0

5 启功服务,开机自启动

[root@localhost /]# systemctl enable target
[root@localhost /]# systemctl start target

四、客户端配置

1 安装包

[root@localhost /]# yum install -y iscsi-initiator-utils

2 启功服务,开机自启动

[root@localhost /]# systemctl enable iscsid
[root@localhost /]# systemctl start iscsid

3 发现服务端已设置好的 Target

[root@localhost Desktop]# iscsiadm -m discovery -t sendtargets -p 172.24.8.138
172.24.8.138:3260,1 iqn.2019-04.com.test:server
或
[root@localhost Desktop]# iscsiadm -m discovery -t st -p 172.24.8.138
172.24.8.138:3260,1 iqn.2019-04.com.test:server

4 验证是否否存储已发现的服务端 Target

[root@localhost Desktop]#  ll -R  /var/lib/iscsi/nodes/
/var/lib/iscsi/nodes/:
total 0
drw-------. 3 root root 32 Apr 15 22:15 iqn.2019-04.com.test:server

/var/lib/iscsi/nodes/iqn.2019-04.com.test:server:
total 0
drw-------. 2 root root 20 Apr 15 22:15 172.24.8.138,3260,1

/var/lib/iscsi/nodes/iqn.2019-04.com.test:server/172.24.8.138,3260,1:
total 4
-rw-------. 1 root root 2037 Apr 15 22:15 default

5 登录服务端已设置好的 Target

[root@Desktop ~]# iscsiadm -m node -T iqn.2019-04.com.test:server -l
Logging in to [iface: default, target: iqn.2019-04.com.test:server, portal: 172.24.8.138,3260] (multiple)
Login to [iface: default, target: iqn.2019-04.com.test:server, portal: 172.24.8.138,3260] successful.

6 验证会话状态及相关的磁盘信息

[root@localhost Desktop]# lsscsi
[0:0:0:0]    disk    VMware,  VMware Virtual S 1.0   /dev/sda 
[4:0:0:0]    cd/dvd  NECVMWar VMware SATA CD01 1.00  /dev/sr0 
[33:0:0:0]   disk    LIO-ORG  disk1            4.0   /dev/sdb

7 在新磁盘上创建分区及文件系统并挂载

[root@localhost Desktop]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x9b6db3a8.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): 
Using default response p
Partition number (1-4, default 1): 
First sector (8192-4194303, default 8192): 
Using default value 8192
Last sector, +sectors or +size{K,M,G} (8192-4194303, default 4194303): 
Using default value 4194303
Partition 1 of type Linux and of size 2 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost Desktop]# partprobe
[root@localhost Desktop]# mkfs -t ext4 /dev/sdb
mke2fs 1.42.9 (28-Dec-2013)
/dev/sdb is entire device, not just one partition!
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=1024 blocks
131072 inodes, 524288 blocks
26214 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=536870912
16 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (16384 blocks): 
done
Writing superblocks and filesystem accounting information:      
done
[root@localhost Desktop]# mkdir /iSCSI1
[root@localhost Desktop]# mount /dev/sdb /iSCSI1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值