作为上一篇函数的举例,也是把它单独拿出来找的时候好找。
如果要看函数的理论部分:点击以下链接
作为举例,只是优化了几个方面,如果想加入其他内容需要自己在编写模块。
- 配置阿里源
- 禁用开机不需要的服务
- 禁用selinux
- 禁用iptables
- 安装常用工具及升级
脚本内容:
#!/bin/bash export PATH=$PATH:/bin:/sbin:/usr/sbin if [ "$UID" != "0" ];then echo "Please run this script by root." exit 1 fi function mod_yum(){ if [ -e /etc/yum.repos.d/CentOS-Base.repo ] then mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak && \ wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-6.repo fi } function close_selinux(){ sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config setenforce 0 &>/dev/null } function close_iptables(){ /etc/init.d/iptables stop chkconfig iptables off } function least_service(){ chkconfig|awk '{print "chkconfig",$1,"off"}'|bash chkconfig|egrep "crond|sshd|network|rsyslog|sysstat"|awk '{print "chkconfig",$1,"on"}'|bash } function update_linux(){ if [ `rpm -qa lrzse nmap tree dos2unix nc|wc -l` -le 3 ] then yum install -y lrzse nmap tree dos2unix nc fi } main(){ mod_yum close_selinux close_iptables least_service update_linux } main
每一个模块实现一个功能,如果想要其他的功能,在main上一行继续按格式添加即可。