磁盤及文件系統(tǒng)管理應(yīng)用實(shí)例
1.創(chuàng)建一個(gè)10G的分區(qū),并格式化為ext4文件系統(tǒng)
要求其block大小為2048,預(yù)留空間百分比為2,卷標(biāo)為MYDATA,默認(rèn)掛載屬性包含acl
掛載至/data/mydata目錄,要求掛載時(shí)禁止程序自動(dòng)運(yùn)行,且不更新文件的訪問時(shí)間戳
- [root@master ~]# fdisk /dev/sdb
- 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-41943039, default 2048):
- Using default value 2048
- Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +10G
- Partition 1 of type Linux and of size 10 GiB is set
- Command (m for help): w
- The partition table has been altered!
- [root@master ~]# mke2fs -t ext4 -b 2048 -m 2 -L MYDATA /dev/sdb1
- [root@master ~]# tune2fs -o acl /dev/sdb1
- [root@master ~]# mount -o noexec,noatime /dev/sdb1 /data/mydata
2.創(chuàng)建一個(gè)大小為1G的swap分區(qū),并創(chuàng)建好文件系統(tǒng),并啟用之,寫一個(gè)腳本
獲取并列出當(dāng)前系統(tǒng)上的所有磁盤設(shè)備
顯示每個(gè)磁盤設(shè)備上每個(gè)分區(qū)的相關(guān)的空間使用信息
- Last sector, +sectors or +size{K,M,G} (20973568-41943039, default 41943039): +1G
- Partition 2 of type Linux and of size 1 GiB is set
- Command (m for help): t
- Partition number (1,2, default 2): 2
- Hex code (type L to list all codes): L
- Hex code (type L to list all codes): 82
- Changed type of partition 'Linux' to 'Linux swap / Solaris'
- Command (m for help): w
- The partition table has been altered!
- [root@master ~]# mkswap -L SWAP /dev/sdb2
- [root@master ~]# swapon /dev/sdb2
- #!/bin/bash
- #
- disks=`fdisk -l|grep -o '^Disk /dev/[sh]d[a-z]'|cut -d' ' -f2`
- echo $disks
- for i in $disks;do
- fdisk -l $i
- done
3.總結(jié)RAID的各個(gè)級(jí)別及其組合方式和性能的不同
RAID(冗余磁盤陣列)是將多塊磁盤當(dāng)做一塊物理磁盤來使用,以達(dá)到容錯(cuò)或者提高讀寫性能的優(yōu)勢(shì)。按照 組織起來的工作方式的不同,我們可以將RAID分為不同的級(jí)別,其中常見的有RAID0、RAID1、RAID5、RAID10
RAID0
俗稱條帶卷,實(shí)現(xiàn)將文件分成多個(gè)chunk后同時(shí)并行存儲(chǔ)到多個(gè)盤中。
特性
讀寫性能得到提升
無冗余能力
最少磁盤數(shù)為2
可用空間為容量最小的磁盤*磁盤數(shù)
RAID1
俗稱鏡像卷,在存儲(chǔ)數(shù)據(jù)的同時(shí)需要再?gòu)?fù)制一份存入另一個(gè)磁盤中。
特性
讀性能提升,寫性能下降
有冗余能力
最少磁盤數(shù)為2,偶數(shù)
可用空間小于1/2
RAID5
將文件分成多個(gè)chunk,兩兩chunk之間作異或運(yùn)算,各盤輪流存儲(chǔ)校驗(yàn)碼
特點(diǎn)
讀寫性能提升
有冗余能力
最少磁盤數(shù)為3
可用空間為容量最小的磁盤*(磁盤數(shù)-1)
RAID10
先兩兩做raid1,后將多組raid1組織成raid0
特點(diǎn)
讀寫性能提升
有冗余能力
最小磁盤數(shù)4
可用空間為容量最小的磁盤*磁盤數(shù)/2
4.創(chuàng)建一個(gè)大小為10G的RAID1,要求有一個(gè)空閑盤,而且chunk大小為128k
- [root@master ~]# fdisk /dev/sdb
- Command (m for help): n
- Partition type:
- p primary (1 primary, 0 extended, 3 free)
- e extended
- Select (default p): p
- Partition number (2-4, default 2): 2
- First sector (20973568-41943039, default 20973568):
- Using default value 20973568
- [root@master ~]# fdisk /dev/sdb
- 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-104857599, default 2048):
- Using default value 2048
- Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599): +10G
- Partition 1 of type Linux and of size 10 GiB is set
- Command (m for help): n
- Partition type:
- p primary (1 primary, 0 extended, 3 free)
- e extended
- Select (default p): p
- Partition number (2-4, default 2): 2
- First sector (20973568-104857599, default 20973568): +10G
- Value out of range.
- First sector (20973568-104857599, default 20973568):
- Using default value 20973568
- Last sector, +sectors or +size{K,M,G} (20973568-104857599, default 104857599): +10G
- Partition 2 of type Linux and of size 10 GiB is set
- Command (m for help): n
- Partition type:
- p primary (2 primary, 0 extended, 2 free)
- e extended
- Select (default p): p
- Partition number (3,4, default 3): 3
- First sector (41945088-104857599, default 41945088):
- Using default value 41945088
- Last sector, +sectors or +size{K,M,G} (41945088-104857599, default 104857599): +10G
- Partition 3 of type Linux and of size 10 GiB is set
- Command (m for help): t
- Partition number (1-3, default 3): 1
- Hex code (type L to list all codes): fd
- Changed type of partition 'Linux' to 'Linux raid autodetect'
- Command (m for help): t
- Partition number (1-3, default 3): 2
- Hex code (type L to list all codes): fd
- Changed type of partition 'Linux' to 'Linux raid autodetect'
- Command (m for help): t
- Partition number (1-3, default 3): 3
- Hex code (type L to list all codes): fd
- Changed type of partition 'Linux' to 'Linux raid autodetect'
- Command (m for help): w
- The partition table has been altered!
- [root@master ~]# mdadm -C /dev/md0 -n 2 -c 128 -x 1 -l 1 -a yes /dev/sdb{1,2,3}
- mdadm: Defaulting to version 1.2 metadata
- mdadm: array /dev/md0 started.
5.創(chuàng)建一個(gè)大小為4G的RAID5設(shè)備,chunk大小為256k,格式化ext4文件系統(tǒng),要求可開機(jī)自動(dòng)掛載至/backup目錄,且不更新訪問時(shí)間戳,且支持acl功
- “`
- [root@master ~]# fdisk /dev/sdb
- Command (m for help): n
- All primary partitions are in use
- Adding logical partition 5
- First sector (62918656-104857599, default 62918656):
- Using default value 62918656
- Last sector, +sectors or +size{K,M,G} (62918656-104857599, default 104857599): +2G
- Partition 5 of type Linux and of size 2 GiB is set
- Command (m for help): n
- All primary partitions are in use
- Adding logical partition 6
- First sector (67115008-104857599, default 67115008):
- Using default value 67115008
- Last sector, +sectors or +size{K,M,G} (67115008-104857599, default 104857599): +2G
- Partition 6 of type Linux and of size 2 GiB is set
- Command (m for help): n
- All primary partitions are in use
- Adding logical partition 7
- First sector (71311360-104857599, default 71311360):
- Using default value 71311360
- Last sector, +sectors or +size{K,M,G} (71311360-104857599, default 104857599): +2G
- Partition 7 of type Linux and of size 2 GiB is set
- Command (m for help): w
- The partition table has been altered!
- [root@master ~]# mdadm -C /dev/md1 -n 3 -c 256 -l 5 -a yes /dev/sdb{5,6,7}
- mdadm: Defaulting to version 1.2 metadata
- mdadm: array /dev/md1 started.
- [root@master ~]# mke2fs -t ext4 /dev/md1
- [root@master ~]# mkdir /backup
- [root@master ~]# mount -o auto /dev/md1 /backup