磁盤配額,RAID和LVM管理
1.磁盤配額的作用
??磁盤配額就限制用戶在該目錄中使用空間的大小和限制用戶 上傳文件的數量(也就是inode號)。
2.舉例
在創建磁盤配額時,需要關閉selinux
[root@centos6 ~]#vim /etc/selinux/config # This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. SELINUX=disabled #更改成disabled # SELINUXTYPE= can take one of these two values: # targeted - Targeted processes are protected, # mls - Multi Level Security protection. SELINUXTYPE=targeted
創建磁盤配額需要在掛載時指定屬性
[root@centos6 app]#mount -o usrquota,grpquota /dev/sdc1 /app/quota/
[root@centos6 app]#mount -l |tail -1
/dev/sdc1 on /app/quota type ext4 (rw,usrquota,grpquota)
創建磁盤配額
[root@centos6 ~]#quotacheck -cugm /app/test/
開啟磁盤配額,不會被任何用戶刪除aquota.group aquota.user兩個文件
[root@centos6 ~]#quotaon /app/test/ [root@centos6 ~]#cd /app/test/ [root@centos6 test]#ls aquota.group aquota.user
命令行的方法給限制,命令格式:setquota username 軟限制大小 硬限制大小 軟限制文件數 硬限制文件數
[root@centos6 test]#setquota ceshi 100M 200M 80 100 /app/test/
查看所有用戶的配額情況
[root@centos6 test]#repquota -av *** Report for user quotas on device /dev/sdc Block grace time: 7days; Inode grace time: 7days Block limits File limits User used soft hard grace used soft hard grace ---------------------------------------------------------------------- root -- 4 0 0 1 0 0 ceshi -- 0 102400 204800 0 80 100 Statistics: Total blocks: 7 Data blocks: 1 Entries: 2 Used average: 2.000000
查看指定用戶大小
[root@centos6 test]#quota -v ceshi #直接跟用戶,不跟用戶則查看自己大小
Disk quotas for user ceshi (uid 502):
Filesystem blocks quota limit grace files quota limit grace
/dev/sdc 0 102400 204800 0 80 100
交互式配置
[root@centos6 test]#edquota -u ceshi
Disk quotas for user ceshi (uid 502):
Filesystem blocks soft hard inodes soft hard
/dev/sdc 0 102400 204800 0 80 100
軟限制大小 硬限制大小 軟限制文件數 硬限制文件數
二、RAID
1.RAID介紹
RAID就是多個磁盤合成一個陣列,來提供更好的性能、冗余。
RAID分為硬件RAID和軟件RAID
硬件RAID:
??外接式磁盤陣列櫃
??內接式磁盤陣列卡
軟件RAID:利用系統自帶的磁盤管理功能將磁盤陣列,不過不會提升性能,一般不會使用
2.常用RAID介紹
RAID0-----條帶卷
將數據平均放到兩塊(以上)盤上
優點:讀寫增加,不浪得磁盤
缺點:沒有備份,盤數越多,安全性越低
RAID1-----鏡像卷
將數據分別寫在兩塊(以上)盤上
優點:安全性高,性能增加
缺點:寫性能略微降低,空間浪費多(1*最小磁盤數)
RAID5
將數據分別寫在所有盤上,拿出一塊盤的空間來備份
優點:讀寫性能增加,數據能恢復
缺點:若果壞兩塊磁盤,數據將丟失
RAID6同RAID5只不過是拿兩塊盤來做備份
RAID01是先做RAID0在做RAID1
RAID10是先做RAID1在做RAID0(RAID10和RAID01浪費空間一樣,但是RAID10安全性更高)
RAID50是先做RAID5在做RAID0(RAID50比RAID10安全性略低)
三、LVM(邏輯卷)
1.LVM介紹
LVM就是把多個物理設備捆綁到一塊,然後從中拿空間,LVM最大的優點就是可以在線擴容,若果空間不夠,可以直接從卷組中拿空間。
2.圖解
3.舉例說明
pvcreate --------------->>在磁盤中添加標識
[root@centos6 ~]#pvcreate /dev/sdc{1,2,3} #這裏我是把一塊硬盤分區然後做的lvm,其實直接做就行
Physical volume "/dev/sdc1" successfully created #創建成功
Physical volume "/dev/sdc2" successfully created
Physical volume "/dev/sdc3" successfully created
pvs&&pvdisplay查看pv信息
[root@centos6 ~]#pvs #簡單列出,pvdisplay詳細列出
PV VG Fmt Attr PSize PFree
/dev/sdc1 lvm2 ---- 509.84m 509.84m
/dev/sdc2 lvm2 ---- 509.88m 509.88m
/dev/sdc3 lvm2 ---- 509.88m 509.88m
vgcreate--------->>創建卷組
vgs&&vgdisplay查看卷組信息
[root@centos6 ~]#vgcreate -s 16M testvg /dev/sdc{1,2,3} #創建卷組,-s設置PE塊大小,默認4M
Volume group "testvg" successfully created
[root@centos6 ~]#vgs #簡單列出卷組,vgdisplay詳細列出
VG #PV #LV #SN Attr VSize VFree
testvg 3 0 0 wz--n- 1.45g 1.45g
lvcreate ----------------------->>創建邏輯卷
選項
-l:從卷組中拿多少PE
-L N:設置大小為N,直接加大小後面跟單位
-n name:設置邏輯卷 名字
-l 100%FREE:直接把卷組中的空間全部拿完,也可以設置百分比
lvs&&lvdisplay查看邏輯卷信息
[root@centos6 ~]#lvcreate -L 100M -n testlv testvg #指定大小為100M 名字為testlv
Rounding up size to full physical extent 112.00 MiB
Logical volume "testlv" created.
[root@centos6 ~]#lvs #簡單列出,lvdisplay詳細列出
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
testlv testvg -wi-a----- 112.00m
最後格式化就可以掛載使用了
[root@centos6 ~]#mkfs.ext4 /dev/testvg/testlv #該命令只支持ext系列,如果需要格式xfs請用xfs.growfs命令來格式化
[root@centos6 ~]#mount /dev/testvg/testlv /app/test/
[root@centos6 ~]#df -h
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/testvg-testlv
105M 1.6M 98M 2% /app/test
增加卷組大小
[root@centos6 ~]#vgextend testvg /dev/sdc5 #如果卷組空間不夠,可以添加硬盤到裏面
Physical volume "/dev/sdc5" successfully created
Volume group "testvg" successfully extended
[root@centos6 ~]#lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
testlv testvg -wi-ao---- 208.00m
添加邏輯卷大小
lvextend:增加大小
[root@centos6 ~]#lvextend -L 200M -n /dev/testvg/testlv 指定要添加空間的邏輯卷
Rounding size to boundary between physical extents: 208.00 MiB.
Size of logical volume testvg/testlv changed from 112.00 MiB (7 extents) to 208.00 MiB (13 extents).
Logical volume testlv successfully resized.
[root@centos6 ~]#lvs #邏輯卷大小添加成功,但是還需要添加系統空間
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
testlv testvg -wi-ao---- 208.00m
[root@centos6 ~]#resize2fs /dev/testvg/testlv #添加系統空間
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/testvg/testlv is mounted on /app/test; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/testvg/testlv to 212992 (1k) blocks.
The filesystem on /dev/testvg/testlv is now 212992 blocks long.
[root@centos6 ~]#df -h #成功增加空間
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/testvg-testlv
198M 1.8M 186M 1% /app/test
縮小邏輯卷空間,一般不建議縮小,縮減空間必須小於不能超過已用空間
縮小系統中的空間
#縮小邏輯卷空間
[root@centos6 ~]#umount /mnt ----->>先卸載
[root@centos6 ~]#e2fsck -f /dev/testvg/testlv ----->>在檢測硬盤,並且縮小範圍不能小於使用範圍
e2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/testvg/testlv: 11/77824 files (0.0% non-contiguous), 15979/307200 blocks
[root@centos6 ~]#resize2fs /dev/testvg/testlv 100M ----->>先縮小系統中的大小
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/testvg/testlv to 102400 (1k) blocks.
The filesystem on /dev/testvg/testlv is now 102400 blocks long.
縮小邏輯卷空間
[root@centos6 ~]#lvreduce -L 100M /dev/testvg/testlv ----->>在縮小邏輯卷的大小
Rounding size to boundary between physical extents: 112.00 MiB.
WARNING: Reducing active logical volume to 112.00 MiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce testvg/testlv? [y/n]: y
Size of logical volume testvg/testlv changed from 304.00 MiB (19 extents) to 112.00 MiB (7 extents).
Logical volume testlv successfully resized.
[root@centos6 ~]#mount /dev/testvg/testlv /test ----->>掛載邏輯卷
[root@centos6 ~]#df -H ----->>縮小成功,xfs不支持縮小,只有ext系統支持,在生產環境中,一般不會縮小
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 61G 20G 39G 34% /
tmpfs 1.1G 74k 1.1G 1% /dev/shm
/dev/sda3 22G 153M 20G 1% /app
/dev/sda1 199M 42M 148M 22% /boot
/dev/mapper/testvg-testlv
98M 1.6M 91M 2% /test
修改卷組名自
[root@centos6 ~]#lvrename /dev/testvg/testlv /dev/testvg/testll ----->>修改邏輯卷名字
Renamed "testlv" to "testll" in volume group "testvg"
[root@centos6 ~]#lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
testll testvg -wi-ao---- 112.00m
刪除邏輯卷
[root@centos6 ~]#lvremove /dev/testvg/testll ----->>刪除邏輯卷
Do you really want to remove active logical volume testll? [y/n]: y
Logical volume "testll" successfully removed
[root@centos6 ~]#vgrename testvg test1 ----------->>修改卷組名字
Volume group "testvg" successfully renamed to "test1"
[root@centos6 ~]#vgremove /dev/testvg ----->>刪除卷組
Volume group "testvg" successfully removed
[root@centos6 ~]#pvremove /dev/sd{b,c,d} ----->>把磁盤中的LVM信息刪除
Labels on physical volume "/dev/sdb" successfully wiped
Labels on physical volume "/dev/sdc" successfully wiped
Labels on physical volume "/dev/sdd" successfully wiped
創建快照
[root@centos6 ~]#lvcreate -s -L 100M -n testlvsnap /dev/testvg/testlv ----------->>創建快照
Logical volume "testlvsnap" created.
[root@centos6 ~]#lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
testlv testvg owi-a-s--- 100.00m
testlvsnap testvg swi-a-s--- 100.00m testlv 0.00
---------->>剛創建的時候大小為0,當原數據改變,快照則變大,
存儲變化的數據,將變化的數據拷過來,如果超過空間,
快照則損壞,一般用於備份,創建虛擬機的時候使用
磁盤配額,RAID和LVM管理