Monday, May 8, 2017

Linux: MySQL and Tomcat(for J2EE) and Setup

Recently, I configured Tomcat and MySQL on Oracle Linux 7 to fix issues reported in a legacy application developed in JSP & Servlets.

Here are the steps, I followed.

======================================================================

MySQL 5.1.71: 

  • Download following RPM packages for Linux x64 platform
    • MySQL-server-community-5.1.71-1.rhel5.x86_64.rpm
    • MySQL-client-community-5.1.71-1.rhel5.x86_64.rpm
    • MySQL-devel-community-5.1.71-1.rhel5.x86_64.rpm
  • Login as root and check for existing setup of MySQL --> rpm -qa | grep -i mysql
  • If not exists, install MySQL server and client packages as shown below
    • rpm -ivh MySQL-server-community-5.1.71-1.rhel5.x86_64.rpm MySQL-client-community-5.1.71-1.rhel5.x86_64.rpm
  • Install the Header and Libraries , which are part of MySQL-devl package
    • rpm -ivh MySQL-devel-community-5.1.71-1.rhel5.x86_64.rpm

MySQL Configuration:

  • Set password for root user in MySQL DB:
    • /usr/bin/mysqladmin -u root password 'password'
  • Run mysql_secure_installation script (/usr/bin/mysql_secure_installation) that will take care of all the typical security related items. On a high level this does the following items:
    • Change the root password
    • Remove the anonymous user
    • Disallow root login from remote machines
    • Remove the default sample test database        
  • Verify the MySQL setup --> mysql -V
  • Connect to the MySQL database using the root user and make sure the connection is successful.
    • mysql -u root -p
  • Follows the steps below to check status, stop and start MySQL.
    • Check status --> service mysql status
    • Stop DB --> service mysql stop
    • Start DB --> service mysql start
======================================================================

JDK 1.7.0_80:

  • Download archive binary file(jdk-7u80-linux-x64.tar.tz) for Linux x64 platform
  • Go to installation folder --> cd /home/lkakarla/java
  • Uncompress archive file --> tar zxvf jdk-7u80-linux-x64.tar.tz
  • Copy JDK & JRE paths
    • JDK --> /home/lkakarla/java/jdk1.7.0_80/bin
    • JRE  --> /home/lkakarla/java/jdk1.7.0_80/jre/bin
======================================================================

Tomcat 6.0.44:

  • Download archive binary file (apache-tomcat-6.0.44.tar.gz) for Linux x64 platform
  • Go to installation folder --> cd /home/lkakarla/tomcat
  • Uncompress archive file --> tar zxvf apache-tomcat-6.0.44.tar.gz
  • Copy Tomcat home directory path --> /home/lkakarla/tomcat/apache-tomcat-6.0.44

Tomcat Configuration:

  • Open file  /etc/environment as a root user and set CATALINA_HOME variable 
    • CATALINA_HOME=/home/lkakarla/tomcat/apache-tomcat-6.0.44
  • Set JAVA_HOME --> Create a file named setenv.sh in $CATALINA_HOME/bin folder and add below lines.
    • JAVA_HOME=/home/lkakarla/java/jdk1.7.0_80
    • JRE_HOME=/home/lkakarla/java/jdk1.7.0_80/jre
    • CATALINA_PID="$CATALINA_BASE/tomcat.pid"
  • Backup existing tomcat-users.xml file in $CATALINA_HOME/conf folder --> $CATALINA_HOME/conf/tomcat-users.xml. 
  • Edit ‘tomcat-users.xml’ file and following lines at EOF :
    • <user username="tomcat" password="tomcat" roles="tomcat,standard,manager"/>
  • Download and place MySQL JDBC driver(mysql-connector-java-5.1.36-bin.jar) in $CATALINA_HOME/lib folder
  • Configure JDBC -->  $CATALINA_HOME/conf/context.xml. 
    • <Resource name="jdbc/automationDB" auth="Container" type="javax.sql.DataSource"
                         maxActive="100" maxIdle="30" maxWait="10000"
                                        username="root" password="password" driverClassName="com.mysql.jdbc.Driver"
                                                       url="jdbc:mysql://localhost:3306/<databasename>"/>
  • Start Tomcat --> $CATALINA_HOME/bin/startup.sh
  • Tomcat test URL --> http://localhost:8080
  • Tomcat Manager URL --> http://localhost:8080/manager/status  -- tomcat/tomcat

  • Shutdown Tomcat --> $CATALINA_HOME/bin/shutdown.sh
======================================================================

No comments:

Post a Comment

Provide your thoughts !