#!/bin/bash


## 关闭防火墙并安装iptables
systemctl stop firewalld.service
systemctl disable firewalld.service
yum install -y iptables-services 
##基本库安装
yum install -y wget lrzsz gcc gcc-c++ perl unzip
yum -y install gcc automake autoconf libtool make
### 安装 Htop 监控软件 ### 
yum -y install htop
### 安装 nslookup ###
yum -y install bind-utils
### 安装 netstat ###
yum -y install net-tools
### 安装 killall ### 
yum -y install psmisc
### 安装 axel 多线程下载工具 ### 
yum -y install  axel
### netcat 端口检测工具 ###
### nc -vv 192.168.42.128 1521 ###
yum -y install netcat
### lsof 工具检测开放端口 ###
###  lsof -i:80 ###
yum -y install lsof
### nmap工具检测开放端口 ###
### nmap 127.0.0.1 查看本机开放的端口,也可以扫描其它服务器端口 ###
yum -y install nmap
### logrotate可以实现自动轮替、删除、压缩和mail日志的功能 ###
yum -y install logrotate


##调整打开文件数
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

cat >/etc/security/limits.conf <<EOF
* soft nproc 1024       
* hard nproc 1024
* soft nofile 51200
* hard nofile  51200
EOF

##设置中国时区

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

service sshd restart

#cd /etc/profile.d
#wget http://8.210.81.239/linux/sh/history.sh
#source /etc/profile

echo -e "\033[31m### 复制上海时区   ###\033[0m"
echo -e "\033[31m### cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime   ###\033[0m"
echo -e "\033[31m### timedatectl set-local-rtc 1 硬件时间默认为UTC 修改RTC时间   ###\033[0m"
echo -e "\033[31m###  timedatectl 查询时间   ###\033[0m"
echo -e "\033[31m###  timedatectl set-ntp yes 启动自动同步时间  ###\033[0m"
echo -e "\033[31m###  timedatectl set-timezone Asia/Shanghai 设置时区  ###\033[0m"
echo -e "\033[31m###  参考文档:  https://www.cnblogs.com/lei0213/p/8723106.html  ###\033[0m"

