前言:本脚本是根据锐志师兄的py脚本改写的shell脚本,貌似平时用起来更方便一些

    1. #! /bin/bash
    2. echo -e "\033[31m ++++++++++MySQL Standardized Check++++++++++++ \033[0m"
    3. echo -e "\n"
    4. echo -e "\033[31m ----------1.File System--------------- \033[0m"
    5. df -Th|awk '{print $1,$2}'|grep -v 'tmpfs'
    6. echo -e "\033[33m 输出建议:数据分区为xfs \033[0m"
    7. echo -e "\n"
    8. echo -e "\033[31m ----------2.IO scheduling algorithm--------------- \033[0m"
    9. cat /sys/block/sda/queue/scheduler
    10. echo -e "\033[33m 输出建议:普通硬盘采用deadline算法,不要用cfg算法;SSD采用noop算法 \033[0m"
    11. echo -e "\n"
    12. echo -e "\033[31m ----------3.max open files--------------- \033[0m"
    13. ulimit -a|grep 'open files'
    14. echo -e "\033[33m 输出建议:建议设置为系统最大65535 \033[0m"
    15. echo -e "\n"
    16. echo -e "\033[31m ----------4.max user processes--------------- \033[0m"
    17. ulimit -a|grep 'processes'
    18. echo -e "\033[33m 输出建议:建议设置为系统最大65535 \033[0m"
    19. echo -e "\n"
    20. echo -e "\033[31m ----------5.numa enable--------------- \033[0m"
    21. grep -i numa /var/log/dmesg
    22. echo -e "\033[33m 输出建议:强烈建议关闭NUMA \033[0m"
    23. echo -e "\n"
    24. echo -e "\033[31m ----------6.swappiness ratio--------------- \033[0m"
    25. sysctl -a | grep swappiness
    26. echo -e "\033[33m 输出建议:建议值设置为1-10 \033[0m"
    27. echo -e "\n"
    28. echo -e "\033[31m ----------7.dirty_ratio--------------- \033[0m"
    29. sysctl -a | grep dirty_ratio
    30. echo -e "\033[33m 设置为10比较好 \033[0m"
    31. echo -e "\n"
    32. echo -e "\033[31m ----------8.dirty_background_ratio--------------- \033[0m"
    33. sysctl -a | grep dirty_background_ratio
    34. echo -e "\033[33m 输出建议:设置为5比较好 \033[0m"
    35. function IO_scheduler()
    36. {
    37. echo -e "\n"
    38. read -t 10 -p "IO scheduling optimization[Y/N]:" need
    39. need_U=$(echo $need | tr '[a-z]' '[A-Z]')
    40. if [ "$need_U" = 'Y' ]; then
    41. echo "deadline" > /sys/block/sda/queue/scheduler
    42. if [ $? = 0 ];then
    43. echo -e "\033[33m IO scheduling changed \033[0m"
    44. else
    45. echo -e "\033[33m error please check manually \033[0m"
    46. fi
    47. fi
    48. }
    49. function open_file()
    50. {
    51. echo -e "\n"
    52. read -t 10 -p "change max open files[Y/N]:" need
    53. need_U=$(echo $need | tr '[a-z]' '[A-Z]')
    54. if [ "$need_U" = 'Y' ]; then
    55. echo '* soft nofile 65536' >>/etc/security/limits.conf
    56. if [ $? = 0 ];then
    57. echo -e "\033[33m soft file changed \033[0m"
    58. else
    59. echo -e "\033[33m error please check manually \033[0m"
    60. fi
    61. echo '* hard nofile 65536' >>/etc/security/limits.conf
    62. if [ $? = 0 ];then
    63. echo -e "\033[33m hard file changed \033[0m"
    64. else
    65. echo -e "\033[33m error please check manually \033[0m"
    66. fi
    67. ulimit -HSn 65535
    68. if [ $? = 0 ];then
    69. echo -e "\033[33m open files changed online \033[0m"
    70. else
    71. echo -e "\033[33m error please check manually \033[0m"
    72. fi
    73. fi
    74. }
    75. function user_process()
    76. {
    77. read -t 10 -p "change max user processes[Y/N]:" need
    78. need_U=$(echo $need | tr '[a-z]' '[A-Z]')
    79. if [ "$need_U" = 'Y' ]; then
    80. echo '* soft nproc 65536' >>/etc/security/limits.conf
    81. if [ $? = 0 ];then
    82. echo -e "\033[33m max user processes changed \033[0m"
    83. else
    84. echo -e "\033[33m error please check manually \033[0m"
    85. fi
    86. ulimit -HSu 65535
    87. if [ $? = 0 ];then
    88. echo -e "\033[33m max user processess changed online \033[0m"
    89. else
    90. echo -e "\033[33m error please check manually \033[0m"
    91. fi
    92. fi
    93. }
    94. function disable_numa()
    95. {
    96. echo -e "\n"
    97. read -t 10 -p "disabled NUMA[Y/N]:" need
    98. need_U=$(echo $need | tr '[a-z]' '[A-Z]')
    99. if [ "$need_U" = 'Y' ]; then
    100. yum install numactl -y
    101. if [ $? = 0 ];then
    102. echo -e "\033[33m numactl is installed successfully \033[0m"
    103. else
    104. echo -e "\033[33m error please check manually \033[0m"
    105. fi
    106. echo -e "\033[33m please use numactl --interleave=all mysqld to start MySQL \033[0m"
    107. fi
    108. }
    109. function swappiness_ratio()
    110. {
    111. read -t 10 -p "change swappiness_ratio[Y/N]:" need
    112. need_U=$(echo $need | tr '[a-z]' '[A-Z]')
    113. if [ "$need_U" = 'Y' ]; then
    114. echo 'vm.swappiness = 10'>>/etc/sysctl.conf
    115. if [ $? = 0 ];then
    116. echo -e "\033[33m swappiness_ratio changed \033[0m"
    117. else
    118. echo -e "\033[33m error please check manually \033[0m"
    119. fi
    120. fi
    121. }
    122. function dirty_ratio()
    123. {
    124. echo -e "\n"
    125. read -t 10 -p "change dirty_ratio[Y/N]:" need
    126. need_U=$(echo $need | tr '[a-z]' '[A-Z]')
    127. if [ "$need_U" = 'Y' ]; then
    128. echo 'vm.dirty_background_ratio = 5' >>/etc/sysctl.conf
    129. if [ $? = 0 ];then
    130. echo -e "\033[33m dirty_background_ratio changed \033[0m"
    131. else
    132. echo -e "\033[33m error please check manually \033[0m"
    133. fi
    134. echo 'vm.dirty_ratio = 10' >>/etc/sysctl.conf
    135. if [ $? = 0 ];then
    136. echo -e "\033[33m dirty_ratio changed \033[0m"
    137. else
    138. echo -e "\033[33m error please check manually \033[0m"
    139. fi
    140. /sbin/sysctl -p
    141. if [ $? = 0 ];then
    142. echo -e "\033[33m changes successfully \033[0m"
    143. else
    144. echo -e "\033[33m error please check manually \033[0m"
    145. fi
    146. fi
    147. }
    148. IO_scheduler
    149. open_file
    150. user_process
    151. disable_numa
    152. swappiness_ratio
    153. dirty_ratio
    154. echo -e "\n"
    155. echo -e "\033[33m restart system and check again! \033[0m"