centos7搭建iscsi存储

本文详细介绍如何在Linux系统上安装并配置iSCSI目标服务,包括安装必要的软件包、设置共享磁盘映像、调整SELinux上下文、启用防火墙规则及启动验证iSCSI目标服务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[1] Install scsi-target-utils.

# install from EPEL
[root@dlp ~]# yum --enablerepo=epel -y install scsi-target-utils

[2] Configure iSCSI Target.
For example, create a disk image under the [/iscsi_disks] directory and set it as a shared disk.

# create a disk image
[root@dlp ~]# mkdir /iscsi_disks 
[root@dlp ~]# dd if=/dev/zero of=/iscsi_disks/disk01.img count=0 bs=1 seek=10G
[root@dlp ~]# vi /etc/tgt/targets.conf
# add follows to the end
# if you set some devices, add <target>-</target> and set the same way with follows
# naming rule : [ iqn.yaer-month.domain:any name ]
<target iqn.2015-12.world.srv:target00>
    # provided devicce as a iSCSI target
    backing-store /iscsi_disks/disk01.img
    # iSCSI Initiator's IP address you allow to connect
    initiator-address 10.0.0.31
    # authentication info ( set anyone you like for "username", "password" )
    incominguser username password
</target>

我自己的/etc/tgt/targets.conf,因为我机器上创建了4个逻辑卷/dev/iscsi/target1-4

<target iqn.2016-06.com.onecloud:server.target>
    <backing-store /dev/iscsi/target1>
      lun 1
    </backing-store>
    <backing-store /dev/iscsi/target2>
      lun 2
    </backing-store>
    <backing-store /dev/iscsi/target3>
      lun 3
    </backing-store>
    <backing-store /dev/iscsi/target4>
      lun 4
    </backing-store>
    write-cache off
    initiator-address 172.16.0.0/16
</target>

[3] If SELinux is enabled, change SELinux Context.

[root@dlp ~]# chcon -R -t tgtd_var_lib_t /iscsi_disks 
[root@dlp ~]# semanage fcontext -a -t tgtd_var_lib_t /iscsi_disks 

[4] If Firewalld is running, allow iSCSI Target service.

[root@dlp ~]# firewall-cmd --add-service=iscsi-target --permanent 
success
[root@dlp ~]# firewall-cmd --reload 
success

[5] Start tgtd and verify status.

[root@dlp ~]# systemctl start tgtd 
[root@dlp ~]# systemctl enable tgtd 
# show status
[root@dlp ~]# tgtadm --mode target --op show 
Target 1: iqn.2015-12.world.srv:target00
    System information:
        Driver: iscsi
        State: ready
    I_T nexus information:
    LUN information:
        LUN: 0
            Type: controller
            SCSI ID: IET     00010000
            SCSI SN: beaf10
            Size: 0 MB, Block size: 1
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            SWP: No
            Thin-provisioning: No
            Backing store type: null
            Backing store path: None
            Backing store flags:
        LUN: 1
            Type: disk
            SCSI ID: IET     00010001
            SCSI SN: beaf11
            Size: 10737 MB, Block size: 512
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            SWP: No
            Thin-provisioning: No
            Backing store type: rdwr
            Backing store path: /iscsi_disks/disk01.img
            Backing store flags:
    Account information:
        username
    ACL information:
        10.0.0.31
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值