#!/bin/bash
 #备份原有文档
 mv /etc/sysctl.conf /etc/sysctl.conf.`date +"%Y-%m-%d_%H-%M-%S"`
 #导入新参数
 echo -e "kernel.sysrq = 0\n"\
 "kernel.core_uses_pid = 1\n"\
 "kernel.msgmnb = 65536\n"\
 "kernel.msgmax = 65536\n"\
 "kernel.shmmax = 2147483648\n"\
 "kernel.shmall = 1048576\n"\
 "net.core.wmem_default = 2097152\n"\
 "net.core.wmem_max = 8388608\n"\
 "net.core.rmem_default = 2097152\n"\
 "net.core.rmem_max = 8388608\n"\
 "net.core.netdev_max_backlog = 4096\n"\
 "net.core.somaxconn = 51200\n"\
 "net.ipv4.conf.default.rp_filter = 1\n"\
 "net.ipv4.conf.default.accept_source_route = 0\n"\
 "net.ipv4.ip_forward = 0\n"\
 "net.ipv4.ip_local_port_range = 2048 65000\n"\
 "net.ipv4.tcp_fin_timeout = 15\n"\
 "net.ipv4.tcp_keepalive_time = 30\n"\
 "net.ipv4.tcp_max_orphans = 3276800\n"\
 "net.ipv4.tcp_max_syn_backlog = 32768\n"\
 "net.ipv4.tcp_max_tw_buckets = 6000\n"\
 "net.ipv4.tcp_mem = 262144 786432 1048576\n"\
 "net.ipv4.tcp_rmem_max = 1048576\n"\
 "net.ipv4.tcp_wmem_max = 1048576\n"\
 "net.ipv4.tcp_rmem = 4096 131072 1048576\n"\
 "net.ipv4.tcp_wmem = 4096 131072 1048576\n"\
 "net.ipv4.tcp_sack = 1\n"\
 "net.ipv4.tcp_syn_retries = 3\n"\
 "net.ipv4.tcp_synack_retries = 3\n"\
 "net.ipv4.tcp_syncookies = 1\n"\
 "net.ipv4.tcp_timestamps = 0\n"\
 "net.ipv4.tcp_tw_reuse = 1\n"\
 "net.ipv4.tcp_tw_recycle = 1\n"\
 "net.ipv4.tcp_window_scaling = 1\n" >/etc/sysctl.conf
 #使新参数生效
 sysctl -p