共計 2212 個字符,預計需要花費 6 分鐘才能閱讀完成。
這篇文章主要講解了“MySQL 中的 swap 怎么配置”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著丸趣 TV 小編的思路慢慢深入,一起來研究和學習“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 的效果。
此修改在很多資料都特別提示了,如 RHEL 官方:
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
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 怎么配置這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是丸趣 TV,丸趣 TV 小編將為大家推送更多相關知識點的文章,歡迎關注!