1.选择合适的IO调度
对于mysql的系统,如果是SSD,那么应该使用NOOP调度算法,如果是磁盘,就应该使用Deadline调度算法。默认是CFQ
echo dealine > /sys/block/{DEV-NAME}/queue/scheduler
mysql服务器系统优化-LMLPHP

 2.选择良好的文件系统

 文件系统强烈推荐: XFS   (使用df -Th查看)

 格式化命令:mkfs.xfs -f /dev/sdb1

3.选择更快的存储设备
对于数据库可以选择SSD硬盘 4.优化挂载文件系统参数
挂载XFS参数:(rw, noatime,nodiratime,nobarrier)
挂载ext4参数:ext4 (rw,noatime,nodiratime,nobarrier,data=ordered)
方法一:修改/etc/fastb文件,将default修改为上面
方法二:热挂载:mount -o remount,rw,noatime /dev/sda3 /var/ 5.硬件层相关优化CPU
一、选择Performance Per Watt Optimized(DAPC)模式,发挥CPU最大性能,跑DB这种通常需要高运算量的服务就不要考虑节电了;
二、关闭C1E和C States等选项,目的也是为了提升CPU效率;
三、Memory Frequency(内存频率)选择Maximum Performance(最佳性能);
四、内存设置菜单中,启用Node Interleaving,避免NUMA问题;
6.选择合适的版本
这里推荐percona版本的mysql,与原生mysql最相近,且优化过提升性能 7.优化内核参数

net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
net.ipv4.tcp_max_tw_buckets = 20000
net.ipv4.tcp_sack = 1
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_rmem = 4096 87380 4194304
net.ipv4.tcp_wmem = 4096 16384 4194304
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.netdev_max_backlog = 262144
net.core.somaxconn = 262144
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_timestamps = 1
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_keepalive_time = 30
net.ipv4.ip_local_port_range = 1024 65000
vm.overcommit_memory = 1

#防火墙参数优化,建议内网运行不开启防火墙,或者云上使用安全组

net.nf_conntrack_max = 524288
net.netfilter.nf_conntrack_max = 524288
net.netfilter.nf_conntrack_tcp_timeout_established = 180
net.netfilter.nf_conntrack_tcp_timeout_close_wait = 60
net.netfilter.nf_conntrack_tcp_timeout_fin_wait = 120
net.netfilter.nf_conntrack_tcp_timeout_time_wait = 120

 
05-28 13:49