温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

MySQL中的swap怎么配置

发布时间:2021-08-12 10:10:33 来源:亿速云 阅读:253 作者:chen 栏目:MySQL数据库

这篇文章主要讲解了“MySQL中的swap怎么配置”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“MySQL中的swap怎么配置”吧!

Swappiness

Swappiness is a parameter 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

 

大概意思是说:Swappiness linuxswappiness0~10060swapswappiness1000

 MySQL中的swap怎么配置

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官方:

MySQL中的swap怎么配置

 

MySQLInnoDBLinuxCPUIO InnoDBcacheInnoDB 

MySQLvm.swappiness=0

OSvm.swappiness = 0swapswapswap

3.5 RHEL/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

修改mysqloom_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怎么配置”的内容了,经过本文的学习后,相信大家对MySQL中的swap怎么配置这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI