#!/bin/bash

##基本库安装
yum install -y wget lrzsz gcc gcc-c++ perl unzip


##调整打开文件数
ulimit_status=`cat /etc/profile |grep ulimit |grep -v grep |wc -l`

if [ $ulimit_status == 0 ];then
        echo  "ulimit -SHn 51200" >>/etc/profile
        source  /etc/profile

else
        echo "ok"


fi

##设置中国时区

cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
cat >/etc/sysconfig/clock <<EOF
ZONE="Asia/Shanghai"
UTC=false
ARC=false

EOF

##添加时间同步计划
yum install -y ntpdate
ntp_cron=`cat /etc/crontab |grep ntpdate |grep -v grep |wc -l`

if [ $ntp_cron == 0 ];then
        echo "10 5 * * * root /usr/sbin/ntpdate timekeeper.isi.edu && /sbin/hwclock -w" >>/etc/crontab 
else 
    echo "Already has the cron"

fi

/usr/sbin/ntpdate timekeeper.isi.edu && /sbin/hwclock -w

##设置内核参数
cat >/etc/sysctl.conf <<EOF

net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.core_uses_pid = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.ip_local_port_range = 1024 65535

EOF

sysctl -p

##设置ssh连接时间
sed -i 's/#ClientAliveInterval.*/ClientAliveInterval 90/g' /etc/ssh/sshd_config
sed -i 's/#ClientAliveCountMax.*/ClientAliveCountMax 3/g' /etc/ssh/sshd_config

/etc/init.d/sshd  restart
