博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Linux中iscsi
阅读量:5910 次
发布时间:2019-06-19

本文共 10568 字,大约阅读时间需要 35 分钟。

iSCSI( Internet Small Computer System Interface 互联网小型计算机系统接口)是由IBM 下属的两大研发机构一一加利福尼亚AImaden和以色列Haifa研究中心共同开发的,是一个供硬件设备使用的、可在IP协议上层运行的SCSI指令集,是一种开放的基于IP协议的工业技术标准。该协议可以用TCP/IP对SCSI指令进行封装,使得这些指令能够通过基于P网络进行传输,从而实现SCSI 和TCP/IP协议的连接。对于局域网环境中的用户来说,采用该标准只需要不多的投资就可以方便、快捷地对信息和数据进行交互式传输及管理。

[root@server ~]# fdisk -l
Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors

[root@server ~]# fdisk /dev/vdb #新建分区

Command (m for help): n
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +5G
Command (m for help): wq
[root@server ~]# partprobe
Linux中iscsi
Linux中iscsi
[root@server ~]# yum install targetcli
Linux中iscsi
[root@server ~]# systemctl start target
Linux中iscsi
[root@server ~]# targetcli
/> /backstores/block create westos:storage1 /dev/vdb1 #/dev/vdb1在软件里起的名字叫 westos:storage1
Created block storage object westos:storage1 using /dev/vdb1.
/> /iscsi create iqn.2017-12.com.example:storage1 #起的设备的名字storage1
Created target iqn.2017-12.com.example:storage1. #iqn:全局唯一名称标示
Created TPG 1.
/> /iscsi/iqn.2017-12.com.example:storage1/tpg1/acls create iqn.2017-12.com.example:westoskey #生成key
Created Node ACL for iqn.2017-12.com.example:westoskey
/> /iscsi/iqn.2017-12.com.example:storage1/tpg1/luns create /backstores/block/westos:storage1 #key和设备关联
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2017-12.com.example:westoskey
/> iscsi/iqn.2017-12.com.example:storage1/tpg1/portals create 172.25.254.125 # ip开机启动,设备识别
Using default IP port 3260
Created network portal 172.25.254.125:3260. #打开此ip端口
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup. #文件
Configuration saved to /etc/target/saveconfig.json #所写内容保存在此文件

Linux中iscsi

Linux中iscsi

[root@server ~]# firewall-cmd --permanent --add-port=3260/tcp #开启端口
success
[root@server ~]# firewall-cmd --reload
success
Linux中iscsi
[root@server ~]# cat /etc/target/saveconfig.json #targetcli中所写内容
Linux中iscsi
客户端:
[root@client ~]# yum search iscsi
iscsi-initiator-utils.x86_64
Linux中iscsi
[root@client ~]# yum install iscsi-initiator-utils.x86_64
Linux中iscsi
[root@client ~]# systemctl start iscsi
Linux中iscsi
[root@client ~]# vim /etc/iscsi/initiatorname.iscsi #key文件
InitiatorName=iqn.2017-12.com.example:westoskey
Linux中iscsi
Linux中iscsi
[root@client ~]# systemctl restart iscsi #重启
Linux中iscsi
[root@client ~]# iscsiadm -m discovery -t st -p 172.25.254.125
172.25.254.125:3260,1 iqn.2017-12.com.example:storage1
m:动作 t:type p:ip #发现设备
Linux中iscsi
[root@client ~]# iscsiadm -m node -T iqn.2017-12.com.example:storage1 -p 172.25.254.125 -l
Logging in to [iface: default, target: iqn.2017-12.com.example:storage1, portal: 172.25.254.125,3260] (multiple)
Login to [iface: default, target: iqn.2017-12.com.example:storage1, portal: 172.25.254.125,3260] successful.
node:节点 T:共享的设备的名字 l:登陆
Linux中iscsi
[root@client ~]# fdisk -l

Disk /dev/sda: 5368 MB, 5368709120 bytes, 10485760 sectors #共享的磁盘/dev/sda

