Linux下配置iSCSI服务器,实现资源共享

iSCSI(Internet SCSI):支持从客户端通过IP向远程服务器上的SCSI存储设备发送SCSI命令

SCSI 结构基于客户/服务器模式,其通常应用环境是:设备互相靠近,并且这些设备由 SCSI 总线连接。iSCSI 的主要功能是在 TCP/IP 网络上的主机系统(启动器 initiator)和存储设备(目标器 target)之间进行大量数据的封装和可靠传输过程。此外,iSCSI 提供了在 IP 网络封装 SCSI 命令,且运行在 TCP 上。

限定名称格式:iqn.yyyy-mm.{reverse domain}:label

一、服务器端配置如下:

1.安装并启动服务

[[email protected] Desktop]# yum install targetcli -y	#安装iSCSI目标软件包
[[email protected] Desktop]# systemctl start target	#启动target服务
[[email protected] Desktop]# systemctl enable target	#设置服务开机自启动

2.进入iSCSI交互式配置模式

[[email protected] Desktop]# targetcli	#输入targetcli命令
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 pt.example.disk1 /dev/sda4		#使用/dev/sda4创建ISCSI远程存储块pt.example.disk1
Created block storage object pt.example.disk1 using /dev/sda4.

/> /iscsi create iqn.2016-03.pt.example1:storage		#创建要分享的ISCSI文件名(格式必须是iqn.yyyy-mm.{reverse domain}:label)
Created target iqn.2016-03.pt.example1:storage.
Created TPG 1.

/> /iscsi/iqn.2016-03.pt.example1:storage/tpg1/acls create iqn.2016-03.pt.example2:desktop		#指定访问ISCSI设备块的ACL权限(即允许initiator name为iqn.2016-03.pt.example2:desktop的客户端可以访问)
Created Node ACL for iqn.2016-03.pt.example2:desktop

/> /iscsi/iqn.2016-03.pt.example1:storage/tpg1/luns create /backstores/block/pt.example.disk1 		#将创建的ISCSI远程存储块加入进来
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2016-03.pt.example2:desktop

/> /iscsi/iqn.2016-03.pt.example1:storage/tpg1/portals create 172.25.254.209		#打开访问所使用的端口
Using default IP port 3260
Created network portal 172.25.254.209:3260.

