zoukankan      html  css  js  c++  java
  • 手动增加swap空间

           在日常工作中,swap没有必要搞那么大的空间,因为现在好多服务器都使用了ssd硬盘,这些硬盘还是比较贵的。如果服务器内存是128G,swap空间还设置成内存的两倍的话,那岂不是很明显是很浪费的?在没有特殊需求的情况下,swao空间最大设置成8个G即可。如果某个服务需要很大swap空间,这时就需要手动增加了。
    在文件系统模拟一个磁盘出来:
    [root@linux-xl ~]# dd if=/dev/zero of=/tmp/newdisk bs=1M count=100 #if是指从哪里去读,/dev/zero是Linux内核的一个倒零器,of写入到某一个文件里面去,然后指定块大小为1M,数量100,也就是拿块大小*数量,等于100M。
    100+0 records in
    100+0 records out
    104857600 bytes (105 MB) copied, 0.664207 s, 158 MB/s
    查看大小
    [root@linux-xl ~]# du -sh /tmp/newdisk
    100M    /tmp/newdisk
    格式化为swap文件系统
    [root@linux-xl ~]# mkswap -f /tmp/newdisk
    Setting up swapspace version 1, size = 102396 KiB
    no label, UUID=c1ce135c-97bb-4601-9991-7ba8fc14f84f
    查看目前swap空间有多大
    [root@linux-xl ~]# free -m
                  total        used        free      shared  buff/cache   available
    Mem:           3774         140        3354           8         280        3374
    Swap:          3968           0        3968
    增加当前swap空间
    [root@linux-xl ~]# swapon /tmp/newdisk
    swapon: /tmp/newdisk: insecure permissions 0644, 0600 suggested.
    [root@linux-xl ~]# free -m    #可以看到已经增加了
                  total        used        free      shared  buff/cache   available
    Mem:           3774         140        3353           8         280        3374
    Swap:          4068           0        4068
    [root@linux-xl ~]# chmod 0600 /tmp/newdisk     #更改权限提高安全性
    [root@linux-xl ~]# swapoff /tmp/newdisk    #卸载swap
    [root@linux-xl ~]# free -m   #恢复原来磁盘的大小
                  total        used        free      shared  buff/cache   available
    Mem:           3774         140        3353           8         280        3374
    [root@linux-xl ~]# rm -rf /tmp/newdisk  #可以删掉它
     
  • 相关阅读:
    BZOJ2023: [Usaco2005 Nov]Ant Counting 数蚂蚁
    BZOJ2044: 三维导弹拦截
    BZOJ2982: combination
    Solidity(address的四个方法)
    Solidity基础
    如何搭建以太坊的私有链
    挖矿
    智能合约
    密码学
    比特币
  • 原文地址:https://www.cnblogs.com/xiaoliangxianshen/p/9186453.html
Copyright © 2011-2022 走看看