Linux中iscsi
Linux中iscsi
[root@client ~]# fdisk /dev/sda #投入使用
Command (m for help): n
Using default response p
Partition number (1-4, default 1):
First sector (8192-10485759, default 8192):
Using default value 8192
Last sector, +sectors or +size{K,M,G} (8192-10485759, default 10485759):
Linux中iscsi
[root@client ~]# partprobe #同步分区表
Linux中iscsi
[root@client ~]# mkfs.xfs /dev/sda1 #格式化文件系统
Linux中iscsi
[root@client ~]# mount /dev/sda1 /mnt/ #挂载
Linux中iscsi
[root@client mnt]# touch file #投入使用 创建的文件保存在服务端的/dev/vdb1
Linux中iscsi
[root@client ~]# blkid #查看投入使用的分区
/dev/vda1: UUID="9bf6b9f7-92ad-441b-848e-0257cbb883d1" TYPE="xfs"
/dev/vdb1: UUID="SIaPf4-OdHu-OzAW-NlQG-vZ3D-X8ZO-1FK3Ih" TYPE="LVM2_member"
/dev/mapper/vg0-vo: UUID="12294be2-bdad-4817-b162-038e22313d9f" TYPE="ext4"
/dev/sda1: UUID="0a645fd3-f948-49a6-896e-c2892d66fe82" TYPE="xfs"
[root@client ~]# vim /etc/fstab #分区永久挂载写入配置文件

UUID="0a645fd3-f948-49a6-896e-c2892d66fe82" /mnt xfs defaults,_netdev 0 0

#_netdev告诉系统它不是真正的物理设备,而是网络虚拟设备
#写上UUID以免发生名称偏移。启动时,让网络先激活在读取设备文件
Linux中iscsi
Linux中iscsi

[root@client ~]# poweroff #强制断电

[root@foundation25 ~]# rht-vmctl start desktop
Starting desktop.
[root@foundation25 ~]# rht-vmctl view desktop
Linux中iscsi

[root@client ~]# vim /etc/fstab #删除挂载信息

Linux中iscsi
Linux中iscsi

[root@client ~]# umount /mnt/ #卸载

Linux中iscsi
[root@client ~]# df
Linux中iscsi
[root@client ~]# yum install tree #安装
Linux中iscsi
[root@client ~]# tree /var/lib/iscsi #树形显示 iscsi的内容
Linux中iscsi
[root@client ~]# iscsiadm -m node -T iqn.2017-12.com.example:storage1 -p 172.25.254.125 -u #退出 重启服务设备又回来了
Linux中iscsi
fdisk -l #查看分区信息
Linux中iscsi
Linux中iscsi
[root@client ~]# systemctl restart iscsi #重启服务
Linux中iscsi
fdisk -l #查看分区信息
/dev/sda1 又回来了
Linux中iscsi
Linux中iscsi
[root@client ~]# iscsiadm -m node -T iqn.2017-12.com.example:storage1 -p 172.25.254.125 -u #退出

[root@client ~]# iscsiadm -m node -T iqn.2017-12.com.example:storage1 -p 172.25.254.125 -o delete #删除

