1.需要把/dev/myvg/mylv逻辑卷以支持磁盘配额的方式挂载到网页目录下
2、在网页目录下创建测试文件index.html,内容为用户名称,通过浏览器访问测试
3、创建用户账户,对LVM配置磁盘配额限制用户磁盘容量为软限制80M;硬限制100M、文件数量软限制为80个;硬限制为100个
[root@localhost ~]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
Device does not contain a recognized partition table
使用磁盘标识符 0xcf2d39c1 创建新的 DOS 磁盘标签。
命令(输入 m 获取帮助):n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
分区号 (1-4,默认 1):
起始 扇区 (2048-125829119,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-125829119,默认为 125829119):+20G
分区 1 已设置为 Linux 类型,大小设为 20 GiB
命令(输入 m 获取帮助):n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
分区号 (2-4,默认 2):
起始 扇区 (41945088-125829119,默认为 41945088):
将使用默认值 41945088
G
分区 2 已设置为 Linux 类型,大小设为 20 GiB
命令(输入 m 获取帮助):
命令(输入 m 获取帮助):n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
分区号 (3,4,默认 3):
起始 扇区 (83888128-125829119,默认为 83888128):
将使用默认值 83888128
Last 扇区, +扇区 or +size{K,M,G} (83888128-125829119,默认为 125829119):
将使用默认值 125829119
分区 3 已设置为 Linux 类型,大小设为 20 GiB
命令(输入 m 获取帮助):p
磁盘 /dev/sdb:64.4 GB, 64424509440 字节,125829120 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0xcf2d39c1
设备 Boot Start End Blocks Id System
/dev/sdb1 2048 41945087 20971520 83 Linux
/dev/sdb2 41945088 83888127 20971520 83 Linux
/dev/sdb3 83888128 125829119 20970496 83 Linux
命令(输入 m 获取帮助):w
The partition table has been altered!
Calling ioctl() to re-read partition table.
正在同步磁盘。
[root@localhost ~]# partprobe /dev/sdb
[root@localhost ~]# mdadm -C /dev/md5 -l 5 -n 3 /dev/sdb[1-3]
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md5 started.
[root@localhost ~]# pvcreate /dev/md5
Physical volume "/dev/md5" successfully created.
[root@localhost ~]# vgcreate myvg /dev/md5
Volume group "myvg" successfully created
[root@localhost httpd-2.4.41]# lvcreate -n mylv -L 20G myvg
Logical volume "mylv" created.
[root@localhost httpd-2.4.41]# lvscan
ACTIVE '/dev/centos/swap' [2.00 GiB] inherit
ACTIVE '/dev/centos/root' [<17.00 GiB] inherit
ACTIVE '/dev/myvg/mylv' [20.00 GiB] inherit
若一开始未建立网页,请在我的博客里搜索下,yum源码安装一个网页
[root@localhost httpd-2.4.41]# mkfs.xfs /dev/myvg/mylv
meta-data=/dev/myvg/mylv isize=512 agcount=16, agsize=327552 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=5240832, imaxpct=25
= sunit=128 swidth=256 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=8 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@localhost httpd-2.4.41]#mount -o usrquota,grpquota /dev/myvg/mylv /usr/local/httpd/htdocs/
[root@localhost htdocs]# touch index.html
[root@localhost htdocs]# echo "aaaxiebiao" > index.html
启动网页
[root@localhost htdocs]# /usr/local/httpd/bin/apachectl start
关闭防火墙,启动远程服务
[root@localhost htdocs]# iptables -F
[root@localhost htdocs]# systemctl stop firewalld
[root@localhost htdocs]# setenforce 0
[root@localhost htdocs]# systemctl restart sshd
[root@localhost ~]# useradd linux
[root@localhost ~]# echo "123456"|passwd --stdin linux
更改用户 linux 的密码 。
passwd:所有的身份验证令牌已经成功更新。
[root@localhost ~]# xfs_quota -x -c 'limit -u isoft=80 ihard=100 bsoft=80M bhard=100M linux' /usr/local/httpd/htdocs/
切换新建的用户linux进行登录测试
[root@localhost ~]# su - linux
[linux@localhost ~]$ cd /usr/local/httpd/htdocs/
[linux@localhost htdocs]$ rm -rf *
[linux@localhost htdocs]$ ls
[linux@localhost htdocs]$ touch {1..81}.txt
[linux@localhost htdocs]$ ls
10.txt 20.txt 30.txt 40.txt 50.txt 60.txt 70.txt 80.txt
11.txt 21.txt 31.txt 41.txt 51.txt 61.txt 71.txt 81.txt
12.txt 22.txt 32.txt 42.txt 52.txt 62.txt 72.txt 8.txt
13.txt 23.txt 33.txt 43.txt 53.txt 63.txt 73.txt 9.txt
14.txt 24.txt 34.txt 44.txt 54.txt 64.txt 74.txt
15.txt 25.txt 35.txt 45.txt 55.txt 65.txt 75.txt
16.txt 26.txt 36.txt 46.txt 56.txt 66.txt 76.txt
17.txt 27.txt 37.txt 47.txt 57.txt 67.txt 77.txt
18.txt 28.txt 38.txt 48.txt 58.txt 68.txt 78.txt
19.txt 29.txt 39.txt 49.txt 59.txt 69.txt 79.txt
1.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt
[linux@localhost htdocs]$ rm -rf *
[linux@localhost htdocs]$ touch {1..101}.txt
touch: 无法创建"101.txt": 超出磁盘限额
接下来测试磁盘的所占磁盘
[linux@localhost htdocs]$ rm -rf *
[linux@localhost htdocs]$ dd if=/dev/zero of=/usr/local/httpd/htdocs/test bs=1M count=81记录了81+0 的读入
记录了81+0 的写出
84934656字节(85 MB)已复制,0.0688961 秒,1.2 GB/秒
[linux@localhost htdocs]$ rm -rf *
[linux@localhost htdocs]$ dd if=/dev/zero of=/usr/local/httpd/htdocs/test bs=1M count=101dd: 写入"/usr/local/httpd/htdocs/test" 出错: 超出磁盘限额
记录了101+0 的读入
记录了100+0 的写出
104857600字节(105 MB)已复制,0.0665262 秒,1.6 GB/秒