Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swap #45

Open
clms2 opened this issue Nov 26, 2020 · 0 comments
Open

swap #45

clms2 opened this issue Nov 26, 2020 · 0 comments

Comments

@clms2
Copy link
Owner

clms2 commented Nov 26, 2020

  • 检查swap文件是否存在,返回空则不存在
    swapon -s
  • 查看文件系统,检查空间是否足够创建swap
    df -hal
  • 创建一个swap目录
    mkdir /swap
  • 创建并允许swap文件 16G
    dd if=/dev/zero of=/swap/swapfile bs=1024 count=16384000
  • 格式化swap文件
    mkswap -f /swap/swapfile
  • 激活swap
    swapon /swap/swapfile
  • 设置开机启动(vim 打开 /etc/fstab)
    /swap/swapfile swap swap defaults 0 0
  • 赋予Swap文件适当的权限
    chown root:root /tmp/swapfile
    chmod 600 /tmp/swapfile
  • 查看swappiness权重(swappiness=0 的时候表示最大限度使用物理内存,然后才是 Swap 空间,swappiness=100 的时候表示积极的使用 Swap 分区,并且把内存上的数据及时的搬运到 Swap 空间里面。)
    cat /proc/sys/vm/swappiness
  • 临时修改swappiness
    sysctl vm.swappiness=10
  • 要永久设置修改swappiness
    vim /etc/sysctl.conf
    在这个文档的最后加上这样一行
    # Search for the vm.swappiness setting. Uncomment and change it as necessary.
    vm.swappiness=10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant