1. #!/bin/bash
    2. #################### 插件一:字体 ######################
    3. ### 设置文件输出警告色,info/warning/error "你要输出信息"
    4. ### 使用方法
    5. ### info "This is a info!"
    6. ### warnning "This is a warn"
    7. ### error "This is a error"
    8. function info(){
    9. # 32 绿色字
    10. ARGE=${1:-'没有传参'}
    11. echo -e "\033[1;32mINFO: $ARGE\033[0m"
    12. }
    13. function warnning(){
    14. # 33 黄色字
    15. ARGE=${1:-'没有传参'}
    16. echo -e "\033[1;33mWARN: $ARGE\033[0m"
    17. }
    18. function error(){
    19. # 31 红色字
    20. ARGE=${1:-'没有传参'}
    21. echo -e "\033[1;5;41;37mERROR: $ARGE\033[0m"
    22. }
    23. init_system(){
    24. info "1. 关闭seLinux,firewalld"
    25. setenforce 0
    26. sed -i '/SELINUX/{s/enforcing/disabled/}' /etc/selinux/config
    27. systemctl disable --now firewalld &>/dev/null
    28. info "2. 配置网络yum源"
    29. if [ ! -f /etc/yum.repos.d/epel.repo &>/dev/null ] ;then
    30. rm -rf /etc/yum.repos.d/*
    31. curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo &>/dev/null
    32. curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo &>/dev/null
    33. yum clean all &>/dev/null && yum makecache &>/dev/null
    34. fi
    35. info "3. 安装需要使用的软件,可能时间较长请等待....."
    36. yum install -y gcc make autoconf vim sysstat net-tools iostat iftop iotop lrzsz epel-release &>/dev/null
    37. yum install -y bash-completion nmap dos2unix openssl openssh bash iproute wget tree &>/dev/null
    38. info "4. 设置文件最大访问量"
    39. grep 'ulimit -SHn 102400' /etc/rc.local &>/dev/null
    40. if ! grep 'hard nproc 102400' /etc/security/limits.conf &>/dev/null ;then
    41. ulimit -SHn 102400
    42. echo "ulimit -SHn 102400" >> /etc/rc.local
    43. echo "* soft nofile 102400" >> /etc/security/limits.conf
    44. echo "* hard nofile 102400" >> /etc/security/limits.conf
    45. echo "* soft nproc 102400" >> /etc/security/limits.conf
    46. echo "* hard nproc 102400" >> /etc/security/limits.conf
    47. fi
    48. info "5. 删除用不到的用户与组"
    49. if cat /etc/passwd |awk -F':' '{print $1}' | grep games &>/dev/null ;then
    50. userdel adm &>/dev/null
    51. userdel lp &>/dev/null
    52. userdel shutdown &>/dev/null
    53. userdel halt &>/dev/null
    54. userdel operator &>/dev/null
    55. groupdel games &>/dev/null
    56. userdel games &>/dev/null
    57. fi
    58. info "6. 关闭swap分区"
    59. if ! cat /etc/sysctl.conf |grep 'vm.swappiness=0' &>/dev/null ;then
    60. swapoff -a
    61. sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
    62. rm -rf /var/swapfile
    63. echo "vm.swappiness=0" >> /etc/sysctl.conf
    64. sysctl -p
    65. echo 0 > /proc/sys/vm/swappiness
    66. fi
    67. }
    68. init_system