Friday 8 November 2013

Wednesday 6 November 2013

Unicast liferay cluster on amazon EC2

Setting up liferay cluster on Aamzon EC2:

Amazon EC2 environment doesn’t allow multicasting that’s the reason. The steps mentioned at wiki http://www.liferay.com/web/ricardo.funke/blog/-/blogs/liferay-6-1-simple-cluster doesn’t work out of the box.

Environment:
·         Liferay 6.0.6 CE
·         Java version 1.7.0_45
·         Red Hat Enterprise Linux Server release 6.4
There are two entities that needs to be taken care while clustering
1.       Tomcat  HTTP Session replication
2.       Liferay cache replication
The scope of document is to cover “Liferay Cache Replication”. If you need information related to tomcat session replication please follow wiki http://techynfreesouls.blogspot.in/2012/04/liferay-cluster-on-amazon-ec2.html

Extract :
·         tcp.xml from “/liferay/tomcat/webapps/ROOT/WEB-INF/lib/jgroups.jar” and copy to /liferay/tomcat/webapps/ROOT/WEB-INF/classes
·         hibernate-clustered.xml from “/liferay/tomcat/webapps/ROOT/WEB-INF/lib/portal-impl.jar ” and copy to /liferay/tomcat/webapps/ROOT/WEB-INF/classes
·         liferay-multi-vm-clustered.xml from “/liferay/tomcat/webapps/ROOT/WEB-INF/lib/portal-impl.jar ” and copy to /liferay/tomcat/webapps/ROOT/WEB-INF/classes

Edit tcp.xml  and set <TCP  singleton_name="liferay_jgroups_tcp" bind_port="7800"

Edit Portal-ext.properties and set below attributes
web.server.display.node=true
#Setup hibernate
net.sf.ehcache.configurationResourceName=/hibernate-clustered.xml
#Setup distributed ehcache
ehcache.multi.vm.config.location=/liferay-multi-vm-clustered.xml
#In order to make use of jgroups
ehcache.bootstrap.cache.loader.factory=com.liferay.portal.cache.ehcache.JGroupsBootstrapCacheLoaderFactory
ehcache.cache.event.listener.factory=net.sf.ehcache.distribution.jgroups.JGroupsCacheReplicatorFactory
ehcache.cache.manager.peer.provider.factory=net.sf.ehcache.distribution.jgroups.JGroupsCacheManagerPeerProviderFactory
net.sf.ehcache.configurationResourceName.peerProviderProperties=file=/tcp.xml
ehcache.multi.vm.config.location.peerProviderProperties=file=/tcp.xml
ehcache.statistics.enabled=true
lucene.replicate.write=true

In my env I have two node cluster. The above changes needs to be performed on both the nodes.

Start tomcat on node1:
export JAVA_HOME=/jdk1.7.0_45
export PATH=$JAVA_HOME/bin:$PATH
export JAVA_OPTS="-Djgroups.bind_addr=node1 -Djgroups.tcpping.initial_hosts=node2[7800],node1[7800] -Djava.net.preferIPv4Stack=true -Xms256m -Xmx1024m -XX:MaxPermSize=512m -Dcom.sun.management.jmxremote   -Dcom.sun.management.jmxremote.port=12345   -Dcom.sun.management.jmxremote.ssl=false   -Dcom.sun.management.jmxremote.authenticate=false"
./startup.sh

Start tomcat on node2:

export JAVA_HOME=/jdk1.7.0_45
export PATH=$JAVA_HOME/bin:$PATH
export JAVA_OPTS="-Djgroups.bind_addr=node2 -Djgroups.tcpping.initial_hosts=node2[7800],node1[7800] -Djava.net.preferIPv4Stack=true -Xms256m -Xmx1024m -XX:MaxPermSize=512m -Dcom.sun.management.jmxremote   -Dcom.sun.management.jmxremote.port=12345   -Dcom.sun.management.jmxremote.ssl=false   -Dcom.sun.management.jmxremote.authenticate=false"
./startup.sh


If everything goes well. You should see following channels gets created .  Verify liferay log.


-------------------------------------------------------------------
GMS: address=node1-17685, cluster=EH_CACHE, physical address=10.0.123.5:33959
-------------------------------------------------------------------
-------------------------------------------------------------------
GMS: address=node1-36406, cluster=EH_CACHE, physical address=10.0.123.5:39875
-------------------------------------------------------------------
-------------------------------------------------------------------
GMS: address=node1-10244, cluster=LIFERAY-CONTROL-CHANNEL, physical address=10.0.123.5:59051
-------------------------------------------------------------------

-------------------------------------------------------------------
GMS: address=node1-22557, cluster=LIFERAY-TRANSPORT-CHANNEL-0, physical address=10.0.123.5:56066
-------------------------------------------------------------------
Test cases:
1.       Create a user in node1 and  search for the same user in node2. You should see user in node2
2.       Add a asset publisher portlet on page1  and access the same page on the other sever. The asset publisher portlet should be seen.

BTW..  ehcache.statistics.enabled=true and “-Dcom.sun.management.jmxremote   -Dcom.sun.management.jmxremote.port=12345   -Dcom.sun.management.jmxremote.ssl=false   -Dcom.sun.management.jmxremote.authenticate=false” are used for debugging purpose of the cache.




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

Tuesday 17 September 2013

Running tomcat in debug mode linux

Probelm: How can I run tomcat in debug mode in Linux

