linux系统优化脚本
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux系统优化脚本相关的知识,希望对你有一定的参考价值。
#!/bin/bash
# this script is created by tangbo.
# e_mail:[email protected]
# version:1.0
#################################################
#################################################
#set -x
# Set Language and must be root
export LANG="zh_CN.GB18030"
if [[ "$(whoami)" != "root" ]]
then
echo "please,Run This Script As root." >&2
exit 1
fi
#soure function library
. /etc/init.d/functions
#config YUM CentOS-Base.repo
ConfigYum(){
echo "Exchange CentOS-Base.repo"
cd /etc/yum.repos.d/
cp CentOS-Base.repo CentOS-Base.repo.backup.$(date +%F)
ping -c1 www.baidu.com &> /dev/null
[ $? -ne 0 ] && echo $"Networking not configured - exiting." && exit 1
wget --quiet -o /dev/null http://mirrors.163.com/.help/CentOS6-Base-163.repo &>/dev/null
mv CentOS6-Base-163.repo CentOS-Base.repo
yum clean all &> /dev/null
echo "Exchange CentOS-Base.repo Success"
sleep 1
}
#Install Init Packages
installTool(){
echo "Please,Wait,Installing:sysstat ntp net-snmp lrzsz"
yum -y install sysstat ntp net-snmp lrzsz >/dev/null 2>&1
echo -e "installTool\nversion information:\n`rpm -qa sysstat ntp net-snmp lrzsz`"
sleep 1
}
#Close Selinux and Iptables
initFirewall(){
echo "Close Selinux and Iptables"
cp /etc/selinux/config /etc/selinux/config.`date +"%Y-%m-%d_%H-%M-%S"`
/etc/init.d/iptables stop &> /dev/null
service iptables status
sed -i ‘/SELINUX/s/enforcing/disabled/‘ /etc/selinux/config
setenforce 0
grep SELINUX=disabled /etc/selinux/config
echo "Close selinux ->OK iptables->OK"
sleep 1
}
#Init Auto Startup service
initService(){
echo "STOP Service"
export LANG="en_US.UTF-8"
for test in `chkconfig --list | grep 3:on | awk ‘{print $1}‘`
do
# print $test
chkconfig --level 3 $test off
done
for tangbo in crond network syslog sshd
do
chkconfig --level 3 $tangbo on &>/dev/null
done
#export LANG="zh_CN.GB18030"
echo "stop not service->OK"
sleep 1
}
#Change SSH port and stop root
initSsh(){
echo "#---sshConfig change 22,stop root ---#"
export LANG="en_US.UTF-8"
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.`date +"%Y-%m-%d_%H-%M-%S"`
sed -i ‘s%#Port 22%Port 4022%‘ /etc/ssh/sshd_config
sed -i ‘s%#PermitRootLogin yes%PermitRootLogin no%‘ /etc/ssh/sshd_config
sed -i ‘s%#Port 22%Port 4022%‘ /etc/ssh/sshd_config
sed -i ‘s%#Port 22%Port 4022%‘ /etc/ssh/sshd_config
/etc/init.d/sshd reload && echo "ssh chang true" || echo "ssh chang false"
}
#set sync-System-Time
syncSystemTime(){
echo "set sync-system-time-success"
echo "*/2 * * * * /usr/sbin/ntpdate time.nist.gov &> /dev/null 2>&1" >>/var/spool/cron/root
}
#set file limits
openFiles(){
echo "#---file=65535---#"
export LANG="en_US.UTF-8"
\cp /etc/security/limits.conf /etc/security/limits.conf.`date +"%Y-%m-%d_%H-%M-%S"`
sed -i ‘/# End of file/i\*\t\t-\tnofile\t\t65535‘ /etc/security/limits.conf
ulimit -HSn 65535
echo "set files success"
sleep 1
}
#set alias
alias(){
echo "set alias"
echo "alias grep=‘grep --color‘" >> /root/.bashrc
source /root/.bashrc
sleep 1
}
本文出自 “山猫” 博客,谢绝转载!
以上是关于linux系统优化脚本的主要内容,如果未能解决你的问题,请参考以下文章
Linux系统最小化安装之后的系统基础环境安装以及内核优化脚本