设为首页 收藏本站
查看: 6410|回复: 0

[经验分享] LVM+RAID5

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2014-8-15 08:52:03 | 显示全部楼层 |阅读模式
环境
[iyunv@localhost ~]# uname -a
Linux localhost.localdomain 3.10.0-123.el7.x86_64 #1 SMP Mon Jun 30 12:09:22 UTC 2014 x86_64

x86_64 x86_64 GNU/Linux
[iyunv@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.0.1406 (Core)
[iyunv@localhost ~]#



先格式化硬盘
[iyunv@localhost ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x9b6fbd48.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-10485759, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-10485759, default 10485759):
Using default value 10485759
Partition 1 of type Linux and of size 5 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[iyunv@localhost ~]# fdisk /dev/sdc
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x922dcb2f.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-10485759, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-10485759, default 10485759):
Using default value 10485759
Partition 1 of type Linux and of size 5 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[iyunv@localhost ~]# fdisk /dev/sdd
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x2ba5a48b.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-10485759, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-10485759, default 10485759):
Using default value 10485759
Partition 1 of type Linux and of size 5 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[iyunv@localhost ~]#

操作完成后创建raid5
[iyunv@localhost ~]# mdadm --create /dev/md0 --level=5 --raid-device=3 /dev/sd[bcd]1
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
然后cat /proc/mdstat查看数据同步状态
[iyunv@localhost ~]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sdd1[3] sdc1[1] sdb1[0]
      10471424 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/2] [UU_]
      [======>..............]  recovery = 33.5% (1754752/5235712) finish=1.4min speed=38698K/sec



可以用mdadm --detail /dev/md0来查看刚才新建的设备状态

[iyunv@localhost ~]# mdadm --detail /dev/md0
/dev/md0:
        Version : 1.2
  Creation Time : Thu Aug 14 21:32:42 2014
     Raid Level : raid5
     Array Size : 10474496 (9.99 GiB 10.73 GB)
  Used Dev Size : 5237248 (4.99 GiB 5.36 GB)
   Raid Devices : 3
  Total Devices : 3
    Persistence : Superblock is persistent

    Update Time : Thu Aug 14 21:33:22 2014
          State : clean
Active Devices : 3
Working Devices : 3
Failed Devices : 0
  Spare Devices : 0

         Layout : left-symmetric
     Chunk Size : 512K

           Name : localhost.localdomain:0  (local to host localhost.localdomain)
           UUID : f609ab00:506281f1:74f679f1:330b997e
         Events : 18

    Number   Major   Minor   RaidDevice State
       0       8       17        0      active sync   /dev/sdb1
       1       8       33        1      active sync   /dev/sdc1
       3       8       49        2      active sync   /dev/sdd1
[iyunv@localhost ~]#
然后配置raid的配置文件
[iyunv@localhost ~]# echo device /dev/sdb1 /dev/sdc1 /dev/sdd1 > /etc/mdadm.conf
[iyunv@localhost ~]# mdadm --detail --scan >> /etc/mdadm.conf



然后我们来做LVM实验
[iyunv@localhost ~]# pvcreate /dev/md0
  Physical volume "/dev/md0" successfully created
[iyunv@localhost ~]# vgcreate vg /dev/md0
  Volume group "vg" successfully created
[iyunv@localhost ~]# pvscan
  PV /dev/md0    VG vg       lvm2 [9.99 GiB / 9.99 GiB free]
  PV /dev/sda2   VG centos   lvm2 [39.51 GiB / 0    free]
  Total: 2 [49.50 GiB] / in use: 2 [49.50 GiB] / in no VG: 0 [0   ]
[iyunv@localhost ~]# vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "vg" using metadata type lvm2
  Found volume group "centos" using metadata type lvm2
