• 企业400电话
  • 网络优化推广
  • AI电话机器人
  • 呼叫中心
  • 全 部 栏 目

    网站建设 商标✡知产 微网小程序 电商运营 彩铃•短信 增值拓展业务
    Linux系统怎么调整swap分区大小?
    POST TIME:2021-10-20 10:05

    这里介绍Linux系统中调整swap大小的方法。

    1、使用free命令带上m参数,查看swap文件大小,官方建议在RAM是2到4.5G时,swap是RAM的2倍;如果RAM大于等于4G则swap等于RAM即可

    2、也可用cat 查看etc目录下的swaps文件,如下图

    3、创建一个swap文件

    复制内容到剪贴板
    1. ########   
    2.   
    3. dd if=/dev/zero of=/tmp/swap bs=1MB count=1024   
    4.   
    5. ########  

    以下仅供参考:不用看

    Creating a swap file

    First of, make sure the file system the disk you wish to swap on is properly mounted. For the purposes of this tutorial we will assume the disk is mounted as /mnt and we want to use the file /mnt/myswap.swp for swapping.

    使用下面的命令创建一个1G的swap文件

    复制内容到剪贴板
    1. Use the following command to create a 1024MB file that we will use for swapping   
    2.   
    3. ########   
    4.   
    5. dd if=/dev/zero of=/mnt/myswap.swp bs=1024MB count=1   
    6.   
    7. ########  

    4、制作一个swap文件,如果觉得繁琐,可以将mkswap文件挂载到tmp目录下,例如:

    复制内容到剪贴板
    1. ########   
    2.   
    3. mkswap /tmp/swap   
    4.   
    5. ########  

    以下仅供参考:不用看

    Preparing the swap file

    Before we enable the swap file we must first set it up. The following command accomplishes just that:

    ########

    mkswap /mnt/myswap.swp

    ########

    5、使用swapon 启动/tmp/swap

    复制内容到剪贴板
    1. ########   
    2.   
    3. swapon /tmp/swap   
    4.   
    5. ########  

    使用一个swap分区,如果已经有一个swap分区,该步骤可以省略

    以下仅供参考:不用看

    Using a swap partition

    Setting up a swap partition is a bit more difficult, as the partition must be first created then formatted using the linux-swap file system. Once that is done, assuming the swap partition is at/dev/scsi/host0/bus0/target0/lun0/part5 (common for v24 USB drives with mutiple partitions), the only command that needs be issued is:

    6、再次使用free查看增加后的swap大小

    7、如果只想增加swap大小,请忽略以下的操作,重要!!如果不使用刚才增加的1G的swap文件,使用下面的swapoff命令,可以关闭,这样swap文件就缩小了1G

    使用swapoff关闭swap文件

    复制内容到剪贴板
    1. ########   
    2.   
    3. swapoff /tmp/swap   
    4.   
    5. ########  

    注意事项:如果只想增加swap大小,请忽略第7步的所有操作。

    相关推荐:

    linux系统怎么增加swap分区空间小?

    CentOS技巧:减小Linux swap分区的方法

    Linux下swap耗尽该怎么办?如何释放swap?

    上一篇:Linux应用帮助你来征服数学学习
    下一篇:Linux中将执行过的命令记录到日志并发送到服务器的方法
  • 相关文章
  • 

    关于我们 | 付款方式 | 荣誉资质 | 业务提交 | 代理合作


    © 2016-2020 巨人网络通讯

    时间:9:00-21:00 (节假日不休)

    地址:江苏信息产业基地11号楼四层

    《增值电信业务经营许可证》 苏B2-20120278

    X

    截屏,微信识别二维码

    微信号:veteran88

    (点击微信号复制,添加好友)

     打开微信