linux服务器如何查看内存,释放内存和缓存

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 ~]#

 

猜你喜欢

转载自www.cnblogs.com/xyhero/p/9344557.html