zoukankan      html  css  js  c++  java
  • How to Add Swap on CentOS

    About Linux Swapping


    Linux RAM is composed of chunks of memory called pages. To free up pages of RAM, a “linux swap” can occur and a page of memory is copied from the RAM to preconfigured space on the hard disk. Linux swaps allow a system to harness more memory than was originally physically available. 

    However, swapping does have disadvantages. Because hard disks have a much slower memory than RAM, server performance may slow down considerably. Additionally, swap thrashing can begin to take place if the system gets swamped from too many files being swapped in and out.

    Check for Swap Space


    Before we proceed to set up a swap file, we need to check if any swap files have been enabled by looking at the summary of swap usage.

    swapon -s


    If nothing is returned, the summary is empty and no swap file exists.

    Check the File System


    After we know that we do not have a swap file enabled, we can check how much space we have on the server with the df command. The swap file will take 512MB— since we are only using up about 7% of the /dev/hda, we can proceed.

    df
    Filesystem           1K-blocks      Used Available Use% Mounted on
    /dev/hda              20642428   1347968  18245884   7% /

    Create and Enable the Swap File


    Now it’s time to create the swap file itself using the dd command :

    sudo dd if=/dev/zero of=/swapfile bs=1024 count=512k


    “of=/swapfile” designates the file’s name. In this case the name is swapfile. 

    Subsequently we are going to prepare the swap file by creating a linux swap area:

    sudo mkswap /swapfile


    The results display:

    Setting up swapspace version 1, size = 536866 kB


    Finish up by activating the swap file:

    sudo swapon /swapfile


    You will then be able to see the new swap file when you view the swap summary.

     swapon -s
    Filename				Type		Size	Used	Priority
    /swapfile                               file		524280	0	-1


    This file will last on the server until the machine reboots. You can ensure that the swap is permanent by adding it to the fstab file.

    Open up the file:

    sudo nano /etc/fstab


    Paste in the following line:

    /swapfile          swap            swap    defaults        0 0
    



    To prevent the file from being world-readable, you should set up the correct permissions on the swap file:

    chown root:root /swapfile 
    chmod 0600 /swapfile

    https://www.digitalocean.com/community/articles/how-to-add-swap-on-centos-6

  • 相关阅读:
    python简单的游戏场景代码
    ZooKeeper应用场景
    Zookeeper配置文件中的配置项解释和Zookeeper的安装
    MapReduce的手机流量统计的案例
    java和js获取当前天之后或之前7天(任意)日期
    JDK中ThreadDump诊断Java代码中的线程死锁问题
    Java代码调用Oracle的存储过程,存储函数和包
    Oracle的卸载过程步骤
    JDK中ConcurrentHashMap效率测试
    JDK提供的四种线程池代码详解
  • 原文地址:https://www.cnblogs.com/moher/p/3236187.html
Copyright © 2011-2022 走看看