Quick way to add swap – Ubuntu

 

One of the quickest way to avoid out of memory errors is by adding some swap space. Swap is an area on hard drive where operating system can temporally store data that it can no longer hold in RAM.

Use following way to add additional swap space in Ubuntu:

First check about swap space with free command:

free -m

Lets say if we need 10GB of swap, for this first create a 10GB file with following command:

sudo fallocate -l 10G /swapfile

View details about created swapfile:

ls -hl /swapfile

Output:

-rw-r–r– 1 root root 10G May 19 06:54 /swapfile

Change permissions of swapfile:

sudo chmod 600 /swapfile

Set swap space with following command:

sudo mkswap /swapfile

Check for new swap space:

sudo swapon -s

Output:

Filename                Type        Size    Used    Priority
/swapfile                               file        10485756    2700    -2

Make swap file permanent by adding it in /etc/fstab

/swapfile none swap sw 0 0

Get Thread and Heap dump – Java

 

Thread and Heap dumps are useful for debugging any Java programme.

To get thread dump:

By using jstack command we can get thread dump of a Java process.

Example:

$ jstack PID

where PID is Java process id for which we want to get thread dump.

To get heap dump:

By using jmap command we can get heap dump of a Java process.

Exmaple:

$ jmap -heap PID

where PID is Java process id for which we want to get heap dump.

ping ip with port

 

Ports are a concept of UDP and TCP. Ping messages are technically referred to as ICMP Echo Request and ICMP Echo Reply which are part of ICMP. ICMP, TCP, and UDP are “siblings”; they are not based on each other, but are three separate protocols that run on top of IP.

Therefore you can not ping a port. What you can do, is use a port scanner like nmap and check if ip/host and port are accessible.

$ nmap -p 80 www.google.com

Output:

Starting Nmap 6.40 ( http://nmap.org ) at 2015-12-02 14:38 IST
Nmap scan report for http://www.google.com (74.125.200.106)
Host is up (0.085s latency).
Other addresses for http://www.google.com (not scanned): 74.125.200.147 74.125.200.104 74.125.200.103 74.125.200.105 74.125.200.99
rDNS record for 74.125.200.106: sa-in-f106.1e100.net
PORT STATE SERVICE
80/tcp open http

Nmap done: 1 IP address (1 host up) scanned in 0.64 seconds

You can also use telnet onofri.org 80

Ubuntu 14.04 – Restore defaults of top bar in gnome session fallback

Due to some reason my top bar in gnome-panel got messed up and it not appearing as intended.

To fix this I tried to restore top bar in gnome-panel by using following command.

$ dconf reset -f /org/gnome/gnome-panel/
$ killall gnome-panel

After running above commands it appeared as intended.

Git – create empty branch

Git represents branches as pointers to the latest commit in that branch. If you haven’t created a commit yet, there’s nothing for that branch to point to. So you can’t really create branches until you have at least one commit.

Git allows to create a empty branch but its not common way of using Git.

First create create an empty Git repository by using following command:

$ git init

To create empty branch use following command:

$ git commit --allow-empty -m "initial commit for empty brach"

After running above command it will create a master branch, run following command to conform:

$ git branch

Output:

* master

By Sandeep Posted in Git Tagged

Hadoop – Decommission datanode

 

Decommissioning is process to remove one or multiple datanodes from Hadoop.

To decommission a datanode you need to use following process:

Login to namenode host.

Add follwoing configuration in/home/guest/hadoop-2.5.1/etc/hadoop/hdfs-site.xml

<property>
 <name>dfs.hosts.exclude</name>
 <value>/home/guest/hadoop-2.5.1/etc/hadoop/decommission-nodes</value>
</property>

After adding dfs.hosts.exclude property you need to restart HDFS.

Then add datanode hostname that you want to remove in /home/guest/hadoop-2.5.1/etc/hadoop/decommission-nodes

Now run follwoing command to start decommissioning datanode

$ hadoop-2.5.1/bin/hdfs dfsadmin -refreshNodes

This process will run for few minutes depending on data size in datanode, keep monitor decommissioning status in on http://namenode:50070

After finishing decommissioning you can remove that datanode.

 

Ansible Playbook – Syntax check and dry run

 

To perform syntax check and dry run for ansible playbook use following command:

ansible-playbook -i hosts_file --syntax-check --list-tasks playbook.yml

where, –syntax-check is used to check syntax of a playbook & –list-tasks is to all tasks that are executed.

Lighttpd both http and https

 

We can configure both http & https on lighttpd webserver.

Use following configuration to serve both http & https requests:

server.document-root = "/var/www"
server.upload-dirs = ( "/var/cache/lighttpd/uploads" )
accesslog.filename = "/var/log/lighttpd/access.log"
server.errorlog = "/var/log/lighttpd/error.log"
server.pid-file = "/var/run/lighttpd.pid"
server.username = "www-data"
server.groupname = "www-data"
server.port = 80

#Configuration for https
$SERVER["socket"] == ":443" {
  ssl.engine = "enable"
  ssl.pemfile = "/etc/lighttpd/certs/www.example.com.pem"
}

In above configuration http://www.example.com.pem file should contain both the private key and the certificate.

After updating lighttpd.conf file restart lighttpd:

$ service lighttpd restart

After restarting both http & https should work for your host.

iptables start on boot – Ubuntu/Debian

 

By default Ubuntu/Debian OS wont load iptable on boot.

So to load iptables on boot use follow procedure:

Save iptable conf with iptables-save command:

iptables-save > /etc/iptables.conf

Next, open file with name /etc/network/if-up.d/iptables and add following content:

#!/bin/sh
iptables-restore < /etc/iptables.conf

Change permission file /etc/network/if-up.d/iptables as executable with following command:

chmod +x /etc/network/if-up.d/iptables

Now, iptables will restored on boot.

Whenever you change iptable rules don’t forgot to update iptables.conf file. Use following command to update iptables.conf file:

iptables-save > /etc/iptables.conf