LVM邏輯卷管理
PV: physical volume 物理卷十气,邏輯意義上硬盤分區(qū)嫁佳;
VG: volume group LVM卷組纸淮;
Lv: logic volume 邏輯卷允趟;
PE: physical extend 實(shí)例延伸區(qū)塊董栽,一個邏輯卷最多能含有65534個PE.
LVM邏輯圖說明:
詳細(xì)參數(shù)說明:
- 實(shí)驗(yàn)?zāi)繕?biāo)1:實(shí)現(xiàn)邏輯卷的擴(kuò)容
第一步:新建4個10G的物理卷
第二步:讓新添加的硬盤支持LVM技術(shù)
[root@oldboy ~]# pvcreate /dev/sd[e-h]
Physical volume "/dev/sde" successfully created.
Physical volume "/dev/sdf" successfully created.
Physical volume "/dev/sdg" successfully created.
Physical volume "/dev/sdh" successfully created.
第三步:加入到卷組doc
[root@oldboy ~]# vgcreate doc /dev/sd[e-h]
Volume group "doc" successfully created
第四步:切割容量200M
[root@oldboy ~]# lvcreate -n test -l 50 doc
WARNING: xfs signature detected on /dev/doc/test at offset 0. Wipe it? [y/n]: y
Wiping xfs signature on /dev/doc/test.
Logical volume "test" created.
第五步:格式化
[root@oldboy ~]# mkfs.xfs /dev/doc/test
meta-data=/dev/doc/test isize=512 agcount=4, agsize=12800 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=51200, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=855, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
第六步:掛載
[root@oldboy ~]# mount /dev/doc/test /mnt/
[root@oldboy ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 47G 1.6G 46G 4% /
devtmpfs 979M 0 979M 0% /dev
tmpfs 991M 0 991M 0% /dev/shm
tmpfs 991M 9.6M 981M 1% /run
tmpfs 991M 0 991M 0% /sys/fs/cgroup
/dev/sda1 1014M 133M 882M 14% /boot
tmpfs 199M 0 199M 0% /run/user/0
/dev/mapper/doc-test 197M 11M 187M 6% /mnt
第七步:卸載
[root@oldboy ~]# umount /mnt/
第八步:擴(kuò)容到500mb
[root@oldboy ~]# lvextend -L 500mb /dev/doc/test
Size of logical volume doc/test changed from 200.00 MiB (50 extents) to 500.00 MiB (125 extents).
Logical volume doc/test successfully resized.
第九步:檢查磁盤完整性
[root@oldboy ~]# e2fsck -f /dev/doc/test
e2fsck 1.42.9 (28-Dec-2013)
ext2fs_open2: Bad magic number in super-block
e2fsck: Superblock invalid, trying backup blocks...
e2fsck: Bad magic number in super-block while trying to open /dev/doc/test
The superblock could not be read or does not describe a correct ext2
filesystem. If the device is valid and it really contains an ext2
filesystem (and not swap or ufs or something else), then the superblock
is corrupt, and you might try running e2fsck with an alternate superblock:
e2fsck -b 8193 <device>
[root@oldboy ~]# resize2fs /dev/doc/test
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/doc/test
Couldn't find valid filesystem superblock.
[root@oldboy ~]# mkfs.xfs -f /dev/doc/test
meta-data=/dev/doc/test isize=512 agcount=4, agsize=6400 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=25600, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=855, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0第十步:掛載
[root@oldboy ~]# mount /dev/doc/test /mnt/
[root@oldboy ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 47G 1.6G 46G 4% /
devtmpfs 979M 0 979M 0% /dev
tmpfs 991M 0 991M 0% /dev/shm
tmpfs 991M 9.6M 981M 1% /run
tmpfs 991M 0 991M 0% /sys/fs/cgroup
/dev/sda1 1014M 133M 882M 14% /boot
tmpfs 199M 0 199M 0% /run/user/0
/dev/mapper/doc-test 497M 26M 472M 6% /mnt
- 實(shí)驗(yàn)?zāi)夸?:邏輯卷的縮容
第一步:檢查磁盤完整性
[root@oldboy ~]# e2fsck /dev/doc/test
e2fsck 1.42.9 (28-Dec-2013)
ext2fs_open2: Bad magic number in super-block
e2fsck: Superblock invalid, trying backup blocks...
e2fsck: Bad magic number in super-block while trying to open /dev/doc/test
The superblock could not be read or does not describe a correct ext2
filesystem. If the device is valid and it really contains an ext2
filesystem (and not swap or ufs or something else), then the superblock
is corrupt, and you might try running e2fsck with an alternate superblock:
e2fsck -b 8193 <device>
第二步:設(shè)置大小
[root@oldboy ~]# lvreduce -L 100M /dev/doc/test
WARNING: Reducing active logical volume to 100.00 MiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce doc/test? [y/n]: Y
Size of logical volume doc/test changed from 500.00 MiB (125 extents) to 100.00 MiB (25 extents).
Logical volume doc/test successfully resized.
第三步:格式化掛載
[root@oldboy ~]# mount /dev/doc/test /mnt/
[root@oldboy ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 47G 1.6G 46G 4% /
devtmpfs 979M 0 979M 0% /dev
tmpfs 991M 0 991M 0% /dev/shm
tmpfs 991M 9.6M 981M 1% /run
tmpfs 991M 0 991M 0% /sys/fs/cgroup
/dev/sda1 1014M 133M 882M 14% /boot
tmpfs 199M 0 199M 0% /run/user/0
/dev/mapper/doc-test 97M 5.3M 92M 6% /mnt
SWAP交換分區(qū)
- 調(diào)整swap分區(qū)的大小
第一步:劃分空間被swap調(diào)用
[root@oldboy ~]# dd if=/dev/zero of=/tmp/1G count=10 bs=100MB
10+0 records in
10+0 records out
1000000000 bytes (1.0 GB) copied, 16.0573 s, 62.3 MB/s
第二步:給swap分區(qū) 做標(biāo)記
[root@oldboy ~]# mkswap /tmp/1G
Setting up swapspace version 1, size = 976556 KiB
no label, UUID=71766332-aebf-4fab-94a9-64bc4606a944
第三步:指明哪個區(qū)分使用swap
[root@oldboy ~]# swapon /tmp/1G
swapon: /tmp/1G: insecure permissions 0644, 0600 suggested
第四步:查找swap分區(qū)大小
[root@oldboy ~]# free -h
total used free shared buff/cache available
Mem: 1.9G 778M 166M 9.5M 1.0G 1.0G
Swap: 2.0G 0B 2.0G
[root@oldboy ~]# free -h
total used free shared buff/cache available
Mem: 1.9G 778M 165M 9.5M 1.0G 1.0G
Swap: 2.9G 0B 2.9G
命令解釋:
dd if: 從哪里取出存儲空間信息码倦;
of: 放到哪里去,一般就是放到swap空間里锭碳;
count: 拿的數(shù)量袁稽;
bs:一次拿的大小。
企業(yè)面試題
1. 在系統(tǒng)掛載文件中內(nèi)容編寫錯誤擒抛,會發(fā)生什么情況推汽?該如何解決补疑?
環(huán)境模擬:例如,在/etc/fstab文件中歹撒,誤將內(nèi)容修改為錯誤莲组,會造成服務(wù)器啟動緩慢;如果對根分區(qū)做了一定的修改栈妆,會造成只能讀文件內(nèi)容胁编,不能修改和保存!鳞尔!
[root@oldboy ~]# cat /etc/fstab 模擬出錯信息**
#
# /etc/fstab
# Created by anaconda on Fri Jun 28 14:14:27 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root / xfs defaults 0 0
**UUID=4bd5-b354-48af-befe-f25680347dbe /boot xfs defaults 0 0**
**#UUID=4bd134d5-b354-48af-befe-f25680347dbe /boot xfs defaults **0 0
/dev/mapper/centos-swap swap swap defaults 0 0
/dev/mapper/doc-test /mnt xfs defaults 0 0
**[root@oldboy ~]# reboot 重啟 **速度會很慢**
解決辦法:
# mount -o remount rw /
# reboot
## 讓根分區(qū)重新掛載嬉橙,有讀寫權(quán)限
- 企業(yè)面試題2:
卸載掛載點(diǎn)常見的有什么問題?
(1)卸載時當(dāng)前目錄就是掛載目錄;
(2)卸載目錄時寥假,目錄下的文件被程序調(diào)用市框;
卸載目錄的方法:umount -lf /mnt
-l lasy 懶惰
-f force 強(qiáng)制
- 企業(yè)面試題3:
28.出現(xiàn)no space on device錯誤是什么原因和解決方法?
(1)Inode 文件過多糕韧;
Inode文件過多的原因:定時任務(wù)中產(chǎn)生的大量的小文件枫振;
環(huán)境模擬:
創(chuàng)建多個空文件:touch oldboy{01..100000000}.txt
解決辦法:
用find命令在當(dāng)前文件中查找小于2kb的文件,進(jìn)行刪除萤彩。
(2)Block 過多粪滤;
Block 文件過多是因?yàn)槎〞r任務(wù)輸出內(nèi)容沒有追加到空文件當(dāng)中。
環(huán)境模擬:
創(chuàng)建一個或多個大文件雀扶,比如10GB的杖小。
解決辦法:
1>用find命令查找大文件;
2>用du命令愚墓;du -sh /* | sort -nrh
參數(shù)詳解:
Du 命令解釋:
-s 匯總 -h 人類可讀
Sort 命令解釋:
-n 排序 -r 倒序 -h 人類可讀 - 企業(yè)面試題4:
如何徹底將文件刪除予权?
(1)硬鏈接數(shù)量為0,i_link=0
(2)進(jìn)程調(diào)用數(shù)
為0浪册,i_count=0
在刪除文件時扫腺,只能看到硬鏈接是否被刪除,進(jìn)程被調(diào)用不是能被看到的村象,所以建議可以清空大文件:>/file
如果誤刪除/var/log/secure文件笆环,再新建一個secure文件,新產(chǎn)生的日志也不會追加到新建的secure文件中厚者,因?yàn)檫@兩個文件的inode不一樣了咧织。
解決辦法:重啟rsyslog服務(wù),secure文件即可產(chǎn)生籍救。