centos 中linux 如何设置swap大小?

swap的值都是安装系统的时候设置好的,一般设置为内存的两倍大小。使用过程中发现swap值过小只能添加。

    [root@host ~]# free -m(命令查看当前swap大小)
    total used free shared buff/cache available
    Mem: 1006 381 190 42 434 427
    Swap: 259 94 165
    [root@host ~]# dd if=/dev/zero of=/var/swap bs=1024 count=2048000(if 表示infile,of表示outfile,bs=1024代表增加的模块大小,count=2048000代表2048000个模块,也就是2G空间,将目的文件设置为swap分区文件)
    2048000+0 records in
    2048000+0 records out
    2097152000 bytes (2.1 GB) copied, 8.71197 s, 241 MB/s
    [root@host ~]# mkswap /var/swap(激活swap,立即启用交换分区文件)
    Setting up swapspace version 1, size = 2047996 KiB
    no label, UUID=941931fe-683b-4082-a6db-82bb741f77e5
    [root@host ~]# mkswap -f /var/swap
    mkswap: /var/swap: warning: wiping old swap signature.
    Setting up swapspace version 1, size = 2047996 KiB
    no label, UUID=17a9a21e-67d2-4343-b95d-d8958814c334
    [root@host ~]# swapon /var/swap
    swapon: /var/swap: insecure permissions 0644, 0600 suggested.
    [root@host ~]# free -m
    total used free shared buff/cache available
    Mem: 1006 388 65 42 552 417
    Swap: 2259 94 2165
    [root@host ~]# cat /proc/swaps
    Filename Type Size Used Priority
    /swap file 266236 96512 -2
    /var/swap file 2047996 0 -3
    [root@host ~]# vi /etc/fstab

最后一行添加

  /var/swap swap swap defaults 0 0

如果不再需要swap,可以清理该分区:

  [root@mysql01 var]# swapoff /var/swap
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

三朝看客

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值