刚刚安装完红帽系统,有很多功能和服务是不需要,例如selinux、禁用ipv6,关闭不必要的服务器,终端默认是6个其实2个就够了,还需要定制一下个性化的设置例如vim的缩进设置,性能上的调优例如最大文件打开数等
#!/bin/bash
#author zhengdazhi
#this script is only for CentOS 6
#check the OS
platform=`uname -i`
if [ $platform != "x86_64" ];then
echo "this script is only for 64bit Operating System !"
exit 1
fi
echo "the platform is ok"
#version=`lsb_release -r |awk '{print substr($2,1,1)}'`
version=`cat /etc/issue | head -1 | awk '{print substr($3,1,1)}'`
if [ $version != 6 ];then
echo "this script is only for CentOS 6 !"
exit 1
fi
cat << EOF
+---------------------------------------+
| your system is CentOS 6 x86_64 |
| start optimizing....... |
+---------------------------------------
EOF
for oldboy in `chkconfig --list |grep "3:on"|awk '{print $1}' |grep -vE" crond|network|sshd|rsyslog|iptables|sysstat"`;do chkconfig $oldbyo off;done
#make the 163.com as the default yum repo
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
mv /etc/yum.repos.d/CentOS-Debuginfo.repo /etc/yum.repos.d/CentOS-Debuginfo.repo.bak
mv /etc/yum.repos.d/CentOS-Vault.repo /etc/yum.repos.d/CentOS-Vault.repo.bak
cp /etc/yum.repos.d/CentOS-Media.repo /etc/yum.repos.d/CentOS-Media.repo.bak
#sed -i 's/baseurl=file\:\/\/\/media\/CentOS\//baseurl=http\:\/\/192.168.2.243\/iso\//' /etc/yum.repos.d/CentOS-Media.repo
sed -i 's#file:///media/CentOS#file:///mnt/cdrom#' /etc/yum.repos.d/CentOS-Media.repo
sed -i '/file:\/\/\/media\/cdrom\//d' /etc/yum.repos.d/CentOS-Media.repo
sed -i '/file:\/\/\/media\/cdrecorder\//d' /etc/yum.repos.d/CentOS-Media.repo
sed -i 's/gpgcheck=1/gpgcheck=0/' /etc/yum.repos.d/CentOS-Media.repo
sed -i 's/enabled=0/enabled=1/' /etc/yum.repos.d/CentOS-Media.repo
yum clean all
mkdir /mnt/cdrom
#mount /dev/cdrom /mnt/cdrom
#wget http://mirrors.163.com/.help/CentOS6-Base-163.repo -O /etc/yum.repos.d/CentOS-Base.repo
#update the system and set the ntp
#yum clean all
#yum -y install lrzsz
#echo "0 4 * * * /usr/sbin/ntpdate 210.72.145.44 > /dev/null 2>&1" >> /var/spool/cron/root
echo "0 4 * * * /usr/sbin/ntpdate cn.pool.ntp.org > /dev/null 2>&1" >> /var/spool/cron/root
service crond restart
#set the file limit
echo "ulimit -SHn 102400" >> /etc/rc.local
cat >> /etc/security/limits.conf << EOF
* soft nofile 65535
* hard nofile 65535
EOF
#disable selinux
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
#set ssh
sed -i 's/^GSSAPIAuthentication yes$/GSSAPIAuthentication no/' /etc/ssh/sshd_config
sed -i 's/#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config
sed -i 's/^PasswordAuthentication yes$/PasswordAuthentication no/' /etc/ssh/sshd_config
sed -i 's/^#ClientAliveInterval 0/ClientAliveInterval 60/' /etc/ssh/sshd_config
sed -i 's/^#ClientAliveCountMax 3/ClientAliveCountMax 3/' /etc/ssh/sshd_config
#add user
useradd remote
mkdir /home/remote/.ssh
chown -R remote:remote /home/remote/.ssh
chmod 700 /home/remote/.ssh
touch /home/remote/.ssh/authorized_keys
chmod 600 /home/remote/.ssh/authorized_keys
chown -R remote:remote /home/remote/.ssh/authorized_keys
cat >> /home/remote/.ssh/authorized_keys <
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC4DFrKsiR+3sM/ffw7/6+Ld4VJLQQoNnYESX8765hutr54DkYV8gQjfWRL9ZM6RC3I4276VfWgUqWl8AYfm7wsfP/i1jqcM580nP693A8fDDFbPUKv5Do3i0oCgovLaPTewMlOmPQS694J2YqBsPe3K4CuEvB1VceBdZszYC/+xzbwwYyZhXhHskSZqGX+AwLi6xWyc5kUWEXx44IzQ48PJ+PO4QGHGDt9oC9LRZNzel5xGZDDeKsx+I8QmySbHv9DAyKzmbDKtaGM+7tXT0yDE8CCcFqxfhvrsBVFiuR4QnFqyhMkO+RCpPST4PIAC6U9i2h+nkM5ZIhReylwVwUt
EOF
service sshd restart
#disable the ipv6
cat >> /etc/modprobe.d/dist.conf << EOF
alias net-pf-10 off
options ipv6 disable=1
EOF
echo "NETWORKING_IPV6=off" >> /etc/sysconfig/network
#set tty
sed -i 's/env ACTIVE_CONSOLES=\/dev\/tty\[1-6\]/env ACTIVE_CONSOLES=\/dev\/tty\[1-2\]/' /etc/init/start-ttys.conf
#set vim
touch /home/remote/.vimrc
cat >> /home/remote/.vimrc << EOF
set nu
set tabstop=4
set softtabstop=4
set shiftwidth=4
set cindent
#set autoindent
EOF
chown -R remote:remote /home/remote/.vimrc
cat << EOF
+-------------------------------------------------+
| optimizer is done |
| it's recommond to restart this server ! |
+-------------------------------------------------+
EOF