Skip to main content

Posts

Showing posts from 2014

Set Up Nginx Load Balancing

About Load Balancing Loadbalancing is a useful mechanism to distribute incoming traffic around several capable Virtual Private servers. By apportioning the processing mechanism to several machines, redundancy is provided to the application -- ensuring fault tolerance and heightened stability. The Round Robin algorithm for load balancing sends visitors to one of a set of IPs. At its most basic level Round Robin, which is fairly easy to implement, distributes server load without implementing considering more nuanced factors like server response time and the visitors’ geographic region. Setup The steps in this tutorial require the user to have root privileges on your VPS. Prior to setting up nginx loadbalancing, you should have nginx installed on your VPS. You can install it quickly with apt-get: sudo apt-get install nginx Upstream Module In order to set up a round robin load balancer, we will need to use the nginx upstream module. We will incorporate the conf

Tomcat Clustering : Session Replication with Backup Manager

Prerequisite Blogs: How To Install Apache Tomcat Multiple Tomcat Instances on Single Machine Tomcat Clustering: Loadbalancing with mod_jk and Apache Tomcat Clustering : Session Affinity    Backup Manager Backup manager usually used clustered environment. Its like delta manger. But it will  replicate to exactly one other instance(backup instance). Its act  like one instance is Primary  and another instance as backup. Steps to make Session Replication in Tomcat Clustering I am continue from exactly where I left in last session affinity post . So check that post and make sure jumRoute all are set properly. Steps are Enable Multicast routing Add <Cluster> Entries in conf/server.xml file for all instances. Enable the Web Application as distributable Step1:  Enable Multicast routing In Linux Environment most of the system kernel is capable to process the multicast address. We need to add route entry in kernel routing table. sudo route add

Tomcat Clustering : Session Affinity

Session affinity/Sticky Session   Session affinity overrides the load-balancing algorithm by directing all requests in a session to a specific tomcat server. So when we setup the session affinity our problem will solved. But how to setup because session values are random value. We need to generate the session value some how identify the which tomcat generate response. Step 1: Tomcat configuration file (conf/server.xml) contain  <Engine> tag have jvmRoute property for this purpose. So edit the config file and update the <Engine > tag like this <Engine name="Catalina" defaultHost="localhost“ jvmRoute=“tomcat1” > Here tomcat1 is worker name of this tomcat. check the workers.properties file in last post .  Change this line to all tomcat instances  conf/server.xml file and change the jvmRoute value according to workers name and restart the tomcat instances. Now all tomcat generate the session-id pattern like thi

Configuring URL Encoding on Tomcat Application Server

Application servers may have different settings for character encodings. We strongly recommend UTF-8 where possible. By default, Tomcat uses ISO-8859-1 character encoding when decoding URLs received from a browser. This can cause problems when Confluence's encoding is UTF-8, and you are using international characters in the names of attachments or pages. To configure the URL encoding in Tomcat: Step 1 - Configure connector: Edit conf/server.xml and find the line where the Coyote HTTP Connector is defined. It will look something like this, possibly with more parameters: < Connector port = "8080" /> Add a URIEncoding="UTF-8" property to the connector: < Connector port = "8080" protocol = "HTTP/1.1"      connectionTimeout = "20000"      redirectPort = "8443"      URIEncoding = "UTF-8" /> If you are using mod_jk you should appl

Java HotSpot VM Settings

The following JVM parameters are recommended: -Djava.awt.headless=true  -Dfile.encoding=UTF-8  -server  -Xms512m  -Xmx1024m  -XX:NewSize=256m  -XX:MaxNewSize=256m  -XX:PermSize=256m  -XX:MaxPermSize=256m  -XX:+DisableExplicitGC -Djava.awt.headless=true Headless mode is a system configuration in which the display device, keyboard, or mouse is lacking. Sounds unexpected, but actually you can perform different operations in this mode, even with graphic data. -server The JDK includes two flavors of the VM -- a client-side offering, and a VM tuned for server applications. These two solutions share the Java HotSpot runtime environment code base, but use different compilers that are suited to the distinctly unique performance characteristics of clients and servers. These differences include the compilation inlining policy and heap defaults. Although the Server and the Client VMs are similar, the Server VM has been specially tuned to maximize peak opera

JavaMelody: Monitoring the Performance of Tomcat Application Server

