#!/bin/bash
echo "内核参数优化,按任意键继续"
read -n1
#内核参数
echo "net.ipv6.conf.all.disable_ipv6 = 1"  >> /etc/sysctl.conf
echo "net.ipv6.conf.default.disable_ipv6 = 1"  >> /etc/sysctl.conf
echo "net.ipv6.conf.lo.disable_ipv6 = 1"  >> /etc/sysctl.conf
echo "net.ipv4.neigh.default.gc_stale_time = 120"  >> /etc/sysctl.conf
echo "net.ipv4.conf.all.rp_filter = 0"  >> /etc/sysctl.conf
echo "net.ipv4.conf.default.rp_filter = 0"  >> /etc/sysctl.conf
echo "net.ipv4.conf.default.arp_announce = 2"  >> /etc/sysctl.conf
echo "net.ipv4.conf.lo.arp_announce = 2"  >> /etc/sysctl.conf
echo "net.ipv4.conf.all.arp_announce = 2"  >> /etc/sysctl.conf
echo "net.ipv4.tcp_max_tw_buckets = 5000"  >> /etc/sysctl.conf
echo "net.ipv4.tcp_syncookies = 1"  >> /etc/sysctl.conf
echo "net.ipv4.tcp_max_syn_backlog = 1024"  >> /etc/sysctl.conf
echo "net.ipv4.tcp_synack_retries = 2"  >> /etc/sysctl.conf
echo "net.ipv4.tcp_fin_timeout = 30"  >> /etc/sysctl.conf
echo "net.ipv4.tcp_keepalive_time = 30"  >> /etc/sysctl.conf
echo "net.ipv4.tcp_keepalive_intvl = 10"  >> /etc/sysctl.conf
echo "net.ipv4.tcp_keepalive_probes = 3"  >> /etc/sysctl.conf
echo "kernel.sysrq = 1"  >> /etc/sysctl.conf
sysctl -p
echo "优化完成，请重启服务器生效"
#文件打开数
echo "文件打开数设置成65535,按任意键继续"
read -n1
echo "root soft nofile 65535"  >> /etc/security/limits.conf
echo "root hard nofile 65535"  >> /etc/security/limits.conf
echo "* soft nofile 65535"  >> /etc/security/limits.conf
echo "* hard nofile 65535"  >> /etc/security/limits.conf
echo "优化完成，请重启服务器生效"
