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

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 enable PPP device/protocol support in OpenVZ container (Centos, Linux system)

First you need to enable the following modules on Openvz HOST:

modprobe ppp_mppe 
modprobe ppp_deflate 
modprobe zlib_deflate 
modprobe ppp_async 
modprobe ppp_generic 
modprobe slhc 
modprobe crc_ccitt 
root@host:~# lsmod | grep ppp
ppp_async               7872  0 
crc_ccitt               1733  1 ppp_async
ppp_deflate             4184  0 
ppp_mppe                6548  0 
ppp_generic            25248  3 ppp_mppe,ppp_deflate,ppp_async
slhc                    6076  1 ppp_generic
zlib_deflate           21663  2 btrfs,ppp_deflate

Replace the ContainerNo with your Virtual Machine id and execute the following commands on openvz host.
for example:

vzctl set 110 --features ppp:on --save
vzctl set [ContainerNo ] --features ppp:on --save
vzctl start [ContainerNo ]
vzctl set [ContainerNo ] --devices c:108:0:rw --save
vzctl exec [ContainerNo ] mknod /dev/ppp c 108 0
vzctl exec [ContainerNo ] chmod 600 /dev/ppp

After installing PPTP, checking the module by the following command:

/usr/sbin/pppd

You should see output is something like this:

