centos/linux 服务器的内存不够了怎么办?centos用虚拟内存扩展内存 – 技术老炮儿 – CSDN博客...

centos/linux 服务器的内存不够了怎么办?centos用虚拟内存扩展内存

2018年05月19日 07:47:12 herobacking 阅读数:2002
c30b793f878ec5084559d0d86cc289a0.jpg 版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/herobacking/article/details/80371242
    最近买了一个centos 的云主机 ,因为贫穷限制了我购买的内存大小,只有500M,所以导致物理内存经常处于饱和状态,无奈虚拟内存设置的只有132M,理论上讲虚拟内存应该要有物理内存的2倍也就是1G大小才够用!
    又由于我安装 微C微信防爆系统 的时候,提示我内存不足,所以想用提高虚拟内存的方法去安装这个软件,本来都已经安装完了,今天我手贱把Linux重启了一下,没看仔细,不过也不是坏事情,正好记录下设置过程,以便下次再重启的时候方便设置!
1
1.打开终端,切换到root用户,输入:free -m查看内存状态
2
[maker@LLM ~]$ free -m
3
total used free shared buff/cache available
4
Mem: 992 189 79 13 722 614
5
Swap: 0 0 0
6
Swap也就是虚拟内存为0
7
8
2.选择一个较大的分区,建立分区文件
9
[root@LLM ~]# dd if=/dev/zero of=/opt/swap bs=1024 count=1024000
10
1024000+0 records in
11
1024000+0 records out
12
1048576000 bytes (1.0 GB) copied, 16.6877 s, 62.8 MB/s
13
[root@LLM ~]#
14
该命令表示在opt分区建立名为swap,大小为1G的虚拟内存文件
15
16
3.将swap文件设置为 swap分区 文件
17
chmod 600 /opt/swap //注意更改swap文件的权限
18
[root@LLM ~]# mkswap /opt/swap
19
Setting up swapspace version 1, size = 1023996 KiB
20
no label, UUID=fc47f29e-31af-401e-856d-0fec5262179e
21
22
4.激活swap,启用分区交换文件
23
swapon /opt/swap
24
5.现在看下结果
25
[root@LLM ~]# free -m
26
total used free shared buff/cache available
27
Mem: 992 191 63 13 737 625
28
Swap: 999 0 999
虚拟内存的设置部分就完成了,接下来讲一下卸载虚拟内存,这个需求也是存在的,比如你走上人生巅峰了,不屑于使用虚拟内存,就需要卸载掉了,就是任性!
1
1.首先停止swap分区
2
[root@LLM ~]# swapoff /opt/swap
3
[root@LLM ~]# free -m
4
total used free shared buff/cache available
5
Mem: 992 191 63 13 738 626
6
Swap: 0 0 0
7
8
2.其次删除掉swap文件即可
9
首先看一下磁盘大小
10
[root@LLM ~]# df -h
11
Filesystem Size Used Avail Use% Mounted on
12
/dev/vda1 40G 3.9G 34G 11% /
13
devtmpfs 487M 0 487M 0% /dev
14
tmpfs 497M 4.0K 497M 1% /dev/shm
15
tmpfs 497M 420K 496M 1% /run
16
tmpfs 497M 0 497M 0% /sys/fs/cgroup
17
tmpfs 100M 0 100M 0% /run/user/0
18
tmpfs 100M 0 100M 0% /run/user/1001
19
[root@LLM ~]# rm -rf /opt/swap
20
[root@LLM ~]# df -h
21
Filesystem Size Used Avail Use% Mounted on
22
/dev/vda1 40G 3.0G 35G 8% /
23
devtmpfs 487M 0 487M 0% /dev
24
tmpfs 497M 4.0K 497M 1% /dev/shm
25
tmpfs 497M 420K 496M 1% /run
26
tmpfs 497M 0 497M 0% /sys/fs/cgroup
27
tmpfs 100M 0 100M 0% /run/user/0
28
tmpfs 100M 0 100M 0% /run/user/1001
29
30
可以看出删除后多了1G的空间
复制


Category: 技术杂谈 Tagged: 虚拟内存swap
Shen sg
分享技术,学习技术
Posts created 124

文章导航

发表评论 取消回复

电子邮件地址不会被公开。 必填项已用*标注

评论

姓名 *

站点

发表评论

【专题】springnetty整合仿微信通讯

关注我

微信公众号

码云:alohasir

QQ:840112979@qq.com

 

标签

我的

Related Posts

搜索:

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top
");setTimeout( page_anim_remove_preloader, 5000);function page_anim_remove_preloader() {jQuery('#page-anim-preloader').remove();}jQuery(".animsition").animsition({inClass : 'fade-in-up',outClass : 'fade-out-up',inDuration : 1400,outDuration : 800,linkElement : 'a:not([target="_blank"]):not([href^="#"]):not([href*=".gif"]):not([href*=".mov"]):not([href*=".swf"]):not([href*=".jpg"]):not([href*=".jpeg"]):not([href*=".png"]):not([href]):not([id="swipebox-close"])',overlay : false,overlayClass : 'animsition-overlay-slide',touchSupport : true,loading : true,loadingParentElement : 'body', //animation wrapper element loadingClass : 'animsition-loading',unSupportCss : [ 'animation-duration','-webkit-animation-duration','-o-animation-duration' ] });});
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值