Friday, April 3, 2015

How to install and configure ODK Aggregate on CentOS / RHEL Using AWS Ec2 Instance


I have an account on Amazon Web Service and created Free Tier RHEL 7 Server. We can login to AWS Ec2 Instance using SSH / Putty. ODK Aggregate installation needs some other softwares like  Java, Tomcat and MySql.

Step 1 - Check the server details like OS and IP-Address using the command as shown below.

Step 2 - Update the server repository using "yum update" command.

Step 3 - We need to install "JAVA" and we can check whether the java is installed or not in this server using this command.

Step 4 - If not installed, we have to install java / openjdk. Before installation check the java package and version on repository.

  java-1.7.0-openjdk - OpenJDK Runtime Environment
  java-1.7.0-openjdk-devel - OpenJDK Development Environment

Step 5 - Set the JAVA_HOME environment variable on CentOS/RHEL Linux. The Java SDK package will be installed in “/usr/lib/jvm” directory by default.

Option 1 : We can set the path temporary, by using the below mentioned command. This option will not work after rebooting the server.

[root@ip-172-31-5-97 ~]# export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.75-2.5.4.2.el7_0.x86_64/

Option 2 : If we need to set the path permanently, open the shell configuration file  "$HOME/.bashrc" and at the bottom of the file, type the following line:

export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.75-2.5.4.2.el7_0.x86_64/

Step 6 - We have successfully installed java/jdk and java environment variable pointed.  Now check the version and path.

Step 7 - Install Tomcat web server on this server. In this case ODK Aggregate recommended "Tomcat 6", we can also install Tomcat 7, but we need to add some setting on tomcat 7 configuration file. 

Apache Tomcat is a opensource web server product of Apache Foundation like Apache HTTP server. It is used to deploy Java Servlet and JSP applications. To deploy any application in Tomcat, we can simply create a war file and deploy them.

First check the tomcat on repository and also check the version and install tomcat on this server.

Check the Tomcat locations. Restart the Tomcat service and check the status. 

Then enable Tomcat service booting time using the command:

        [root@ip-172-31-5-97 ~]# systemctl enable tomcat

Step 8 - Check the Tomcat service is running by using the command :

Step 9 - Now we need to install mysql-server and mysql on this server. Centos7 comes with MariaDB instead of MySQL. MariaDb is an open source equivalent to MySQL and can be installed with "yum -y install mariadb-server mariadb". If you must have mysql, you need to add the "mysql-community repo" and then you can install MySQLl like you normally do.

[root@ip-172-31-5-97 ~]#  wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
[root@ip-172-31-5-97 ~]#  rpm -ivh mysql-community-release-el7-5.noarch.rpm 
  
After installing mysql-community, check the repository directory whether it is added on this server or not.

Now, Mysql-Community is added. Next, we need to update the repository and install mysql.

[root@ip-172-31-5-97 ~]# yum update

After installing, restart the mysql service and check mysql status. Then mysql server enable booting time.

[root@ip-172-31-5-97 ~]# systemctl enable mysqld

On fresh installation of MySQL Server, the MySQL root user password will be blank. For good security practice, we should reset the password for MySQL root user by using the command :
        Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y

Step 10 - Finally we can check whether mysql server is working or not by login mysql server.

Step 11 - Download and Install ODK Aggregate files. Before downloading you can select 64bit or 32bit according to your choice. 
 

I have already downloaded the ODK Aggregate file on my server. Go to the download directory and extract the file, then provide execute permission on ODK script.

Now we can start the installation, it is a long configuration process.

Step 12 - After installing ODK Aggregate, a directory will be created under parent directory "/". Under this directory, we can see ODK Database and ODK war file.

Then we need to create ODK databases on mysql server. At the time of ODK Aggregate installation, DB created on "/ODK\Aggregate/create_db_and_user.sql". 