asdf(*!^"£)(&!"£!"))_...

Now it means that PPP is loaded and setup.

Read More

vi commands cheat sheet/command list

Cursor movement

  • h – move left
  • j – move down
  • k – move up
  • l – move right
  • w – jump by start of words (punctuation considered words)
  • W – jump by words (spaces separate words)
  • e – jump to end of words (punctuation considered words)
  • E – jump to end of words (no punctuation)
  • b – jump backward by words (punctuation considered words)
  • B – jump backward by words (no punctuation)
  • 0 – (zero) start of line
  • ^ – first non-blank character of line
  • $ – end of line
  • G – Go To command (prefix with number – 5G goes to line 5)

Note: Prefix a cursor movement command with a number to repeat it. For example, 4j moves down 4 lines.

Insert Mode – Inserting/Appending text

  • i – start insert mode at cursor
  • I – insert at the beginning of the line
  • a – append after the cursor
  • A – append at the end of the line
  • o – open (append) blank line below current line (no need to press return)
  • O – open blank line above current line
  • ea – append at end of word
  • Esc – exit insert mode

Editing

  • r – replace a single character (does not use insert mode)
  • J – join line below to the current one
  • cc – change (replace) an entire line
  • cw – change (replace) to the end of word
  • c$ – change (replace) to the end of line
  • s – delete character at cursor and subsitute text
  • S – delete line at cursor and substitute text (same as cc)
  • xp – transpose two letters (delete and paste, technically)
  • u – undo
  • . – repeat last command

Marking text (visual mode)

  • v – start visual mode, mark lines, then do command (such as y-yank)
  • V – start Linewise visual mode
  • o – move to other end of marked area
  • Ctrl+v – start visual block mode
  • O – move to Other corner of block
  • aw – mark a word
  • ab – a () block (with braces)
  • aB – a {} block (with brackets)
  • ib – inner () block
  • iB – inner {} block
  • Esc – exit visual mode

Visual commands

  • > – shift right
  • < – shift left
  • y – yank (copy) marked text
  • d – delete marked text
  • ~ – switch case

Cut and Paste

  • yy – yank (copy) a line
  • 2yy – yank 2 lines
  • yw – yank word
  • y$ – yank to end of line
  • p – put (paste) the clipboard after cursor
  • P – put (paste) before cursor
  • dd – delete (cut) a line
  • dw – delete (cut) the current word
  • x – delete (cut) current character

Exiting

  • :w – write (save) the file, but don’t exit
  • :wq – write (save) and quit
  • :q – quit (fails if anything has changed)
  • :q! – quit and throw away changes

Search/Replace

  • /pattern – search for pattern
  • ?pattern – search backward for pattern
  • n – repeat search in same direction
  • N – repeat search in opposite direction
  • :%s/old/new/g – replace all old with new throughout file
  • :%s/old/new/gc – replace all old with new throughout file with confirmations

Working with multiple files

  • :e filename – Edit a file in a new buffer
  • :bnext (or :bn) – go to next buffer
  • :bprev (of :bp) – go to previous buffer
  • :bd – delete a buffer (close a file)
  • :sp filename – Open a file in a new buffer and split window
  • ctrl+ws – Split windows
  • ctrl+ww – switch between windows
  • ctrl+wq – Quit a window
  • ctrl+wv – Split windows vertically

Reference:
http://www.worldtimzone.com/res/vi.html

Read More

Vim Commands Cheat Sheet/Command List

How to Exit

:q[uit] Quit Vim. This fails when changes have been made.
:q[uit]! Quit without writing.
:cq[uit] Quit always, without writing.
:wq Write the current file and exit.
:wq! Write the current file and exit always.
:wq {file} Write to {file}. Exit if not editing the last
:wq! {file} Write to {file} and exit always.
:[range]wq[!] [file] Same as above, but only write the lines in [range].
ZZ Write current file, if modified, and exit.
ZQ Quit current file and exit (same as “:q!”).

 


Editing a File

:e[dit] Edit the current file. This is useful to re-edit the current file, when it has been changed outside of Vim.
:e[dit]! Edit the current file always. Discard any changes to the current buffer. This is useful if you want to start all over again.
:e[dit] {file} Edit {file}.
:e[dit]! {file} Edit {file} always. Discard any changes to the current buffer.
gf Edit the file whose name is under or after the cursor. Mnemonic: “goto file”.

 


Inserting Text

a Append text after the cursor [count] times.
A Append text at the end of the line [count] times.
i Insert text before the cursor [count] times.
I Insert text before the first non-blank in the line [count] times.
gI Insert text in column 1 [count] times.
o Begin a new line below the cursor and insert text, repeat [count] times.
O Begin a new line above the cursor and insert text, repeat [count] times.

 


Inserting a file

:r[ead] [name] Insert the file [name] below the cursor.
:r[ead] !{cmd} Execute {cmd} and insert its standard output below the cursor.

 


Deleting Text

<Del> or
x
Delete [count] characters under and after the cursor
X Delete [count] characters before the cursor
d{motion} Delete text that {motion} moves over
dd Delete [count] lines
D Delete the characters under the cursor until the end of the line
{Visual}x or
{Visual}d
Delete the highlighted text (for {Visual} see Selecting Text).
{Visual}CTRL-H or
{Visual}
When in Select mode: Delete the highlighted text
{Visual}X or
{Visual}D
Delete the highlighted lines
:[range]d[elete] Delete [range] lines (default: current line)
:[range]d[elete] {count} Delete {count} lines, starting with [range]

(more…)

Read More

HBase does not support row key renaming

As far as I know, in HBase, the key of the row can not be changed. But if you really need a row key rename function, the best thing to do is to copy all the data one row to another row in HBase using JAVA.

e.g. I have existing row with key “key1”, and I want to create a row with key “key2” copied from “key1” row. It is simple:

 // lets say your already got the result from table.get(Bytes.toBytes("key1")) 
Put put = new Put(Bytes.toBytes("key2")); 
NavigableMap&gt; familyQualifierMap = result.getNoVersionMap(); 
for (byte[] familyBytes : familyQualifierMap.keySet()) {
 NavigableMap qualifierMap = familyQualifierMap.get(familyBytes); 
for (byte[] qualifier : qualifierMap.keySet()) {
 put.add(familyBytes, qualifier, qualifierMap.get(qualifier)); } } 
table.put(put); 
table.flushCommits(); 
table.close();

Read More