文件共享之iscsi

2024-02-13 00:48
文章标签 文件共享 iscsi

本文主要是介绍文件共享之iscsi,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1.
iscsi 是直接对设备进行共享的服务

2.启动iscsi共享设备


****server端****
1.
建立一个lvm设备

[root@server40 ~]# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x0099d7b4.

Command (m for help): p       

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x0099d7b4

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n        
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (2048-20971519, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +1000M
Partition 1 of type Linux and of size 1000 MiB is set

Command (m for help): p

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x0099d7b4

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048     2050047     1024000   83  Linux

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

Command (m for help): p

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x0099d7b4

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048     2050047     1024000   8e  Linux LVM

Command (m for help): q   

[root@server40 ~]# pvcreate /dev/vdb1
  Physical volume "/dev/vdb1" successfully created
[root@server40 ~]# vgcreate vg0 /dev/vdb1
  Volume group "vg0" successfully created
[root@server40 ~]# vgdisplay
  --- Volume group ---
  VG Name               vg0
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               996.00 MiB
  PE Size               4.00 MiB
  Total PE              249
  Alloc PE / Size       0 / 0   
  Free  PE / Size       249 / 996.00 MiB
  VG UUID               oEjeoF-I07m-UJOg-JJFX-4X3S-xNst-2k4bsD
   
[root@server40 ~]# lvcreate -l 249 -n iscsi_storage vg0
  Logical volume "iscsi_storage" created
[root@server40 ~]# lvs
  LV            VG   Attr       LSize   Pool Origin Data%  Move Log Cpy%Sync Convert
  iscsi_storage vg0  -wi-a----- 996.00m

2.下载并开启客户服务                                            
[root@server40 ~]# yum install targetcli -y
[root@server40 ~]# systemctl enable target
ln -s '/usr/lib/systemd/system/target.service' '/etc/systemd/system/multi-user.target.wants/target.service'
[root@server40 ~]# systemctl stop  firewalld.service
[root@server40 ~]# 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 serverlstorage /dev/vg0/                       
/> /backstores/block create serverlstorage /dev/vg0/iscsi_storage   ##
提供硬盘,建立存储设备

Created block storage object serverlstorage using /dev/vg0/iscsi_storage.
/> /iscsi create iqn.2017-06.com.example:strage1                            ##创建iqn
Created target iqn.2017-06.com.example:strage1.
Created TPG 1.
/> /iscsi/iqn.2017-06.com.example:strage1/tpg1/luns create /backstores/block/serverlstorage   ##创建目标地址
Created LUN 0.
/> /iscsi/iqn.2017-06.com.example:strage1/tpg1/acls create iqn.2017-06.com.example:serverlstorage  ##创建ian密匙,只用明文密码
Created Node ACL for iqn.2017-06.com.example:serverlstorage
Created mapped LUN 0.
/> /iscsi/iqn.2017-06.com.example:strage1/tpg1/portals create 172.25.40.11   ##设置目标门户,即服务器ip,打开3260端口
Using default IP port 3260
Created network portal 172.25.40.11: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@server40 ~]# 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: 1]
  | | o- serverlstorage ............... [/dev/vg0/iscsi_storage (996.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-06.com.example:strage1 ............................................... [TPGs: 1]
  |   o- tpg1 ........................................................... [no-gen-acls, no-auth]
  |     o- acls ...................................................................... [ACLs: 1]
  |     | o- iqn.2017-06.com.example:serverlstorage ........................... [Mapped LUNs: 1]
  |     |   o- mapped_lun0 .................................... [lun0 block/serverlstorage (rw)]
  |     o- luns ...................................................................... [LUNs: 1]
  |     | o- lun0 .............................. [block/serverlstorage (/dev/vg0/iscsi_storage)]
  |     o- portals ................................................................ [Portals: 1]
  |       o- 172.25.40.11:3260 ............................................................ [OK]
  o- loopback ..................................................................... [Targets: 0]
/>

****desktop端****
[root@desktop40 ~]# yum whatprovides */genkey
Loaded plugins: langpacks
rhel_dvd/filelists_db                                                    | 3.0 MB  00:00:00     
crypto-utils-2.4.1-42.el7.x86_64 : SSL certificate and key management utilities
Repo        : rhel_dvd
Matched from:
Filename    : /usr/bin/genkey



[root@desktop40 ~]# vim /etc/iscsi/initiatorname.iscsi    ##设置发起端iqn

                                    =后为iqn密匙
[root@desktop40 ~]# iscsiadm -m discovery -t st -p 172.25.40.11           ##登陆服务器
172.25.40.11:3260,1 iqn.2017-06.com.example:strage1
[root@desktop40 ~]# fdisk -l

Disk /dev/vda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x00013f3e

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    20970332    10484142+  83  Linux

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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

[root@desktop40 ~]# iscsiadm -m node -T iqn.2017-06.com.example:strage1 -p 172.25.40.11 -l
Logging in to [iface: default, target: iqn.2017-06.com.example:strage1, portal: 172.25.40.11,3260] (multiple)
Login to [iface: default, target: iqn.2017-06.com.example:strage1, portal: 172.25.40.11,3260] successful.
[root@desktop40 ~]# fdisk -l

Disk /dev/vda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x00013f3e

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    20970332    10484142+  83  Linux

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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 /dev/sda: 1044 MB, 1044381696 bytes, 2039808 sectors    ##iscsi磁盘
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@desktop40 ~]# systemctl restart iscsi
[root@desktop40 ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xea14d41e.

Command (m for help):
Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (8192-2039807, default 8192):
Using default value 8192
Last sector, +sectors or +size{K,M,G} (8192-2039807, default 2039807):
Using default value 2039807
Partition 1 of type Linux and of size 992 MiB is set

Command (m for help): p

Disk /dev/sda: 1044 MB, 1044381696 bytes, 2039808 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: 0xea14d41e

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            8192     2039807     1015808   83  Linux

Command (m for help): wq
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@desktop40 ~]# mkfs.xfs /dev/sda
sda   sda1  
[root@desktop40 ~]# mkfs.xfs /dev/sda1
meta-data=/dev/sda1              isize=256    agcount=8, agsize=31744 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0
data     =                       bsize=4096   blocks=253952, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=853, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@desktop40 ~]# mount /dev/sda1 /mnt                       ##挂载iscsi设备
[root@desktop40 ~]# df
Filesystem           1K-blocks    Used Available Use% Mounted on
/dev/vda1             10473900 3209332   7264568  31% /
devtmpfs                927072       0    927072   0% /dev
tmpfs                   942660     124    942536   1% /dev/shm
tmpfs                   942660   17048    925612   2% /run
tmpfs                   942660       0    942660   0% /sys/fs/cgroup
/dev/sr0               3654720 3654720         0 100% /run/media/root/RHEL-7.0 Server.x86_64
172.25.40.11:/public   1012396   33056    979340   4% /mnt
[root@desktop40 ~]# yum install tree.x86_64 -y         ##下载树形菜单控件
[root@desktop40 ~]# tree -C /var/lib/iscsi/                  ##查看iscsi目标
/var/lib/iscsi/
|-- ifaces
|-- isns
|-- nodes
|   `-- iqn.2017-06.com.example:strage1
|       `-- 172.25.40.11,3260,1
|           `-- default
|-- send_targets
|   `-- 172.25.40.11,3260
|       |-- iqn.2017-06.com.example:strage1,172.25.40.11,3260,1,default -> /var/lib/iscsi/nodes/iqn.2017-06.com.example:strage1/172.25.40.11,3260,1
|       `-- st_config
|-- slp
`-- static

