Linux系统优化脚本
生活随笔
收集整理的這篇文章主要介紹了
Linux系统优化脚本
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
--------------------------------------------------------------------
注:如果你對python感興趣,我這有個學習Python基地,里面有很多學習資料,感興趣的+Q群:895817687
--------------------------------------------------------------------
--------------------- #!/bin/bash
##############################################################################
# File Name : Linux system config
# description : This script is used to set linux system
# Author : simon
# Mail : 24731701@qq.com
##############################################################################
. /etc/init.d/functions
IP=`/sbin/ifconfig|awk -F '[ :]+' 'NR==2{print $4}'`# Defined result functionfunction Msg(){if [ $? -eq 0 ];thenaction "$1" /bin/trueelseaction "$1" /bin/falsefi}# Defined Close selinux Functions
function selinux(){[ if "/etc/selinux/config" ] && {sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/configsetenforce 0Msg "Close selinux" }
}# Defined add Ordinary users Functionsfunction AddUser(){id simon &>/dev/nullif [ $? -ne 0 ];thenuseradd simon &>/dev/nullecho "123456"|passwd --stdin simon &>/dev/null &&\sed -ir '98a simon ALL=(ALL) NOPASSWD:ALL' /etc/sudoers &&\visudo -c &>/dev/nullMsg "AddUser simon"elseecho "simon user is exist."fi
}# Defined Hide the system version number Functionsfunction HideVersion(){[ -f "/etc/issue" ] && >/etc/issue[ -f "/etc/issue.net"] && > /etc/issue.netMsg "Hide sys info."
}# Defined sshd config Functionsfunction sshd(){sshd_file=/etc/ssh/sshd_configif [ `grep "52113" $sshd_file|wc -l` -eq 0 ];thensed -ir "13 iPort 52113\nPermitRootLogin no\nPermitEmptyPasswords no\nUseDNS no\nGSSAPIAuthentication no" $sshd_filesed -i 's@#ListenAddress 0.0.0.0@ListenAddress '${IP}':52113@g' $sshd_file/etc/init.d/sshd restart > /dev/null 2>&1Msg "sshd config"fi
}# Defined OPEN FILES Functions
function openfiles(){if [ `grep "nofile 65535" /etc/security/limits.conf|wc -l` -eq 0 ];thenecho '* - nofile 65535' >> /etc/security/limits.confulimit -SHn 65535Msg "open files"fi
}function hosts(){if [ ! -f /server/scripts/hosts ];thenecho "/server/scripts/hosts is not exist,please solve this question"sleep 300exit 1fi/bin/cp /server/scripts/hosts /etc/hosts
}# Defined System Startup Services Functionsfunction boot(){export LANG=enfor simon in `chkconfig --list|grep "3:on"|awk '{print $1}'|egrep -v "crond|network|rsyslog|sshd|sysstat"`dochkconfig $simon offdoneMsg "BOOT config"
}# Deined Time Synchronization Functions
function Time(){grep "time.nist.gov" /var/spool/cron/root > /dev/null 2>&1if [ $? -ne 0 ];thenecho "#time sync by simon at $(date +%F)" >>/var/spool/cron/rootecho "*/5 * * * * /usr/sbin/ntpdate time.nist.gov &>/dev/null" >>/var/spool/cron/rootfiMsg "Time Synchronization"}
# Defined Kernel parameters Functions
function Kernel(){/bin/cp /etc/sysctl.conf /etc/sysctl.conf.$RANDOM/bin/cp /server/scripts/sysctl.conf /etc/Msg "kernel"}function iptables(){/etc/init.d/iptables stop/etc/init.d/iptables stopMsg "iptables"}function hostname(){ip=`/sbin/ifconfig eth1|awk -F "[: ]+" 'NR==2 {print $4}'`name=`grep -w "$ip" /etc/hosts |awk '{print $2}'`sed -i 's/HOSTNAME=*/HOSTNAME='"$name"'/g' /etc/sysconfig/network/bin/hostname $nameMsg "hostname"}# Defined main Functions
function main(){AddUserHideVersionsshdopenfileshostsbootTimeKerneliptableshostname
}main
總結
以上是生活随笔為你收集整理的Linux系统优化脚本的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: LNMP shell
- 下一篇: Linux系统用户和用户组介绍