[root@linux-node1 ~]# cat optimize.sh
!/bin/bash
********************************************************************
Author:
URL:
Date:
FileName: centos7_reset.sh
Description: The script for centos7 reset
********************************************************************
設(shè)置命令提示符顏色
echo 'PS1="[\e[1;31m][\u@\h \W]\$[\e[0m]"' >> /etc/profile.d/env.sh
設(shè)置系統(tǒng)默認(rèn)編輯器為vim
echo export EDITOR=vim >> /etc/profile.d/env.sh
檢查腳本運(yùn)行用戶是否為root
if [ $(id -u) !=0 ];then
echo -e "\033[1;31m Error! You must be root to run this script! \033[0m"
exit 10
fi
禁用selinux
sed -ri 's/^(SELINUX=)enforcing/\1disabled/' /etc/selinux/config
禁用防火墻
systemctl stop firewalld.service
systemctl disable firewalld.service
優(yōu)化ssh登錄
sed -ri 's/GSSAPIAuthentication yes/GSSAPIAuthentication no/' /etc/ssh/sshd_config
sed -ri 's/#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config
修改網(wǎng)卡名稱為統(tǒng)一為傳統(tǒng)方式命名
sed -ri '/CMDLINE/s#(.*)"#\1 net.ifnames=0"#' /etc/default/grub
grub2-mkconfig -o /etc/grub2.cfg
禁用不需要的服務(wù)
systemctl stop postfix.service
systemctl disable postfix.service
安裝wget工具
yum -y install wget
配置系統(tǒng)使用阿里云yum源和EPEL源
替換成阿里云的yum源速度更快一些稚配,替換很簡單港华,簡單記錄一下步驟
1、備份原來的yum源
sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
2冒萄、安裝wget工具
yum install wget
3橙数、設(shè)置aliyun的yum源
sudo wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
4、添加EPEL源
EPEL(http://fedoraproject.org/wiki/EPEL)是由 Fedora 社區(qū)打造崖技,為 RHEL 及衍生發(fā)行版如 CentOS钟哥、Scientific Linux 等提供高質(zhì)量軟件包的項(xiàng)目。裝上 EPEL后腻贰,可以像在 Fedora 上一樣,可以通過 yum install package-name践盼,安裝更多軟件宾巍。
sudo wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-7.repo
5、清理緩存并生成新的緩存
sudo yum clean all
sudo yum makecache
安裝bash命令tab自動補(bǔ)全組件
yum -y install bash-completion
安裝vim編輯器
yum -y install vim screen lrzsz tree psmisc
安裝壓縮解壓工具
yum -y install zip unzip bzip2 gdisk
安裝網(wǎng)絡(luò)及性能監(jiān)控工具
yum -y install telnet net-tools sysstat iftop lsof iotop htop dstat
安裝源碼編譯工具及開發(fā)組件
yum -y install cmake gcc gcc-c++ zib zlib-devel open openssl-devel pcre pcre-devel curl
安裝chrony時間同步服務(wù)
yum -y install chrony
systemctl enable chronyd.service
systemctl start chronyd.service
配置chrony時間同步阿里云ntp服務(wù)器
sed -i -e '/server/s//#/' -e '1a server ntp.aliyun.com iburst' /etc/chrony.conf
systemctl restart chronyd.service
初始化完成重啟系統(tǒng)
echo -e "\033[1;32m System initialization is complete and will be reboot in 10s...\033[0m"
sleep 10
reboot