首页 > 系统相关 >【iscsi使用】2.CentOS7搭建iscsi服务器

【iscsi使用】2.CentOS7搭建iscsi服务器

时间:2024-12-31 16:30:18浏览次数:5  
标签:default iscsi Storage server CentOS7 Objects 服务器 disk

目录


1.SAN存储及NAS存储

2.CentOS7搭建iscsi服务器

3.无盘启动CentOS7


前言


为了探究 SAN存储及iscsi ,通过模拟的方式软件搭建服务。

iscsi 又称为 IP-SAN,是一种基于因特网及SCSI-3协议下的存储技术。


环境介绍


主机名 操作系统 IP
server CentOS7.9 10.0.0.10
node01 CentOS7.9 10.0.0.11
> lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0  100G  0 disk
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   99G  0 part
  ├─centos-root 253:0    0 95.1G  0 lvm  /
  └─centos-swap 253:1    0  3.9G  0 lvm  [SWAP]
sdb               8:16   0   20G  0 disk	#将该磁盘做为LUNs使用。
sr0              11:0    1 1024M  0 rom

iscsi服务器配置


  1. 将磁盘分区
> fdisk /dev/sdb
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 0x928654bb.

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-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039):
Using default value 41943039
Partition 1 of type Linux and of size 20 GiB is set

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

Calling ioctl() to re-read partition table.
Syncing disks.

> lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0  100G  0 disk
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   99G  0 part
  ├─centos-root 253:0    0 95.1G  0 lvm  /
  └─centos-swap 253:1    0  3.9G  0 lvm  [SWAP]
sdb               8:16   0   20G  0 disk
└─sdb1            8:17   0   20G  0 part
sr0              11:0    1 1024M  0 rom
  1. 安装scsi 工具
> yum install -y targetcli
> systemctl enable --now target
Created symlink from /etc/systemd/system/multi-user.target.wants/target.service to /usr/lib/systemd/system/target.service.
  1. 创建 iscsi 磁盘(块设备)
> targetcli
targetcli shell version 2.1.53
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.

/> ls
o- / ......................................................................................................................... [...]
  o- backstores .............................................................................................................. [...]
  | o- block .................................................................................................. [Storage Objects: 0]	#说明:block 中创建的是以硬盘形式的存储空间
  | o- fileio ................................................................................................. [Storage Objects: 0]	#说明:fileio 中创建的是以文件形式的存储空间
  | o- pscsi .................................................................................................. [Storage Objects: 0]
  | o- ramdisk ................................................................................................ [Storage Objects: 0]
  o- iscsi ............................................................................................................ [Targets: 0]
  o- loopback ......................................................................................................... [Targets: 0]

/> backstores/block create disk.node1 /dev/sdb1	#disk.node1 是磁盘名称,后面接磁盘本地存储路径
Created block storage object disk.node1 using /dev/sdb1.
/> ls
o- / ......................................................................................................................... [...]
  o- backstores .............................................................................................................. [...]
  | o- block .................................................................................................. [Storage Objects: 1]
  | | o- disk.node1 ................................................................... [/dev/sdb1 (20.0GiB) write-thru deactivated]	#查看创建成功。
  | |   o- alua ................................................................................................... [ALUA Groups: 1]
  | |     o- default_tg_pt_gp ....................................................................... [ALUA state: Active/optimized]
  | o- fileio ................................................................................................. [Storage Objects: 0]
  | o- pscsi .................................................................................................. [Storage Objects: 0]
  | o- ramdisk ................................................................................................ [Storage Objects: 0]
  o- iscsi ............................................................................................................ [Targets: 0]
  o- loopback ......................................................................................................... [Targets: 0]

  1. 创建服务端程序(iscsi目标)
