您的位置:首页 > 运维架构 > Linux

LVM磁盘配额

2016-08-14 15:13 239 查看
Logical Volume Manager,逻辑卷管理
作用:动态调整磁盘容量,从而提高磁盘管理的灵活性
PS:
/boot 分区用于存放引导文件,不能基于 LVM 创建

PV(Physical Volume,物理卷)
整个硬盘,或使用fdisk等工具建立的普通分区

包括许多默认4MB大小的PE(Physical Extent,基本单元)

VG(Volume Group,卷组)
一个或多个物理卷组合而成的整体

LV(Logical Volume,逻辑卷)
从卷组中分割出的一块空间,用于建立文件系统








Linux 磁盘限额的特点
作用范围:针对指定的文件系统(分区)
限制对象:用户帐号、组帐号
限制类型
磁盘容量(默认单位为 KB)

文件数量

限制方法
软限制

硬限制

主要命令:
功能物理卷管理卷组管理逻辑卷管理
Scan 扫描pvscanvgscanlvscan
Create 创建pvcreatevgcreatelvcreate
Display 显示pvdisplayvgdisplaylvdisplay
Remove 删除pvremovevgremovelvremove
Extend 扩展vgextendlvextend
Reduce 减少vgreducelvreduce
pvcreate 设备名1[设备名2 … …]
vgcreate 卷组名 物理卷名1 物理卷2
lvcreate -L 容量大小 -n 逻辑卷名 卷组名
lvextend -L +大小 /dev/卷组名/逻辑卷名
实验需求:
公司准备在Internet中搭建邮件服务器(RHEL6系统平台),面向全国各地的员工及部分VIP客户提供电子邮箱空间。由于用户数量众多,邮件存储需要大量的空间,考虑到动态扩容的需要,计划增加两块SCSI硬盘并构建LVM逻辑卷(挂载到“/mailbox”目录下)专门用于存放邮件数据;
实验步骤:



[root@localhost ~]# pvcreate /dev/sdb /dev/sdc         //创建PV物理卷;
Physical volume "/dev/sdb" successfully created
Physical volume "/dev/sdc" successfully created
[root@localhost ~]# pvscan     //PV扫描;
PV /dev/sdb                      lvm2 [1.00 GiB]
PV /dev/sdc                      lvm2 [1.00 GiB]
Total: 2 [2.00 GiB] / in use: 0 [0   ] / in no VG: 2 [2.00 GiB]
[root@localhost ~]# vgcreate mail /dev/sdb /dev/sdc   //创建mail VG卷组;
Volume group "mail" successfully created
[root@localhost ~]# lvcreate -n mail01 -L 500M /dev/mail    //创建mail01 lv逻辑卷,指定大小500M;
Logical volume "mail01" created
[root@localhost ~]# mkfs -t ext4 /dev/mail/mail01   //格式化转换格式为EXT4;
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=1024 (log=0)
分块大小=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
128016 inodes, 512000 blocks
25600 blocks (5.00%) reserved for the super user
第一个数据块=1
Maximum filesystem blocks=67633152
63 block groups
8192 blocks per group, 8192 fragments per group
2032 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409
正在写入inode表: 完成
Creating journal (8192 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 29 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@localhost ~]# mount /dev/mail/mail01 /mnt    //挂载到/mnt目录;
[root@localhost ~]# mount -o remount,usrquota,grpquota /dev/mail/mail01 /mnt     //以支持配额功能的方式挂载文件系统;
[root@localhost ~]# mount   //查看是否挂载usrquota、grpquota;
/dev/sda1 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda3 on /opt type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/dev/mapper/mail-mail01 on /mnt type ext4 (rw,usrquota,grpquota)
[root@localhost ~]# quotacheck -cvug /mnt    //检测磁盘配额并生成配额文件;
quotacheck: Your kernel probably supports journaled quota but you are not using it. Consider switching to journaled quota to avoid running quotacheck after an unclean shutdown.
quotacheck: Scanning /dev/mapper/mail-mail01 [/mnt] done
quotacheck: Cannot stat old user quota file: 没有那个文件或目录
quotacheck: Cannot stat old group quota file: 没有那个文件或目录
quotacheck: Cannot stat old user quota file: 没有那个文件或目录
quotacheck: Cannot stat old group quota file: 没有那个文件或目录
quotacheck: Checked 2 directories and 0 files
quotacheck: Old file not found.
quotacheck: Old file not found.
[root@localhost ~]# quotaon /mnt    //打开磁盘配额功能;
[root@localhost ~]# ls /mnt     //查看是否正确生成文件;
aquota.group  aquota.user  lost+found
[root@localhost ~]# useradd tom   //添加用户tom;
[root@localhost ~]#edquota -u tom    //配置tom用户磁盘配额;
Disk quotas for user tom (uid 501):
Filesystem                   blocks       soft       hard     inodes     soft     hard
/dev/mapper/mail-mail01           0          10240          20480          0        3        5
~
//配置磁盘配额大小软限制为10240kb,硬限制为20480kb,软件个数软限制3,硬限制5;
[root@localhost ~]# chmod 777 /mnt   //修改/mnt目录权限;
[root@localhost ~]# passwd tom  //设置tom用户密码;
更改用户 tom 的密码 。
新的 密码:
无效的密码: WAY 过短
无效的密码: 过于简单
重新输入新的 密码:
passwd: 所有的身份验证令牌已经成功更新。
[root@localhost ~]# su tom   //切换用户tom登陆;
[tom@localhost root]$ cd /mnt  //cd到mnt目录;
[tom@localhost mnt]$ dd if=/dev/zero of=tom bs=4M count=6  //测试磁盘配额限制;
dd: 正在写入"tom": 超出磁盘限额
记录了3+0 的读入
记录了2+0 的写出
8388608字节(8.4 MB)已复制,0.0406565 秒,206 MB/秒
[tom@localhost mnt]$ dd if=/dev/zero of=tom01 bs=4M count=1
记录了1+0 的读入
记录了1+0 的写出
....
[tom@localhost mnt]$ dd if=/dev/zero of=tom06 bs=4M count=1
dd: 正在打开"tom06": 超出磁盘限额
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Linux 磁盘管理 动态