RHEL6 搭建部署共享存储服务

本文涉及的产品
简介:

什么是存储

存储是根据不同的应用环境通过采取合理,安全,有效的方式将数据保存到某些介质上并能保证有效的访问

一方面它是数据临时或长期驻留的物理媒介

另一方面,它是保证数据完整安全存放的方式或行为

存储就是把这两方面结合起来,向客户提供一套数据存放解决方案


存储介质: 内存(临时存储)  磁盘(永久存储)


数据存储位置: 云存储 本地 共享存储 分布式存储



存储技术分类

SCSI 小型计算机系统接口                        

DAS 直连式存储

NAS 网络技术存储

SAN 存储区域网络

FC 光纤通道

存储.jpg


SCSI技术

Small Computer System Interface的简称

作为输入/输出接口

主要用于硬盘,光盘,磁带机等设备


DAS技术

Direct-Attached Storage的简称

将存储设备通过SCSI接口或光纤通道直接连接到计算机上

不能实现数据与其他主机的共享

占用服务器操作系统资源,如CPU,IO

数据量越大,性能越差


NAS技术

Network-Attached Storage的简称

一种专用数据存储服务器,以数据为中心,将存储设备与服务器彻底分离,集中管理数据,从而释放带宽,提取性能,降低总拥有成分,保护投资

用户通过TCP/IP协议访问数据


SAN技术

Storage Area Network的简称

    — 通过光纤交换机,光纤路由器,光纤集线器等设备将磁盘阵列,磁带等存储设备与相关服器连接起来,形成高速专用网络

组成部分

    — 如路由器,光纤交换机

    — 接口:如SCSI,FC

    — 通用协议:如IP,SCSI


FC技术

Fibre Channel

    — 一种合适千兆数据传输的,成熟而安全解决方案

    — 与传统的SCSI相比,FC提供更高的数据传输速率,更远的传输速率,更远的传输距离,更多的设备连接支持以及更稳定的性能,更简易的安装

FC主要组件

    — 光纤

    — HBA (主机总线适配置器 )

    — FC交换机

FC交换机交换拓扑

    — 点到点:point-to-point

        简单将两个设备互连

    — 已裁定的环路:arbitrated loop

        可多达126个设备共享一段信或环路

    — 交换式拓扑:switched fabric

        所有设备通过光纤交换机互连


ISCI技术

    Inetnet SCSI

    IETF制定的标准,将SCSI数据块映射为以太网数据包

    是一种基于IP Storage理论的新型存储技术

    将存储行业广泛应用的SCSI接口技术与IP网络像结合

    可以在IP网络上构建SAN

    最初由Cisco和IBM开放

isci优势

    — 基于IP协议技术的标准

    — 允许网络在TCP/IP协议上传输SCSI命令

    — 相对了传输效率,存储容量,兼容性,开放性,安全性等方面的问题

    — 没有距离限制

客户端

    — ISCSI Initiator : 软件实现,成本低,性能较低

    — ISCSI HBA:硬件实现,性能好,成本较高

存储设备端

    — ISCSI Target

存储.jpg.jpg


配置iSCSI服务


在存储设备端  主机56 上添加 三块 3G 硬盘

# lsblk 

NAME                        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT

...

vdb                         252:16   0    3G  0 disk 

vdc                         252:32   0    3G  0 disk 

vdd                         252:48   0    3G  0 disk 



在56 主机上使用SAN技术共享存储空间

(/dev/vdb  /dev/vdc) 给前端应服务器 53 和 54

4.jpg




