1. 程式人生 > >linux服務器如何查看內存,釋放內存和緩存

linux服務器如何查看內存,釋放內存和緩存

應該 buffers span 緩沖區 手動 服務器 技術 alt 表示

1、使用df -hl 命令,查看掛載空間是否充足;

技術分享圖片

2、使用top命令,查看內存運行情況;

技術分享圖片

使用free -m命令應該也可以:

[root@testserver ~]# free -m
total used free shared buffers cached
Mem: 2013 1661 352 0 223 1206
-/+ buffers/cache: 231 1782
Swap: 2047 0 2047

3、使用sync命令,將緩存寫入文件中;

[root@server test]# sync

手動執行sync命令(描述:sync 命令運行 sync 子例程。如果必須停止系統,則運行sync 命令以確保文件系統的完整性。sync 命令將所有未寫的系統緩沖區寫到磁盤中,包含已修改的 i-node、已延遲的塊 I/O 和讀寫映射文件)

To free pagecache, use
echo 1 > /proc/sys/vm/drop_caches;
To free dentries and inodes, use
echo 2 > /proc/sys/vm/drop_caches;
To free pagecache, dentries and inodes, use
echo 3 >/proc/sys/vm/drop_caches.

默認是0,1表示清空頁緩存,2表示清空inode和目錄樹緩存,3清空所有的緩存。

查看:

[root@testserver ~]# cat /proc/sys/vm/drop_caches

4、冗余數據及時刪除,生產數據備份;

測試
[root@testserver ~]# uname -a
Linux testserver 2.6.18-164.el5 #1 SMP Thu Sep 3 03:28:30 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux

[root@testserver ~]# free -m
total used free shared buffers cached
Mem: 2013 1661 352 0 223 1206
-/+ buffers/cache: 231 1782
Swap: 2047 0 2047

[root@testserver ~]# sync
[root@testserver ~]# sync
[root@testserver ~]# cat /proc/sys/vm/drop_caches
0
[root@testserver ~]# echo 3 > /proc/sys/vm/drop_caches
[root@testserver ~]# cat /proc/sys/vm/drop_caches
3
[root@testserver ~]# free -m
total used free shared buffers cached
Mem: 2013 100 1913 0 0 14
-/+ buffers/cache: 85 1927
Swap: 2047 0 2047
[root@testserver ~]#

技術分享圖片

linux服務器如何查看內存,釋放內存和緩存