/> iscsi/ create iqn.2024-12.linux.iscsi.server:server	#创建服务的程序,以时间命名,注意一定要遵循这个格式,否则无法创建。
Created target iqn.2024-12.linux.iscsi.server:server.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/> ls
o- / ......................................................................................................................... [...]
  o- backstores .............................................................................................................. [...]
  | o- block .................................................................................................. [Storage Objects: 1]
  | | o- disk.node1 ................................................................... [/dev/sdb1 (20.0GiB) write-thru deactivated]
  | |   o- alua ................................................................................................... [ALUA Groups: 1]
  | |     o- default_tg_pt_gp ....................................................................... [ALUA state: Active/optimized]
  | o- fileio ................................................................................................. [Storage Objects: 0]
  | o- pscsi .................................................................................................. [Storage Objects: 0]
  | o- ramdisk ................................................................................................ [Storage Objects: 0]
  o- iscsi ............................................................................................................ [Targets: 1]
  | o- iqn.2024-12.linux.iscsi.server:server ............................................................................. [TPGs: 1]
  |   o- tpg1 ............................................................................................... [no-gen-acls, no-auth]
  |     o- acls .......................................................................................................... [ACLs: 0]
  |     o- luns .......................................................................................................... [LUNs: 0]
  |     o- portals .................................................................................................... [Portals: 1]
  |       o- 0.0.0.0:3260 ..................................................................................................... [OK]
  o- loopback ......................................................................................................... [Targets: 0]

  1. 创建服务卷(逻辑单元LUN:为了让客户端识别)
/> iscsi/iqn.2024-12.linux.iscsi.server:server/tpg1/luns create /backstores/block/disk.node1	# 通过iscsi磁盘创建luns
Created LUN 0.
/> ls
o- / ......................................................................................................................... [...]
  o- backstores .............................................................................................................. [...]
  | o- block .................................................................................................. [Storage Objects: 1]
  | | o- disk.node1 ..................................................................... [/dev/sdb1 (20.0GiB) write-thru activated]
  | |   o- alua ................................................................................................... [ALUA Groups: 1]
  | |     o- default_tg_pt_gp ....................................................................... [ALUA state: Active/optimized]
  | o- fileio ................................................................................................. [Storage Objects: 0]
  | o- pscsi .................................................................................................. [Storage Objects: 0]
  | o- ramdisk ................................................................................................ [Storage Objects: 0]
  o- iscsi ............................................................................................................ [Targets: 1]
  | o- iqn.2024-12.linux.iscsi.server:server ............................................................................. [TPGs: 1]
  |   o- tpg1 ............................................................................................... [no-gen-acls, no-auth]
  |     o- acls .......................................................................................................... [ACLs: 0]
  |     o- luns .......................................................................................................... [LUNs: 1]
  |     | o- lun0 ................................................................ [block/disk.node1 (/dev/sdb1) (default_tg_pt_gp)]
  |     o- portals .................................................................................................... [Portals: 1]
  |       o- 0.0.0.0:3260 ..................................................................................................... [OK]
  o- loopback ......................................................................................................... [Targets: 0]
  1. 创建客户端连接器
/> iscsi/iqn.2024-12.linux.iscsi.server:server/tpg1/acls create iqn.2024-12.linux.iscsi.server:client
Created Node ACL for iqn.2024-12.linux.iscsi.server:client
Created mapped LUN 0.
/> ls
o- / ......................................................................................................................... [...]
  o- backstores .............................................................................................................. [...]
  | o- block .................................................................................................. [Storage Objects: 1]
  | | o- disk.node1 ..................................................................... [/dev/sdb1 (20.0GiB) write-thru activated]
  | |   o- alua ................................................................................................... [ALUA Groups: 1]
  | |     o- default_tg_pt_gp ....................................................................... [ALUA state: Active/optimized]
  | o- fileio ................................................................................................. [Storage Objects: 0]
  | o- pscsi .................................................................................................. [Storage Objects: 0]
  | o- ramdisk ................................................................................................ [Storage Objects: 0]
  o- iscsi ............................................................................................................ [Targets: 1]
  | o- iqn.2024-12.linux.iscsi.server:server ............................................................................. [TPGs: 1]
  |   o- tpg1 ............................................................................................... [no-gen-acls, no-auth]
  |     o- acls .......................................................................................................... [ACLs: 1]
  |     | o- iqn.2024-12.linux.iscsi.server:client ................................................................ [Mapped LUNs: 1]	#客户端连接器
  |     |   o- mapped_lun0 ............................................................................ [lun0 block/disk.node1 (rw)]
  |     o- luns .......................................................................................................... [LUNs: 1]
  |     | o- lun0 ................................................................ [block/disk.node1 (/dev/sdb1) (default_tg_pt_gp)]
  |     o- portals .................................................................................................... [Portals: 1]
  |       o- 0.0.0.0:3260 ..................................................................................................... [OK]
  o- loopback ......................................................................................................... [Targets: 0]
  1. 保存配置并重启target
