zoukankan      html  css  js  c++  java
  • 配置一个IP SAN 存储服务器

    实战: 配置一个IP SAN 存储服务器

    IP-SAN的运行模式:C/S模式,工作端口3260

    服务端:服务名-target             机器A(目标)

    客户端:服务名-initator        机器B,机器C(发起人).

     

    安装target

    [root@机器A ~]# yum -y install epel-release

    [root@机器A Desktop]# yum install -y scsi-target-utils

     

    主配置文件:

    [root@机器A ~]# ls  /etc/tgt/targets.conf

     

    启动服务:

    [root@机器A ~]# /etc/init.d/tgtd start

    [root@机器A ~]# netstat -antup | grep 3260

     

    新建存储分区: sda4  大小5G

    [root@机器A ~]# fdisk /dev/sda    #划分出sda4分区

    WARNING: DOS-compatible mode is deprecated. It's strongly recommended to

             switch off the mode (command 'c') and change display units to

             sectors (command 'u').

    Command (m for help): p

    Disk /dev/sda: 21.5 GB, 21474836480 bytes

    255 heads, 63 sectors/track, 2610 cylinders

    Units = cylinders of 16065 * 512 = 8225280 bytes

    Sector size (logical/physical): 512 bytes / 512 bytes

    I/O size (minimum/optimal): 512 bytes / 512 bytes

    Disk identifier: 0x000b8b35

       Device Boot      Start         End      Blocks   Id  System

    /dev/sda1   *           1          26      204800   83  Linux

    Partition 1 does not end on cylinder boundary.

    /dev/sda2              26        1301    10240000   83  Linux

    /dev/sda3            1301        1428     1024000   82  Linux swap / Solaris

     

    Command (m for help): n

    Command action

       e   extended

       p   primary partition (1-4)

    p

    Selected partition 4

    First cylinder (1428-2610, default 1428):

    Using default value 1428

    Last cylinder, +cylinders or +size{K,M,G} (1428-2610, default 2610): +5G

     

    Command (m for help): w

    The partition table has been altered!

    Calling ioctl() to re-read partition table.

    WARNING: Re-reading the partition table failed with error 16: Device or resource busy.

    The kernel still uses the old table. The new table will be used at

    the next reboot or after you run partprobe(8) or kpartx(8)

    Syncing disks.

     

    [root@thinkmo3 ~]#reboot  或者   partx -a /dev/sda  #使分区生效,多执行几次即可

     

    配置sda4共享

     

    修改配置文件

    [root@机器A ~]# vim /etc/tgt/targets.conf       #写入以下内容

    下面这段内容是参考模板

     75 #<target iqn.2008-09.com.example:server.target4>

     76 #    direct-store /dev/sdb      # Becomes LUN 1

     77 #    direct-store /dev/sdc      # Becomes LUN 2

     78 #    direct-store /dev/sdd      # Becomes LUN 3

     79 #    write-cache off

     80 #    vendor_id MyCompany Inc.

     81 #</target>

    在上面模版后面新增内容为:

    <target iqn.2018-01.cn.thinkmo.www:target_san1>

             backing-store  /dev/sda4

             initiator-address 192.168.1.64

             vendor_id  thinkmo

             product_id   target1

    </target>

     

    注释:

    default-driver iscsi      #此配置文件默认全部注释,使用iscsi驱动  

    <tarrget iqn.2018-1.cn.thinkmo.www:target_san1>  # iscsi正规名字格式:  iqn.年-月.主机名倒着写: target端名字

    backing-store /dev/hda4     #可以是具体的分区,也可以是DD出来的文件。不能小于5G。 (后面的文件系统是GFS,光日志空间就128M)        

    initiator-address 192.168.1.62   #指定允许访问的此存储主机

    initiator-address 192.168.1.64   #指定允许访问的此存储主机

    vendor_id “thinkmo”    #vendor是供应厂商编号标识这个设备(字符不要过长)

    product_id "TARGET1"     # 产品编号

    </target>

    启动服务

    [root@机器A Desktop]# systemctl restart tgtd

    [root@机器A Desktop]# netstat  -antup | grep 3260或者tgt-admin  –show查看状态

    Target 1: iqn.2015-01.cn.thinkmo.www:target_san1

        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: 5372 MB, Block size: 512

                Online: Yes

                Removable media: No

                Readonly: No

                Backing store type: rdwr

                Backing store path: /dev/sda4

                Backing store flags:

        Account information:

        ACL information: #允许哪些客户端可以访问

            192.168.1.64

     

    配置客户端: 机器B

    安装包:

    [root@机器B ~]# yum install -y iscsi-initiator-utils

     

    启动客户端服务:

    [root@机器B~]# systemctl start iscsid #直接启动没有任何反应, 这里首先要发现target存储,再启动客户端服务,才有效

    [root@机器B~]# iscsiadm -m discovery -t sendtargets -p 192.168.1.63:3260

    Starting iscsid:                                           [  OK  ]

    192.168.1.63:3260,1 iqn.2018-01.cn.thinkmo.www:target_san1

    [root@机器B~]#  /etc/init.d/iscsid status

    iscsid (pid  2607) is running...

     

    target存储服务器信息在客户端存储的位置:

    [root@机器B~]# yum install -y tree      #安装tree命令,用于查询树

    [root@机器B~]# tree /var/lib/iscsi/       #发现target后,会在此目录先生成树结构

    /var/lib/iscsi/

    ├── ifaces

    ├── isns

    ├── nodes

    │   └── iqn.2015-01.cn.thinkmo.www:target_san1

    │       └── 192.168.1.63,3260,1

    │           └── default

    ├── send_targets

    │   └── 192.168.1.63,3260

    │       ├── iqn.2015-01.cn.thinkmo.www:target_san1,192.168.1.63,3260,1,default -> /var/lib/iscsi/nodes/iqn.2015-01.cn.thinkmo.www:target_san1/192.168.1.63,3260,1

    │       └── st_config

    ├── slp

    └── static

     

    客户端服务启动关系

     

    先启动iscsid,再启动iscsi,iscsi是根据/var/lib/iscsi/中发现的信息,识别设备

    [root@机器B~]#systemctl start iscsid  #先启动iscsid

    [root@机器B~]# systemctl start iscsi   # 根据/var/lib/iscsi/  中发现的信息,识别设备

    Stopping iscsi:                                            [  OK  ]

    Starting iscsi:                                            [  OK  ]

    关闭:

    [root@机器B~]# systemctl stop iscsi

    [root@机器B~]# systemctl stop iscsid

     

    开机自动启动:

    [root@机器B~]# chkconfig  iscsi on

    [root@机器B~]# chkconfig  iscsid on

     

     

     

    查看发现到新硬盘:

    [root@机器B~]# ll /dev/sdb

    brw-rw---- 1 root disk 8, 16 Jul 30 19:11 /dev/sdb

     

      卸载,挂载存储设备

    卸载

    [root@机器B~]#  iscsiadm -m node -T iqn.2018-01.cn.thinkmo.www:target_san1 -u

    Logging out of session [sid: 1, target: iqn.2015-01.cn.thinkmo.www:target_san1, portal: 192.168.1.63,3260]

    Logout of [sid: 1, target: iqn.2015-01.cn.thinkmo.www:target_san1, portal: 192.168.1.63,3260] successful.

    [root@机器B~]# ls /dev/sdb  #查看设备不存在

    ls: cannot access /dev/sdb: No such file or directory

     

    登录存储存储设备

    [root@机器B~]# iscsiadm -m node -T iqn.2018-01.cn.thinkmo.www:target_san1 -l

    Logging in to [iface: default, target: iqn.2018-01.cn.thinkmo.www:target_san1, portal: 192.168.1.63,3260] (multiple)

    Login to [iface: default, target: iqn.2018-01.cn.thinkmo.www:target_san1, portal: 192.168.1.63,3260] successful.

    [root@机器B~]# ls /dev/sdb  

    /dev/sdb

     

    上面的方法看起来比较复杂,命令比较长,简单的通过服务卸载与登陆

     

    卸载方法二:

    [root@机器B~]# systemctl stop iscsi

    Stopping iscsi:                                            [  OK  ]

    [root@机器B~]# ls /dev/sdb

    ls: cannot access /dev/sdb: No such file or directory

    登录方法二:

    [root@机器B~]# systemctl restart iscsi

     

    彻底退出:

    [root@机器B~]# systemctl stop iscsi

    [root@机器B~]# rm -rf /var/lib/iscsi/*

     

     

    实例1: 在thinkmo4上对识别出来的硬盘,分区格式化,挂载使用。

    [root@机器B~]# iscsiadm -m discovery -t sendtargets -p 192.168.1.63:3260   #发现存储设备

    [root@机器B~]# systemctl restart iscsid  #登录存储

    [root@机器B~]# systemctl restart iscsi

    [root@机器B~]# ls /dev/sdb      #发现sdb

    /dev/sdb

     

     

    分区格式化,挂载使用

    [root@机器B~]# fdisk /dev/sdb   #划分一个分区当作本地盘使用即可

    [root@机器B~]# ll /dev/sdb*      #查看分区

    [root@机器B~]# mkfs.ext4 /dev/sdb1     #格式化分区

    [root@机器B~]# mount /dev/sdb1 /opt/      #挂载使用

    [root@机器B~]# cp /etc/passwd /opt/          #测试文件写入

     

    例2: 在target服务端,再添加一个存储客户端:

    添加如下内容:

    [root@机器A~]# vim /etc/tgt/targets.conf

    <target iqn.2018-01.cn.thinkmo.www:target_san1>

             backing-store  /dev/sda4

             initiator-address 192.168.1.64

             initiator-address 192.168.1.62  #添加一个客户端                 

     vendor_id  thinkmo

             product_id   target1

    </target>

     

    [root@机器A ~]# systemctl restart tgtd

    Stopping SCSI target daemon: initiators still connected    [FAILED]

    Starting SCSI target daemon:                               [FAILED]

    解决:客户端退出一下

    [root@机器B~]# umount /opt/   #客户端卸载

    [root@机器B~]# systemctl stop  iscsi  #客户端停止服务,做了这两个,再启动服务器端,否则,数据损失丢弃清空的情况发生。

     

    客户端退出后,再测试启动:

    [root@机器A~]# /etc/init.d/tgtd restart

    Stopping SCSI target daemon:                               [  OK  ]

    Starting SCSI target daemon:                               [  OK  ]

    [root@机器A~]# tgt-admin –show  #查看情况

     

    测试: 机器B机器C都挂载上硬盘,数据同步

     

    [root@机器B~]# systemctl start iscsid

    [root@机器B~]# systemctl start iscsi

    [root@机器B~]# ls /dev/sdb*

    /dev/sdb  /dev/sdb1

    [root@机器B~]# ls /dev/sdb*

    /dev/sdb  /dev/sdb1

    [root@机器B~]# mount /dev/sdb1 /opt/

    [root@机器B~]# cp /etc/passwd /opt/    #复制一些数据

     

     

    测试:机器C是否数据同步

    [root@机器C ~]# yum –y install iscsi-initiator-utils

    [root@机器C~]#  iscsiadm -m discovery -t sendtargets -p 192.168.1.63:3260

    192.168.1.63:3260,1 iqn.2018-01.cn.thinkmo.www:target_san1

    [root@机器C~]# systemctl restart iscsid

    [root@机器C~]# systemctl restart iscsi

    有时候环境和你操作的顺序问题,可能无法发现,重启一下SAN Server,然后两台客户端重新sendtargets一下,重新启动服务和挂载.

    [root@机器C~]# ls /dev/sdb*

    /dev/sdb  /dev/sdb1

    [root@机器C~]# mount /dev/sdb1 /opt/

    [root@机器C~]#ls /opt/      #可以看到数据已经同步过来了

    lost+found  passwd

    添加新数据测试同步:

    [root@机器C~]# cp  /etc/hosts   /opt

    [root@机器C~]# ls /opt

    hosts  lost+found  passwd

     

    机器B上查看:

    [root@机器B~]# ls /opt

    lost+found  passwd

    # passwd  #只看到passwd

     

    没有同步,是因为我们使用的ext4 文件系统,ext4文件系统不支持多个客户端同时使用。 使用GFS文件系统就可以同步。

  • 相关阅读:
    POJ 2947:Widget Factory 求同余方程
    高斯消元几道入门题总结POJ1222&&POJ1681&&POJ1830&&POJ2065&&POJ3185
    POJ 1166:The Clocks
    神经网络 --学习之路,资料汇编
    机器学习 入门资料汇编
    无符号 coredump调试
    CentOS 6.3 升级软件 gcc等,并安装部署DNN环境 (未完成,不完整)
    OpenCL size_t error
    Nervanasys --> pycuda --> installation
    tmux.conf
  • 原文地址:https://www.cnblogs.com/wendyluo/p/13393434.html
Copyright © 2011-2022 走看看