磁盘及文件系统管理应用实例

存储 存储设备
RAID(冗余磁盘阵列)是将多块磁盘当做一块物理磁盘来使用,以达到容错或者提高读写性能的优势。按照 组织起来的工作方式的不同,我们可以将RAID分为不同的级别,其中常见的有RAID0、RAID1、RAID5、RAID10.

1.创建一个10G的分区,并格式化为ext4文件系统

要求其block大小为2048,预留空间百分比为2,卷标为MYDATA,默认挂载属性包含acl

挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳

[[200320]]

  1. [root@master ~]# fdisk /dev/sdb  
  2. Command (m for help): n  
  3. Partition type:  
  4. primary (0 primary, 0 extended, 4 free 
  5. e extended  
  6. Select (default p): p  
  7. Partition number (1-4, default 1): 1  
  8. First sector (2048-41943039, default 2048):  
  9. Using default value 2048  
  10. Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +10G  
  11. Partition 1 of type Linux and of size 10 GiB is set  
  12. Command (m for help): w  
  13. The partition table has been altered!  
  14. [root@master ~]# mke2fs -t ext4 -b 2048 -m 2 -L MYDATA /dev/sdb1  
  15. [root@master ~]# tune2fs -o acl /dev/sdb1  
  16. [root@master ~]# mount -o noexec,noatime /dev/sdb1 /data/mydata 

2.创建一个大小为1G的swap分区,并创建好文件系统,并启用之,写一个脚本

获取并列出当前系统上的所有磁盘设备

显示每个磁盘设备上每个分区的相关的空间使用信息

  1. Last sector, +sectors or +size{K,M,G} (20973568-41943039, default 41943039): +1G 
  2. Partition 2 of type Linux and of size 1 GiB is set 
  3. Command (m for help): t 
  4. Partition number (1,2, default 2): 2 
  5. Hex code (type L to list all codes): L 
  6. Hex code (type L to list all codes): 82 
  7. Changed type of partition 'Linux' to 'Linux swap / Solaris' 
  8. Command (m for help): w 
  9. The partition table has been altered! 
  10. [root@master ~]# mkswap -L SWAP /dev/sdb2 
  11. [root@master ~]# swapon /dev/sdb2 
  12. #!/bin/bash 
  13. disks=`fdisk -l|grep -o '^Disk /dev/[sh]d[a-z]'|cut -d' ' -f2` 
  14. echo $disks 
  15. for i in $disks;do 
  16. fdisk -l $i 
  17. done 

3.总结RAID的各个级别及其组合方式和性能的不同

RAID(冗余磁盘阵列)是将多块磁盘当做一块物理磁盘来使用,以达到容错或者提高读写性能的优势。按照 组织起来的工作方式的不同,我们可以将RAID分为不同的级别,其中常见的有RAID0、RAID1、RAID5、RAID10

RAID0

俗称条带卷,实现将文件分成多个chunk后同时并行存储到多个盘中。

特性

读写性能得到提升

无冗余能力

最少磁盘数为2

可用空间为容量最小的磁盘*磁盘数

RAID1

俗称镜像卷,在存储数据的同时需要再复制一份存入另一个磁盘中。

特性

读性能提升,写性能下降

有冗余能力

最少磁盘数为2,偶数

可用空间小于1/2

RAID5

将文件分成多个chunk,两两chunk之间作异或运算,各盘轮流存储校验码

特点

读写性能提升

有冗余能力

最少磁盘数为3

可用空间为容量最小的磁盘*(磁盘数-1)

RAID10

先两两做raid1,后将多组raid1组织成raid0

特点

读写性能提升

有冗余能力

最小磁盘数4

可用空间为容量最小的磁盘*磁盘数/2

4.创建一个大小为10G的RAID1,要求有一个空闲盘,而且chunk大小为128k

  1. [root@master ~]# fdisk /dev/sdb 
  2. Command (m for help): n 
  3. Partition type: 
  4. primary (1 primary, 0 extended, 3 free
  5. e extended 
  6. Select (default p): p 
  7. Partition number (2-4, default 2): 2 
  8. First sector (20973568-41943039, default 20973568): 
  9. Using default value 20973568 
  10. [root@master ~]# fdisk /dev/sdb 
  11. Command (m for help): n 
  12. Partition type: 
  13. primary (0 primary, 0 extended, 4 free
  14. e extended 
  15. Select (default p): p 
  16. Partition number (1-4, default 1): 1 
  17. First sector (2048-104857599, default 2048): 
  18. Using default value 2048 
  19. Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599): +10G 
  20. Partition 1 of type Linux and of size 10 GiB is set 
  21. Command (m for help): n 
  22. Partition type: 
  23. primary (1 primary, 0 extended, 3 free
  24. e extended 
  25. Select (default p): p 
  26. Partition number (2-4, default 2): 2 
  27. First sector (20973568-104857599, default 20973568): +10G 
  28. Value out of range. 
  29. First sector (20973568-104857599, default 20973568): 
  30. Using default value 20973568 
  31. Last sector, +sectors or +size{K,M,G} (20973568-104857599, default 104857599): +10G 
  32. Partition 2 of type Linux and of size 10 GiB is set 
  33. Command (m for help): n 
  34. Partition type: 
  35. primary (2 primary, 0 extended, 2 free
  36. e extended 
  37. Select (default p): p 
  38. Partition number (3,4, default 3): 3 
  39. First sector (41945088-104857599, default 41945088): 
  40. Using default value 41945088 
  41. Last sector, +sectors or +size{K,M,G} (41945088-104857599, default 104857599): +10G 
  42. Partition 3 of type Linux and of size 10 GiB is set 
  43. Command (m for help): t 
  44. Partition number (1-3, default 3): 1 
  45. Hex code (type L to list all codes): fd 
  46. Changed type of partition 'Linux' to 'Linux raid autodetect' 
  47. Command (m for help): t 
  48. Partition number (1-3, default 3): 2 
  49. Hex code (type L to list all codes): fd 
  50. Changed type of partition 'Linux' to 'Linux raid autodetect' 
  51. Command (m for help): t 
  52. Partition number (1-3, default 3): 3 
  53. Hex code (type L to list all codes): fd 
  54. Changed type of partition 'Linux' to 'Linux raid autodetect' 
  55. Command (m for help): w 
  56. The partition table has been altered! 
  57. [root@master ~]# mdadm -C /dev/md0 -n 2 -c 128 -x 1 -l 1 -a yes /dev/sdb{1,2,3} 
  58. mdadm: Defaulting to version 1.2 metadata 
  59. mdadm: array /dev/md0 started. 

5.创建一个大小为4G的RAID5设备,chunk大小为256k,格式化ext4文件系统,要求可开机自动挂载至/backup目录,且不更新访问时间戳,且支持acl功

  1. “` 
  2. [root@master ~]# fdisk /dev/sdb 
  3. Command (m for help): n 
  4. All primary partitions are in use 
  5. Adding logical partition 5 
  6. First sector (62918656-104857599, default 62918656): 
  7. Using default value 62918656 
  8. Last sector, +sectors or +size{K,M,G} (62918656-104857599, default 104857599): +2G 
  9. Partition 5 of type Linux and of size 2 GiB is set 
  10. Command (m for help): n 
  11. All primary partitions are in use 
  12. Adding logical partition 6 
  13. First sector (67115008-104857599, default 67115008): 
  14. Using default value 67115008 
  15. Last sector, +sectors or +size{K,M,G} (67115008-104857599, default 104857599): +2G 
  16. Partition 6 of type Linux and of size 2 GiB is set 
  17. Command (m for help): n 
  18. All primary partitions are in use 
  19. Adding logical partition 7 
  20. First sector (71311360-104857599, default 71311360): 
  21. Using default value 71311360 
  22. Last sector, +sectors or +size{K,M,G} (71311360-104857599, default 104857599): +2G 
  23. Partition 7 of type Linux and of size 2 GiB is set 
  24. Command (m for help): w 
  25. The partition table has been altered! 
  26. [root@master ~]# mdadm -C /dev/md1 -n 3 -c 256 -l 5 -a yes /dev/sdb{5,6,7} 
  27. mdadm: Defaulting to version 1.2 metadata 
  28. mdadm: array /dev/md1 started. 
  29. [root@master ~]# mke2fs -t ext4 /dev/md1 
  30. [root@master ~]# mkdir /backup 
  31. [root@master ~]# mount -o auto /dev/md1 /backup 
责任编辑:武晓燕 来源: 运维部落
相关推荐

2009-10-12 11:14:51

LinuxLinux磁盘文件系统管理

2010-04-07 18:42:42

Unix命令

2009-10-13 14:31:26

:Linux系统磁盘系统管理

2009-02-25 11:53:23

文件管理POSIX备份

2010-01-14 17:05:42

MySQL CentO

2013-09-18 10:57:09

虚拟化应用

2010-05-05 15:56:37

Unix系统

2014-01-13 10:02:11

虚拟化系统管理

2011-09-01 13:42:15

优化布线系统管理布线系统

2010-05-05 16:27:22

Unix系统

2010-05-04 15:22:25

Unix系统

2013-08-22 10:15:32

应用性能监控系统管理

2011-11-23 10:21:44

思科云计算IaaS

2010-05-07 17:16:36

Unix系统

2013-05-02 14:06:30

Android开发用户系统管理

2017-03-27 09:30:14

Linux系统管理技巧

2013-05-09 09:27:46

2021-06-28 06:24:12

磁盘存储VFS

2021-06-22 15:16:01

磁盘机械磁盘固态磁盘

2021-06-21 14:52:45

磁盘机械磁盘固态磁盘
点赞
收藏

51CTO技术栈公众号