netstat -na|grep ESTABLISHED|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -r +0n
netstat -na|grep SYN|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -r +0n
Onecent:~ # netstat -an | grep 80 | awk '{print $6}' | sort | uniq -c | sort -rn
681 TIME_WAIT
122 ESTABLISHED
107 FIN_WAIT2
44 FIN_WAIT1
14 SYN_SENT
3 LAST_ACK
2 SYN_RECV
1 LISTEN
1 CLOSING
linux可以查看多少人连接了80端口:
Onecent:~ # netstat -na | grep ":80" | wc
1074 6444 86994
1074 6444 86994
Onecent:~ # netstat -atlunp|grep 80|grep TIME_WAIT|wc
787 5509 79487
787 5509 79487
Oncecent:~ # netstat -atlunp|grep 80|wc
1030 7210 104030
1030 7210 104030
线程数:
Onecent:/usr/local/apache2/conf # ps -ef |grep httpd |wc -l
360
360
工作模式查看:
Onecent:/usr/local/apache2/conf # /usr/local/apache2/bin/httpd -l
Compiled in modules:
core.c
mod_access.c
mod_auth.c
mod_cache.c
mod_disk_cache.c
mod_mem_cache.c
mod_include.c
mod_deflate.c
mod_log_config.c
mod_env.c
mod_expires.c
mod_setenvif.c
prefork.c
http_core.c
mod_mime.c
mod_status.c
mod_autoindex.c
mod_asis.c
mod_cgi.c
mod_negotiation.c
mod_dir.c
mod_imap.c
mod_actions.c
mod_userdir.c
mod_alias.c
mod_rewrite.c
mod_so.c
Compiled in modules:
core.c
mod_access.c
mod_auth.c
mod_cache.c
mod_disk_cache.c
mod_mem_cache.c
mod_include.c
mod_deflate.c
mod_log_config.c
mod_env.c
mod_expires.c
mod_setenvif.c
prefork.c
http_core.c
mod_mime.c
mod_status.c
mod_autoindex.c
mod_asis.c
mod_cgi.c
mod_negotiation.c
mod_dir.c
mod_imap.c
mod_actions.c
mod_userdir.c
mod_alias.c
mod_rewrite.c
mod_so.c
注意:prefork.c //此处为mpm工作模式,也可使用worker.c模式
netstat -n | awk '/^tcp/ {++S[$NF]};END {for(a in S) print a, S[a]}'
Onecent:/usr/local/# netstat -n | awk '/^tcp/ {++S[$NF]};END {for(a in S) print a, S[a]}'
LAST_ACK 3
SYN_RECV 5
ESTABLISHED 207
FIN_WAIT1 63
FIN_WAIT2 105
SYN_SENT 1
TIME_WAIT 912
LAST_ACK 3
SYN_RECV 5
ESTABLISHED 207
FIN_WAIT1 63
FIN_WAIT2 105
SYN_SENT 1
TIME_WAIT 912
修理修理下面的参数:
sysctl -p
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.conf.all.rp_filter = 1
kernel.sysrq = 1
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.ip_local_port_range = 2048 65000
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_max_tw_buckets = 5000
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.conf.all.rp_filter = 1
kernel.sysrq = 1
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.ip_local_port_range = 2048 65000
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_max_tw_buckets = 5000
修改:
1, sysctl命令的作用
在运行时配置内核参数
2,用法举例:
-w 用此选项来改变一个sysctl设置
例:sysctl -w net.ipv4.ip_forward=1
-p 载入sysctl配置文件
如-p后未指定路径,则载入 /etc/sysctl.conf
例: sysctl -p /etc/sysctl.conf
3,修改/etc/sysctl.conf可以保存设置在机器重启后仍然有效
例如:
vi /etc/sysctl.conf
修改: net.ipv4.ip_forward=0的值为1
作用:打开数据包的转发功能
如何使修改马上生效?
sysctl -p /etc/sysctl.conf // 作用:重新载入/etc/sysctl.conf文件
整个张宴的nginx的配置,如下,可以参考:
优化Linux内核参数
vi /etc/sysctl.conf
在末尾增加以下内容:
引用
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 300
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.ip_local_port_range = 5000 65000
使配置立即生效:
/sbin/sysctl -p
作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:http://jackxiang.com/post/3529/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
最后编辑: jackxiang 编辑于2010-9-25 11:46
评论列表