Linux中iscsi
[root@client ~]# systemctl restart iscsi #重启服务
Linux中iscsi
[root@client ~]# fdisk -l #退出再删除后,网络设备消失
Linux中iscsi
Linux中iscsi
[root@client ~]# tree /var/lib/iscsi/ #用树形图查看/var/lib/iscsi/无数据
/var/lib/iscsi/
|-- ifaces
|-- isns
|-- nodes
|-- send_targets
| -- 172.25.254.125,3260<br/>|-- st_config
|-- slp
`-- static
Linux中iscsi

服务端不想共享:

[root@server ~]# targetcli
/> clearconfig confirm=true
All configuration cleared #清除共享信息
Linux中iscsi
[root@server ~]# fdisk /dev/vdb
Command (m for help): d #删除分区
wq
Linux中iscsi
Linux中iscsi
Linux中iscsi
一般分区采用lvm分区,解决设备不够用问题

[root@server ~]# fdisk /dev/vdb

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes):
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p

Device Boot Start End Blocks Id System
/dev/vdb1 2048 2099199 1048576 8e Linux LVM
[root@server ~]# partprobe
[root@server ~]# cat /proc/partitions
major minor #blocks name
253 17 1048576 vdb1
Linux中iscsi
Linux中iscsi
Linux中iscsi
Linux中iscsi
[root@server ~]# pvcreate /dev/vdb1 #/dev/vdb1创建物理卷
Linux中iscsi
[root@server ~]# vgcreate iscsi_vg /dev/vdb1 #为/dev/vdb1创建物理卷组,名字叫iscsi_vg
Linux中iscsi
[root@server ~]# vgdisplay #卷组展示,查看有多少物理单元,有255个
Total PE 255
Linux中iscsi
[root@server ~]# lvcreate -l 255 -n iscsi_lv0 iscsi_vg #逻辑卷iscsi_lv0的大小为255个物理扩展单元

[root@server ~]# lvs

LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
iscsi_lv0 iscsi_vg -wi-a----- 1020.00m
Linux中iscsi
[root@server ~]# targetcli
/> /backstores/block create westos:storage1 /dev/iscsi_vg/iscsi_lv0
Created block storage object westos:storage1 using /dev/iscsi_vg/iscsi_lv0.
/> /iscsi create iqn.2017-12.com.example:storage1
Created target iqn.2017-12.com.example:storage1.
Created TPG 1.
/> /iscsi/iqn.2017-12.com.example:storage1/tpg1/acls create iqn.2017-12.com.example:key1
Created Node ACL for iqn.2017-12.com.example:key1
/> /iscsi/iqn.2017-12.com.example:storage1/tpg1/luns create /backstores/block/westos:storage1
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2017-12.com.example:key1
/> /iscsi/iqn.2017-12.com.example:storage1/tpg1/portals create 172.25.254.125
Using default IP port 3260
Created network portal 172.25.254.125:3260.
/> ls
o- / ......................................... [...]
o- backstores .............................. [...]
| o- block .................. [Storage Objects: 1]
| | o- westos:storage1 [/dev/iscsi_vg/iscsi_lv0 (1020.0MiB) write-thru activated]
| o- fileio ................. [Storage Objects: 0]
| o- pscsi .................. [Storage Objects: 0]
| o- ramdisk ................ [Storage Objects: 0]
o- iscsi ............................ [Targets: 1]
| o- iqn.2017-12.com.example:storage1 .. [TPGs: 1]
| o- tpg1 ............... [no-gen-acls, no-auth]
| o- acls .......................... [ACLs: 1]
| | o- iqn.2017-12.com.example:key1 [Mapped LUNs: 1]
| | o- mapped_lun0 [lun0 block/westos:storage1 (rw)]
| o- luns .......................... [LUNs: 1]
| | o- lun0 [block/westos:storage1 (/dev/iscsi_vg/iscsi_lv0)]
| o- portals .................... [Portals: 1]
| o- 172.25.254.125: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
Linux中iscsi
Linux中iscsi
客户端:
[root@client ~]# tree /var/lib/iscsi/
/var/lib/iscsi/
|-- ifaces
|-- isns
|-- nodes
|-- send_targets
| -- 172.25.254.125,3260<br/>|-- st_config
|-- slp
`-- static

Linux中iscsi

[root@client ~]# vim /etc/iscsi/initiatorname.iscsi
Linux中iscsi
Linux中iscsi
[root@client ~]# systemctl restart iscsi
Linux中iscsi
[root@client ~]# iscsiadm -m discovery -t st -p 172.25.254.125
[root@client ~]# iscsiadm -m node -T iqn.2017-12.com.example:storage1 -p 172.25.254.125 -l
iscsiadm: initiator reported error (24 - iSCSI login failed due to authorization failure)
iscsiadm: Could not log into all portals #当登陆不成功时,解决方法如下:
[root@client ~]# tree /var/lib/iscsi/ #查看树形图,登陆信息已被记录,需要删除,在重新生成
/var/lib/iscsi/
|-- ifaces
|-- isns
|-- nodes
| -- iqn.2017-12.com.example:storage1<br/>|-- 172.25.254.125,3260,1
| -- default<br/>|-- send_targets<br/>|-- 172.25.254.125,3260
| |-- iqn.2017-12.com.example:storage1,172.25.254.125,3260,1,default -> /var/lib/iscsi/nodes/iqn.2017-12.com.example:storage1/172.25.254.125,3260,1
| -- st_config<br/>|-- slp<br/>-- static

