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
======================================================================

Sunday, May 7, 2017

Virtual Box: Mount Host Shared Folders in Guest

I installed Oracle VM Virtual Box v 5.1.14 on Windows 7 Professional (64 bit) PC and installed Oracle Linux (OEL) 7.2 as a guest OS.

However, I was not able to share folders between host & guest. I received following error in Guest OS, when I clicked on shared folder mount.

Error: "The folder contents could not be displayed. You do not have the permissions necessary to view the contents of sf_temp."

I followed below steps to resolve the issue and mount shared folder in Guest OS.
  • Download and Install Oracle VM Virtual Box Extension Pack
  • Restart Virtual Machine
  • Install Guest Additions. Go to Devices > Insert Guest Additions CD image...
  • Restart Virtual Machine
  • Add the shared folder to the virtual machine using Virtual Box graphical interface. Make sure to select 'Auto-mount' and 'Make Permanent'
  • Restart Virtual Machine
Try to access /media/sf_your_shared_folder_name. If you still don't have access, that means you don't belong to the vboxsf group.
  • Login to the virtual machine using a root account
  • Check vboxsf group exists
          ~$ grep vboxsf /etc/group
          vboxsf:x:983:
  • Check user is not already in vboxsf group
          ~$ id lkakarla
          uid=1000(lkakarla) gid=1000(lkakarla) groups=1000(lkakarla)
  • Add user lkakarla to vboxsf group
          ~$ sudo usermod -a -G vboxsf lkakarla
  • Check again user groups
          ~$ id lkakarla
          uid=1000(lkakarla) gid=1000(lkakarla) groups=1000(lkakarla),983(vboxsf)
  • Restart Virtual Machine and login as lkakarla
  • Shared folder is now accessible in desktop and /media/sf_temp (temp is the name I gave to the share)

Click Here for more info.