1. 磁碟滿了
如果一臺機器磁碟滿了,首先我們需要確定其位置,命令為
df(或者 df -h)
//顯示結果
Filesystem 512-blocks Used Available Capacity iused ifree %iused Mounted on
/dev/disk0s2 488555536 124047536 363996000 26% 15569940 45499500 25% /
devfs 361 361 0 100% 626 0 100% /dev
map -hosts 0 0 0 100% 0 0 100% /net
找到那一塊盤滿了以後,使用命令 du 一級一級的查詢,確定最大檔案。
du -h –max-depth=1 | grep ‘G’ | sort -n
如果是日誌檔案過大需要刪除時候,使用日誌切割,保留最新日誌。
//指定分割後檔案行數
split -l 300 largelog newlog
//指定分割後檔案大小
split -b 10m largelog newlog
2. 負載過高
使用 uptime 命令檢視機器負載。
uptime
//輸出
up 1 day, 23:14, 2 users, load averages: 1.69 2.21 2.09
平均負載表示 1 、 5 、 15 分鐘程式佇列中的平均程式數量。一般單核大於 3 的話負載就算高了。檢視 linux 多少 cpu 與核的命令如下:
#檢視物理 CPU 個數
cat /proc/cpuinfo| grep “physical id”| sort| uniq| wc -l
#檢視每個物理 CPU 中 core 的個數 (即核數)
cat /proc/cpuinfo| grep “cpu cores”| uniq
# 檢視邏輯 CPU 的個數
cat /proc/cpuinfo| grep “processor”| wc -l
然後使用 top 命令檢視每個程式佔用 CPU,記憶體情況。 top 顯示時候使用 “M” 程式會按記憶體使用排序,按 “P” 會按 CPU 使用排序。
如果沒有程式佔用大量 CPU,記憶體資源的話,可能就是某個程式阻塞了。使用 ps -ef, 看到哪個程式會卡住,然後去/proc/中找到這個程式對應的檔案,看是否能正常開啟。
找到以後殺死這個程式或者重啟機器。
3. can’t lock /etc/passwd;try again later
首先檢視是在/etc 下否存在 lock 檔案,
$cd /etc
$ls *.lock
$ rm -f *.lock //刪除檔案鎖
沒有的話,使用 df -i 看是否 inode 滿了,如果是 查詢每個檔案下的檔案數目
for i in ./*; do echo $i; find $i | wc -l |sort -n ; done
找到後刪除沒用的小檔案。 建議去/var/spool/postfix/maildrop 去看看。
科普一下 df -i 與 df -h,一個是總共能建立多少檔案,一個是總共能建立多大的檔案。