Javamelody is an opensource (LGPL) application to monitor Java or Java EE application servers in QA and production environments. JavaMelody is mainly based on statistics of requests and on evolution charts. (Extract from the Javamelody home page) It allows to improve applications in QA and production Give facts about the average response times and number of executions Make decisions when trends are bad, before problems become too serious Optimize based on the more limiting response times Find the root causes of response times Verify the real improvement after optimization It includes summary charts showing the evolution over time of the following indicators: Number of executions, mean execution times and percentage of errors of http requests, sql requests, jsp pages or methods of business façades (if EJB3, Spring or Guice) Java memory Java CPU Number of user sessions Number of jdbc connections These charts can be viewed on the current day, week, month, year or cu

Tomcat Clustering: Loadbalancing with mod_jk and Apache

We already see how to run multiple tomcat instance in a single machine in my previous blog ( http://kmlsarwar.blogspot.com/2014/08/multiple-tomcat-instances-on-single.html ). In this post we will see how to configure load balancing with mod_jk and Apache on Ubuntu. Suppose we have two hosts, node1 and node2 . Node1 runs an Apache and a Tomcat instance. On node2 we’ve got another Tomcat. A browser will connect to the host that’s running the Apache. Since the load on a single server running a web application can be pretty severe, we’re going to share the burden of serving servlets with multiple hosts (in our case two hosts). And we’re going to make mod_jk to do that for us. Steps to Implement Virtual Host/Loadbalancer Concept in this Scenario: Install Apache httpd Web Server  Install mod_jk connector  Configure JK Connector  Configure Apache httpd server, apply loadbalancer concepts Step One—Install Apache We can install Apache web server in two way

Multiple Tomcat Instances on Single Machine

In this post we will see how to run multiple tomcat instances on a single machine and under a single user account. Setup We already see how to run tomcat in Ubuntu machine in my previous blog ( http://kmlsarwar.blogspot.com/2014/08/how-to-install-apache-tomcat-on-ubuntu.html ). Step One—Create folder Create two folder named " tomcat-instance1 " and " tomcat-instance2 " anywhere, and copy conf, logs, temp, webapps and work   folder from CATALINA_HOME folder and change conf/server.xml file in  tomcat-instance1 and tomcat-instance2 . we need to change 3 port shutdown port, connector port and ajp port. Shutdown port - this port is used for shutdown the tomcat. when we call the shutdown.sh script they send signal to shutdown port. this port listen by tomcat java process. if signal is received the that process then its cleanup and exit by itself. Connector Port -This port is actual port to expose the application to outside client.

Configure Tomcat Web Management Interface

We already see, how to install tomcat in ubuntu in my previous blog( http://kmlsarwar.blogspot.com/2014/08/how-to-install-apache-tomcat-on-ubuntu.html ) In order to use the manager webapp installed, we must add a login to our Tomcat server. We will do this by editing the tomcat-users.xml file: sudo nano /etc/tomcat7/tomcat-users.xml    This file is filled with comments which describe how to configure the file. You may want to delete all the comments between the following two lines, or you may leave them if you want to reference the examples: <tomcat-users> </tomcat-users>  You will want to add a user who can access the manager-gui and admin-gui (the management interface that we installed in Step Three). You can do so by defining a user similar to the example below. Be sure to change the password and username if you wish: <tomcat-users> <user username="admin" password="password" roles="manager-gui,admin-gui"

How To Install Apache Tomcat on Ubuntu

Apache tomcat is a Java based application server released by the Apache Software Foundation. It is a web server and a servlet container for Java web applications. Setup Tomcat installation on a virtual private server is relatively easy. Its single required dependency is Java and this tutorial will include a step on how to install that platform. You do need to have a user with sudo privileges for this tutorial. There are two basic ways to install Tomcat on Ubuntu: Install through apt-get. This is the simplest method.  Download the binary distribution from the Apache Tomcat site . Step One—Install Through apt-get   The first thing you will want to do is update your apt-get package lists:   sudo apt-get update The most recent version of Tomcat is 7, and it can be easily downloaded through apt-get sudo apt-get install tomcat7   Install additional packages sudo apt-get install tomcat7-docs tomcat7-admin tomcat7-examples     Step Two—Install Through Bi

How to install Oracle JDK on Ubuntu from repository

This package provides Oracle Java JDK 7 (which includes Java JDK, JRE and the Java browser plugin). However, you can't only install Oracle JRE - the PPA only provides the full Oracle JDK7 package. To install: sudo add-apt-repository ppa:webupd8team/java sudo apt-get update sudo apt-get install oracle-jdk7-installer And to uninstall: sudo apt-get remove oracle-jdk7-installer And to verify your installation: java -version java version "1.7.0_51" Java(TM) SE Runtime Environment (build 1.7.0_51-b13) Java HotSpot(TM) 64-Bit Server VM (build 22.0-b10, mixed mode) And to verify the web browser installation: http://java.com/en/download/installed.jsp Verified Java Version Congratulations! You have the recommended Java installed (1.7.0_51). And to update: If for some reason, the Java version in use is not 1.7.0, you can try to run the following command: sudo update-java-alternatives -s java-7-oracle To Install and Set in environment variable: To

How to set JAVA_HOME environment variable in Ubuntu

Setting the JAVA_HOME variable can be done in several ways. 1. Globally and at System level, i.e. no user is required to be logged in. This is the preferred way if you are configuring a server and planning to use boot strapped program that needs JAVA_HOME variable. 2. Globally and set for all logged in user, i.e. one user is needed to be logged in, to have the JAVA_HOME variable set. 3. User specific. Then the variable is only set when the designated user is logged in. First open a Terminal (Applications → Accessories → Terminal), then enter: sudo gedit /etc/environment Append to the end of the file: JAVA_HOME=/usr/lib/jvm/java-7-oracle Check with this echo command. echo $JAVA_HOME

Integrating code coverage tool JaCoCo in your play 2.1.x project

I've been looking into code coverage for Play 2.1.x and found that the only good option is Jacoco. Its always good to have a fine test coverage in any project. I am working on Play framework & this time i’ve tried to integrate the JaCoCo with my play java project & it’s cool to have it in my project. There are few easy steps to integrate the JaCoCo in Play project. 1. Add the following lines of code in your plugin.sbt file. You’ve to add the plugin dependency to your project’s plugins.sbt. libraryDependencies ++= Seq(   "org.jacoco" % "org.jacoco.core" % "0.5.9.201207300726" artifacts(Artifact("org.jacoco.core", "jar", "jar")),   "org.jacoco" % "org.jacoco.report" % "0.5.9.201207300726" artifacts(Artifact("org.jacoco.report", "jar", "jar"))) addSbtPlugin("de.johoop" % "jacoco4sbt" % "1.2.4") 2. Have

Using the Play console

Launching the console The Play 2.0 console is a development console based on sbt that allows you to manage a Play application’s complete development cycle. To launch the console, enter any existing Play application directory and run the play script: $ cd / path / to / any / application $ play          Getting help Use the help play command to get basic help about the available commands: [ My first application ] $ help play   Running the server in development mode To run the current application in development mode, use the run command: [ My first application ] $ run In this mode, the server will be launched with the auto-reload feature enabled, meaning that for each request Play will check your project and recompile required sources. If needed the application will restart automatically. If there are any compilation errors you will see the result of the compilation directly in your browser: To stop the server, type Crtl+D key, a

Play Framework: Setting up your preferred IDE

Working with Play is easy. You don’t even need a sophisticated IDE, because Play compiles and refreshes the modifications you make to your source files automatically, so you can easily work using a simple text editor. However, using a modern Java or Scala IDE provides cool productivity features like auto-completion, on-the-fly compilation, assisted refactoring and debugging. Eclipse Generate configuration Play provides a command to simplify Eclipse configuration. To transform a Play application into a working Eclipse project, use the eclipse command: without the source jars: [ My first application ] $ eclipse   if you want to grab the available source jars (this will take longer and it’s possible a few sources might be missing): [ My first application ] $ eclipse with - source = true     IntelliJ Generate configuration Play provides a command to simplify Intellij IDEA configuration. To transform a Play application into a working IDEA module, use the

Play Framework: How to create a new play application

Creating a Play application is pretty easy and fully managed by the Play command line utility. This encourages a standard project layout across all Play applications. Open a new command line and enter: $ play new myProject       The play new myProject command creates a new directory  myProject / and populates it with a series of files and directories. The most important are as follows. app/ contains the application’s core, split between models, controllers and views directories. This is the directory where .java source files live. conf/ contains all the application’s configuration files, especially the main application.conf file, the routes definition files and the messages files used for internationalization. project/ contains the build scripts. The build system is based on sbt. But a new play application comes with a default build script that will just work fine for our application. public/ contains all the publicly available resources, which includes Ja

How to install play framework

Prerequisites To run the Play framework, you need JDK 6 or later . If you are using MacOS, Java is built-in. If you are using Linux, make sure to use either the Sun JDK or OpenJDK (and not gcj, which is the default Java command on many Linux distros). If you are using Windows, just download and install the latest JDK package. Note, Java 7 pre update 9 on MacOS has a bug that causes problems with futures and iteratees, including making large file uploads hang. If using Java 7 on MacOS, make sure you are using the latest version. Be sure to have the java and javac commands in the current path (you can check this by typing java -version and javac -version at the shell prompt). Download the binary package Download the latest Play standalone distribution and extract the archive to a location where you have both read and write access. (Running play writes some files to directories within the archive, so don’t install to /opt , /usr/local or anywhere else you’d need s