一 配置后端存储

    装包

    # yum list | grep -i scsi

    iscsi-initiator-utils.x86_64           6.2.0.873-14.el6                  dvd    

    lsscsi.x86_64                          0.23-3.el6                        dvd    

    scsi-target-utils.x86_64               1.0.24-16.el6                     dvd    

    # yum -y install scsi-target-utils

    # rpm -q scsi-target-utils

    scsi-target-utils-1.0.24-16.el6.x86_64

    # rpm -qc scsi-target-utils

    /etc/sysconfig/tgtd

    /etc/tgt/targets.conf    //主配置文件

    # cp /etc/tgt/targets.conf /root/  //备份主配置文件

    # chkconfig tgtd on

    # chkconfig --list tgtd 

    tgtd            0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭


    修改配置文件

    # vim /etc/tgt/targets.conf 

    .. ..

      <target iqn.2018-01.com.www:pc56.diskb> //iqn描述信息 

          backing-store /dev/vdb //定义存储设备/dev/vdb

          write-cache off

         #initiator-address 192.168.4.53 //限制只有此ip可以访问  这里注释是采取默认共享给所有人

          vendor_id  xuenqlve //生产厂家

          product_id disk1 //型号

      </target>

      

      <target iqn.2018-01.com.www:pc56.diskc>

          backing-store /dev/vdc

         write-cache off

         #initiator-address 192.168.4.54

          vendor_id  xuenqlve

          product_id disk2

      </target>

    .. ..

    启动服务

    # service tgtd start

    正在启动 SCSI target daemon:                              [确定]

    # netstat -pantu | grep tgtd

    tcp        0      0 0.0.0.0:3260                0.0.0.0:*                   LISTEN      2728/tgtd           

    tcp        0      0 :::3260                     :::*                        LISTEN      2728/tgtd 

    

查看共享信息

    # tgt-admin --show //查看共享信息   命令行输出配置文件内容

    Target 1: iqn.2018-01.com.www:pc56.diskb

        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

                Backing store type: null

                Backing store path: None

                Backing store flags: 

            LUN: 1

                Type: disk

                SCSI ID: IET     00010001

                SCSI SN: beaf11

                Size: 3221 MB, Block size: 512

                Online: Yes

                Removable media: No

                Prevent removal: No

                Readonly: No

                Backing store type: rdwr

                Backing store path: /dev/vdb

                Backing store flags: 

        Account information:

        ACL information:

            ALL

    Target 2: iqn.2018-01.com.www:pc56.diskc

        System information:

            Driver: iscsi //设备

            State: ready //状态

        I_T nexus information:

        LUN information:

            LUN: 0

                Type: controller

                SCSI ID: IET     00020000

                SCSI SN: beaf20

                Size: 0 MB, Block size: 1

                Online: Yes

                Removable media: No

                Prevent removal: No

                Readonly: No

                Backing store type: null

                Backing store path: None

                Backing store flags: 

            LUN: 1

                Type: disk

                SCSI ID: IET     00020001

                SCSI SN: beaf21

                Size: 3221 MB, Block size: 512

                Online: Yes //当前是否可用

                Removable media: No

                Prevent removal: No

                Readonly: No

                Backing store type: rdwr

                Backing store path: /dev/vdc    //共享盘

                Backing store flags: 

        Account information:

        ACL information: //访问控制列表

            ALL

    

    

二  配置前端

    装包

    # yum list | grep -i scsi

    iscsi-initiator-utils.x86_64           6.2.0.873-14.el6                  dvd    

    lsscsi.x86_64                          0.23-3.el6                        dvd    

    scsi-target-utils.x86_64               1.0.24-16.el6                     dvd =

    # yum -y install iscsi-initiator-utils

    # rpm -qc iscsi-initiator-utils

    /etc/iscsi/iscsid.conf

    /etc/logrotate.d/iscsiuiolog

    

    # /etc/init.d/iscsi status    //当前为启动

    iscsi 已停

    # chkconfig --list iscsid //默认开机自启

    iscsid          0:关闭 1:关闭 2:关闭 3:启用 4:启用 5:启用 6:关闭

    

    发现设备

    # iscsiadm --mode discoverydb --type sendtargets --portal 192.168.4.56 --discover

    正在启动 iscsid:                                          [确定]

    192.168.4.56:3260,1 iqn.2018-01.com.www:pc56.diskb

    192.168.4.56:3260,1 iqn.2018-01.com.www:pc56.diskc

    

    登录设备

    # iscsiadm --mode node --targetname iqn.2018-01.com.www:pc56.diskb --portal 192.168.4.56:3260 --login

    Logging in to [iface: default, target: iqn.2018-01.com.www:pc56.diskb, portal: 192.168.4.56,3260] (multiple)

    Login to [iface: default, target: iqn.2018-01.com.www:pc56.diskb, portal: 192.168.4.56,3260] successful.

    

    查看登录信息

    # fdisk -l

    ...

    Disk /dev/sda: 3221 MB, 3221225472 bytes

    100 heads, 62 sectors/track, 1014 cylinders

    Units = cylinders of 6200 * 512 = 3174400 bytes

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

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

    Disk identifier: 0x00000000

    

    # ls /dev/sd*

    /dev/sda

    

    登出设备   

    # iscsiadm --mode node --targetname iqn.2018-01.com.www:pc56.diskb --portal 192.168.4.56:3260 --logout

    Logging out of session [sid: 1, target: iqn.2018-01.com.www:pc56.diskb, portal: 192.168.4.56,3260]

    Logout of [sid: 1, target: iqn.2018-01.com.www:pc56.diskb, portal: 192.168.4.56,3260] successful.

    

    //--mode 可以用 -m    --type 可以换用 -t   --login 可以换用 -l  --logout 可以换用 -u  

    

    登录共享磁盘 顺序会影响设备在本机的命名名称

     

