ISCSI网络服务共享

一、什么是ISCSI服务

iSCSI(iSCSI = internet Small Computer System Interface )是由IEETF开发的网络存储标准,目的是为了用IP协议将存储设备连接在一起。通过在IP网上传送SCSI命令和数据,ISCSI推动了数据在网际之 间的传递,同时也促进了数据的远距离管理。由于其出色的数据传输能力,ISCSI协议被认为是促进存储区域网(SAN)市场快速发展的关键因素之一。因为 IP网络的广泛应用, ISCSI能够在LAN、WAN甚至internet上进行数据传送,使得数据的存储不再受地域的现在。

ISCSI技术的核心是在TCP/IP网络上传输SCSI协议,是指用TCP/IP报文、和ISCSI报文封装SCSI报文,使得SCSI命令和数据可以在普通以太网络上进行传输,如下图:

iSCSI 协议定义了在 TCP/IP 网络发送、接收 block(数据块)级的存储数据的规则和方 法。发送端将SCSI命令和数据封装到 TCP/IP 包中再通过网络转发,接收端收到 TCP/IP 包 之后,将其还原为SCSI命令和数据并执行,完成之后将返回的SCSI命令和数据再封装到 TCP/IP 包中再传送回发送端。而整个过程在用户看来,使用远端的存储设备就象访问本地的 SCSI设备一样简单。

二、iscsi的安装和配置 (储存分离式共享文件)

1.服务机的设置:

[root@localhost ~]# yum install targetcli -y    //下载安装targetcli 
[root@localhost ~]# fdisk /dev/vdb    //创建分区vdb1
[root@localhost ~]# targetcli    //进入编写环境
Warning: Could not load preferences file /root/.targetcli/prefs.bin.
targetcli shell version 2.1.fb34
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]
/> /backstores/block create westos:storage1 /dev/vdb1  //创建设备名称 
Created block storage object westos:storage1 using /dev/vdb1.
/> ls
o- / .................................................................... [...]
  o- backstores ......................................................... [...]
  | o- block ............................................. [Storage Objects: 1]
  | | o- westos:storage1 .......... [/dev/vdb1 (1.0GiB) write-thru deactivated]
  | o- fileio ............................................ [Storage Objects: 0]
  | o- pscsi ............................................. [Storage Objects: 0]
  | o- ramdisk ........................................... [Storage Objects: 0]
  o- iscsi ....................................................... [Targets: 0]
  o- loopback .................................................... [Targets: 0]
/> iscsi/ create iqn.2018-11.com.example:disk1  //创建iscsi共享名称
Created target iqn.2018-11.com.example:disk1.
Created TPG 1.
/> ls
o- / .................................................................... [...]
  o- backstores ......................................................... [...]
  | o- block ............................................. [Storage Objects: 1]
  | | o- westos:storage1 .......... [/dev/vdb1 (1.0GiB) write-thru deactivated]
  | o- fileio ............................................ [Storage Objects: 0]
  | o- pscsi ............................................. [Storage Objects: 0]
  | o- ramdisk ........................................... [Storage Objects: 0]
  o- iscsi ....................................................... [Targets: 1]
  | o- iqn.2018-11.com.example:disk1 ................................ [TPGs: 1]
  |   o- tpg1 .......................................... [no-gen-acls, no-auth]
  |     o- acls ..................................................... [ACLs: 0]
  |     o- luns ..................................................... [LUNs: 0]
  |     o- portals ............................................... [Portals: 0]
  o- loopback .................................................... [Targets: 0]
/> iscsi/iqn.2018-11.com.example:disk1/tpg1/luns create /backstores/block/westos:storage1    //关联设备,创建一个连接,将共享与分区关联
Created LUN 0.
/> iscsi/iqn.2018-11.com.example:disk1/tpg1/acls create iqn.2018-11.com.example:westoskey1   //为文件加密
Created Node ACL for iqn.2018-11.com.example:westoskey1
Created mapped LUN 0.
/> iscsi/iqn.2018-11.com.example:disk1/tpg1/portals create 172.25.254.110
Using default IP port 3260  //该设备连接的端口为3260/tcp
Created network portal 172.25.254.110:3260.
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
[root@localhost ~]# firewall-cmd --permanent --add-port=3260/tcp  //添加火墙端口
success
[root@localhost ~]# firewall-cmd --reload   //刷新火墙

                                                                                                             

  

2.客户机的设置:

[root@station westos]# yum install iscsi-initiator-utils -y
[root@station westos]# vim /etc/iscsi/initiatorname.iscsi  //修改加密字符串

InitiatorName=iqn.2018-11.com.example:westoskey1

[root@station westos]# systemctl restart iscsi
[root@station westos]# iscsiadm -m discovery -t st -p 172.25.254.110  //#-m表示动作,使用检测的方式进行iscsiadm命令 ;-t表示st类型 ;-p(ip:port)表示从210主机获取iscsi设备与端口,不写端口就是默认的3260
172.25.254.110:3260,1 iqn.2018-11.com.example:disk1
[root@station westos]# iscsiadm -m node -T iqn.2018-11.com.example:disk1 -p 172.25.254.110 -l   //加入共享服务   -l 为加入
Logging in to [iface: default, target: iqn.2018-11.com.example:disk1, portal: 172.25.254.110,3260] (multiple)
Login to [iface: default, target: iqn.2018-11.com.example:disk1, portal: 172.25.254.110,3260] successful.
[root@station westos]# fdisk -l   //查看共享服务
Disk /dev/sda: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 4194304 bytes
[root@station westos]# fdisk /dev/sda   //为/dev/sda设备分区
[root@station westos]# partprobe     //生成分区表
[root@station westos]# mkfs.xfs /dev/sda1   //格式化
[root@station westos]# mount /dev/sda1  /mnt/   
[root@station westos]# df

 编辑文件vim /etc/iscsi/initiatorname.iscsi  进行加密

格式化,进行挂载,可以正常使用。

三、设置开机自动挂载

[root@station ~]# systemctl enable iscsi  //开机自启动该服务
[root@station ~]# vim /etc/fstab  //打开永久挂载配置文件
/dev/sda1   /mnt   xfs  defaults,_netdev   0 0
[root@station ~]# mount -a  //激活永久挂载
[root@station ~]# reboot  //系统重启
[root@station ~]# df   //查看挂载情况
root@station ~]# iscsiadm -m node -T iqn.2018-11.com.example:disk1 -p 172.25.254.110 -u  //退出共享服务   -u 为退出

四、ISCSI的删除

[root@station ~]# yum install tree.x86_64 -y  //下载安装tree命令
[root@station ~]# tree /var/lib/iscsi/    //查看
[root@station ~]# iscsiadm -m node -T iqn.2018-11.com.example:disk1 -p 172.25.254.210 -o delete      //删除共享的信息文件
[root@station ~]# tree /var/lib/iscsi/
├── ifaces
├── isns
├── nodes
├── send_targets
│   └── 172.25.254.210,3260
│       └── st_config
├── slp
└── static

7 directories, 1 file
[root@station ~]# systemctl restart iscsi   //重启服务
[root@station ~]# fdisk -l

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值