仙游阁 2010-04-27
分析:netstat -an查看到大量的80端口进程僵死,重启tomcat.tomcat启动失败,网页依然无法打开.
停止tomcat进程shutdown.sh,停止tomcat后telnet 127.0.0.1 80,发现80端口依然可用。netstat -an|grep 80 查看发现有许多80端口进程在里面,使用kill pid命令终止进程,无用。使用lsof -i :80|grep -v "PID"|awk '{print "kill -9",$2}'命令后所有80端口进程删除。重新启动tomcat,系统正常运行。不过为什么tomcat在关闭时却不能将80端口的进程一并关闭的原因需要分析一下。
[root@gzcourt bin]# netstat -an |grep 80 tcp 0 0 ::ffff:127.0.0.1:8005 :::* LIST EN tcp 0 0 :::8009 :::* LIST EN tcp 0 0 :::80 :::* LIST EN tcp 0 0 :::8080 :::* LIST EN tcp 0 0 ::ffff:172.16.1.153:80 ::ffff:202.160.179.12:36057 TIME _WAIT tcp 0 0 ::ffff:172.16.1.153:80 ::ffff:202.160.178.15:39176 TIME _WAIT tcp 0 0 ::ffff:172.16.1.153:80 ::ffff:218.20.57.173:55001 ESTA BLISHED tcp 0 0 ::ffff:172.16.1.153:80 ::ffff:218.20.57.173:3516 ESTA BLISHED tcp 0 0 ::ffff:172.16.1.153:80 ::ffff:218.20.57.173:55037 ESTA BLISHED tcp 0 0 ::ffff:172.16.1.153:80 ::ffff:218.20.57.173:3518 ESTA BLISHED tcp 0 0 ::ffff:172.16.1.153:80 ::ffff:61.135.162.208:57893 TIME _WAIT tcp 0 0 ::ffff:172.16.1.153:80 ::ffff:210.72.4.122:39196 ESTA BLISHED tcp 0 0 ::ffff:172.16.1.153:80 ::ffff:59.32.124.136:22529 ESTA BLISHED tcp 0 0 ::ffff:172.16.1.153:80 ::ffff:218.20.57.173:55222 ESTA BLISHED tcp 0 0 ::ffff:172.16.1.153:80 ::ffff:218.20.57.173:3510 ESTA BLISHED tcp 0 0 ::ffff:172.16.1.153:80 ::ffff:59.32.124.136:22530 ESTA BLISHED tcp 0 0 ::ffff:172.16.1.153:80 ::ffff:210.72.4.122:39198 ESTA BLISHED unix 3 [ ] STREAM CONNECTED 6880 /tmp/.X11-unix/X0 # lsof -i :80|grep -v "PID"|awk '{print "kill -9",$2}'|sh
以上脚本可以清除80端口的进程
解决方案:linux 下将tomcat的server.xml的端口改为80后以tomcat身份无法启动tomcat。
在redhat上启动tomcat(将server.xml中的端口改为80)
su – tomcat -c "$CATALINA_HOME/bin/startup.sh"
后出现:Catalina.start: LifecycleException: null.open: java.net.BindException: Permission denied:80
这是因为只有root用户才可访问1024以下的端口。
解决方法:重将server.xml中的端口改为8080
然后:iptables -t nat -A PREROUTING -p tcp –dport 80 -j REDIRECT –to-port 8080
(如果用到443,也相应执行以上方法)
即可。