三. 配置UDV

    1 获取硬件设备的参数信息

    # ls /dev/sd*

    /dev/sda

    # ls /etc/udev/rules.d/   UDV程序目录   文件名命名规则 数字-描述信息.rules   数字越小 运行时优先级越高

    # which udevadm

    /sbin/udevadm

    # udevadm --help

    Usage: udevadm [--help] [--version] [--debug] COMMAND [COMMAND OPTIONS]

      info         query sysfs or the udev database

      trigger      request events from the kernel

      settle       wait for the event queue to finish

      control      control the udev daemon

      monitor      listen to kernel and udev events

      test         simulation run

    //获取 加载设备 路径信息

    # udevadm info  --query=path --name=/dev/sda

    /devices/platform/host3/session2/target3:0:0/3:0:0:1/block/sda

    //获取路径信息对应的设备参数

    # udevadm info  --path=/devices/platform/host3/session2/target3:0:0/3:0:0:1/block/sda --attribute-walk

    ...

        SUBSYSTEM=="block"

        ATTR{size}=="6291456"

    ...

        ATTRS{vendor}=="xuenqlve"

        ATTRS{model}=="disk1           "

    ...

    //登录另一个设备

    #  iscsiadm --mode node --targetname iqn.2018-01.com.www:pc56.diskc --portal 192.168.4.56:3260 --login

    # ls /dev/sd*

    /dev/sda  /dev/sdb

    # udevadm info  --query=path --name=/dev/sdb

    /devices/platform/host4/session3/target4:0:0/4:0:0:1/block/sdb

    # udevadm info  --path=/devices/platform/host4/session3/target4:0:0/4:0:0:1/block/sdb --attribute-walk

    ...

        SUBSYSTEM=="block"

        ATTR{size}=="6291456"

    ...

        ATTRS{vendor}=="xuenqlve"

        ATTRS{model}=="disk2           "

    ...

    

    

    2 编写存放硬件设备的参数的UDV程序的配置文件

    # vim /etc/udev/rules.d/70-iscsidisk.rules

    SUBSYSTEM=="block", ATTR{size}=="6291456", ATTRS{vendor}=="xuenqlve", ATTRS{model}=="disk1           ", SYMLINK+="iscsi/sdb"

    SUBSYSTEM=="block", ATTR{size}=="6291456", ATTRS{vendor}=="xuenqlve", ATTRS{model}=="disk2           ", SYMLINK+="iscsi/sdc"

    

               // SYMLINK+=""    生成一个链接文件


    3 启动UDV

    # start_udev

    正在启动 udev:                                            [确定]

    # ls /dev/iscsi/ -l

    总用量 0

    lrwxrwxrwx. 1 root root 6 1月  13 06:13 sdb -> ../sda

    lrwxrwxrwx. 1 root root 6 1月  13 06:13 sdc -> ../sdb

    

    4 查看命名信息

    //测试 全部登出

    # iscsiadm --mode node --targetname iqn.2018-01.com.www:pc56.diskb --portal 192.168.4.56:3260 --logout

    # iscsiadm --mode node --targetname iqn.2018-01.com.www:pc56.diskc --portal 192.168.4.56:3260 --logout

    # ls /dev/sd*

    ls: 无法访问/dev/sd*: 没有那个文件或目录

    //先登录 diskc

    # iscsiadm --mode node --targetname iqn.2018-01.com.www:pc56.diskc --portal 192.168.4.56:3260 --login

    # ls /dev/sd*

    /dev/sda

    # ls /dev/iscsi/ -l

    总用量 0

    lrwxrwxrwx. 1 root root 6 1月  13 06:16 sdc -> ../sda

    //再登录 diskb

    # iscsiadm --mode node --targetname iqn.2018-01.com.www:pc56.diskb --portal 192.168.4.56:3260 --login

    # ls /dev/sd*

    /dev/sda  /dev/sdb

    # ls /dev/iscsi/ -l

    总用量 0

    lrwxrwxrwx. 1 root root 6 1月  13 06:17 sdb -> ../sdb

    lrwxrwxrwx. 1 root root 6 1月  13 06:16 sdc -> ../sda

    

    

        