When I created DB in mysql server, I got an error as shown below.
Error :
mysql> source /ODK\ Aggregate/create_db_and_user.sql
ERROR: Failed to open file '/ODK\ Aggregate/create_db_and_user.sql', error: 2

Solution :
Copy "create_db_and_user.sql" to any home directory. Here I have copied to root home directory. 

Again run the command on mysq server : "source ~/create_db_and_user.sql". This will automatically create ODK user and Database.

Step 13 - We want to install mysql-connector. Download the mysql Connector/J from the mysql download site  (http://dev.mysql.com/downloads/connector/j/)

Unzip the mysql-connector and copy the “mysql-connector-java-5.1.33-bin.jar" file to "/usr/share/tomcat6/lib/" directory.

Note : After installation, we need to open the port on firewall. Here I have enabled in security option of AWS Ec2 Instance. Otherwise we can enable on firewall, which port we need to open.

OR

[root@ip-172-31-5-97 ~]# iptables -I INPUT -p tcp --dport 8o80 -j ACCEPT
[root@ip-172-31-5-97 ~]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT
[root@ip-172-31-5-97 ~]# iptables -I INPUT -p tcp --dport 3306 -j ACCEPT

[root@ip-172-31-5-97 ~]# systemctl iptables res

Step 14 - At the time of installation, it will also created an ODKAggregate.war file. Rename this file to ROOT.war and copy this to /usr/share/tomcat6/webapps/ directory.

We can chek the /usr/share/tomcat6/webapps/ after copying ROOT.war, it will automatically create new directory for "ROOT".

Then check your browser with IP-Address and Port Number (52.74.28.236:8080/ROOT.war), first time you may get blank page. In that case, run again IP-Address:Port number without ROOT.war (52.74.28.236:8080).

Step 15 - Unsupported Webserver Configurations for Tomcat 7. Sometimes we get an error as "Invalid Request".

Tomcat 7, Glassfish and Jetty require additional configuration steps to run ODK Aggregate; we don't support either Tomcat 7 or Glassfish or Jetty. All of these webservers require configuration settings to enable cookies under HTTPS. Otherwise, ODK Aggregate uses no special Tomcat features and it should operate correctly within any compliant Servlet 2.5 web container.

Soltion :
1st - Edit "context.xml" (under Tomcat 7's conf directory /etc/tomcat/) to have the attribute 'useHttpOnly' set to false. I.e.,

[root@ip-172-31-5-97 ~]# vi /etc/tomcat/context.xml

<Context useHttpOnly="false">
    <!-- Default set of monitored resources -->
    <WatchedResource>WEB-INF/web.xml</WatchedResource>

    <!-- Uncomment this to disable session persistence across Tomcat restarts -->
    <!--
    <Manager pathname="" />
    -->
    <!-- Uncomment this to enable Comet connection tacking (provides events
         on session expiration as well as webapp lifecycle) -->
    <!--
    <Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
    -->
</Context>

2nd - Then go to /usr/share/tomcat6/webapps/WEB-INF/

Add "glassfish-web.xml" under ODK Aggregate's WEB-INF directory with the content:

<?xml version="1.0" encoding="UTF-8"?>
<glassfish-web-app>
    <session-config>
        <cookie-properties>
            <property name="cookieHttpOnly" value="false" />
        </cookie-properties>
    </session-config>
</glassfish-web-app>

Add "jetty-web.xml" under ODK Aggregate's WEB-INF directory with the content:

<?xml version="1.0"  encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
    <Get name="sessionHandler">
        <Get name="sessionManager">
            <Set name="secureCookies" type="boolean">true</Set>
        </Get>
    </Get>
</Configure>

[root@ip-172-31-5-97 ~]# systemctl restart tomcat

Step 16 - After changing the settings, go to the browser and check ODK Aggregate is working fine.

Here, ODK Aggregate is working fine, Now we can use it, click on Login and create user account and set the permissions.

Note : At fresh login the password will be "aggregate". We can change it afterwards.

That's it....

28 comments:

  1. Thanks for a very detailed post!

    ReplyDelete
  2. Thanks for this great tutorial...it realy helpfull

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Hi Shyam . Can you help me in installing ODK aggregate on my shared linux server through Cpanel. please ..

    ReplyDelete

  5. I try to install tomcat with "yum install tomcat.noarch", but I see that message
    [root@centos-2gb-results ~]# yum install tomcat.noarch
    Loaded plugins: fastestmirror
    Setting up Install Process
    Loading mirror speeds from cached hostfile
    * base: mirror.cogentco.com
    * extras: mirrors.lga7.us.voxel.net
    * updates: mirrors.centos.webair.com
    No package tomcat.noarch available.
    Error: Nothing to do

    So impossible to have tomcat, on my server.
    Please, I need your help.

    ReplyDelete
    Replies
    1. Hi Fofana,
      Please search the tomcat using above steps, may the version is changed or depending on OS.

      Delete
    2. please use the below to install tomcat6

      yum install yum-priorities
      rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm
      rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.5.2-2.el5.rf.i386.rpm
      cd /etc/yum.repos.d/
      wget http://jpackage.org/jpackage50.repo
      yum install tomcat6 tomcat6-webapps tomcat6-admin-webapps

      Delete
  6. Hello,

    Thank you for the tutorial, can you please help me? I have done everything like you have, no error but I can't login, default password won't work and therefore I can't do the first login with the admin account :(

    Any help will be much appreciated.
    Thank you for your work and contributions.

    ReplyDelete
    Replies
    1. Hi alexis,
      Have you entered the spelling correctly? Otherwise please check the tomcat service is running or not.

      Delete
    2. for the odk admin use aggregate as default password

      Delete
  7. many thanks for all the teams in ODK community...

    ReplyDelete
  8. Thanks for tutorial ver clear enough

    ReplyDelete
  9. Hi

    I have installed tomcat6 successfully and postgres as a database. I have followed your steps for ODK Aggregate and have copies the ROOT.war file into the /usr/share/tomcat6/webapps folder, but when I go to http://my.ip.address:8080/ROOT.war I get an HTTP 404 error.

    Can I please get some help as to why this is happening?

    Otherwise it is a great article, well done!

    Regards,

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
    2. Hi Shyam,

      I am facing the same issue.

      "HTTP Status 404 -"

      Great article. Thanks a lot.

      Delete
    3. You should go to http://my.ip.address:8080/ROOT and not http://my.ip.address:8080/ROOT.war
      I hope this helps

      Delete
  10. Hi Shyam,

    I have installed postgres on different server.

    Pls. guide me how to connect odkApp to my DB.

    ReplyDelete
  11. HI Shyam,
    I'm lost at step 11 - Can't figure out how you get it to your computer.
    Can you provide more info please? what command did you use on the linux box? i tried wget ... didn't work. anyone, please help

    ReplyDelete
  12. successfully installed tomcat7 , mysql etc but cannot run ./ODK Aggregate v1.4.12 linux-x64-installer.run ;;; need help

    ReplyDelete
  13. after all steps how to configure (url and user name and password) in ODK APP.

    ReplyDelete
  14. Hi Shyam,
    I have a quick question. How many instance can you have on the same box? For example, once i follow all your steps for this instance, is it possible to add another study basically using the same box? I assume it would create another table? on the same mysql? I want to run multiple ODK studies, but using only one server and not multiple odk aggregate servers. Is it possible? i.e http:\\serverip\odk\8080:local\study1" ....study2....study3...
    Thank you so much!!
    Mike

    ReplyDelete
  15. Hey Syam Kumar,

    I want to ODK latest version on Ubuntu 16.04 x64 with Postgresql as DB server.
    Could you please help me to do the same.

    Thanks & Regards,
    Nitin

    ReplyDelete
  16. Hai Shyam How can in install this in Linux Share hosting server

    ReplyDelete