#!/bin/bash

#安装系统需要的基本应用工具

yum -y install ntp yum-plugin* nmap telnet lrzsz gcc*


#系统内核参数优化,适用于高并发服务如nginx\varnish\lvs

sysctl(){
cat /dev/null >/etc/sysctl.conf
cat >> /etc/sysctl.conf < 
  

#以3级别启动系统,注销ctl+alt+del重启功能

initab(){
sed -i 's/id:5:initdefault:/id:3:initdefault:/' /etc/initab
sed -i 's/start on control-alt-delete/#start on control-alt-delete/' /etc/init/control-alt-delete.conf
}

#重要文件加不可操作权限

purview(){
chattr +i /etc/passwd
chattr +i /etc/shadow
chattr +i /etc/group
chattr +i /etc/gshadow
chattr +i /etc/inittab
#将chattr命令隐藏
mv /usr/bin/chattr /usr/bin/bdmlcha
}

#关闭selinux

selinux(){
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
}

#校正系统时间

ntpdate(){
echo "0 4 * * * /usr/sbin/ntpdate 210.72.145.44 > /dev/null 2>&1" >>/var/spool/cron/root
clock -w
}

#进程可打开文件数限制

ulimit(){
echo
"*   -   nofile  102400" >> /etc/security/limits.conf
echo "ulimit -SHn 102400"
}

#调整语系、字符集支持

lang(){
sed-i 's/LANG="en_US.UTF-8"/LANG="zh_CN.GB18030/' /etc/sysconfig/i18n
source/etc/sysconfig/i18n
}

#ssh 设置

ssh(){
#不允许空密码登陆
sed -i 's/#PermitEmptyPasswords no/PermitEmptyPasswords no/' /etc/ssh/sshd_config
#不允许root远程登陆
sed -i 's/#PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config
#不适用dns反向解析
sed -i 's/#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config
#修该端口号
sed -i 's/#Port 22/Port 32168/' /etc/ssh/sshd_config
service sshd restart
}

#关闭不必要的tty端口

tty(){
sed -i 's/6\]/2\]/' /etc/init/start-ttys.conf
}

#优化系统开启服务管理

services(){
for SERVER in `chkconfig --list | awk '{print $1}'`
do
chkconfig $SERVER off
done
for SERVER in sshd messagebus rngd network crond rsyslog irqbalance lvm2-monitor
do
chkconfig --level 35 $SERVER on
done
}
sysctl
initab
purview
ntpdate
ulimit
ssh
lang
tty
services