/> ls		#完成后如下所示
o- / ..................................................................... [...]
  o- backstores .......................................................... [...]
  | o- block .............................................. [Storage Objects: 1]
  | | o- pt.example.disk1 ............ [/dev/sda4 (1.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.2016-03.pt.example1:storage ............................... [TPGs: 1]
  |   o- tpg1 ........................................... [no-gen-acls, no-auth]
  |     o- acls ...................................................... [ACLs: 1]
  |     | o- iqn.2016-03.pt.example2:desktop .................. [Mapped LUNs: 1]
  |     |   o- mapped_lun0 .................. [lun0 block/pt.example.disk1 (rw)]
  |     o- luns ...................................................... [LUNs: 1]
  |     | o- lun0 ......................... [block/pt.example.disk1 (/dev/sda4)]
  |     o- portals ................................................ [Portals: 1]
  |       o- 172.25.254.209: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

设置防火墙

[[email protected] Desktop]# firewall-cmd --permanent --add-port=3260/tcp	#将要使用的端口加入到防火墙允许之中
success
[[email protected] Desktop]# firewall-cmd --reload 	#重载防火墙的设置
success

二、客户端配置如下:

[[email protected] Desktop]# yum install iscsi-initiator-utils -y		#安装iSCSI发起端软件包
[[email protected] Desktop]# vim /etc/iscsi/initiatorname.iscsi	#设置发起端的IQN
InitiatorName=iqn.2016-03.pt.example2:desktop

[[email protected] Desktop]# iscsiadm -m discovery -t st -p 172.25.254.209	  #获得可以访问共享的块
172.25.254.209:3260,1 iqn.2016-03.pt.example1:storage

[[email protected] Desktop]# iscsiadm -m node -T iqn.2016-03.pt.example1:storage -p 172.25.254.209 -l	#连接服务端的ISCSI目标块到本机
Logging in to [iface: default, target: iqn.2016-03.pt.example1:storage, portal: 172.25.254.209,3260] (multiple)
Login to [iface: default, target: iqn.2016-03.pt.example1:storage, portal: 172.25.254.209,3260] successful.

[[email protected] Desktop]# fdisk -l	#查看磁盘,多了/dev/sdb

Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000c235a

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      411647      204800   83  Linux
/dev/sda2          411648     4605951     2097152   82  Linux swap / Solaris
/dev/sda3         4605952    35796991    15595520   83  Linux

Disk /dev/sdb: 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
Disk label type: dos
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System

然后就可以正常使用所得到的ISCSI资源,正常格式化,并挂载。

########中断使用ISCSI目标#########

先将挂载进行卸载,确保没有使用目标所提供的任何设备

[[email protected] Desktop]# iscsiadm -m node -T iqn.2016-03.pt.example1:storage -p 172.25.254.209 -u		#退出ISCSI目标,以暂时断开连接
[[email protected] Desktop]# iscsiadm -m node -T iqn.2016-03.pt.example1:storage -p 172.25.254.209 -o -delete 	#删除本地连接ISCSI目标的本地记录,以永久断开连接
时间: 2024-08-08 17:46:41

Linux下配置iSCSI服务器,实现资源共享的相关文章

Linux下配置Tomcat服务器

Linux下配置Tomcat服务器和Windows下其实差不多,可以去官网下载安装包释放或者在线下载,只是当时下载的windows.zip文件,现在下载.tar.gz格式的即可,下面使用命令行的方式安装 还是在/usr/local下新建目录tomcat进入后用wget命令下载最新包,tomcat9.0现在已经出来了,但是为了和eclipse项目更好的兼容,建议下载tomcat8.0的最新包 下载好之后进行释放 tar -xzvf apache-tomcat-8.0.30.tar.gz 释放出来之

在linux下配置tftp服务器和nfs服务器

提示:该实验平台是在RedHatb6下进行的 配置成功的前提有三个: (1):在window下能ping的通linux (2):关闭linux 防火墙      执行指令:/etc/init.d/iptables stop (3):使SElinux处于宽容模式   执行指令:setenforce permissive 一.配置tftp服务器步骤 (1):挂载磁盘,安装tptp-server软件包 mount /dev/cdrom    /mnt/                        

linux下配置samba服务器

linux下配置samba服务器 1. 什么是samba Samba服务类似于windows上的共享功能,可以实现在Linux上共享文件,windows上访问,当然在Linux上也可以访问到. 是一种在局域网上共享文件和打印机的一种通信协议,它为局域网内的不同计算机之间提供文件及打印机等资源的共享服务. 2.安装配置samba 安装命令:yum install -y samba samba-client 配置文件:/etc/samba/smb.conf [global] workgroup = 

阿里云linux下配置php服务器环境,及遇到的问题解决方法

服务器的镜像我们是选择了第三方配置好的Centos 6.3 64 位 Apache2+php5.2+Mysql5+vsftpd ,所以一键安装镜像后php环境基本就有了,所以以下是除去安装lamp之外的配置. 1.首先是配置虚拟站点,我们的服务器虚拟站点配置文件在/usr/local/apache/conf/extra/httpd-vhosts.conf ,以前用过vim但是早就忘了,所以安装了nano,还带有提示,nano的安装命 yum -y install nano  安装完成后用命令na

linux下配置samba服务器(以CentOS6.7为例)

一.简介(百度百科) Samba是在Linux和UNIX系统上实现SMB协议的一个免费软件,由服务器及客户端程序构成.SMB(Server Messages Block,信息服务块)是一种在局域网上共享文件和打印机的一种通信协议,它为局域网内的不同计算机之间提供文件及打印机等资源的共享服务.SMB协议是客户机/服务器型协议,客户机通过该协议可以访问服务器上的共享文件系统.打印机及其他资源.通过设置"NetBIOS over TCP/IP"使得Samba不但能与局域网络主机分享资源,还能

在Linux下配置NFS服务器

网络文件系统(NFS,Network File System)是一种将远程主机上的分区(目录)经网络挂载到本地系统的一种机制,通过对网络文件系统的支持,用户可以在本地系统上像操作本地分区一样来对远程主机的共享分区(目录)进行操作. 在嵌入式Linux 的开发过程中,开发者需要在Linux 服务器上进行所有的软件开发,交叉编译后,通用FTP 方式将可执行文件下载到嵌入式系统运行,但这种方式不但效率低下,且无法实现在线的调试.因此,可以通过建立NFS,把Linux 服务器上的特定分区共享到待调试的嵌

Linux下配置SFTP服务器

最近在做一个微信支付水电费的项目,是与兴业银行合作的项目,按照银行的要求要配置一个SFTP服务器,上传每天缴费的对账单到SFTP服务器里面,经过一段时间的摸索,终于配置成功了,跟大家分享一下,配置过程如下: 0.查看openssh的版本 1. ssh -V 使用ssh -V 命令来查看openssh的版本,版本必须大于4.8p1,低于的这个版本需要升级. 1.创建sftp组 1. groupadd sftp 2.创建一个sftp用户,用户名为mysftp,密码为mysftp 修改用户密码和修改L

手把手教你linux下配置vsftp服务器(以CentOS为例)--非常的详细

VSFTP 简介:VSFTP是一个基于GPL发布的类Unix系统上使用的FTP服务器软件,它的全称是Very Secure FTP 从此名称可以看出来,编制者的初衷是代码的安全.安全性是编写VSFTP的初衷,除了这与生俱来的安全特性以外,高速与高稳定性也是VSFTP的两个重要特点.在速度方面,使用ASCII代码的模式下载数据时,VSFTP的速度是Wu-FTP的两倍,如果Linux主机使用2.4.*的内核,在千兆以太网上的下载速度可达86MB/S.在稳定方面,VSFTP就更加的出色,VSFTP在单

Linux下配置iscsi网络存储

1. 服务端配置 实验环境系统版本: CentOS Linux release 7.3.1611 (Core) 1) 安装软件包 yum -y install targetcli 2) 创建要输出的iscsi存储 可输出的设备有如下几种: a.lvm卷设备: b.由文件组成的块设备(经过tgtimg工具处理过的): c.单一的分区: d.整个磁盘: e.RAID组成的卷设备: 这里准备了一个lvm逻辑卷,如下: [[email protected] conf.d]# lvdisplay