CentOS 7 快速初始化脚本 for MySQL

#!/bin/bash

#

# CentOS 7.x

# SSH configure

sshd_port=22

# Disable SElinux

printf "Disable SElinux..."

setenforce 0 &> /dev/null

sed -i "/^SELINUX=/s/.*/SELINUX=disabled/g" /etc/selinux/config

printf "\033[32;1m%20s\033[0m\n" "[ DONE ]"

# Disable firewalld and stop auto running

printf "Disable firewalld..."

systemctl stop firewalld &> /dev/null

systemctl disable firewalld &> /dev/null

printf "\033[32;1m%18s\033[0m\n" "[ DONE ]"

# configure SSHD service

printf "Config sshd..."

sed -i "/Port /s/.*/Port ${sshd_port}/g" /etc/ssh/sshd_config

sed -i "/UseDNS/s/.*/UseDNS no/g" /etc/ssh/sshd_config

printf "\033[32;1m%24s\033[0m\n" "[ DONE ]"

printf "Config ssh..."

sed -i "/^Host/aPort ${sshd_port}\n" /etc/ssh/ssh_config

printf "\033[32;1m%25s\033[0m\n" "[ DONE ]"

# update limits

printf "Config limit..."

sed -i "$(( $(sed -n '/# End of file/=' limits.conf) + 1 )),\$d" /etc/security/limits.conf

echo "* soft nproc 65536" >> /etc/security/limits.conf

echo "* hard nproc 65536" >> /etc/security/limits.conf

echo "* soft nofile 65536" >> /etc/security/limits.conf

echo "* hard nofile 65536" >> /etc/security/limits.conf

printf "\033[32;1m%23s\033[0m\n" "[ DONE ]"

# enable chrony service

printf "Config chrony..."

yum -y install chrony &> /dev/null

systemctl start chronyd

systemctl enable chronyd &> /dev/null

printf "\033[32;1m%22s\033[0m\n" "[ DONE ]"

# change timezone

timedatectl set-timezone Asia/Shanghai

# 优化文件系统调度策略 和关闭NUMA

printf "optimize file system IO and disable NUMA"

echo deadline >/sys/block/sda/queue/scheduler

sed -i '/rhgb/ {s/rhgb/numa=off elevator=deadline rhgb/g}' /boot/grub2/grub.cfg

printf "\033[32;1m%22s\033[0m\n" "[ DONE ]"

#禁用 Swappiness

printf "Disable Swappiness"

echo 0 >/proc/sys/vm/swappiness

echo "vm.swapiness=0" >> /etc/sysctl.conf

printf "\033[32;1m%22s\033[0m\n" "[ DONE ]"

# Yum update

printf "yum upgrade..."

yum -y upgrade &> /dev/null

printf "\033[32;1m%24s\033[0m\n" "[ DONE ]"

# wait for 30s then reboot

printf "\033[32;1mInitialize Successful...\033[0m\n"

printf "\033[32;1mReboot...\033[0m\n"

printf "\033[32;1mYou Can Enter Ctrl+C To Stop Reboot\033[0m\n"

sec=30

while [ $sec -ge 0 ]

do

printf "\033[32;1mWait for %d Seconds\r\033[0m" $sec

sleep 1

sec=$(( $sec - 1 ))

done

reboot