10 directories, 2 files


这篇关于文件共享之iscsi的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/704049

相关文章

使用Python本地搭建http.server文件共享服务并实现公网环境远程访问——“cpolar内网穿透”

前言 本文主要介绍如何在Windows系统电脑上使用python这样的简单程序语言,在自己的电脑上搭建一个共享文件服务器,并通过cpolar创建的公网地址,打造一个可以随时随地远程访问的私人云盘。 数据共享作为和连接作为互联网的基础应用,不仅在商业和办公场景有广泛的应用,对于个人用户也有很强的实用意义。也正因如此,大量数据共享软件被开发出来,云存储的概念也被重复炒作。对于爱好折腾的笔者来说,用

Windows电脑本地安装HFS文件共享服务结合内网穿透搭建低成本NAS

文章目录 前言1.软件下载安装1.1 设置HFS访客1.2 虚拟文件系统 2. 使用cpolar建立一条内网穿透数据隧道2.1 保留隧道2.2 隧道名称2.3 创建二级子域名访问本地hfs 总结 前言 本文主要介绍如何在Windows系统电脑使用HFS并结合cpolar内网穿透工具搭建低成本NAS,并实现使用公网地址远程访问管理本地局域网电脑存储的文件。 云存储作为一个新概念

如何在本地服务器部署SeaFile自托管文件共享服务结合内网穿透打造私有云盘?

