2013년 12월 19일 목요일

How to block spamming IP coming to your environment in Tomcat?

There is a case that ton of requests are rushing into your Tomcat webapps, mostly because your service becomes rock star, the bug of your new implementation cause user's "refresh", or maybe something else.

For non-heavy requests which hits cached data most of the time would be fine for those cases, but other types of requests like new login account creation, real-time status query like server status, place order, etc are highly related to database call, and mostly will not be cached. Those calls can exhaust your Tomcat webapps JDBC connection pool too fast and make the service unrecoverable.
Implementing throttling in app would be definitely helpful in this case, but even the solution might need some time to coding. There are other ways you can filter spamming IP in OS level using iptables things or Apache mod_xxx plugin, etc, but probably the easiest and fastest way to block those spamming(well, at least to you) IP would be adding following "Valve" configuration into Tomcat's server.xml.
      </Host>
<Valve className="org.apache.catalina.valves.RemoteAddrValve" deny="xx.x.xx.xxx" />
  
</Engine>
This set up need to be located under <Engine> section, and at the same level with "Host". ( chanse xx.x.xx.xxx to the IP which you want to block).
You can either use "deny" or "allow" for Valve configuration, but "deny" would be what you ant to use at this moment.
For more information about Valve configuration in Tomcat, check http://tomcat.apache.org/tomcat-7.0-doc/config/valve.html

댓글 없음:

댓글 쓰기

가장 많이 본 글