#!/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
###安装 vim ###
yum -y install vim
### 安装 Traceroute ###
yum -y install traceroute
### 安装 Htop 监控软件 ### 
yum -y install htop
### 安装 nslookup ###
yum -y install bind-utils
### 安装 rz 上传下载软件 ###
yum -y install lrzsz
### 安装 telnet ###
yum -y install telnet
### 安装 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
### TAB自动补全的包 ###
yum -y install bash-completion
### 安装 7z 解压 ###
yum -y install p7zip
### 安装 rar 解压 ###
yum install epel-release -y
yum -y install unar


##调整打开文件数
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 10240       
* hard nproc 10240
* soft nofile 51200
* hard nofile  51200
EOF

### 修改最大进程数 ###
# vim  /etc/security/limits.conf #
#  * soft nproc 10240       
#  * hard nproc 10240
#  * soft nofile 51200
#  * hard nofile  51200
### ulimit -u  查询当前最大进程数 ###
### ulimit -a  查询当前所有数量  ###
### 前面的*星号代表针对所有的用户；noproc 是代表最大进程数；nofile代表最大文件打开数；soft nofile的值不能超过hard nofile的值 ###
### 修改/etc/security/limits.conf文件，重启后不生效怎么办 ###
### Linux操作系统云服务器中限制资源使用的配置文件是/etc/security/limits.conf和/etc/security/limits.d/目录 ###
### /etc/security/limits.d/目录中的配置优先级高于/etc/security/limits.conf的配置 ###
### /etc/security/limits.d/ 在这个目录下面tab一下用文件可以修改试试 ###
### 但是vim  /etc/security/limits.conf 修改完成后重启终端也会生效的 ###


##设置中国时区

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"