四 . 使用共享存储磁盘存储数据

    分区 — > 格式化 — > 挂载 —> 存储数据

    分区

    # fdisk /dev/iscsi/sdb 

    Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

    Building a new DOS disklabel with disk identifier 0x23b0ff1a.

    Changes will remain in memory only, until you decide to write them.

    After that, of course, the previous content won't be recoverable.

    

    Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

    

    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): n

    Command action

       e   extended

       p   primary partition (1-4)

    p

    Partition number (1-4): 1

    First cylinder (1-1014, default 1): 1

    Last cylinder, +cylinders or +size{K,M,G} (1-1014, default 1014): 

    Using default value 1014

    

    Command (m for help): p

    

    Disk /dev/iscsi/sdb: 3221 MB, 3221225472 bytes

    100 heads, 62 sectors/track, 1014 cylinders

    Units = cylinders of 6200 * 512 = 3174400 bytes

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

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

    Disk identifier: 0x23b0ff1a

    

             Device Boot      Start         End      Blocks   Id  System

    /dev/iscsi/sdb1               1        1014     3143369   83  Linux

    

    Command (m for help): w

    The partition table has been altered!

    

    Calling ioctl() to re-read partition table.

    Syncing disks.

    

格式化

    # ls /dev/iscsi/

    sdb  sdc

    # ls /dev/sd*

    /dev/sda  /dev/sda1  /dev/sdb

    

    # mkfs.ext4 /dev/sda1

    mke2fs 1.41.12 (17-May-2010)

    文件系统标签=

    操作系统:Linux

    块大小=4096 (log=2)

    分块大小=4096 (log=2)

    Stride=0 blocks, Stripe width=0 blocks

    196608 inodes, 785842 blocks

    39292 blocks (5.00%) reserved for the super user

    第一个数据块=0

    Maximum filesystem blocks=805306368

    24 block groups

    32768 blocks per group, 32768 fragments per group

    8192 inodes per group

    Superblock backups stored on blocks: 

     32768, 98304, 163840, 229376, 294912

    

    正在写入inode表: 完成                            

    Creating journal (16384 blocks): 完成

    Writing superblocks and filesystem accounting information: 完成

    

    This filesystem will be automatically checked every 33 mounts or

    180 days, whichever comes first.  Use tune2fs -c or -i to override.

    

    # blkid /dev/sda1 

    /dev/sda1: UUID="342994ac-4bce-4b21-9755-3377a79bb453" TYPE="ext4"

    # vim /etc/fstab 

    # tail -1 /etc/fstab

    UUID=342994ac-4bce-4b21-9755-3377a79bb453 /var/www/html  ext4  defaults 0 0

    # mount -a

    # mount | grep var

    /dev/sda1 on /var/www/html type ext4 (rw)

    # ls /var/www/html/

    lost+found

    # echo "Hello World" > /var/www/html/test.html

    

