Monday, 23 June 2014

Find inside a file or directory

Problem: Find a word inside a file or directory

Solution: grep command can be used to find a word inside a file.


[root@iravath search]# grep -rnw '.' -e "Apple"
./names.txt:3:Apple
 
The above command search for word "Apple" inside a file. The word "Apple" was found in names.txt at line number 3.

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)