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

posted on 2017-08-03 16:28 Rayment 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/rayment/p/7280392.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值