标签:lvm+raid5
桌面
环境
[root@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
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.0.1406 (Core)
[root@localhost ~]#
先格式化硬盘
[root@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.
[root@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.
[root@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.
[root@localhost ~]#
操作完成后创建raid5
[root@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查看数据同步状态
[root@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来查看刚才新建的设备状态
[root@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
[root@localhost ~]#
然后配置raid的配置文件
[root@localhost ~]# echo device /dev/sdb1 /dev/sdc1 /dev/sdd1 > /etc/mdadm.conf
[root@localhost ~]# mdadm --detail --scan >> /etc/mdadm.conf
然后我们来做LVM实验
[root@localhost ~]# pvcreate /dev/md0
Physical volume "/dev/md0" successfully created
[root@localhost ~]# vgcreate vg /dev/md0
Volume group "vg" successfully created
[root@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 ]
[root@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
[root@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
[root@localhost ~]#
[root@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
[root@localhost ~]#
创建LVM
[root@localhost ~]# lvcreate -L 1g -n lvm vg
Logical volume "lvm" created
[root@localhost ~]# lvcreate -L 500m -n lvm1 vg
Logical volume "lvm1" created
[root@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
[root@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
[root@localhost ~]#
[root@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.
[root@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‘
[root@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
[root@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
[root@localhost ~]#
[root@localhost ~]# ^C
创建目录,然后vi /etc/fstab 将挂载点写入fstab,实现开机自动挂载
[root@localhost ~]# mkdir /mnt/test1
[root@localhost ~]# mkdir /mnt/test2
[root@localhost ~]# mount /dev/vg/lvm /mnt/test1
[root@localhost ~]# mount /dev/vg/lvm1 /mnt/test2
[root@localhost ~]#
[root@localhost ~]# vi /etc/fstab
/dev/vg/lvm1/ /mnt/test1 ext3 defaults 0 0
/dev/vg/lvm2/ /mnt/test2 ext3 defaults 0 0
把RAID5 中的sdb1干掉
[root@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
[root@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>
[root@localhost ~]#
[root@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,
[root@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
新硬盘分区
[root@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.
[root@localhost ~]#
呵呵,成功了.
[root@localhost ~]# mdadm /dev/md0 -a /dev/sdb1
mdadm: added /dev/sdb1
[root@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>
[root@localhost ~]#
标签:lvm+raid5
原文地址:http://buzhisuowei.blog.51cto.com/8110825/1540206