CentOS 7.x 下配置iSCSI网络存储

2019-05-26 09:41:06 浏览数 (1)

版权声明:本文为木偶人shaon原创文章,转载请注明原文地址,非常感谢。 https://cloud.tencent.com/developer/article/1434711

一、iSCSI简介

  • iSCSI(internet SCSI)技术由IBM公司研究开发,是一个供硬件设备使用的、可以在IP协议的上层运行的SCSI指令集,这种指令集合可以实现在IP网络上运行SCSI协议,使其能够在诸如高速千兆以太网上进行路由选择。iSCSI技术是一种新储存技术,该技术是将现有SCSI接口与以太网络(Ethernet)技术结合,使服务器可与使用IP网络的储存装置互相交换资料。
  • iSCSI是一种基于TCP/IP 的协议,用来建立和管理IP存储设备、主机和客户机等之间的相互连接,并创建存储区域网络(SAN)。SAN 使得SCSI 协议应用于高速数据传输网络成为可能,这种传输以数据块级别(block-level)在多个数据存储网络间进行。SCSI 结构基于C/S模式,其通常应用环境是:设备互相靠近,并且这些设备由SCSI 总线连接。
  • iSCSI 的主要功能是在TCP/IP 网络上的主机系统(启动器 initiator)和存储设备(目标器
  • 完整的iSCSI系统的拓扑结构如下:
  • 备注:上面一段内容出处:http://www.cnblogs.com/mchina/p/centos-iscsi-network-storage.html

二、实验环境

操作系统:CentOS Linux release 7.2.1511 (Core)

iSCSI Target:10.1.1.56 / vdevops.org

iSCSI Initiator:10.1.1.53 / linuxprobe.org

防火墙已关闭/iptables: Firewall is not running.

SELINUX已禁用:SELINUX=disabled

三、配置iSCSI Target

  • 首先安装管理工具 [root@vdevops ~]# yum -y install targetcli
  • 配置iSCSI目标。 例如,在/ iscsi_disks目录下创建磁盘映像并将其设置为SCSI设备
代码语言:javascript复制
#进入管理控制台
[root@vdevops ~]# targetcli
Warning: Could not load preferences file /root/.targetcli/prefs.bin.
targetcli shell version 2.1.fb41
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.
#在/iscsi_disks/disk01.img上使用2G创建名为“disk01”的磁盘映像
/> cd backstores/fileio 
/backstores/fileio> create disk01 /iscsi_disks/disk01.img 2G
Created fileio disk01 with size 2147483648
/backstores/fileio> cd /iscsi 
#创建目标
/iscsi> create iqn.2016-10.vdevops.org:storage.target00
Created target iqn.2016-10.vdevops.org:storage.target00.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/iscsi> cd iqn.2016-10.vdevops.org:storage.target00/tpg1/luns 
#设置 luns
/iscsi/iqn.20...t00/tpg1/luns> create /backstores/fileio/disk01 
Created LUN 0.
/iscsi/iqn.20...t00/tpg1/luns> cd ../acls 
/iscsi/iqn.20...t00/tpg1/acls> create iqn.2016-10.vdevops.org:vdevops.org
Created Node ACL for iqn.2016-10.vdevops.org:vdevops.org
Created mapped LUN 0.
#设置ACL(它是允许连接的启动器的IQN)
/iscsi/iqn.20...t00/tpg1/acls> cd iqn.2016-10.vdevops.org:vdevops.org/
#设置用于验证的UserID
/iscsi/iqn.20...g:vdevops.org> set auth userid=username
Parameter userid is now 'username'.
/iscsi/iqn.20...g:vdevops.org> set auth password=password
Parameter password is now 'password'.
/iscsi/iqn.20...g:vdevops.org> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
[root@vdevops ~]# ss -napt | grep 3260
LISTEN     0      256          *:3260                     *:*                  
[root@vdevops ~]# systemctl enable target
Created symlink from /etc/systemd/system/multi-user.target.wants/target.service to /usr/lib/systemd/system/target.service.
[root@vdevops ~]# firewall-cmd --add-service=iscsi-target --permanent
success
[root@vdevops ~]# firewall-cmd --reload
success 
  • 使用iSCSI配置存储服务器 这是使用scsi-target-utils配置iSCSI目标的示例
代码语言:javascript复制
[1] 安装 scsi-target-utils.
# 使用EPEL源安装
[root@vdevops ~]# yum --enablerepo=epel -y install scsi-target-utils 
[2]配置iSCSI目标。  
例如,在[/ iscsi_disks]目录下创建磁盘映像并将其设置为共享磁盘。
# 创建硬盘镜像
[root@vdevops ~]# mkdir /iscsi_disks   #无需重复创建
[root@vdevops ~]# dd if=/dev/zero of=/iscsi_disks/disk01.img count=0 bs=1 seek=2G  #同样无需重复创建 
[root@vdevops iscsi_disks]# vi /etc/tgt/targets.conf 
<target iqn.2016-10.vdevops.org: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.1.1.53
  # authentication info ( set anyone you like for "username", "password" )
  #
  incominguser username password
</target>
[3]如果SElinux为enable状态, 改变SElinux类型.
[root@vdevops ~]# chcon -R -t tgtd_var_lib_t /iscsi_disks
[root@vdevops ~]# semanage fcontext -a -t tgtd_var_lib_t /iscsi_disks
[4]如果防火墙开启,允许iSCSI Target服务
[root@vdevops ~]# firewall-cmd --add-service=iscsi-target --permanent
success
[root@vdevops ~]# firewall-cmd --reload
success 
  • 启动 tgtd并验证状态
代码语言:javascript复制
[root@vdevops ~]# systemctl start tgtd
[root@vdevops ~]# systemctl status tgtd
● tgtd.service - tgtd iSCSI target daemon
   Loaded: loaded (/usr/lib/systemd/system/tgtd.service; disabled; vendor preset: disabled)
   Active: active (running) since Mon 2016-10-31 20:46:10 CST; 7s ago
  Process: 2860 ExecStartPost=/usr/sbin/tgtadm --op update --mode sys --name State -v ready (code=exited, status=0/SUCCESS)
  Process: 2830 ExecStartPost=/usr/sbin/tgt-admin -e -c $TGTD_CONFIG (code=exited, status=0/SUCCESS)
  Process: 2829 ExecStartPost=/usr/sbin/tgtadm --op update --mode sys --name State -v offline (code=exited, status=0/SUCCESS)
  Process: 2828 ExecStartPost=/bin/sleep 5 (code=exited, status=0/SUCCESS)
 Main PID: 2827 (tgtd)
   CGroup: /system.slice/tgtd.service
           └─2827 /usr/sbin/tgtd -f

Oct 31 20:46:04 vdevops.org systemd[1]: Starting tgtd iSCSI target daemon...
Oct 31 20:46:04 vdevops.org tgtd[2827]: tgtd: iscsi_tcp_init_portal(347) unable to bind server socket, Address already in use
Oct 31 20:46:04 vdevops.org tgtd[2827]: tgtd: iser_ib_init(3436) Failed to initialize RDMA; load kernel modules?
Oct 31 20:46:04 vdevops.org tgtd[2827]: tgtd: work_timer_start(146) use timer_fd based scheduler
Oct 31 20:46:04 vdevops.org tgtd[2827]: tgtd: bs_init_signalfd(267) could not open backing-store module directory /usr/lib64/tgt/backing-store
Oct 31 20:46:04 vdevops.org tgtd[2827]: tgtd: bs_init(386) use signalfd notification
Oct 31 20:46:10 vdevops.org tgtd[2827]: tgtd: device_mgmt(246) sz:29 params:path=/iscsi_disks/disk01.img
Oct 31 20:46:10 vdevops.org tgtd[2827]: tgtd: bs_thread_open(408) 16
Oct 31 20:46:10 vdevops.org systemd[1]: Started tgtd iSCSI target daemon.
Hint: Some lines were ellipsized, use -l to show in full.
[root@vdevops ~]# systemctl enable tgtd
Created symlink from /etc/systemd/system/multi-user.target.wants/tgtd.service to /usr/lib/systemd/system/tgtd.service.
#查看状态
[root@vdevops ~]# tgtadm --mode target --op show
Target 1: iqn.2016-10.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: 2147 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.1.1.53
  • 配置iSCSI启动器
代码语言:javascript复制
#使用EPEL安装iscsi-initiator-utils
[root@linuxprobe ~]# yum -y install iscsi-initiator-utils 
[root@linuxprobe ~]# vi /etc/iscsi/initiatorname.iscsi
# change to the same IQN you set on the iSCSI target server
InitiatorName=iqn.2016-10.vdevops.org:vdevops.org
[root@linuxprobe ~]# vi /etc/iscsi/iscsid.conf
# line 57: 取消注释
node.session.auth.authmethod = CHAP
# line 61,62: 取消注释 and specify the username and password you set on the iSCSI target server
node.session.auth.username = username
node.session.auth.password = password
# 发现target
[root@linuxprobe ~]# iscsiadm -m discovery -t sendtargets -p 10.1.1.56
10.1.1.56:3260,1 iqn.2016-10.vdevops.org:storage.target00
[root@linuxprobe ~]# iscsiadm -m node -o show
# BEGIN RECORD 6.2.0.873-33.2
node.name = iqn.2016-10.vdevops.org:storage.target00
node.tpgt = 1
node.startup = automatic
node.leading_login = No
...
...
node.conn[0].iscsi.MaxXmitDataSegmentLength = 0
node.conn[0].iscsi.MaxRecvDataSegmentLength = 262144
node.conn[0].iscsi.HeaderDigest = None
node.conn[0].iscsi.IFMarker = No
node.conn[0].iscsi.OFMarker = No
# END RECORD
#登录target
[root@linuxprobe ~]# iscsiadm -m node --login
Logging in to [iface: default, target: iqn.2016-10.vdevops.org:storage.target00, portal: 10.1.1.56,3260] (multiple)
Login to [iface: default, target: iqn.2016-10.vdevops.org:storage.target00, portal: 10.1.1.56,3260] successful.
#确认连接状态
[root@linuxprobe ~]# iscsiadm -m session -o show
tcp: [1] 10.1.1.56:3260,1 iqn.2016-10.vdevops.org:storage.target00 (non-flash)
#确认分区状况
[root@linuxprobe ~]# cat /proc/partitions
major minor  #blocks  name

   2        0          4 fd0
   8        0   20971520 sda
   8        1     512000 sda1
   8        2   20458496 sda2
  11        0    4228096 sr0
 253        0   18317312 dm-0
 253        1    2097152 dm-1
   8       16    2097152 sdb
 #从目标服务器提供的添加的新设备为“sdb”
  • 设置iSCSI设备后,在启动器上配置如下所示
代码语言:javascript复制
#创建标签
[root@linuxprobe ~]# parted --script /dev/sdb "mklabel msdos"
# 创建分区
[root@linuxprobe ~]# parted --script /dev/sdb "mkpart primary 0% 100%"
# 格式化分区
[root@linuxprobe ~]# mkfs.xfs -i size=1024 -s size=4096 /dev/sdb1
meta-data=/dev/sdb1              isize=1024   agcount=4, agsize=130560 blks
         =                       sectsz=4096  attr=2, projid32bit=1
         =                       crc=0        finobt=0
data     =                       bsize=4096   blocks=522240, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=4096  sunit=1 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
# 挂载分区
[root@linuxprobe ~]# mount /dev/sdb1 /mnt/
# 查看系统挂载
[root@linuxprobe ~]# df -hT
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs        18G  1.9G   16G  11% /
devtmpfs                devtmpfs  483M     0  483M   0% /dev
tmpfs                   tmpfs     493M     0  493M   0% /dev/shm
tmpfs                   tmpfs     493M  6.7M  487M   2% /run
tmpfs                   tmpfs     493M     0  493M   0% /sys/fs/cgroup
/dev/sda1               xfs       497M  125M  373M  26% /boot
tmpfs                   tmpfs      99M     0   99M   0% /run/user/0
**/dev/sdb1               xfs       2.0G   33M  2.0G   2% /mnt**

到此,我们可以看到ISCSI配置完成,可以正常使用。

  • ISCSI百度百科:http://baike.baidu.com/link?url=-OA1le_DbAh5ybVq1ZBTbPHJqQb5-jma5vhKR5nCAC7C11UDSwNn_6mPYj0AiABrm8OM2MoExN__9GvzvhVg8K

0 人点赞