How to add SWAP space in Linux to avoid Tomcat, Mysql being killed by the Kernel

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

If you Tomcat, Mysql, JAVA programs got killed by the kernel for memory space issues, adding a SWAP space in your Virtual Machine or Physical Machine may help.

Make sure you have login as root:
To create a 2GB swap space:

dd if=/dev/zero of=/mnt/swap bs=1024 count=2048000

Make it a swap area:

/sbin/mkswap /mnt/swap

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

Make it live:

/sbin/swapon /mnt/swap

add the following codes in


to make SWAP area consistence after reboot.

/mnt/swap swap swap defaults 0 0

Read More

Using ‘ab’ (Apache Benchmark) for concurrent/many different (or random) URLs, Requests or connections

Two options:

Easy and Simple run with compiled 64bit executable version :

Download at: ab-patched-for-mutiple-requests.tar

To build it by yourself:

  • Download httpd-2.2.4.tar from here or Apache’s archive site
  • Unpack the tar file and cd into it
  • Copy and Paste the patch into the source folder and apply it.  (Download at: ab_append_requests)
  • $ cd httpd-2.2.4/support/
    $ patch -p0 < ~/ab_append_requests.patch
  • Run ./configure –with-included-apr –enable-static-ab –enable-ssl (the first option will ignore the more recent copy of apr that’ll be on your machine already, and the second will build a static binary—well, not completely static, but good enough to be independent)
  • make (you can specify -jn where n is the number of processor cores you have; this will speed up the build a lot)


use -R command with the URL file path and other parameters you want:

./ab -n 2 -R randomList.txt -c 2 -g /test/testgnu ""

randomList.txt contains your URLs or parameters to be appended to the URL. For example:


The connections and requests will be sent to the URL one by one from the list.

Thanks to Chris, reference:

Read More

Apache Benchmark (ab) tools GNUPLOT output meanings

Apache Benchmark (ab) tools GNUPLOT output

  • ctime: Connection Time
  • dtime: Processing Time
  • ttime: Total Time
  • wait: Waiting Time

For example:

root@wh-query:/test# ab -n 2 -c 2 -g /test/gnup ""
This is ApacheBench, Version 2.3 <$Revision: 1528965 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd,
Licensed to The Apache Software Foundation,

Benchmarking (be patient).....done

Server Software: Apache-Coyote/1.1
Server Hostname:
Server Port: 55555

Document Path: /healthbook/v1/health/title/ecg/datapoints?accesstoken=5b08af23d9f2490cb253fa5d221aa74e&max=10&start=1406224391
Document Length: 984 bytes

Concurrency Level: 2
Time taken for tests: 0.051 seconds
Complete requests: 2
Failed requests: 0
Total transferred: 3734 bytes
HTML transferred: 1968 bytes
Requests per second: 39.43 [#/sec] (mean)
Time per request: 50.726 [ms] (mean)
Time per request: 25.363 [ms] (mean, across all concurrent requests)
Transfer rate: 71.89 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 1 1 0.0 1 1
Processing: 43 46 4.7 50 50
Waiting: 42 46 4.6 49 49
Total: 44 47 4.6 51 51

Percentage of the requests served within a certain time (ms)
50% 51
66% 51
75% 51
80% 51
90% 51
95% 51
98% 51
99% 51
100% 51 (longest request)

With corresponding output of GNUPLOT:

root@wh-query:/test# cat gnup 
starttime	seconds	ctime	dtime	ttime	wait
Fri Jul 25 19:28:32 2014	1406316512	1	43	44	42
Fri Jul 25 19:28:32 2014	1406316512	1	50	51	49

Read More

Tomcat 7 hangs/freezes while starting in Ubuntu 14.04

I tried to run tomcat 7 in a new Ubuntu 14.04 server. It hangs every time when
INFO: Deploying configuration descriptor ......
No other error logs were produced. After searching on the web, I finally found a solution:

Add the following line into the beginning of the file: “tomcatFolder/bin/”

Then, restart tomcat, it will boot as normal!

Read More

Example of Iptable rules to keep your Linux server safe

iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -p tcp --dport 23 -j ACCEPT
iptables -A INPUT -p tcp --dport 25 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 81 -j ACCEPT
iptables -A INPUT -p tcp --dport 110 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
iptables -A INPUT -p tcp --dport 587 -j ACCEPT
iptables -A INPUT -p tcp --dport 3306 -j ACCEPT
iptables -A INPUT -p tcp --dport 8080 -j ACCEPT
iptables -A INPUT -p tcp --dport 8009 -j ACCEPT
iptables -A INPUT -p tcp --dport 8089 -j ACCEPT
iptables -A INPUT -p tcp --dport 8443 -j ACCEPT
iptables -A INPUT -p tcp --dport 8081 -j ACCEPT
iptables -A INPUT -p tcp --dport 81 -j ACCEPT
iptables -A INPUT -p tcp --dport 11211 -j ACCEPT
iptables -A INPUT -p udp --dport 11211 -j ACCEPT
iptables -A INPUT -p tcp --dport 50000 -j ACCEPT
iptables -A INPUT -p tcp --dport 50001 -j ACCEPT
iptables -A INPUT -p tcp --dport 60000 -j ACCEPT
iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
iptables -A INPUT -p tcp --syn -m limit --limit 1/s --limit-burst 3 -j RETURN

You can use -I and with a number to add a rule to the top of the list (highest priority). For example:

iptables -I INPUT 1 -p tcp --sport 80 -j ACCEPT
iptables -I INPUT 1 -p tcp --sport 8080 -j ACCEPT
iptables -I OUTPUT 1 -p tcp --dport 8080 -j ACCEPT
iptables -I OUTPUT 1 -p tcp --dport 80 -j ACCEPT
iptables -I OUTPUT 1 -p tcp --sport 8080 -j ACCEPT
iptables -I OUTPUT 1 -p tcp --sport 80 -j ACCEPT

Refuse all other requests depends on your network settings

iptables -A INPUT -i eth0 -j REJECT
iptables -A INPUT -i venet0 -j REJECT

Save and restart Iptables to active the firewall.

/etc/init.d/iptables save
/etc/init.d/iptables restart

Simple! Isnt it?

Read More

How to secure Memcached and ensure its security

To allow only the IP addresses that you know to connect to Memcached service, create the iptable rules like these and save it:

iptables -I INPUT -p tcp --dport 11211 -s IPADDRESS -j ACCEPT
iptables -I INPUT -p tcp --dport 11211 -s -j ACCEPT
iptables -A INPUT -p tcp --dport 11211 -j DROP

You can test it by running telnet from other servers to see if it is activated:
for example

telnet IPADDRESS 11211

To check status and then quit:


Make sure you configure MemCached to listen to the IP address of the server it is on, for example:
In Debian:


or in CentOS:


You will find the line like this:

-l means it listens to any ip address on the server.
Change it to if you only wants connections from the local server itself.

Read More





.modal {
display: none;
position: fixed;
z-index: 1000;
top: 0;
left: 0;
height: 100%;
width: 100%;
background: rgba( 255, 255, 255, .8 )
50% 50%
/* loading时候页面锁定 */
body.loading {
overflow: hidden;
/* loading时候页面锁定,显示modal部分 */
body.loading .modal {
display: block;


最后, 通过body的加载和删除loading class来控制loading的gif动画锁定。
$body = $("body");$body.addClass("loading");
放置在发送请求之前。 并将
$body = $("body");$body.removeClass("loading");


$body = $("body");
ajaxStart: function() { $body.addClass("loading"); },
ajaxStop: function() { $body.removeClass("loading"); }

Read More