Solution:
Naviagate to tomcat bin directory



 
#cd /opt/webservers/tomcat/bin
//Execute below script
#export JPDA_ADDRESS=8000
#export JPDA_TRANSPORT=dt_socket
#export JPDA_SUSPEND=n
#./catalina.sh jpda start

Hint: Connect to 8000 port for debugging the application

Monday 16 September 2013

Dynamically change request cookie name apache


Problem:
I want to dynamically replace cookie name coming from browser to Apache web server.

Solution: The below example will replace all the incoming requests that has cookie name as "SESSION" to "LUCKY.SESSION"

Edit:  httpd.conf

 
RequestHeader edit Cookie "SESSION" "LUCKY.SESSION"
Hint: Please include headers module to work. For ex: Uncomment "LoadModule headers_module modules/mod_headers.so" in httpd.conf

Send Cookie and custom HTTP header using java.net.URLConnection

Problem: Often sites accepts custom http headers and cookies to get data from them. In below example we are going to read data from URL by send http cookie and header.

Solution:

 
package com;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
/**
 * It reads data from a site by sending cookie and custom http header
 * @author lucky academy
 *
 */

public class URLReaderDemo {
public static void main(String[] args)throws Exception {
 //URL of the site
 URL site = new URL("http://www.luckyacademy.com/services/odata/Person");
 //Open Connection
 URLConnection uc = site.openConnection();
 //Set Cookie
 uc.setRequestProperty("Cookie", "JSESSIONID=F2845FC15FCF6660EB093D00DAE73BB2; rememberMe=false");
 //Set custom http header
 uc.setRequestProperty("tenantId","ebay");
 //read data from the site
 //Setting http headers after opening input stream will not have any effect
 BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream()));
 String inputLine;
 while ((inputLine = in.readLine()) != null) {
  System.out.println(inputLine);
 }

 in.close();

 
}
}

Wednesday 11 September 2013

Find and Replace a string in a file

Problem: In linux I want to find a string and replace it with other string in a file.

Solution:  Use the below command.

 
find . -type f  -print | xargs sed -i 's/abc/123/g'

The above command will recursively searches for all the files in current working directory and it replaces all the occurrences of abc with 123 in the found files.

Sunday 8 September 2013

Unable to detect Bluetooth for HP Pavilion g6-2010ax in Windows7


Problem: I am unable to bind any of the Bluetooth devices to my laptop though it says blue tooth is on.

Reason: By default Microsoft Bluetooth drivers are getting installed and they doesn’t work well with the hardware.

Solution:
1.       Install “Atheros Wireless LAN Driver” from http://ftp.hp.com/pub/softpaq/sp56501-57000/sp56572.exe
2.       Install  “Atheros Bluetooth 4.0 + HS Driver” from http://ftp.hp.com/pub/softpaq/sp56501-57000/sp56573.exe
3.       Restart the machine.

Hopefully the above steps should solve the problem.

Tuesday 18 June 2013

Kill all java process in linux

Problem: To kill all the running java process in linux
Solution : killall java

Wednesday 15 May 2013

Gunzip a file on linux

Problem: To zip a file on linux we can use utility like gzip

Solutiongzip -c trace.txt > trace.gz
The above command will compress the file trace.txt

Taking TCP Dump on Linux

Problem: Some times we need to monitor data that is flowing between systems. We can use tcpdump utility to take dump of the data and analyze the data (trace) with tools like wireshark.

Solution
tcpdump -i <interface> -s 65535 -w <some-file> 

Example:  tcpdump -i eth0 -s 65535 -w trace.txt

Tuesday 7 May 2013

Running jetty server as background process in linux

Problem: Some times we need to run jetty server as background process in linux so that when we close the terminal the server will not stop.

Solution: nohup utility can be used to run jetty server (java process) in background. Following command can be used.

#nohup java   -jar start.jar jetty.port=18080  &

In the above command we are running jetty server on port 18080 as back ground process.

Monday 29 April 2013

Finding files with time stamp linux

Problem:  Find files should list time stamp along with file name.

Solution
find -name demo.jar -printf '%Tc %p\n'

The above command will search for "demo.jar" file in current working directory and list results along with time stamp

Monday 22 April 2013

HTML Encoding of data in EXT Template

Problem: HTML Encoding of data in  EXT Template.
Solution:
Ext provided an attribute "htmlEncode" to support encoding.

Example:

var tpl = new Ext.XTemplate('<p>Name: {name:htmlEncode}</p>');

Tuesday 5 February 2013

Changing Command Prompt in Linux

Problem: Changing Command Prompt in Linux.
Solution: By default when you logged into terminal. You will see prompt as "[root@mydesktop build]#" (i.e)
[user@hostname current-workingdir]#. If you want to change these prompt settings change the environment variable PS1

To know default value:
[root@mydesktop build]# echo $PS1
[\u@\h \W]\$
To change value:
[root@mydesktop build]#export PS1='[\u@dragon \W]\$'
[root@dragon build]#

The values are lost when terminal is closed. To persist values for ever update file "/root/.bashrc"
My Bash file:
[root@dragon ~]#cat .bashrc
# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi
export PS1='[\u@dragon \W]\$'


Monday 4 February 2013

set mysql root user password

Problem: Set password for mysql root user
Solution: The default installation of mysql on CentOS doesnt set password for root user. To set password for root user type below command.



 [root@dragon ~]# mysqladmin -u root password root 

The password for the root user we are setting here is root