Wednesday 30 October 2013

Deleting ipv6 address

Problem: Deleting ipv6 address in Linux
Solution:

ifconfig eth0 inet6 del fd00:7a06:a248:1:250:56ff:fe86:32cb/64

Tuesday 29 October 2013

Counting number of files in a directory -Linux

Problem:  I want to find number of files in a directory
Solution:

 
[root@dragon bin]# ls -l | wc -l
25
[root@dragon bin]#

Friday 25 October 2013

Downloading JDK7 using wget on linux

Problem: I have to download Oracle JDK7 on linux using wget.

Solution: Please use below command and replace jdk url with appropriate version. Here I am downloading JDK7  update 45 on x64 linux



wget --no-check-certificate --no-cookies --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com" "http://download.oracle.com/otn-pub/java/jdk/7u45-b18/jdk-7u45-linux-x64.tar.gz" 

Thursday 24 October 2013

504 Gateway Timeout Error

Problem: My load balancer machine is giving me 504 Gateway Timeout Error.

HTTP request flow :

Browser <-> nginx(load balaencer on port 80) <-> Apache ( reverse proxy on port 85) <-> haproxy (load balaencer on 7070) <-> Tomcat ( Servlet Enginge 8080)


When I am accessing resource http://www.mydomain.com/helloworld/hello.jsp I receive 504 Gateway Timeout Error gateway time out. I am clue less which server is sending this error. I verified the logs of ngnix,apache,haproxy,tomcat none of them revel evident root cause.

Approach Taken to solve the Problem:

Let’s access the resource from bottom to top


http://tomcat-ip:8080 /helloworld/hello.jsp  (Resource is served in  5min. No time out)
http://Apache-ip:8585 /helloworld/hello.jsp (Received 504 Gateway time out)
http://nginx:80 /helloworld/hello.jsp (Received 504 Gateway time out)

We identified the root cause for this problem is haproxy and we need to increase the load_balancer time out of it.

Solution:

  • Stop haproxy .  ( I  greped for process id and killed the process)
  • Edit  /etc/haproxy/haproxy.cfg
  • Increase the value of
  •        clitimeout              9930000
  •         contimeout              9930000
  •         srvtimeout              9930000
  • Start haproxy  (./haproxy-1.4.24 -f /etc/haproxy/haproxy.cfg)



Finding process path associated to a port on linux

Problem: I want to find out process path that is associated to port 8080 on my linux system.

Solution:
We can use netstat along with grep to do this.

Command:
 [root@dragon ~]# netstat -tulpn | grep 8080

Output:
 tcp        0      0 0.0.0.0:8080                0.0.0.0:*                   LISTEN      14491/./haproxy-1.4


In the above command. We can observe ./haproxy-1.4 is a process with process id 14491 is associated to port 8080.

We can use ps command to find out process path associated to process id

Command:
 [root@dragon ~]# ps -aef | grep 14491 


Output:
80       14491     1  0 Oct24 ?        00:00:04 ./haproxy-1.4.24-pcre-40kses-linux-i586.stripped -f /etc/haproxy/haproxy.cfg
 


We can observe haproxy was started using command:

./haproxy-1.4.24-pcre-40kses-linux-i586.stripped -f /etc/haproxy/haproxy.cfg

Finding files inside a jar - Linux


Problem: I have to find a jar file in which class named DataSource is present.

Solution: We can use linux find command along with grep to do this job.

 
find -name "*.jar" |  xargs grep -l "DataSource"
The above command searches for DataSource class in all jar files located in current working directory