#!/usr/bin/bash # < /dev/null 2>&1 if [ $? -ne 0 ];then colorTools ERROR "网络连接失败" exit 1 else colorTools SUCCESS "网络检测成功" fi # 执行用户检测 colorTools INFO "开始用户检测" if [ $UID -ne 0 ];then colorTools ERROR "请使用root用户执行此脚本" exit 1 else colorTools SUCCESS "用户检测完成,当前用户为root" fi # 执行系统检测 colorTools INFO "开始系统检测" if [ -f /etc/redhat-release ];then colorTools SUCCESS "系统检测完成,当前系统为CentOS/RedHat" else colorTools ERROR "系统检测失败,仅支持CentOS/RedHat" exit 1 fi } # 网络配置 function networkConfigure(){ systemctl stop NetworkManager &>/dev/null systemctl disable NetworkManager &>/dev/null systemctl enable network &>/dev/null for i in ${netInterface};do colorTools INFO "开始网络配置,网卡名称 $i" address=$(ip a show dev $i | grep -oP "[1-9][\d]{1,2}(\.\d{1,3}){3}/(\d+)") ipaddr=$(echo $address | awk -F'/' '{print $1}') netmask=$(echo $address | awk -F'/' '{print $2}') gateway=$(ip r show dev $i | grep -oP "default via \K[1-9][\d]{1,2}(\.\d{1,3}){3}") cat > /etc/sysconfig/network-scripts/ifcfg-$i </dev/null set -e if [ $localYum -eq 1 ];then curl -s download.beyourself.org.cn/yum.sh | bash colorTools SUCCESS "配置本地源完成,请在/etc/hosts文件中修改本地源ip地址解析" elif [ $localYum -eq 0 ];then curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo fi set +e colorTools SUCCESS "yum 源配置完成" } # 系统常规配置 function other(){ colorTools INFO "开始常规配置" colorTools INFO "开始防火墙配置" systemctl stop firewalld && \ systemctl disable firewalld colorTools INFO "开始selinux配置" sed -i 's/^SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config && \ setenforce 0 colorTools INFO "开始安装常用软件 ${yumList}" yum install -y ${yumList} colorTools INFO "开始主机名配置 ${HOSTNAME}" hostnamectl set-hostname $HOSTNAME colorTools INFO "开始时区配置并进行时间校准" timedatectl set-timezone Asia/Shanghai && \ ntpdate ntp.aliyun.com colorTools SUCCESS "常规配置完成" } # 系统参数优化 function optimized(){ colorTools INFO "开始优化系统" colorTools INFO "开始优化内核参数" cat > /etc/sysctl.conf < /etc/security/limits.conf <