/> saveconfig
Configuration saved to /etc/target/saveconfig.json
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup/.
Configuration saved to /etc/target/saveconfig.json

> systemctl restart target

#查询端口是否开启
> netstat -ntplu | egrep 3260
tcp        0      0 0.0.0.0:3260            0.0.0.0:*               LISTEN      -

客户端使用iscsi


  1. 安装程序包
> yum install -y iscsi*
  1. 修改配置文件
> vim /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2024-12.linux.iscsi.server:client #这里填写上面添加的客户端连接器
  1. 启动服务
> systemctl enable --now iscsid
Created symlink from /etc/systemd/system/multi-user.target.wants/iscsid.service to /usr/lib/systemd/system/iscsid.service.
  1. 挂载iscsi
# 发现可用的iscsi
> iscsiadm -m discovery -t st -p 10.0.0.10	
10.0.0.10:3260,1 iqn.2024-12.linux.iscsi.server:server

# login 该iscsi
> iscsiadm -m node -T iqn.2024-12.linux.iscsi.server:server -p 10.0.0.10:3260 --login
Logging in to [iface: default, target: iqn.2024-12.linux.iscsi.server:server, portal: 10.0.0.10,3260] (multiple)
Login to [iface: default, target: iqn.2024-12.linux.iscsi.server:server, portal: 10.0.0.10,3260] successful.
> lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0  100G  0 disk
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   99G  0 part
  ├─centos-root 253:0    0 95.1G  0 lvm  /
  └─centos-swap 253:1    0  3.9G  0 lvm  [SWAP]
sdb               8:16   0   20G  0 disk	#该块设备就是通过iscsi发现
sr0              11:0    1 1024M  0 rom

#格式化并挂载
> lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0  100G  0 disk
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   99G  0 part
  ├─centos-root 253:0    0 95.1G  0 lvm  /
  └─centos-swap 253:1    0  3.9G  0 lvm  [SWAP]
sdb               8:16   0   20G  0 disk
sr0              11:0    1 1024M  0 rom

> fdisk /dev/sdb
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 0x6ae7176e.

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-41940991, default 8192):
Using default value 8192
Last sector, +sectors or +size{K,M,G} (8192-41940991, default 41940991):
Using default value 41940991
Partition 1 of type Linux and of size 20 GiB is set

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

Calling ioctl() to re-read partition table.
Syncing disks.

> lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0  100G  0 disk
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   99G  0 part
  ├─centos-root 253:0    0 95.1G  0 lvm  /
  └─centos-swap 253:1    0  3.9G  0 lvm  [SWAP]
sdb               8:16   0   20G  0 disk
└─sdb1            8:17   0   20G  0 part
sr0              11:0    1 1024M  0 rom

> mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1              isize=512    agcount=4, agsize=1310400 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=5241600, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

> mkdir -p /mnt/data

> mount /dev/sdb1 /mnt/data/

> df -Th
Filesystem              Type      Size  Used Avail Use% Mounted on
devtmpfs                devtmpfs  1.9G     0  1.9G   0% /dev
tmpfs                   tmpfs     1.9G     0  1.9G   0% /dev/shm
tmpfs                   tmpfs     1.9G   12M  1.9G   1% /run
tmpfs                   tmpfs     1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/centos-root xfs        96G  1.5G   94G   2% /
/dev/sda1               xfs      1014M  150M  865M  15% /boot
tmpfs                   tmpfs     378M     0  378M   0% /run/user/0
/dev/sdb1               xfs        20G   33M   20G   1% /mnt/data

注意:客户端挂载iscsi块存储使用时,当服务器需要重启,建议先停止业务服务,再umount 该块设备的挂载,然后重启主机。

  1. 卸载 iscsi
> iscsiadm -m node -T iqn.2024-12.linux.iscsi.server:server -p 10.0.0.10:3260 --logout

