CentOS7 ISCSI服务器搭建
  aOYB9Qh7rxCg 2023年11月02日 44 0

网络上大量关于搭建ISCSI服务器的文章,说使用yum install scsi-target-utils -y来安装依赖,实际上是不可行的。基本上都会显示Nothing to do。那么,应该怎么安装呢?

一、安装iscsi服务器软件:

yum install epel-release -y
yum --enablerepo=epel -y install scsi-target-utils

完成后,需要启动:

[root@gzdg yum.repos.d]# systemctl start tgtd
[root@gzdg yum.repos.d]# systemctl enable tgtd
Created symlink from /etc/systemd/system/multi-user.target.wants/tgtd.service to /usr/lib/systemd/system/tgtd.service.

二、新建磁盘空间给iscsi使用 本次测试,将多个磁盘分配给iscsi使用:

[root@gzdg yum.repos.d]# fdisk /dev/sdc   # /dev/sdd, /dev/sde两个操作类似,不显示了
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 0x723a8211.
Command (m for help): n
Partition type:
 p primary (0 primary, 0 extended, 4 free)
 e extended
Select (default p): 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):
Using default value 20971519
Partition 1 of type Linux and of size 10 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

完成后检查:

[root@gzdg yum.repos.d]# ll /dev/sd*
brw-rw---- 1 root disk 8, 0 May 10 09:53 /dev/sda
brw-rw---- 1 root disk 8, 1 May 10 09:53 /dev/sda1
brw-rw---- 1 root disk 8, 2 May 10 09:53 /dev/sda2
brw-rw---- 1 root disk 8, 16 May 10 09:53 /dev/sdb
brw-rw---- 1 root disk 8, 32 May 10 15:35 /dev/sdc
brw-rw---- 1 root disk 8, 33 May 10 15:35 /dev/sdc1
brw-rw---- 1 root disk 8, 48 May 10 15:36 /dev/sdd
brw-rw---- 1 root disk 8, 49 May 10 15:36 /dev/sdd1
brw-rw---- 1 root disk 8, 64 May 10 15:37 /dev/sde
brw-rw---- 1 root disk 8, 65 May 10 15:37 /dev/sde1

三、创建连接 首先添加一个目标连接:

[root@gzdg yum.repos.d]# tgtadm --lld iscsi -m target --op new --tid 1 --targetname iqn.20220510.test.target.com

然后为目标添加逻辑单元:

[root@gzdg yum.repos.d]# tgtadm --mode logicalunit --op new --tid 1 --lun 1 --backing-store /dev/sdb1

如果还需要其他连接,可继续:

tgtadm --lld iscsi -m target --op new --tid 2 --targetname iqn.20230629.test.target.com
tgtadm --mode logicalunit --op new --tid 2 --lun 1 --backing-store /dev/sdb2

如需删除,可执行:

tgtadm --lld iscsi --op delete --mode logicalunit --tid 1 --lun 2

再后,配置访问控制:

tgtadm -m target --op bind -t 1 -I ALL # 允许所有IP访问

或者删除ALL的访问

tgtadm -m target --op unbind -t 1 -I ALL

添加某个IP对目标1的访问

tgtadm -m target --op bind -t 1 -I 10.10.10.40

至此完成配置。

最后需要保存配置不然iscsi服务可能会有问题

tgt-admin --dump > /etc/tgt/targets.conf

该命令是将刚刚的配置写入到 /etc/tgt/targets.conf 这个文件。 察看现有的连接目标,及其详细lun配置。

tgtadm -m target --op show

或者使用

tgt-admin -s

注意: 如果客户端无法发现服务器,如:

[root@rac01 ~]# iscsiadm -m discovery -t st -p 192.168.203.10
iscsiadm: cannot make connection to 192.168.203.10: No route to host
iscsiadm: cannot make connection to 192.168.203.10: No route to host
iscsiadm: cannot make connection to 192.168.203.10: No route to host
iscsiadm: cannot make connection to 192.168.203.10: No route to host
iscsiadm: cannot make connection to 192.168.203.10: No route to host
iscsiadm: cannot make connection to 192.168.203.10: No route to host
iscsiadm: connection login retries (reopen_max) 5 exceeded
iscsiadm: Could not perform SendTargets discovery: encountered connection failure

这是因为iscsi服务器的防火墙阻碍。需关闭防火墙,或准许对应设备连接:

systemctl stop firewalld.service
systemctl disable firewalld.service
systemctl status firewalld.service
【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  ehrZuhofWJiC   2024年05月17日   37   0   0 服务器linux
aOYB9Qh7rxCg