#!/bin/bash


## 关闭防火
systemctl stop firewalld.service
systemctl disable firewalld.service
sudo ufw disable

##基本库安装
apt -y install gcc automake autoconf libtool make
### 安装 Htop 监控软件 ### 
apt -y install net-tools


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

##设置内核参数
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.ip_local_port_range = 1024 65535

EOF

sysctl -p

###关闭自动更新和禁用更新重启
# 1) 关闭自动更新
sudo cp -a /etc/apt/apt.conf.d/20auto-upgrades /etc/apt/apt.conf.d/20auto-upgrades.bak.$(date +%Y%m%d%H%M%S)
printf 'APT::Periodic::Update-Package-Lists "0";\nAPT::Periodic::Unattended-Upgrade "0";\n' | sudo tee /etc/apt/apt.conf.d/20auto-upgrades >/dev/null

# 2) 禁用自动升级 timer
sudo systemctl disable --now unattended-upgrades.service
sudo systemctl disable --now apt-daily.timer apt-daily-upgrade.timer
sudo systemctl mask apt-daily.timer apt-daily-upgrade.timer

# 3) 安装包后不再提示重启服务
sudo tee /etc/needrestart/conf.d/99-local.conf >/dev/null <<'EOF'
$nrconf{restart} = 'l';
EOF


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"