标签:default,iscsi,Storage,server,CentOS7,Objects,服务器,disk
From: https://www.cnblogs.com/hukey/p/18644271

相关文章

  • 使用expect复制系统配置文件压缩打包上传到其他服务器上面
    #!/bin/bashhost="192.168.0.111"username="root"password="niway"#cp/etc/inittab/usr/local/tmp/#用于系统初始化,定义了系统的运行级别。cp/etc/fstab/usr/local/tmp/#定义了需要在启动时自动挂载的文件系统。cp/etc/hosts/usr/local/tmp/#定义了主机名与IP地址的映射。cp......
  • 高防服务器在网络游戏中起着哪些作用?
    高防服务器是一种具有着强大防御能力的服务器,是专门针对网络攻击进行设计和优化的一种服务器,可以有效抵御各种网络攻击类型,其中包括分布式拒绝服务攻击和CC攻击等较为常见的攻击类型,能够为网站提供安全保障。在大型的网络游戏行业当中是受到网络攻击的重灾区,经常会遭到大规模......
  • 实践项目-Web服务器架构调整
    (241231)实践目标将公司原来的多数单点服务器变成了集群,提升了网站的稳定性与高并发的应用场景。目标:将现有的单点Web服务器架构调整为高可用的集群架构,解决单点故障问题。使用LVS+Keepalived或Nginx+Keepalived实现负载均衡和高可用性。实现动静分离,提升网站性能。确......
  • centos7 下 nginx 启动,关闭,重启配置 -
    centos7下nginx启动,关闭,重启配置-|Id|Title|DateAdded|SourceUrl|PostType|Body|BlogId|Description|DateUpdated|IsMarkdown|EntryName|CreatedTime|IsActive|AutoDesc|AccessPermission||-------------|-------------|-------------|---......
  • 全球和中国时间服务器
    全球通用时间服务器这些时间服务器适合大部分地区使用:NTPPoolProject(全球NTP池)官网:https://www.pool.ntp.org推荐配置:0.pool.ntp.org1.pool.ntp.org2.pool.ntp.org3.pool.ntp.orgGoogleNTP服务器IP地址:time.google.com216.239.35.0216.......
  • centos7快速部署MySQL8
    一、yum安装wgethttps://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpmrpm-Uvhmysql80-community-release-el7-3.noarch.rpmyuminstallmysql-community-serversystemctlstartmysqldgrep'temporarypassword'/var/log/mysqld.log2024-1......
  • 云服务器登录失败,如何解决?
    当您遇到云服务器无法远程登录的问题时,可能是由多种原因引起的。以下是详细的排查步骤和解决方案,帮助您快速解决问题:确认登录凭证:首先,请确保您使用的用户名和密码是正确的。如果之前修改过密码,可能会导致登录失败。建议重新获取最新的登录凭证。如果您不确定密码是否正确,可......
  • 服务器配置显示异常,带宽和内存与预期不符
    关于您提到的服务器配置显示异常的问题,我们非常理解您的困惑。根据您的描述,您发现服务器的带宽从原来的8M变成了4M,内存也从4G变成了2G。为了帮助您更好地解决这个问题,我们需要进行以下几个步骤的排查和确认。首先,请确保您登录的是正确的服务器账号和密码。有时由于多台服务器共用......
  • 如何处理服务器端口888突然无法访问的问题
    关于您提到的服务器端口888突然无法访问的问题,我们非常理解您的困扰。根据您的描述,宝塔面板因存在致命漏洞,为了保障数据安全,我们在安全组中暂时阻止了888端口。以下是详细的解决方案和建议,帮助您尽快恢复正常访问。首先,强烈建议您立即更新宝塔面板的安全补丁。这是确保服务器安全......
  • 如何解决修改密码后无法远程连接服务器的问题?
    在修改过服务器密码后,您遇到了无法远程连接服务器的问题。以下是详细的分析和解决方案:确认密码修改成功:首先,确保您提供的新密码是正确的,并且已经正确保存。有时在修改密码时可能会出现输入错误或未保存的情况。如果不确定具体哪个密码是正确的,建议尝试所有可能的密码组合,或......