磁盘配额,RAID和LVM管理
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了磁盘配额,RAID和LVM管理相关的知识,希望对你有一定的参考价值。
一、磁盘配额
1.磁盘配额的作用
??磁盘配额就限制用户在该目录中使用空间的大小和限制用户 上传文件的数量(也就是inode号)。
2.举例
在创建磁盘配额时,需要关闭selinux
[[email protected] ~]#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
创建磁盘配额需要在挂载时指定属性
[[email protected] app]#mount -o usrquota,grpquota /dev/sdc1 /app/quota/
[[email protected] app]#mount -l |tail -1
/dev/sdc1 on /app/quota type ext4 (rw,usrquota,grpquota)
创建磁盘配额
[[email protected] ~]#quotacheck -cugm /app/test/
开启磁盘配额,不会被任何用户删除aquota.group aquota.user两个文件
[[email protected] ~]#quotaon /app/test/
[[email protected] ~]#cd /app/test/
[[email protected] test]#ls
aquota.group aquota.user
命令行的方法给限制,命令格式:setquota username 软限制大小 硬限制大小 软限制文件数 硬限制文件数
[[email protected] test]#setquota ceshi 100M 200M 80 100 /app/test/
查看所有用户的配额情况
[[email protected] 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
查看指定用户大小
[[email protected] 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
交互式配置
[[email protected] 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 --------------->>在磁盘中添加标识
[[email protected] ~]#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信息
[[email protected] ~]#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查看卷组信息
[[email protected] ~]#vgcreate -s 16M testvg /dev/sdc{1,2,3} #创建卷组,-s设置PE块大小,默认4M
Volume group "testvg" successfully created
[[email protected] ~]#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查看逻辑卷信息
[[email protected] ~]#lvcreate -L 100M -n testlv testvg #指定大小为100M 名字为testlv
Rounding up size to full physical extent 112.00 MiB
Logical volume "testlv" created.
[[email protected] ~]#lvs #简单列出,lvdisplay详细列出
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
testlv testvg -wi-a----- 112.00m
最后格式化就可以挂载使用了
[[email protected] ~]#mkfs.ext4 /dev/testvg/testlv #该命令只支持ext系列,如果需要格式xfs请用xfs.growfs命令来格式化
[[email protected] ~]#mount /dev/testvg/testlv /app/test/
[[email protected] ~]#df -h
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/testvg-testlv
105M 1.6M 98M 2% /app/test
增加卷组大小
[[email protected] ~]#vgextend testvg /dev/sdc5 #如果卷组空间不够,可以添加硬盘到里面
Physical volume "/dev/sdc5" successfully created
Volume group "testvg" successfully extended
[[email protected] ~]#lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
testlv testvg -wi-ao---- 208.00m
添加逻辑卷大小
lvextend:增加大小
[[email protected] ~]#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.
[[email protected] ~]#lvs #逻辑卷大小添加成功,但是还需要添加系统空间
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
testlv testvg -wi-ao---- 208.00m
[[email protected] ~]#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.
[[email protected] ~]#df -h #成功增加空间
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/testvg-testlv
198M 1.8M 186M 1% /app/test
缩小逻辑卷空间,一般不建议缩小,缩减空间必须小于不能超过已用空间
缩小系统中的空间
#缩小逻辑卷空间
[[email protected] ~]#umount /mnt ----->>先卸载
[[email protected] ~]#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
[[email protected] ~]#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.
缩小逻辑卷空间
[[email protected] ~]#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.
[[email protected] ~]#mount /dev/testvg/testlv /test ----->>挂载逻辑卷
[[email protected] ~]#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
修改卷组名自
[[email protected] ~]#lvrename /dev/testvg/testlv /dev/testvg/testll ----->>修改逻辑卷名字
Renamed "testlv" to "testll" in volume group "testvg"
[[email protected] ~]#lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
testll testvg -wi-ao---- 112.00m
删除逻辑卷
[[email protected] ~]#lvremove /dev/testvg/testll ----->>删除逻辑卷
Do you really want to remove active logical volume testll? [y/n]: y
Logical volume "testll" successfully removed
[[email protected] ~]#vgrename testvg test1 ----------->>修改卷组名字
Volume group "testvg" successfully renamed to "test1"
[[email protected] ~]#vgremove /dev/testvg ----->>删除卷组
Volume group "testvg" successfully removed
[[email protected] ~]#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
创建快照
[[email protected] ~]#lvcreate -s -L 100M -n testlvsnap /dev/testvg/testlv ----------->>创建快照
Logical volume "testlvsnap" created.
[[email protected] ~]#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管理的主要内容,如果未能解决你的问题,请参考以下文章