文章目录 1. 前言2. SeaFile云盘设置2.1 Owncould的安装环境设置2.2 SeaFile下载安装2.3 SeaFile的配置 3. cpolar内网穿透3.1 下载安装3.2 Cpolar注册3.3 Cpolar云端设置3.4 Cpolar本地设置 4.公网访问测试5.结语 1. 前言 本文主要为大家介绍,如何使用两个简单软件,SeaFile云存储平台和cpo

ubuntu 14.04虚拟机下通过samba实现和windows文件共享

之前在网上搜索到了大量类似的文章,然而,99.999999%都是不能用的。所以特此写一篇博客记录自己正确的操作,以备后续使用。 1.常规步骤,安装samba,这个步骤一般都不会有问题的 安装samba: sudo apt-get install samba 安装smbclie sudo apt-get install smbclient 2.关键步骤:修改配置文件: 编辑sm

ceph-iscsi 手动安装过程中的一些问题记录以及解决办法

ceph-iscsi 手动安装教程 安装教程,建议直接看官方文档,猛戳传送门。官方教程是英文版的(不知道有没有中文版),都是一些基础英语,问题不大,实在不行找个翻译软件帮帮忙,哈哈哈。 多啰嗦一点,官方教程里面全部是通过git 一个一个安装的,比较麻烦。可以使用如下命令,比较省事(以ubuntu系统作为示例): `sudo apt update // 更新apt 数据库 sudo apt -

win10 WSL(1903)安装samba服务器实现文件共享

https://blog.csdn.net/fuyuande/article/details/90368576

Windows 局域网文件共享

文章目录 设置共享文件夹需要鉴权无需鉴权 访问共享文件夹WindowsiPhone / iPadmacOS 取消共享文件夹匿名连接失败排查 相同 WiFi 环境下的设备(电脑、手机、平板)可以访问 Windows 电脑上的文件(图片、视频等) 设置共享文件夹 需要鉴权 需添加一个或多个本地账户,并设置用户名(假设 user01)和密码 创建本地账户:目录属性 > 共享

【网络安全】服务基础第一阶段——第四节:Windows系统管理基础---- NTFS安全权限与SMB文件共享服务器

目录 一、NTFS安全权限 1.1 文件系统 1.2 格式化磁盘中的文件系统 1.FAT32 2.NTFS 3.EXT 4.XFS 应用场景: 1.3 文件操作权限 1.4 权限管理系统 1.5 特殊权限 1.6 NTFS权限类型 二、权限管理实践 三、SMB文件共享服务器 3.1 文件共享服务器 3.2 常用的文件共享技术 3.3 SMB协议 3.4 SM

linux使用samba访问windows文件共享问题记录

我使用的环境是windows xp和centos6.10。 centos安装samba之后,可以用samba命令进行交互模式访问共享。但是在尝试挂载模式访问共享时遇到问题。需要cifs-utils包支持,虽然不是强制依赖,但有决定性影响。 mount -t cifs //server/share /mount_point -o user*=username 没有安装cifs-utils时,如

NSF服务 -- 文件共享 (windows挂载centos)

CentOS 配置 1.安装NFS服务端 yum install -y nfs-utils rpcbind 2.为NFS制定端口 vi /etc/sysconfig/nfs 将下列端口复制到文件的最下方 并注释 RQUOTAD_PORT=30001 LOCKD_TCPPORT=30002 LOCKD_UDPPORT=30002 MOU