• ADADADADAD

    MySQL中的swap怎么配置[ mysql数据库 ]

    mysql数据库 时间:2024-11-28 13:24:22

    作者:文/会员上传

    简介:

    SwappinessSwappinessis aparameter that controls the relative weight given to swapping out runtime memory, as opposed to dropping pages from the system. Swappine

    以下为本文的正文内容,内容仅供参考!本站为公益性网站,复制本文以及下载DOC文档全部免费。

    Swappiness

    Swappinessis aparameter that controls the relative weight given to swapping out runtime memory, as opposed to dropping pages from the system. Swappiness can be set to values between 0 and 100 inclusive. A low value causes the kernel to avoid swapping, a higher value causes the kernel to try to use swap space. The default value is60, and for most desktop systems, setting it to 100 may affect the overall performance, whereas setting it lower (even 0) may decrease response latency。

    大概意思是说:Swappinesslinuxswappiness0~10060swapswappiness1000

    With kernel version 3.5 and over, as well as kernel version 2.6.32-303 and over, it is likely better to use 1 for cases where 0 used to be optimal

    在内核版本3.5以及以上和RHEL/CentOS kernels内核版本2.6.32-303.el6以及以上,建议使用1来代替之前内核版本下的swappiness=0的效果。

    此修改在很多资料都特别提示了,如RHEL官方:

    MySQLInnoDBLinuxCPUIO InnoDBcacheInnoDB

    MySQLvm.swappiness=0

    OSvm.swappiness = 0swapswapswap

    3.5RHEL/CentOS kernels2.6.32-303vm.swappiness = 0swapnr_free + nr_filebacked < high watermarkswapswapLinuxOOMkillMySQL

    wiki

    解决办法

    1、尽量保证Linux操作系统还有足够的内存

    2、针对MySQL的服务器OS:

    之vm.swappiness=0

    3.5以及以上和 RHEL/CentOS kernels内核版本2.6.32-303.el6以及以上),建议设置vm.swappiness=1

    3、考虑设置 /proc/(pidof -s mysqld)/oom_adj为较小的值来尽量避免MySQL由于内存不足而被关闭。

    值的范围为-16~15,“-17”是一个特殊的值。如果设置为-17,就会禁止OOM Killer发出的信号(从Linux 2.6.12开始支持设置-17)。

    例如:echo -15 > /proc/(pidof -s mysqld)/oom_score_adj

    修改swappiness的方法

    #临时修改

    # Set the swappiness value as root

    echo 10 > /proc/sys/vm/swappiness

    # Alternatively, run this

    sysctl -w vm.swappiness=10

    # Verify the change

    cat /proc/sys/vm/swappiness

    10

    # Alternatively, verify the change

    sysctl vm.swappiness

    vm.swappiness = 10

    #永久生效需要修改配置文件sysctl.conf

    /etc/sysctl.conf

    vm.swappiness=10

    修改mysql的oom_adj值

    # cat /proc/(pidof -s mysqld)/oom_score_adj

    0

    # echo -15 > /proc/(pidof -s mysqld)/oom_score_adj

    #当然,如果需要的话可以完全关闭 OOM killer(不推荐用在生产环境):

    # sysctl -w vm.overcommit_memory=2

    # echo "vm.overcommit_memory=2" >> /etc/sysctl.conf

    https://en.wikipedia.org/wiki/Swappiness#cite_note-2

    https://www.percona.com/blog/2014/04/28/oom-relation-vm-swappiness0-new-kernel/

    http://blog.csdn.net/longxibendi/article/details/38146521

    http://www.vpsee.com/2013/10/how-to-configure-the-linux-oom-killer/

    MySQL中的swap怎么配置.docx

    将本文的Word文档下载到电脑

    推荐度:

    下载
    热门标签: mysqlswap