linux安装iscsi服务器搭建,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目标的本地记录,以永久断开连接

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值