ISCSI服务的配置

简介:

首先是安装,在配置好yum源的情况下直接安装scsi-target-utils即可:

yum -y install scsi-target-utils

然后查看下scsi-target-utils的信息
[root@monitor ~]# yum info scsi-target-utils


启动iscsi服务
[root@monitor ~]# service tgtd start


创建一个target

tgtadm --lld <driver> --op new --mode target --tid <id> --targetname <name>
<driver>   表示要加载的驱动类型(一般为iscsi)
<id>  指定target的id号
<name>  指定iqn名称一般是iqn.日期.翻转域名.磁盘名称

[root@monitor ~]# tgtadm --lld iscsi --op new --mode target --tid=1  --targetname iqn.20160203.cn.cdzyczs:disk1




查看当前建好的target
[root@monitor ~]# tgtadm --lld iscsi --op show --mode target
[root@rac1 ~]# tgtadm --lld iscsi --op show --mode target
Target 1: iqn.20160203.cn.cdzyczs:disk1
    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
            Readonly: No
            Backing store type: null
            Backing store path: None
            Backing store flags: 
    Account information:
    ACL information:


target创建lun并且添加硬盘(可以多次执行添加多块,不过注意lun不可以重复出现)
[root@monitor ~]# tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 1 --backing-store /dev/sharedisk1



创建ACL访问控制

[root@monitor ~]# tgtadm --lld iscsi --op bind --mode target --tid 1 --initiator-address ALL
将tid绑定到特定的客户端IP,仅绑定的主机可以访问本iscsi,如果使用“ALL”,则表示所有IP都允许访问。

查看当target信息
[root@monitor ~]# tgtadm --lld iscsi --op show --mode target
Target 1: iqn.20160203.cn.cdzyczs:disk1
    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
            Readonly: No
            Backing store type: null
            Backing store path: None
            Backing store flags: 
        LUN: 1
            Type: disk
            SCSI ID: IET     00010001
            SCSI SN: beaf11
            Size: 107373 MB, Block size: 512
            Online: Yes
            Removable media: No
            Readonly: No
            Backing store type: rdwr
            Backing store path: /dev/sharedisk1
            Backing store flags: 
    Account information:
    ACL information:
        10.0.0.7,10.0.0.8
        ALL
[root@monitor ~]# 

客户端挂载
安装iscsi客户端程序
yum -y install  iscsi-initiator-utils

[root@monitor ~]# iscsiadm --mode discoverydb --type sendtargets --portal 10.0.0.5 --discover
正在启动 iscsid:                                          [确定]
10.0.0.5:3260,1 iqn.20160203.cn.cdzyczs:disk1   //检测到的iqn名称
[root@monitor ~]# 

挂载iscsi磁盘
[root@monitor ~]# iscsiadm --mode node --targetname iqn.20160203.cn.cdzyczs:disk1 --portal 10.0.0.5:3260 --login

如果要卸载磁盘,卸载iscsi磁盘的命令:
[root@monitor ~]# iscsiadm --mode node --targetname iqn.20160203.cn.cdzyczs:disk1 --portal 10.0.0.5:3260 --logout


配置文件的方式创建永久的iscsi服务器

vi  /etc/tgt/targets.conf
<target iqn.20160203.cn.cdzyczs:disk1>    #iqn名称
    backing-store /dev/sdg     # Becomes LUN 1   添加磁盘
    initiator-address ALL     #创建ACL,允许哪些主机访问
</target>


共享磁盘的分区、格式化和挂载(在其中一台客户端上执行):

1、在客户端使用fdisk -l查看共享磁盘的名称,例如是  /dev/sdb

2、分区,使用命令:fdisk /dev/sdb   ->  n   -> p   ->  1,根据实际需要分配空间

3、格式化,使用命令:  mkfs -t ext4 /dev/sdb1

4、建立文件系统并且挂载。  建目录:   mkdir /home/tools/sharedir,挂载文件系统:  mount /dev/sdb1 /home/tools/sharedir





收尾工作:

1、检查服务端的tgtd服务是否开机自启动:

 chkconfig --list tgtd 
 如果不是自启动,使用"chkconfig 服务名 on  "命令开启。

2、检查客户端的iscsi服务、iscsid服务是否开机自启动:

 chkconfig --list |grep iscsi

如果不是自启动,使用"chkconfig 服务名 on  "命令开启。






本文转自yuweibing51CTO博客,原文链接:http://blog.51cto.com/yuweibing/1740866,如需转载请自行联系原作者






相关文章
|
1月前
|
数据安全/隐私保护
|
1月前
|
存储 运维 Linux
ISCSI详解(五)——ISCSI客户端配置实战
ISCSI详解(五)——ISCSI客户端配置实战
39 5
|
1月前
|
运维 Linux
ISCSI详解(四)——ISCSI服务端配置实战
ISCSI详解(四)——ISCSI服务端配置实战
31 5
|
Linux Shell 开发工具
|
Shell Linux 开发工具
|
存储 网络协议 IDE
|
存储 网络协议 开发工具
|
存储 Unix Linux