另一端测试

    # ls /dev/sd*

    /dev/sda  /dev/sdb

    # ls /dev/iscsi/ -l

    总用量 0

    lrwxrwxrwx. 1 root root 6 1月  13 06:17 sdb -> ../sdb

    lrwxrwxrwx. 1 root root 6 1月  13 06:16 sdc -> ../sda

    # iscsiadm --mode node --targetname iqn.2018-01.com.www:pc56.diskc --portal 192.168.4.56:3260 -u

    # iscsiadm --mode node --targetname iqn.2018-01.com.www:pc56.diskb --portal 192.168.4.56:3260 -u

    # ls /dev/sd*

    ls: 无法访问/dev/sd*: 没有那个文件或目录

    # iscsiadm --mode node --targetname iqn.2018-01.com.www:pc56.diskb --portal 192.168.4.56:3260 -l

    # iscsiadm --mode node --targetname iqn.2018-01.com.www:pc56.diskc --portal 192.168.4.56:3260 -l

    # ls /dev/sd*

    /dev/sda  /dev/sda1  /dev/sdb

    # ls /dev/iscsi/sd*

    /dev/iscsi/sdb  /dev/iscsi/sdc

    # ls /dev/iscsi/sd* -l

    lrwxrwxrwx. 1 root root 6 1月  13 07:27 /dev/iscsi/sdb -> ../sda

    lrwxrwxrwx. 1 root root 6 1月  13 07:27 /dev/iscsi/sdc -> ../sdb

    # blkid /dev/sda1  // 会发现uuid相同

    /dev/sda1: UUID="342994ac-4bce-4b21-9755-3377a79bb453" TYPE="ext4" 

    

    # vim /etc/fstab 

    # tail -1 /etc/fstab

    UUID=342994ac-4bce-4b21-9755-3377a79bb453 /var/www/html  ext4  defaults 0 0

    # mount -a

    # mount | grep var

    /dev/sda1 on /var/www/html type ext4 (rw)

    # ls /var/www/html/

    lost+found  test.html

    


    pc53 和 pc 54  配置keepalived 高可用集群 

    具体步骤可以参考: http://blog.51cto.com/13558754/2060950

    [root@pc53 ~]# ip addr show | grep 192.168.4

        inet 192.168.4.53/24 brd 192.168.4.255 scope global eth0

        inet 192.168.4.251/32 scope global eth0

    [root@pc54 ~]# ip addr show | grep 192.168.4

        inet 192.168.4.54/24 brd 192.168.4.255 scope global eth0

    

    //客户端测试

    # elinks --dump 192.168.4.251/test.html

       Hello World

    

    [root@pc53 ~]# service keepalived stop

    停止 keepalived:                                          [确定]

    [root@pc53 ~]# ip addr show | grep 192.168.4

        inet 192.168.4.53/24 brd 192.168.4.255 scope global eth0

    

    [root@pc54 ~]# ip addr show | grep 192.168.4

        inet 192.168.4.54/24 brd 192.168.4.255 scope global eth0

        inet 192.168.4.251/32 scope global eth0

    

    

    # elinks --dump 192.168.4.251/test.html

       Hello World

    

    

    [root@pc53 ~]# echo "123" > /var/www/html/one.html

    [root@pc53 ~]# ls /var/www/html/

    lost+found  one.html  test.html

    [root@pc54 ~]# ls /var/www/html/

    lost+found  test.html

    [root@pc54 ~]# umount /var/www/html/

    [root@pc54 ~]# mount -a

    [root@pc54 ~]# ls /var/www/html/

    lost+found  one.html  test.html


    所以说 不能同时挂载 

    应该给VIP设备挂载 从而达到实现数据实时同步

    可以写一个监控脚本 监控当前机器是否获得VIP地址

    当其刚刚获得 VIP时 进行挂载


iSCSI服务多路径 

   环境准备

    存储服务器 有两个网络地址 

    eth0 192.168.4.56/24

    eth1 192.168.2.56/24

    应用服务器

    pc 53

    eth0 192.168.4.53/24

    eth1 192.168.2.53/24

    pc 54

    eth0 192.168.4.54/24

    eth1 192.168.2.54/24

    

    配置后端存储

    [root@pc56 ~]# vim /etc/tgt/targets.conf 

    <target iqn.2018-01.com.www:pc56.diskd>

        backing-store /dev/vdd

        write-cache off

       #initiator-address 192.168.4.54

       #vendor_id  xuenqlve

       #product_id disk2

    </target>

    

    [root@pc56 ~]# /etc/init.d/tgtd restart

    [root@pc56 ~]# tgt-admin --show

    ....

    Target 3: iqn.2018-01.com.www:pc56.diskd

        System information:

            Driver: iscsi

            State: ready

        I_T nexus information:

        LUN information:

            LUN: 0

                Type: controller

                SCSI ID: IET     00030000

                SCSI SN: beaf30

                Size: 0 MB, Block size: 1

                Online: Yes

                Removable media: No

                Prevent removal: No

                Readonly: No

                Backing store type: null

                Backing store path: None

                Backing store flags: 

            LUN: 1

                Type: disk

                SCSI ID: IET     00030001

                SCSI SN: beaf31

                Size: 3221 MB, Block size: 512

                Online: Yes

                Removable media: No

                Prevent removal: No

                Readonly: No

                Backing store type: rdwr

                Backing store path: /dev/vdd

                Backing store flags: 

        Account information:

        ACL information:

            ALL

        

    [root@pc53 ~]# iscsiadm --mode discoverydb --type sendtargets --portal 192.168.4.56 --discover

    192.168.4.56:3260,1 iqn.2018-01.com.www:pc56.diskb

    192.168.4.56:3260,1 iqn.2018-01.com.www:pc56.diskc

    192.168.4.56:3260,1 iqn.2018-01.com.www:pc56.diskd

    [root@pc53 ~]# iscsiadm --mode discoverydb --type sendtargets --portal 192.168.2.56 --discover

    192.168.2.56:3260,1 iqn.2018-01.com.www:pc56.diskb

    192.168.2.56:3260,1 iqn.2018-01.com.www:pc56.diskc

    192.168.2.56:3260,1 iqn.2018-01.com.www:pc56.diskd

    

          

    [root@pc53 ~]# iscsiadm --mode node --targetname iqn.2018-01.com.www:pc56.diskd --portal 192.168.4.56:3260 -l

    [root@pc53 ~]# ls /dev/sd*

    /dev/sda

    

    [root@pc53 ~]# iscsiadm --mode node --targetname iqn.2018-01.com.www:pc56.diskd --portal 192.168.2.56:3260 -l    

    [root@pc53 ~]# ls /dev/sd*

    /dev/sda  /dev/sdb

    

    // /dev/sda  和 /dev/sdb 时后端的同一个设备

    

    

    [root@pc53 ~]# which scsi_id

    /sbin/scsi_id

    [root@pc53 ~]# scsi_id --whitelisted --device=/dev/sda //获取WWID 

    1IET     00030001

    [root@pc53 ~]# scsi_id --whitelisted --device=/dev/sdb

    1IET     00030001

    

    装包  安装提供多路径需要的软件包

    [root@pc53 ~]# yum -y install device-mapper-multipath

    [root@pc53 ~]# rpm -q device-mapper-multipath

    device-mapper-multipath-0.4.9-87.el6.x86_64

    

    创建并修改配置文件

    [root@pc53 ~]# mpathconf --user_friendly_names n //生成配置文件

    [root@pc53 ~]# ls /etc/multipath.conf 

    /etc/multipath.conf

    

    

    [root@pc53 ~]# vim /etc/multipath.conf 

    

     25 defaults {

     26         user_friendly_names no

     27         getuid_callout          "/lib/udev/scsi_id --whitelisted --device=/dev/%n"

    

     38 #       getuid_callout          "/lib/udev/scsi_id --whitelisted --device=/dev/%n"

    

    102 multipaths{

    103         multipath{

    104                 wwid "1IET     00030001"

    105                 alias  mpatha

    106         }

    107 }

        

    [root@pc53 ~]# /etc/init.d/multipathd start

    正在启动守护进程multipathd:                               [确定]

    [root@pc53 ~]# chkconfig multipathd on

    [root@pc53 ~]# ls /dev/mapper/mpatha 

    /dev/mapper/mpatha

    格式化

    [root@pc53 ~]# mkfs.ext4 /dev/mapper/mpatha

    mke2fs 1.41.12 (17-May-2010)

    文件系统标签=

    操作系统:Linux

    块大小=4096 (log=2)

    分块大小=4096 (log=2)

    Stride=0 blocks, Stripe width=0 blocks

    196608 inodes, 786432 blocks

    39321 blocks (5.00%) reserved for the super user

    第一个数据块=0

    Maximum filesystem blocks=805306368

    24 block groups

    32768 blocks per group, 32768 fragments per group

    8192 inodes per group

    Superblock backups stored on blocks: 

     32768, 98304, 163840, 229376, 294912

    

    正在写入inode表: 完成                            

    Creating journal (16384 blocks): 完成

    Writing superblocks and filesystem accounting information: 完成

    

    This filesystem will be automatically checked every 27 mounts or

    180 days, whichever comes first.  Use tune2fs -c or -i to override.

    

    [root@pc53 ~]# blkid /dev/mapper/mpatha 

    /dev/mapper/mpatha: UUID="cbdb1867-a537-4349-9c9d-f7ab08e917cb" TYPE="ext4" 

    

    查看多路径信息

    

    [root@pc53 ~]# multipath -ll //查看多路径信息

    mpatha (1IET     00030001) dm-2 IET,VIRTUAL-DISK

    size=3.0G features='0' hwhandler='0' wp=rw

    |-+- policy='round-robin 0' prio=1 status=active

    | `- 5:0:0:1 sda 8:0   active ready running

    `-+- policy='round-robin 0' prio=1 status=enabled

      `- 6:0:0:1 sdb 8:16  active ready running

    

    [root@pc53 ~]# multipath -rr

    

    [root@pc53 ~]# multipath -ll

    mpatha (1IET     00030001) dm-2 IET,VIRTUAL-DISK

    size=3.0G features='0' hwhandler='0' wp=rw

    `-+- policy='round-robin 0' prio=1 status=active

      `- 5:0:0:1 sda 8:0   active ready  running

    

    


NFS网络文件系统


主要软件包 nfs-utils      rpcbind

5.jpg


配置NFS服务器 pc56

分区 格式化 挂载(开机挂载)

    //分区

    # fdisk /dev/vde 

    Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

    Building a new DOS disklabel with disk identifier 0x1daab7a9.

    Changes will remain in memory only, until you decide to write them.

    After that, of course, the previous content won't be recoverable.

    

    Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

    

    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): n

    Command action

       e   extended

       p   primary partition (1-4)

    p

    Partition number (1-4): 1

    First cylinder (1-6241, default 1): 

    Using default value 1

    Last cylinder, +cylinders or +size{K,M,G} (1-6241, default 6241): 

    Using default value 6241

    

    Command (m for help): p

    

    Disk /dev/vde: 3221 MB, 3221225472 bytes

    16 heads, 63 sectors/track, 6241 cylinders

    Units = cylinders of 1008 * 512 = 516096 bytes

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

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

    Disk identifier: 0x1daab7a9

    

       Device Boot      Start         End      Blocks   Id  System

    /dev/vde1               1        6241     3145432+  83  Linux

    

    Command (m for help): w

    The partition table has been altered!

    

    Calling ioctl() to re-read partition table.

    Syncing disks.

    

    //格式化分区

    # mkfs.ext4 /dev/vde1 

    mke2fs 1.41.12 (17-May-2010)

    文件系统标签=

    操作系统:Linux

    块大小=4096 (log=2)

    分块大小=4096 (log=2)

    Stride=0 blocks, Stripe width=0 blocks

    196608 inodes, 786358 blocks

    39317 blocks (5.00%) reserved for the super user

    第一个数据块=0

    Maximum filesystem blocks=805306368

    24 block groups

    32768 blocks per group, 32768 fragments per group

    8192 inodes per group

    Superblock backups stored on blocks: 

     32768, 98304, 163840, 229376, 294912

    

    正在写入inode表: 完成                            

    Creating journal (16384 blocks): 完成

    Writing superblocks and filesystem accounting information: 完成

    

    This filesystem will be automatically checked every 35 mounts or

    180 days, whichever comes first.  Use tune2fs -c or -i to override.

    //创建挂载文件

    # mkdir /sharespace

    //查看分区UUID

    # blkid /dev/vde1

    /dev/vde1: UUID="e3dad5d2-eae2-4290-ba5e-935e6eda59c7" TYPE="ext4" 

    //配置开机自动挂载

    [root@pc56 ~]# vim /etc/fstab 

    [root@pc56 ~]# tail -1 /etc/fstab

    UUID=e3dad5d2-eae2-4290-ba5e-935e6eda59c7 /sharespace ext4  defaults 0 0

    //挂载 分区

    [root@pc56 ~]# mount -a

    //查看挂载情况

    [root@pc56 ~]# df -h

    Filesystem            Size  Used Avail Use% Mounted on

    /dev/mapper/VolGroup-lv_root

                           47G  1.4G   43G   4% /

    tmpfs                 499M     0  499M   0% /dev/shm

    /dev/vda1             477M   36M  416M   8% /boot

    /dev/sr0              3.6G  3.6G     0 100% /mnt/2018-01-15

    /dev/vde1             2.9G  4.5M  2.8G   1% /sharespace

    [root@pc56 ~]# mount | grep /dev/vde1

    /dev/vde1 on /sharespace type ext4 (rw)

    


使用nfs 服务共享挂载目录

装包 修改配置文件 启动服务


    # yum -y install rpcbind

    # /etc/init.d/rpcbind start

    正在启动 rpcbind:                                         [确定]

    # chkconfig rpcbind on

    # yum -y install nfs-utils

    # vim /etc/exports 

    # tail -1 /etc/exports

    /sharespace *(rw)

    # chmod o+w /sharespace/

    # /etc/init.d/nfs start

    启动 NFS 服务:                                            [确定]

    关掉 NFS 配额:                                            [确定]

    启动 NFS mountd:                                          [确定]

    启动 NFS 守护进程:                                        [确定]

    正在启动 RPC idmapd:                                      [确定]

    # chkconfig nfs on

     # showmount -e localhost

    Export list for localhost:

    /sharespace *


Web服务器 访问查看共享信息 pc 51 / pc 52

# yum -y install nfs-uits

# showmount -e 192.168.4.56

Export list for 192.168.4.56:

/sharespace *


[root@pc51 ~]# mount -t nfs 192.168.4.56:/sharespace /var/www/html/

[root@pc51 ~]# mount | tail -1

192.168.4.56:/sharespace on /var/www/html type nfs (rw,vers=4,addr=192.168.4.56,clientaddr=192.168.4.51)

[root@pc52 ~]# mount -t nfs 192.168.4.56:/sharespace /var/www/html/

[root@pc52 ~]# mount | tail -1

192.168.4.56:/sharespace on /var/www/html type nfs (rw,vers=4,addr=192.168.4.56,clientaddr=192.168.4.52)


[root@pc51 ~]# ls /var/www/html/

lost+found

[root@pc51 ~]# echo "hello" > /var/www/html/index.html

[root@pc51 ~]# ls /var/www/html/

index.html  lost+found

//会在pc52 端会生成同样的文件  实现了实时同步

[root@pc52 ~]# ls /var/www/html/

index.html  lost+found


//完成 pc51 和 pc52 上的开机自动挂载

# vim /etc/fstab

# tail -1 /etc/fstab 

192.168.4.56:/sharespace /var/www/html/   nfs defaults   0 0











本文转自 Xuenqlve 51CTO博客,原文链接:http://blog.51cto.com/13558754/2061297,如需转载请自行联系原作者
相关实践学习
基于函数计算一键部署掌上游戏机
本场景介绍如何使用阿里云计算服务命令快速搭建一个掌上游戏机。
建立 Serverless 思维
本课程包括: Serverless 应用引擎的概念, 为开发者带来的实际价值, 以及让您了解常见的 Serverless 架构模式
目录
相关文章
|
6月前
|
网络协议 安全 Unix
centos7.9系统部署NFS详细流程—2023.04
centos7.9系统部署NFS详细流程—2023.04
367 0
|
4月前
|
存储 关系型数据库 应用服务中间件
私有云盘:lamp部署nextcloud+高可用集群
lamp部署nextcloud+高可用集群,配置mariadb主从复制,台主机下载mariadb,配置nfs让web服务挂载,web 服务器 配置 lamp,配置nginx反向代理&&haproxy&&keepalived。
160 0
|
5月前
|
存储 网络协议 Linux
CentOS 7.6 部署 GlusterFS 分布式存储系统
CentOS 7.6 部署 GlusterFS 分布式存储系统
125 0
|
存储 Linux 网络安全
CentOS7下搭建ScaleIO分布式存储集群
CentOS7下搭建ScaleIO分布式存储集群
430 0
CentOS7下搭建ScaleIO分布式存储集群
|
存储 关系型数据库 数据库
CloudStack+XenServer详细部署方案 CloudStack管理节点的安装和配置
CloudStack+XenServer详细部署方案 CloudStack管理节点的安装和配置 本文将根据设计文档, 安装和配置CloudStack管理节点。 本文只对配置流程和结果进行举例说明, 具体 细节和配置操作请参考 CloudStack安装文档. 实际部署架构: 管理机柜规划: Step1. 安装和配置MySQL数据库. 根据设计部署2台MySQL数据库服务器, 安装过程和配置过程请参考CloudStack管理文档. 辅DB 对主DB 采用Replication方式进行备份。
1315 0
|
测试技术 Linux 应用服务中间件

热门文章

最新文章