#!/bin/bash
#################### 插件一:字体 ######################
### 设置文件输出警告色,info/warning/error "你要输出信息"
### 使用方法
### info "This is a info!"
### warnning "This is a warn"
### error "This is a error"
function info(){
# 32 绿色字
ARGE=${1:-'没有传参'}
echo -e "\033[1;32mINFO: $ARGE\033[0m"
}
function warnning(){
# 33 黄色字
ARGE=${1:-'没有传参'}
echo -e "\033[1;33mWARN: $ARGE\033[0m"
}
function error(){
# 31 红色字
ARGE=${1:-'没有传参'}
echo -e "\033[1;5;41;37mERROR: $ARGE\033[0m"
}
init_system(){
info "1. 关闭seLinux,firewalld"
setenforce 0
sed -i '/SELINUX/{s/enforcing/disabled/}' /etc/selinux/config
systemctl disable --now firewalld &>/dev/null
info "2. 配置网络yum源"
if [ ! -f /etc/yum.repos.d/epel.repo &>/dev/null ] ;then
rm -rf /etc/yum.repos.d/*
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo &>/dev/null
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo &>/dev/null
yum clean all &>/dev/null && yum makecache &>/dev/null
fi
info "3. 安装需要使用的软件,可能时间较长请等待....."
yum install -y gcc make autoconf vim sysstat net-tools iostat iftop iotop lrzsz epel-release &>/dev/null
yum install -y bash-completion nmap dos2unix openssl openssh bash iproute wget tree &>/dev/null
info "4. 设置文件最大访问量"
grep 'ulimit -SHn 102400' /etc/rc.local &>/dev/null
if ! grep 'hard nproc 102400' /etc/security/limits.conf &>/dev/null ;then
ulimit -SHn 102400
echo "ulimit -SHn 102400" >> /etc/rc.local
echo "* soft nofile 102400" >> /etc/security/limits.conf
echo "* hard nofile 102400" >> /etc/security/limits.conf
echo "* soft nproc 102400" >> /etc/security/limits.conf
echo "* hard nproc 102400" >> /etc/security/limits.conf
fi
info "5. 删除用不到的用户与组"
if cat /etc/passwd |awk -F':' '{print $1}' | grep games &>/dev/null ;then
userdel adm &>/dev/null
userdel lp &>/dev/null
userdel shutdown &>/dev/null
userdel halt &>/dev/null
userdel operator &>/dev/null
groupdel games &>/dev/null
userdel games &>/dev/null
fi
info "6. 关闭swap分区"
if ! cat /etc/sysctl.conf |grep 'vm.swappiness=0' &>/dev/null ;then
swapoff -a
sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
rm -rf /var/swapfile
echo "vm.swappiness=0" >> /etc/sysctl.conf
sysctl -p
echo 0 > /proc/sys/vm/swappiness
fi
}
init_system