[iyunv@localhost ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/md0
  VG Name               vg
  PV Size               9.99 GiB / not usable 0
  Allocatable           yes
  PE Size               4.00 MiB
  Total PE              2557
  Free PE               2557
  Allocated PE          0
  PV UUID               09m55X-PS71-FRHm-W8Y0-T7Po-87vA-7jfMzz

  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               centos
  PV Size               39.51 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              10114
  Free PE               0
  Allocated PE          10114
  PV UUID               10uSSs-Vbxx-SZAw-l4HS-pSdA-zfzV-wm5BMf

[iyunv@localhost ~]#

[iyunv@localhost ~]# vgdisplay
  --- Volume group ---
  VG Name               vg
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               9.99 GiB
  PE Size               4.00 MiB
  Total PE              2557
  Alloc PE / Size       0 / 0
  Free  PE / Size       2557 / 9.99 GiB
  VG UUID               bPFe6k-4SHi-CocW-EBDR-Ccqk-bRWc-JVdsCD

  --- Volume group ---
  VG Name               centos
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               39.51 GiB
  PE Size               4.00 MiB
  Total PE              10114
  Alloc PE / Size       10114 / 39.51 GiB
  Free  PE / Size       0 / 0
  VG UUID               NpPwU7-zaAR-hMdL-jFZm-PXVf-Q7OM-0Zk6iQ

[iyunv@localhost ~]#

创建LVM

[iyunv@localhost ~]# lvcreate -L 1g -n lvm vg
  Logical volume "lvm" created
[iyunv@localhost ~]# lvcreate -L 500m -n lvm1 vg
  Logical volume "lvm1" created
[iyunv@localhost ~]# lvscan
  ACTIVE            '/dev/vg/lvm' [1.00 GiB] inherit
  ACTIVE            '/dev/vg/lvm1' [500.00 MiB] inherit
  ACTIVE            '/dev/centos/swap' [1.03 GiB] inherit
  ACTIVE            '/dev/centos/root' [38.48 GiB] inherit
[iyunv@localhost ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/vg/lvm
  LV Name                lvm
  VG Name                vg
  LV UUID                Uu3AVp-L3L8-l670-kVuQ-F4nU-Hs4w-J0Sxto
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2014-08-14 21:48:24 +0800
  LV Status              available
  # open                 0
  LV Size                1.00 GiB
  Current LE             256
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     4096
  Block device           253:2

  --- Logical volume ---
  LV Path                /dev/vg/lvm1
  LV Name                lvm1
  VG Name                vg
  LV UUID                eBscVc-LveI-VtE8-QWCd-tI0F-q231-IvCpwG
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2014-08-14 21:48:54 +0800
  LV Status              available
  # open                 0
  LV Size                500.00 MiB
  Current LE             125
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     4096
  Block device           253:3

  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                AmdypQ-FIaA-85Ni-VATw-KDIz-Rt2I-C5DrXt
  LV Write Access        read/write
  LV Creation host, time localhost, 2014-08-12 17:24:27 +0800
  LV Status              available
  # open                 2
  LV Size                1.03 GiB
  Current LE             264
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                rYxDWG-EmTn-61IU-HD52-Lnqv-n6yk-OvNlR3
  LV Write Access        read/write
  LV Creation host, time localhost, 2014-08-12 17:24:28 +0800
  LV Status              available
  # open                 1
  LV Size                38.48 GiB
  Current LE             9850
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

[iyunv@localhost ~]#
[iyunv@localhost ~]# mkfs.ext4 /dev/vg
mke2fs 1.42.9 (28-Dec-2013)
/dev/vg is not a block special device.
Proceed anyway? (y,n) y
mkfs.ext4: Device size reported to be zero.  Invalid partition specified, or
        partition table wasn't reread after running fdisk, due to
        a modified partition being busy and in use.  You may need to reboot
        to re-read your partition table.

[iyunv@localhost ~]# mkfs.ext4 /dev/vg/lvm*
mke2fs 1.42.9 (28-Dec-2013)
mkfs.ext4: invalid blocks '/dev/vg/lvm1' on device '/dev/vg/lvm'
[iyunv@localhost ~]# mkfs.ext4 /dev/vg/lvm
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=128 blocks, Stripe width=256 blocks
65536 inodes, 262144 blocks
13107 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376

Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

[iyunv@localhost ~]# mkfs.ext4 /dev/vg/lvm1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=512 blocks, Stripe width=1024 blocks
128016 inodes, 512000 blocks
25600 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=34078720
63 block groups
8192 blocks per group, 8192 fragments per group
2032 inodes per group
Superblock backups stored on blocks:
        8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409

Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

[iyunv@localhost ~]#
[iyunv@localhost ~]# ^C

创建目录,然后vi /etc/fstab 将挂载点写入fstab,实现开机自动挂载
[iyunv@localhost ~]# mkdir /mnt/test1
[iyunv@localhost ~]# mkdir /mnt/test2
[iyunv@localhost ~]# mount /dev/vg/lvm /mnt/test1
[iyunv@localhost ~]# mount /dev/vg/lvm1 /mnt/test2
[iyunv@localhost ~]#
[iyunv@localhost ~]# vi /etc/fstab
/dev/vg/lvm1/ /mnt/test1 ext3 defaults 0 0
/dev/vg/lvm2/ /mnt/test2 ext3 defaults 0 0
把RAID5 中的sdb1干掉

[iyunv@localhost ~]# reboot
login as: root
root@192.168.188.100's password:
Last login: Thu Aug 14 21:25:32 2014 from 192.168.188.1
[iyunv@localhost ~]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sdb1[1] sdc1[3]
      10474496 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/2] [_UU]

unused devices: <none>
[iyunv@localhost ~]#
[iyunv@localhost ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/md0
  VG Name               vg
  PV Size               9.99 GiB / not usable 0
  Allocatable           yes
  PE Size               4.00 MiB
  Total PE              2557
  Free PE               2176
  Allocated PE          381
  PV UUID               09m55X-PS71-FRHm-W8Y0-T7Po-87vA-7jfMzz

  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               centos
  PV Size               39.51 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              10114
  Free PE               0
  Allocated PE          10114
  PV UUID               10uSSs-Vbxx-SZAw-l4HS-pSdA-zfzV-wm5BMf

添加硬盘
把硬盘设为6G,
[iyunv@localhost ~]# fdisk -l

/dev/sdd1            2048    10485759     5241856   83  Linux

Disk /dev/sdb: 6442 MB, 6442450944 bytes, 12582912 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/sdc: 5368 MB, 5368709120 bytes, 10485760 sectors






新硬盘分区
[iyunv@localhost ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x79185e00.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-12582911, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-12582911, default 12582911):
Using default value 12582911
Partition 1 of type Linux and of size 6 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[iyunv@localhost ~]#
呵呵,成功了.
[iyunv@localhost ~]# mdadm /dev/md0 -a /dev/sdb1
mdadm: added /dev/sdb1
[iyunv@localhost ~]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sdb1[4] sdd1[3] sdc1[1]
      10474496 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/2] [_UU]
      [======>..............]  recovery = 33.7% (1769268/5237248) finish=0.4min speed=126376K/sec

unused devices: <none>
[iyunv@localhost ~]#



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-23869-1-1.html 上篇帖子: samba配置实验 下篇帖子: linux软件包管理之RPM
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表