加入收藏 | 设为首页 | 会员中心 | 我要投稿 云计算网_泰州站长网 (http://www.0523zz.com/)- 视觉智能、AI应用、CDN、行业物联网、智能数字人!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

MySQL中的swap怎么配置

发布时间:2022-01-21 09:12:20 所属栏目:MySql教程 来源:互联网
导读:这篇文章主要讲解了MySQL中的swap怎么配置,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习MySQL中的swap怎么配置吧! Swappiness Swappiness is a parameter that controls the relative weight given to
        这篇文章主要讲解了“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
 
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的效果。
 
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
修改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
 
感谢各位的阅读,以上就是“MySQL中的swap怎么配置”的内容了,经过本文的学习后,相信大家对MySQL中的swap怎么配置这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。

(编辑:云计算网_泰州站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读