CentOS 优化脚本【转】
时间:2010-10-09 来源:hmilyfe
#!/usr/bin/env bash
#########################################################################
# WARNING - Read First Before Running This Script!
# Running this script maybe HARMFUL to your system. Therefor, the user shall
# carefully read all of this script and bear the relevant risks by
# himself/herself. Running this script means the user accepting agreement above.
#########################################################################
#########################################################################
# Centos Tweak script for server
# Licenced under GPLv3
# Writen by: leo <[email protected]>
# Inspired by: [email protected]
# Feed back: http://www.himysql.com/groups/centos-tweak/
#########################################################################
#########################################################################
# History:
# 2010-08-10:
# Fixed:
# Disable ius yum repository by default.
# 2010-08-09:
# Add:
# Tweak enviroment like PATH, LDFLAGS and LD_LIBRARY_PATH for easy using sudo.
# 2010-08-08:
# Add:
# Firstly check running this script as root.
# Disable gpgcheck and plugins for running fastly.
# Increase yum cache expire time from 1h to 24h.
# Turn off auto running fsck while days duration.
# Turn off writing file reading time (add noatime in /etc/fstab).
# Fixed:
# Change file name to centostweak.sh
# Change /etc/cron.daily/ntpdate with run mode(+x).
# 2010-08-04:
# Add:
# Install sudo & enable wheel group to use nopasswrd sudo.
# 2010-08-02:
# Add:
# Install & config snmpd.
# Default iptables rules.
# Fixed:
# ntp package name from ntpdate.
# 2010-08-01:
# To avoid backup file overried, Change backup file name ended from ".origin" to ".%Y-%m-%d_%H-%M-%S".
# 2010-07-31:
# Modified to be used with CentOS 5.x Server and sohu mirrors.
# Removed some unuseful functions.
# Add functions for turnning unuseful service off while system start.
# Add functions for kernel & TCP parameters optimizing.
# 2010-06-06:
# Copied from http://laohuanggua.info/archives/695.
#########################################################################
# Require root to run this script.
if [[ "$(whoami)" != "root" ]]; then
echo "Please run this script as root." >&2
exit 1
fi
#设置升级源
cd /etc/yum.repos.d/
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.`date +"%Y-%m-%d_%H-%M-%S"`
sed -i -e 's/mirrorlist/#mirrorlist/' CentOS-Base.repo
sed -i -e 's/#baseurl/baseurl/' CentOS-Base.repo
sed -i -e 's/mirror.centos.org/mirrors.sohu.com/' CentOS-Base.repo
cp /etc/yum.conf /etc/yum.conf.`date +"%Y-%m-%d_%H-%M-%S"`
sed -i 's/gpgcheck=1/gpgcheck=0/' /etc/yum.conf
sed -i 's/plugins=1/plugins=0/' /etc/yum.conf
sed -i 's/metadata_expire=1h/metadata_expire=24h/' /etc/yum.conf
# 添加dag@sohu源
# relver=`uname -r | awk -F. '{print $NF}'`
echo -e "# Name: SOHU RPM Repository for Red Hat Enterprise 5 – dag\n"\
"# URL: http://mirrors.sohu.com/fedora-epel/\n"\
"[epel-sohu]\n"\
"name = Fedora EPEL \$releasever - sohu.com\n"\
"baseurl = http://mirrors.sohu.com/fedora-epel/5Server/\$basearch\n"\
"enabled = 1\n"\
"gpgcheck = 0" > /etc/yum.repos.d/epel-sohu.repo
# 添加ius源
# 使用方法:--enablerepo=ius,如yum install python26 --enablerepo=ius
echo -e "# Name: IUS RPM Repository for Red Hat Enterprise 5\n"\
"# URL: