设为首页 收藏本站
查看: 1377|回复: 0

[经验分享] Linux中iscsi

[复制链接]

尚未签到

发表于 2018-5-16 11:57:51 | 显示全部楼层 |阅读模式
  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
DSC0000.jpg
DSC0001.jpg
[root@server ~]# yum install targetcli
DSC0002.jpg
[root@server ~]# systemctl start target
DSC0003.jpg
[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  #所写内容保存在此文件
DSC0004.jpg

DSC0005.jpg
[root@server ~]# firewall-cmd --permanent --add-port=3260/tcp  #开启端口
success
[root@server ~]# firewall-cmd --reload
success
DSC0006.jpg
[root@server ~]# cat /etc/target/saveconfig.json  #targetcli中所写内容
DSC0007.jpg
客户端:
[root@client ~]# yum search iscsi
iscsi-initiator-utils.x86_64
DSC0008.jpg
[root@client ~]# yum install iscsi-initiator-utils.x86_64
DSC0009.jpg
[root@client ~]# systemctl start iscsi
DSC00010.jpg
[root@client ~]# vim /etc/iscsi/initiatorname.iscsi  #key文件
InitiatorName=iqn.2017-12.com.example:westoskey
DSC00011.jpg
DSC00012.jpg
[root@client ~]# systemctl restart iscsi #重启
DSC00013.jpg
[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   #发现设备
DSC00014.jpg
[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:登陆
DSC00015.jpg
[root@client ~]# fdisk -l

  Disk /dev/sda: 5368 MB, 5368709120 bytes, 10485760 sectors  #共享的磁盘/dev/sda
DSC00016.jpg
DSC00017.jpg
[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):
DSC00018.jpg
[root@client ~]# partprobe  #同步分区表
DSC00019.jpg
[root@client ~]# mkfs.xfs /dev/sda1  #格式化文件系统
DSC00020.jpg
[root@client ~]# mount /dev/sda1 /mnt/ #挂载
DSC00021.jpg
[root@client mnt]# touch file  #投入使用 创建的文件保存在服务端的/dev/vdb1
DSC00022.jpg
[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以免发生名称偏移。启动时,让网络先激活在读取设备文件
DSC00023.jpg
DSC00024.jpg
  [root@client ~]# poweroff  #强制断电
[root@foundation25 ~]# rht-vmctl start desktop
Starting desktop.
[root@foundation25 ~]# rht-vmctl view desktop
DSC00025.jpg
  [root@client ~]# vim /etc/fstab #删除挂载信息
DSC00026.jpg
DSC00027.jpg
  [root@client ~]# umount /mnt/ #卸载
DSC00028.jpg
[root@client ~]# df
DSC00029.jpg
[root@client ~]# yum install tree  #安装
DSC00030.jpg
[root@client ~]# tree /var/lib/iscsi #树形显示 iscsi的内容
DSC00031.jpg
[root@client ~]# iscsiadm -m node -T iqn.2017-12.com.example:storage1 -p 172.25.254.125 -u  #退出 重启服务设备又回来了
DSC00032.jpg
fdisk -l #查看分区信息
DSC00033.jpg
DSC00034.jpg
[root@client ~]# systemctl restart iscsi #重启服务
DSC00035.jpg
fdisk -l #查看分区信息
/dev/sda1  又回来了
DSC00036.jpg
DSC00037.jpg
[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  #删除  
DSC00038.jpg
[root@client ~]# systemctl restart iscsi #重启服务
DSC00039.jpg
[root@client ~]# fdisk -l  #退出再删除后,网络设备消失
DSC00040.jpg
DSC00041.jpg
[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
DSC00042.jpg
  服务端不想共享:
[root@server ~]# targetcli
/> clearconfig confirm=true
All configuration cleared   #清除共享信息
DSC00043.jpg
[root@server ~]# fdisk /dev/vdb
Command (m for help): d  #删除分区
wq
DSC00044.jpg
DSC00045.jpg
DSC00046.jpg
一般分区采用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
DSC00047.jpg
DSC00048.jpg
DSC00049.jpg
DSC00050.jpg
[root@server ~]# pvcreate /dev/vdb1  #/dev/vdb1创建物理卷
DSC00051.jpg
[root@server ~]# vgcreate iscsi_vg /dev/vdb1   #为/dev/vdb1创建物理卷组,名字叫iscsi_vg
DSC00052.jpg
[root@server ~]# vgdisplay  #卷组展示,查看有多少物理单元,有255个
Total PE              255
DSC00053.jpg
[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
DSC00054.jpg
[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
DSC00055.jpg
DSC00056.jpg
客户端:
[root@client ~]# tree /var/lib/iscsi/
/var/lib/iscsi/
|-- ifaces
|-- isns
|-- nodes
|-- send_targets
|   -- 172.25.254.125,3260<br/>|-- st_config
|-- slp
`-- static
DSC00057.jpg
[root@client ~]# vim /etc/iscsi/initiatorname.iscsi
DSC00058.jpg
DSC00059.jpg
[root@client ~]# systemctl restart iscsi
DSC00060.jpg
[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. #成功
DSC00061.jpg
  服务端
当分区不够用时,新建分区
[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
DSC00062.jpg
DSC00063.jpg
[root@server ~]# partprobe
[root@server ~]# cat /proc/partitions
DSC00064.jpg
[root@server ~]# pvcreate /dev/vdb2
[root@server ~]# vgextend iscsi_vg /dev/vdb2
Volume group &quot;iscsi_vg&quot; successfully extended
[root@server ~]# lvextend -L 1500M /dev/iscsi_vg/iscsi_lv0
DSC00065.jpg
[root@server ~]# lvs
LV        VG       Attr       LSize Pool Origin Data%  Move Log Cpy%Sync Convert
iscsi_lv0 iscsi_vg -wi-ao---- 1.46g                     
DSC00066.jpg
[root@client ~]# fdisk -l  #看出还是原来的分区大小
退出后在登陆才能更新
DSC00067.jpg
DSC00068.jpg
  [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.
DSC00069.jpg
[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  #登陆
DSC00070.jpg
  [root@client ~]# fdisk -l  #可以看出服务端磁盘增大后客户端更新了
DSC00071.jpg
DSC00072.jpg

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-460973-1-1.html 上篇帖子: linux安装mysql 5.7 下篇帖子: Linux系统的PXE
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表