[root@client ~]# rm -fr /var/lib/iscsi/nodes/*

[root@client ~]# rm -fr /var/lib/iscsi/send_targets
[root@client ~]# tree /var/lib/iscsi//var/lib/iscsi/
|-- ifaces
|-- isns
|-- nodes
|-- slp
`-- static

[root@client ~]# systemctl restart iscsid.service #当删除tree中内容时,要重启主目录

[root@client ~]# systemctl restart iscsi #重启子目录
[root@client ~]# iscsiadm -m discovery -t st -p 172.25.254.125 #发现设备
172.25.254.125:3260,1 iqn.2017-12.com.example:storage1
[root@client ~]# iscsiadm -m node -T iqn.2017-12.com.example:storage1 -p 172.25.254.125 -l #登陆
Login to [iface: default, target: iqn.2017-12.com.example:storage1, portal: 172.25.254.125,3260] successful. #成功
Linux中iscsi

服务端

当分区不够用时,新建分区
[root@server ~]# fdisk /dev/vdb
Command (m for help): n
Last sector, +sectors or +size{K,M,G} (2099200-20971519, default 20971519): +1G
Partition 2 of type Linux and of size 1 GiB is set
Command (m for help): t
Partition number (1,2, default 2): 2
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): wq
Linux中iscsi
Linux中iscsi
[root@server ~]# partprobe
[root@server ~]# cat /proc/partitions
Linux中iscsi
[root@server ~]# pvcreate /dev/vdb2
[root@server ~]# vgextend iscsi_vg /dev/vdb2
Volume group "iscsi_vg" successfully extended
[root@server ~]# lvextend -L 1500M /dev/iscsi_vg/iscsi_lv0
Linux中iscsi
[root@server ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
iscsi_lv0 iscsi_vg -wi-ao---- 1.46g
Linux中iscsi
[root@client ~]# fdisk -l #看出还是原来的分区大小
退出后在登陆才能更新
Linux中iscsi
Linux中iscsi

[root@client ~]# iscsiadm -m node -T iqn.2017-12.com.example:storage1 -p 172.25.254.125 -u #退出,再登陆,才能更新新的分区大小

Logging out of session [sid: 3, target: iqn.2017-12.com.example:storage1, portal: 172.25.254.125,3260]
Logout of [sid: 3, target: iqn.2017-12.com.example:storage1, portal: 172.25.254.125,3260] successful.
Linux中iscsi
[root@client ~]# iscsiadm -m discovery -t st -p 172.25.254.125 #发现设备
172.25.254.125:3260,1 iqn.2017-12.com.example:storage1
[root@client ~]# iscsiadm -m node -T iqn.2017-12.com.example:storage1 -p 172.25.254.125 -l #登陆
Linux中iscsi

[root@client ~]# fdisk -l #可以看出服务端磁盘增大后客户端更新了

Linux中iscsi
Linux中iscsi

转载于:https://blog.51cto.com/13363488/2050057

你可能感兴趣的文章
Ubuntu下errno值
查看>>
HDU 4786 Fibonacci Tree 最小生成树
查看>>
docker实践4
查看>>
selenium测试(Java)--多表单切换(十二)
查看>>
PHP自学,第一阶段,基础学习
查看>>
curl命令使用
查看>>
Ubuntu 12.04将默认集成Landscape管理套件【转】
查看>>
js数组实现不重复插入数据
查看>>
vim配置
查看>>
VS 远程发布IIS
查看>>
基于winner 滤波平稳降噪效果
查看>>
Oracle_spatial的空间操作符介绍
查看>>
git分享(二)git checkout
查看>>
剑指 offer set 24 扑克牌的顺子
查看>>
关于Vue.js面试题汇总
查看>>
微信小程序第三方开发需要注意的点
查看>>
大话爬虫的实践技巧
查看>>
react-native 学习心得
查看>>
[译]使用 Siesta 处理 Swift 网络请求
查看>>
Android 中的子线程解析
查看>>