sysctl是一个允许您改变正在运行中的Linux系统的接口。它包含一些TCP/IP堆栈和虚拟内存系统的高级选项, 这可以让有经验的管理员提高引人注目的系统性能。sysctl配置与显示在/proc/sys目录中的内核参数,可以用sysctl来设置或重新设置联网功能,如IP转发、IP碎片去除以及源路由检查等。用户只需要编辑/etc/sysctl.conf文件,即可手工或自动执行由sysctl控制的功能。
一、 问题出现
今天晚上有网友反应我们网站打开很慢,甚至打不开,我登录远程服务器(CentOS系统)发现大量TIME_WAIT,服务器可能被人恶意攻击了。正常情况下,我们网站服务器TIME_WAIT只有几百,一般不会超过1000。
[root@localhost ~]# netstat -nat | awk '{print $6}' | sort | uniq -c | sort -rn 5453 TIME_WAIT 248 ESTABLISHED 11 LISTEN 2 SYN_RECV 2 CLOSING 1 Foreign 1 established)
怎么办呢?修改/etc/sysctl.conf文件吧。可能是net.ipv4.tcp_max_syn_backlog太小,修改大一点,最终修改为10240。
net.ipv4.tcp_max_syn_backlog = 10240
二、 执行“sysctl -p”报错
[root@localhost ~]# sysctl -p error: "net.bridge.bridge-nf-call-ip6tables" is an unknown key error: "net.bridge.bridge-nf-call-iptables" is an unknown key error: "net.bridge.bridge-nf-call-arptables" is an unknown key
三、 问题解决
[root@localhost ~]# modprobe bridge [root@localhost ~]# lsmod | grep bridge bridge 83177 0 stp 2218 1 bridge llc 5546 2 bridge,stp
使用“modprobe bridge”加载bridge模块后该错误不在出现;modprobe可载入指定的个别模块,或是载入一组相依的模块。modprobe会根据depmod所产生的相依关系,决定要载入哪些模块。若在载入过程中发生错误,在modprobe会卸载整组的模块。
使用“lsmod | grep bridge”显示加载的模块。lsmod是一个小程序,用来显示文件、proc/modules的信息,也就是显示当前内核模块装载的模块。
再执行“sysctl -p”没有报错。
[root@localhost ~]# sysctl -p net.ipv4.ip_forward = 0 net.ipv4.conf.default.rp_filter = 1 net.ipv4.conf.default.accept_source_route = 0 kernel.sysrq = 0 kernel.core_uses_pid = 1 net.ipv4.tcp_syncookies = 1 net.bridge.bridge-nf-call-ip6tables = 0 net.bridge.bridge-nf-call-iptables = 0 net.bridge.bridge-nf-call-arptables = 0 kernel.msgmnb = 65536 kernel.msgmax = 65536 kernel.shmmax = 68719476736 kernel.shmall = 4294967296 net.ipv4.tcp_fin_timeout = 30 net.ipv4.tcp_keepalive_time = 600 net.ipv4.tcp_syncookies = 1 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_tw_recycle = 1 net.ipv4.tcp_max_tw_buckets = 5000 net.ipv4.tcp_max_syn_backlog = 10240 net.core.netdev_max_backlog = 10240 net.core.somaxconn = 2048 net.core.wmem_default = 8388608 net.core.rmem_default = 8388608 net.core.rmem_max = 16777216 net.core.wmem_max = 16777216 net.ipv4.tcp_synack_retries = 1 net.ipv4.tcp_syn_retries = 1 net.ipv4.tcp_max_orphans = 3276800 net.ipv4.icmp_echo_ignore_all = 1
至此,网站正常访问,大功告成了。