赞
踩
查看连接数及状态统计
netstat -n | awk '/^tcp/ {++state[$NF]} END {for(key in state) print key,"t",state[key]}'
编辑 /etc/sysctl.conf
shell: sysctl -p 生效
- # sysctl settings are defined through files in
- # /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
- #
- # Vendors settings live in /usr/lib/sysctl.d/.
- # To override a whole file, create a new file with the same in
- # /etc/sysctl.d/ and put new settings there. To override
- # only specific settings, add a file with a lexically later
- # name in /etc/sysctl.d/ and put new settings there.
- #
- # For more information, see sysctl.conf(5) and sysctl.d(5).
- #禁用ipv6
- net.ipv6.conf.all.disable_ipv6 = 1
- net.ipv6.conf.default.disable_ipv6 = 1
- net.ipv6.conf.lo.disable_ipv6 = 1
- net.ipv6.conf.eth0.disable_ipv6 = 1
- net.ipv6.conf.pan0.disable_ipv6 = 1
-
- #使用swap资源
- vm.swappiness = 10
- net.ipv4.neigh.default.gc_stale_time=120
-
-
- # see details in https://help.aliyun.com/knowledge_detail/39428.html
- net.ipv4.conf.all.rp_filter=0
- net.ipv4.conf.default.rp_filter=0
- net.ipv4.conf.eth0.rp_filter = 0
- net.ipv4.conf.default.arp_announce = 2
- net.ipv4.conf.lo.arp_announce=2
- net.ipv4.conf.all.arp_announce=2
-
-
- # see details in https://help.aliyun.com/knowledge_detail/41334.html
- #net.ipv4.tcp_max_tw_buckets = 5000
- net.ipv4.tcp_syncookies = 1
- #net.ipv4.tcp_max_syn_backlog = 1024
- net.ipv4.tcp_synack_retries = 2
- #最大连接数
- fs.file-max=65535
-
- #处理TIME_OUT连接过多
- net.ipv4.tcp_max_tw_buckets = 10000
- net.ipv4.tcp_tw_reuse = 1
- net.ipv4.tcp_tw_recycle = 1
- net.ipv4.tcp_fin_timeout = 10
- net.ipv4.tcp_keepalive_time = 60
- net.ipv4.ip_local_port_range = 11000 65000
- net.ipv4.tcp_keepalive_time = 120
- net.ipv4.tcp_keepalive_intvl = 15
- net.ipv4.tcp_keepalive_probes = 5
-
- #记录的那些尚未收到客户端确认信息的连接请求的最大值。对于有128M内存的系统而言,缺省值是1024,小内存的系统则是128
- net.ipv4.tcp_max_syn_backlog = 262144
-
- #web应用中listen函数的backlog默认会给我们内核参数的net.core.somaxconn限制到128,而nginx定义的NGX_LISTEN_BACKLOG默认为511,所以有必要调整这个值。
- net.core.somaxconn = 65535
-
- #系统中最多有多少个TCP套接字不被关联到任何一个用户文件句柄上。如果超过这个数字,孤儿连接将即刻被复位并打印出警告信息。
- #这个限制仅仅是为了防止简单的DoS攻击,不能过分依靠它或者人为地减小这个值,更应该增加这个值(如果增加了内存之后)。
- net.ipv4.tcp_max_orphans = 262144
-
- #时间戳可以避免序列号的卷绕。一个1Gbps的链路肯定会遇到以前用过的序列号。时间戳能够让内核接受这种“异常”的数据包。这里需要将其关掉。
- net.ipv4.tcp_timestamps = 0
-
- #内核放弃连接之前发送SYN+ACK包的数量
- net.ipv4.tcp_synack_retries = 1
-
- #在内核放弃建立连接之前发送SYN包的数量
- net.ipv4.tcp_syn_retries = 1
查看tcp前10的连接数IP , 本地IP除外
netstat -na|grep ESTABLISHED|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -rn|head -10|grep -v -E '192.168|127.0'
查看连接数IP,按连接数排序
netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
监控网络带宽
iftop
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。