前言:本脚本是根据锐志师兄的py脚本改写的shell脚本,貌似平时用起来更方便一些
#! /bin/bashecho -e "\033[31m ++++++++++MySQL Standardized Check++++++++++++ \033[0m"echo -e "\n"echo -e "\033[31m ----------1.File System--------------- \033[0m"df -Th|awk '{print $1,$2}'|grep -v 'tmpfs'echo -e "\033[33m 输出建议:数据分区为xfs \033[0m"echo -e "\n"echo -e "\033[31m ----------2.IO scheduling algorithm--------------- \033[0m"cat /sys/block/sda/queue/schedulerecho -e "\033[33m 输出建议:普通硬盘采用deadline算法,不要用cfg算法;SSD采用noop算法 \033[0m"echo -e "\n"echo -e "\033[31m ----------3.max open files--------------- \033[0m"ulimit -a|grep 'open files'echo -e "\033[33m 输出建议:建议设置为系统最大65535 \033[0m"echo -e "\n"echo -e "\033[31m ----------4.max user processes--------------- \033[0m"ulimit -a|grep 'processes'echo -e "\033[33m 输出建议:建议设置为系统最大65535 \033[0m"echo -e "\n"echo -e "\033[31m ----------5.numa enable--------------- \033[0m"grep -i numa /var/log/dmesgecho -e "\033[33m 输出建议:强烈建议关闭NUMA \033[0m"echo -e "\n"echo -e "\033[31m ----------6.swappiness ratio--------------- \033[0m"sysctl -a | grep swappinessecho -e "\033[33m 输出建议:建议值设置为1-10 \033[0m"echo -e "\n"echo -e "\033[31m ----------7.dirty_ratio--------------- \033[0m"sysctl -a | grep dirty_ratioecho -e "\033[33m 设置为10比较好 \033[0m"echo -e "\n"echo -e "\033[31m ----------8.dirty_background_ratio--------------- \033[0m"sysctl -a | grep dirty_background_ratioecho -e "\033[33m 输出建议:设置为5比较好 \033[0m"function IO_scheduler(){echo -e "\n"read -t 10 -p "IO scheduling optimization[Y/N]:" needneed_U=$(echo $need | tr '[a-z]' '[A-Z]')if [ "$need_U" = 'Y' ]; thenecho "deadline" > /sys/block/sda/queue/schedulerif [ $? = 0 ];thenecho -e "\033[33m IO scheduling changed \033[0m"elseecho -e "\033[33m error please check manually \033[0m"fifi}function open_file(){echo -e "\n"read -t 10 -p "change max open files[Y/N]:" needneed_U=$(echo $need | tr '[a-z]' '[A-Z]')if [ "$need_U" = 'Y' ]; thenecho '* soft nofile 65536' >>/etc/security/limits.confif [ $? = 0 ];thenecho -e "\033[33m soft file changed \033[0m"elseecho -e "\033[33m error please check manually \033[0m"fiecho '* hard nofile 65536' >>/etc/security/limits.confif [ $? = 0 ];thenecho -e "\033[33m hard file changed \033[0m"elseecho -e "\033[33m error please check manually \033[0m"fiulimit -HSn 65535if [ $? = 0 ];thenecho -e "\033[33m open files changed online \033[0m"elseecho -e "\033[33m error please check manually \033[0m"fifi}function user_process(){read -t 10 -p "change max user processes[Y/N]:" needneed_U=$(echo $need | tr '[a-z]' '[A-Z]')if [ "$need_U" = 'Y' ]; thenecho '* soft nproc 65536' >>/etc/security/limits.confif [ $? = 0 ];thenecho -e "\033[33m max user processes changed \033[0m"elseecho -e "\033[33m error please check manually \033[0m"fiulimit -HSu 65535if [ $? = 0 ];thenecho -e "\033[33m max user processess changed online \033[0m"elseecho -e "\033[33m error please check manually \033[0m"fifi}function disable_numa(){echo -e "\n"read -t 10 -p "disabled NUMA[Y/N]:" needneed_U=$(echo $need | tr '[a-z]' '[A-Z]')if [ "$need_U" = 'Y' ]; thenyum install numactl -yif [ $? = 0 ];thenecho -e "\033[33m numactl is installed successfully \033[0m"elseecho -e "\033[33m error please check manually \033[0m"fiecho -e "\033[33m please use numactl --interleave=all mysqld to start MySQL \033[0m"fi}function swappiness_ratio(){read -t 10 -p "change swappiness_ratio[Y/N]:" needneed_U=$(echo $need | tr '[a-z]' '[A-Z]')if [ "$need_U" = 'Y' ]; thenecho 'vm.swappiness = 10'>>/etc/sysctl.confif [ $? = 0 ];thenecho -e "\033[33m swappiness_ratio changed \033[0m"elseecho -e "\033[33m error please check manually \033[0m"fifi}function dirty_ratio(){echo -e "\n"read -t 10 -p "change dirty_ratio[Y/N]:" needneed_U=$(echo $need | tr '[a-z]' '[A-Z]')if [ "$need_U" = 'Y' ]; thenecho 'vm.dirty_background_ratio = 5' >>/etc/sysctl.confif [ $? = 0 ];thenecho -e "\033[33m dirty_background_ratio changed \033[0m"elseecho -e "\033[33m error please check manually \033[0m"fiecho 'vm.dirty_ratio = 10' >>/etc/sysctl.confif [ $? = 0 ];thenecho -e "\033[33m dirty_ratio changed \033[0m"elseecho -e "\033[33m error please check manually \033[0m"fi/sbin/sysctl -pif [ $? = 0 ];thenecho -e "\033[33m changes successfully \033[0m"elseecho -e "\033[33m error please check manually \033[0m"fifi}IO_scheduleropen_fileuser_processdisable_numaswappiness_ratiodirty_ratioecho -e "\n"echo -e "\033[33m restart system and check again! \033[0m"
