来源:自学PHP网 时间:2015-04-14 11:12 作者: 阅读:次
[导读] 磁盘管理小实验一 实验要求1.保证数据的安全,任何一块磁盘坏掉不影响数据丢失,还要考虑IO性能2.划分两个单独的磁盘分区/web和/data3.可以动态地扩展分区的大小二 实现功能第一步...
磁盘管理——小实验
一 实验要求
1.保证数据的安全,任何一块磁盘坏掉不影响数据丢失,还要考虑IO性能
2.划分两个单独的磁盘分区/web和/data
3.可以动态地扩展分区的大小
二 实现功能
第一步 对磁盘进行分区
[plain]
[root@serv01 ~]# fdisk /dev/sdb
[root@serv01 ~]# fdisk /dev/sdc
[root@serv01 ~]# fdisk /dev/sdd
[root@serv01 ~]# fdisk /dev/sde
第二步 制作RAID5硬盘
[plain]
[root@serv01 ~]# mdadm -C /dev/md5 -l 5 -n3 /dev/sdb1 /dev/sdc1 /dev/sdd1
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
[root@serv01 ~]# mkfs.ext4 /dev/md5
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=128 blocks, Stripe width=256 blocks
262144 inodes, 1047552 blocks
52377 blocks (5.00%) reserved for the superuser
First data block=0
Maximum filesystem blocks=1073741824
32 block groups
32768 blocks per group, 32768 fragments pergroup
8192 inodes per group
Superblock backups stored on blocks:
32768,98304, 163840, 229376, 294912, 819200, 884736
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystemaccounting information: done
This filesystem will be automaticallychecked every 27 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
第三步 创建物理卷
[plain]
[root@serv01 ~]# pvcreate /dev/md5
Physical volume "/dev/md5" successfully created
第四步 创建卷组
[plain]
[root@serv01 ~]# vgcreate myvg /dev/md5
Volume group "myvg" successfully created
第五步 创建逻辑卷
[plain]
#创建逻辑卷mylv01
[root@serv01 ~]# lvcreate -L 1000M -n mylv01 myvg
Logical volume "mylv01" created
#创建逻辑卷mylv02
[root@serv01 ~]# lvcreate -L 1000M -n mylv02 myvg
Logical volume "mylv02" created
第六步 创建相关目录和配置文件
[plain]
#创建mdadm.conf文件
[root@serv01 ~]# mdadm --detail --scan >/etc/mdadm.conf
#创建/web目录
[root@serv01 ~]# mkdir /web
#创建/data目录
[root@serv01 ~]# mkdir /data
#将挂载信息写到fstab文件中
[root@serv01 ~]# echo"/dev/myvg/mylv01 /web ext4 defaults 1 2" >> /etc/fstab
[root@serv01 ~]# echo"/dev/myvg/mylv02 /data ext4 defaults 1 2" >> /etc/fstab
[root@serv01 ~]# tail -n 2 /etc/fstab
/dev/myvg/mylv01 /web ext4 defaults 1 2
/dev/myvg/mylv02 /data ext4 defaults 1 2
第七步 格式化硬盘
[plain]
#格式化mylv01
[root@serv01 ~]# mkfs.ext4 /dev/myvg/mylv01
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=128 blocks, Stripe width=256 blocks
64000 inodes, 256000 blocks
12800 blocks (5.00%) reserved for the superuser
First data block=0
Maximum filesystem blocks=264241152
8 block groups
32768 blocks per group, 32768 fragments pergroup
8000 inodes per group
Superblock backups stored on blocks:
32768,98304, 163840, 229376
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystemaccounting information: done
This filesystem will be automaticallychecked every 28 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
#格式化mylv02
[root@serv01 ~]# mkfs.ext4 /dev/myvg/mylv02
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=128 blocks, Stripe width=256 blocks
64000 inodes, 256000 blocks
12800 blocks (5.00%) reserved for the superuser
First data block=0
Maximum filesystem blocks=264241152
8 block groups
32768 blocks per group, 32768 fragments pergroup
8000 inodes per group
Superblock backups stored on blocks:
32768,98304, 163840, 229376
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystemaccounting information: done
This filesystem will be automaticallychecked every 24 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
第八步 挂载
[plain]
#挂载web
[root@serv01 ~]# mount /dev/myvg/mylv01/web
#挂载data
[root@serv01 ~]# mount /dev/myvg/mylv02/data
#查看磁盘信息
[root@serv01 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 9.7G 1.1G 8.1G 12% /
tmpfs 188M 0 188M 0% /dev/shm
/dev/sda1 194M 25M 160M 14% /boot
/dev/sda5 4.0G 137M 3.7G 4% /opt
/dev/sr0 3.4G 3.4G 0 100% /iso
/dev/mapper/myvg-mylv01
985M 18M 918M 2% /web
/dev/mapper/myvg-mylv02
985M 18M 918M 2% /data
第九步 模拟硬盘坏掉
[plain]
#拷贝文件到web目录
[root@serv01 ~]# cp /boot/* /web/
#查看RAID5的详细信息
[root@serv01 ~]# mdadm -D /dev/md5
/dev/md5:
Version : 1.2
Creation Time : Fri Aug 200:35:07 2013
Raid Level : raid5
Array Size : 4190208 (4.00 GiB 4.29 GB)
Used Dev Size : 2095104 (2046.34 MiB 2145.39 MB)
Raid Devices : 3
Total Devices : 3
Persistence : Superblock is persistent
Update Time : Fri Aug 2 00:46:462013
State : clean
Active Devices : 3
Working Devices : 3
Failed Devices : 0
Spare Devices : 0
Layout : left-symmetric
Chunk Size : 512K
Name : serv01.host.com:5 (local to host serv01.host.com)
UUID : 97c47faa:972aba90:2248d692:b7fc2b6f
Events : 22
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
#清除/dev/sdb,o
[root@serv01 ~]# fdisk /dev/sdb
[root@serv01 ~]# ls /web/
config-2.6.32-131.0.15.el6.x86_64 lost+found System.map-2.6.32-131.0.15.el6.x86_64
initramfs-2.6.32-131.0.15.el6.x86_64.img symvers-2.6.32-131.0.15.el6.x86_64.gz vmlinuz-2.6.32-131.0.15.el6.x86_64
#再次查看,发现/dev/sdb被标记为removed
[root@serv01~]# mdadm -D /dev/md5
/dev/md5:
Version : 1.2
Creation Time : Fri Aug 200:35:07 2013
Raid Level : raid5
Array Size : 4190208 (4.00 GiB 4.29 GB)
Used Dev Size : 2095104 (2046.34 MiB 2145.39 MB)
Raid Devices : 3
Total Devices : 2
Persistence : Superblock is persistent
Update Time : Fri Aug 2 00:48:192013
State : clean, degraded
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
Layout : left-symmetric
Chunk Size : 512K
Name : serv01.host.com:5 (localto host serv01.host.com)
UUID : 97c47faa:972aba90:2248d692:b7fc2b6f
Events : 30
Number Major Minor RaidDevice State
0 0 0 0 removed
1 8 33 1 active sync /dev/sdc1
3 8 49 2 active sync /dev/sdd1
第十步 添加硬盘
[plain]
#添加/dev/sde1磁盘
[root@serv01 ~]# mdadm --manage /dev/md5--add /dev/sde1
mdadm: added /dev/sde1
#再次查看,发现/dev/sde被标记为active
[root@serv01 ~]# mdadm -D /dev/md5
/dev/md5:
Version : 1.2
Creation Time : Fri Aug 200:35:07 2013
Raid Level : raid5
Array Size : 4190208 (4.00 GiB 4.29 GB)
Used Dev Size : 2095104 (2046.34 MiB 2145.39 MB)
Raid Devices : 3
TotalDevices : 3
Persistence : Superblock is persistent
Update Time : Fri Aug 2 00:49:192013
State : clean
Active Devices : 3
Working Devices : 3
Failed Devices : 0
Spare Devices : 0
Layout : left-symmetric
Chunk Size : 512K
Name : serv01.host.com:5 (localto host serv01.host.com)
UUID : 97c47faa:972aba90:2248d692:b7fc2b6f
Events : 51
Number Major Minor RaidDevice State
4 8 65 0 active sync /dev/sde1
1 8 33 1 active sync /dev/sdc1
3 8 49 2 active sync /dev/sdd1
#查看RAID信息
[root@serv01 ~]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md5 : active raid5 sde1[4] sdc1[1] sdd1[3]
4190208 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]
unused devices: <none>
第十一步 增加逻辑卷
[plain]
#可以增加逻辑卷的大小
[root@serv01 ~]# lvextend -L +1G/dev/myvg/mylv01
Extending logical volume mylv01 to 1.98 GiB
Logical volume mylv01 successfully resized
#让增加的操作生效
[root@serv01 ~]# resize2fs /dev/myvg/mylv01
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/myvg/mylv01 is mountedon /web; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of/dev/myvg/mylv01 to 518144 (4k) blocks.
The filesystem on /dev/myvg/mylv01 is now518144 blocks long.
#再次查看,发现磁盘空间变大
[root@serv01 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 9.7G 1.1G 8.1G 12% /
tmpfs 188M 0 188M 0% /dev/shm
/dev/sda1 194M 25M 160M 14% /boot
/dev/sda5 4.0G 137M 3.7G 4% /opt
/dev/mapper/myvg-mylv01
2.0G 36M 1.9G 2% /web
/dev/mapper/myvg-mylv02
985M 18M 918M 2% /data
/dev/sr0 3.4G 3.4G 0 100% /iso
#再添加一块硬盘
[root@serv01 ~]# mdadm --manage /dev/md5--add /dev/sdf1
mdadm: added /dev/sdf1
[root@serv01 ~]# mdadm -D /dev/md5
/dev/md5:
Version : 1.2
Creation Time : Fri Aug 200:35:07 2013
Raid Level : raid5
Array Size : 4190208 (4.00 GiB 4.29 GB)
Used Dev Size : 2095104 (2046.34 MiB 2145.39 MB)
Raid Devices : 3
Total Devices : 4
Persistence : Superblock is persistent
Update Time : Fri Aug 2 00:56:132013
State : clean
Active Devices : 3
Working Devices : 4
Failed Devices : 0
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 512K
Name : serv01.host.com:5 (localto host serv01.host.com)
UUID : 97c47faa:972aba90:2248d692:b7fc2b6f
Events : 52
Number Major Minor RaidDevice State
4 8 65 0 active sync /dev/sde1
1 8 33 1 active sync /dev/sdc1
3 8 49 2 active sync /dev/sdd1
5 8 81 - spare /dev/sdf1
#让添加的硬盘生效
[root@serv01 ~]# mdadm --grow /dev/md5—raid-device=4
[root@serv01 ~]# pvdisplay
---Physical volume ---
PVName /dev/md5
VGName myvg
PVSize 4.00 GiB / not usable4.00 MiB
Allocatable yes
PESize 4.00 MiB
Total PE 1022
Free PE 266
Allocated PE 756
PVUUID uZoEve-F3Dr-KSBL-tXpA-ZtX5-9ZPM-64uv06
#让物理卷的大小同步
[root@serv01 ~]# pvresize /dev/md5
Physical volume "/dev/md5" changed
1physical volume(s) resized / 0 physical volume(s) not resized
[root@serv01 ~]# pvdisplay
---Physical volume ---
PVName /dev/md5
VGName myvg
PVSize 5.99 GiB / not usable0
Allocatable yes
PESize 4.00 MiB
Total PE 1534
Free PE 778
Allocated PE 756
PVUUID uZoEve-F3Dr-KSBL-tXpA-ZtX5-9ZPM-64uv06
#可以监控文件的变化
[root@serv01 ~]# watch cat /proc/mdstat
|
自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习
京ICP备14009008号-1@版权所有www.zixuephp.com
网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com