實驗需求:
1.需要把/dev/myvg/mylv邏輯卷以支持磁盤配額的方式掛載到網頁目錄下
2、在網頁目錄下創建測試文件index.html,內容爲用戶名稱,通過瀏覽器訪問測試
3、創建用戶賬戶,對LVM配置磁盤配額限制用戶磁盤容量爲軟限制80M;硬限制100M、文件數量軟限制爲80個;硬限制爲100個
首先使用fdisk 創建分區三個20G 的分區
[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
分區完成,開始製作磁盤陣列5
[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
邏輯卷製作完畢,格式化完成後,掛載到網頁目錄下,網頁目錄在做好的製作網頁中
若一開始未建立網頁,請在我的博客裏搜索下,linux製作簡單網頁介紹
[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/
在網頁目錄下新建文件index.html文件 輸入本機ip 訪問瀏覽器測試
[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/秒