Linux系統最小化安裝完成後,一般須要進行初始化,如下爲centos7系統初始化腳本,待繼續優化ing...linux
#!/bin/bash # #******************************************************************** #Author: Eddie.Peng #URL: https://www.cnblogs.com/eddie1127/ #Date: 2019-09-06 #FileName: centos7_reset.sh #Description: The script for centos7 reset #******************************************************************** #設置命令提示符顏色 echo 'PS1="\[\e[1;31m\][\u@\h \W]\\$\[\e[0m\]"' >> /etc/profile.d/env.sh #設置系統默認編輯器爲vim echo export EDITOR=vim >> /etc/profile.d/env.sh #檢查腳本運行用戶是否爲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 #優化ssh登陸 sed -ri 's/GSSAPIAuthentication yes/GSSAPIAuthentication no/' /etc/ssh/sshd_config sed -ri 's/#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config #修改網卡名稱爲統一爲傳統方式命名 sed -ri '/CMDLINE/s#(.*)"#\1 net.ifnames=0"#' /etc/default/grub grub2-mkconfig -o /etc/grub2.cfg #禁用不須要的服務 systemctl stop postfix.service systemctl disable postfix.service #安裝wget工具 yum -y install wget #配置系統使用阿里雲yum源和EPEL源 mkdir /etc/yum.repos.d/bak mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak/ wget -P /etc/yum.repos.d http://mirrors.aliyun.com/repo/Centos-7.repo wget -P /etc/yum.repos.d http://mirrors.aliyun.com/repo/epel-7.repo yum make clean all yum makecache #安裝bash命令tab自動補全組件 yum -y install bash-completion #安裝vim編輯器 yum -y install vim screen lrzsz tree psmisc #安裝壓縮解壓工具 yum -y install zip unzip bzip2 gdisk #安裝網絡及性能監控工具 yum -y install telnet net-tools sysstat iftop lsof iotop htop dstat #安裝源碼編譯工具及開發組件 yum -y install cmake gcc gcc-c++ zib zlib-devel open openssl-devel pcre pcre-devel curl #安裝chrony時間同步服務 yum -y install chrony systemctl enable chronyd.service systemctl start chronyd.service #配置chrony時間同步阿里雲ntp服務器 sed -i -e '/^server/s/^/#/' -e '1a server ntp.aliyun.com iburst' /etc/chrony.conf systemctl restart chronyd.service #初始化完成重啓系統 echo -e "\033[1;32m System initialization is complete and will be reboot in 10s...\033[0m" sleep 10 reboot