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

/etc/fstab

to make SWAP area consistence after reboot.

/mnt/swap swap swap defaults 0 0

Read More

Microsoft Surface Pro 3 UK Keyboard

Microsoft Surface Pro 3 UK Keyboard – No “Insert” Key on it.

Just received my Microsoft  Surface Pro 3, Intel i7, 8GB Memory, 512GB storage.

Pros: 

  • The combination of “FN”+”Caps Lock” keys change the settings of the functions like F5, F6 and etc.
  • Microsoft has enlarged the size of the mouse touch pad in the Surface 3 than the previous versions.

To anyone is going to buy the device. I have listed some drawbacks I found as follows:

Cons: 

  • There is no “insert” key, and there is no way to use any combination to type it. I have also tried some key mapping software, none of them works.
  • The “Enter” key is very narrow, you can easily mistype it by hitting the “#” key.

The UK version Microsoft  Surface Pro 3 keyboard looks like this: 

Microsoft Surface Pro 3 UK Keyboard

Microsoft Surface Pro 3 UK Keyboard

Read More

Heart and Soul Piano Duet Sheet (Four hands- One piano)

If you are looking for the Heart and Soul Piano Duet sheet, you have come to the right place.

This is the best version of Heart and Soul piano duet sheet I have found.  The piece starts with the Blue Moon, then comes to the original Heart and Soul. It is quite simple, good for beginners. You can play it on a single piano with two persons (four hands) . Excellent choice if you are considering performing it in the wedding scene!

Here is a video of the song using a similar sheet: https://www.youtube.com/watch?v=tqH5apBj6bE

Here is the Download Link of the piano sheet in PDF format: Heart-and-soul.pdf

Enjoy this best piano duet sheet!

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)

Instructions

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

./ab -n 2 -R randomList.txt -c 2 -g /test/testgnu "http://api.wiki-health.org:55555/healthbook/v1/"

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

max=10&start=1406224391
max=100&start=1406224391

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

Thanks to Chris, reference: http://chrismiles.livejournal.com/21720.html

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 "http://api.wiki-health.org:55555/healthbook/v1/health/title/ecg/datapoints?accesstoken=5b08af23d9f2490cb253fa5d221aa74e&max=10&start=1406224391"
This is ApacheBench, Version 2.3 <$Revision: 1528965 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking api.wiki-health.org (be patient).....done

Server Software: Apache-Coyote/1.1
Server Hostname: api.wiki-health.org
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/catalina.sh”
export CATALINA_OPTS="-Djava.security.egd=file:/dev/./urandom"

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 127.0.0.1 -j ACCEPT
iptables -A INPUT -p tcp --dport 11211 -j DROP
iptables-save

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:

stats
quit

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

/etc/memcached.conf

or in CentOS:

/etc/sysconfig/memcached

You will find the line like this:

-l 0.0.0.0

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

Read More