用于linux操作系统,部署完成后,一键优化及安装软件

#!/bin/bash

# 更新系统
yum update -y

# 安装必备软件
yum install -y vim wget ntp

# 设置时区为上海
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
echo "Asia/Shanghai" > /etc/timezone

# 同步时间
ntpdate pool.ntp.org
systemctl enable ntpd
systemctl start ntpd

# 禁用 SELinux
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=disabled/' /etc/selinux/config

# 设置最大打开文件数
echo "* soft nofile 65535" >> /etc/security/limits.conf
echo "* hard nofile 65535" >> /etc/security/limits.conf

# 禁止 Swap
swapoff -a
sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab

# History 优化
echo 'export HISTTIMEFORMAT="%F %T `whoami` "' >> /etc/profile
echo 'export HISTSIZE=5000' >> /etc/profile
source /etc/profile

# 系统内核参数优化
cat <<EOF >>  /etc/sysctl.conf
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 30
EOF

sysctl -p