Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Java Web Environment Setup on Enterprise Linux

Tech 2

Perrequisites

Verify no existing Java installation conflicts:

java -version 2>&1 || echo "Java not detected - proceeding with installation"

Remove MariaDB libraries to prevent MySQL conflicts:

rpm -e --nodeps $(rpm -qa | grep mariadb) 2>/dev/null || true

JDK Configuration

Deploy the JDK to system libraries:

mkdir -p /usr/java
tar -zxf jdk-8u333-linux-x64.tar.gz -C /usr/java/

Persist environment configuration in /etc/profile.d/java.sh:

export JAVA_HOME=/usr/java/jdk1.8.0_333
export PATH=${JAVA_HOME}/bin:${PATH}
export CLASSPATH=.:${JAVA_HOME}/lib

Activate immediately:

source /etc/profile.d/java.sh

Servlet Container Installation

Extract Tomcat to application server directory:

install -d /srv/tomcat
tar -zxf apache-tomcat-9.0.70.tar.gz -C /srv/tomcat/
ln -sf /srv/tomcat/apache-tomcat-9.0.70 /srv/tomcat/current

Configure automatic startup via systemd unit /etc/systemd/system/tomcat.service:

[Unit]
Description=Apache Tomcat Web Application Container
After=network.target

[Service]
Type=forking
Environment="JAVA_HOME=/usr/java/jdk1.8.0_333"
Environment="CATALINA_HOME=/srv/tomcat/current"
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M"
ExecStart=/srv/tomcat/current/bin/startup.sh
ExecStop=/srv/tomcat/current/bin/shutdown.sh
SuccessExitStatus=143

[Install]
WantedBy=multi-user.target

Enable service:

systemctl daemon-reload
systemctl enable --now tomcat

Database Server Configuration

Install prerequisite libraries:

yum install -y libaio numactl

Install MySQL 5.7 packages sequentially:

cd /opt/software/mysql/
rpm -ivh mysql-community-common-5.7.40-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.40-1.el7.x86_64.rpm  
rpm -ivh mysql-community-client-5.7.40-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.40-1.el7.x86_64.rpm

Initialize and secure:

systemctl enable --now mysqld
temp_pass=$(grep 'temporary password' /var/log/mysqld.log | tail -1 | awk '{print $NF}')
mysql -uroot -p"${temp_pass}" --connect-expired-password -e "
  SET GLOBAL validate_password_policy=LOW;
  SET GLOBAL validate_password_length=6;
  ALTER USER 'root'@'localhost' IDENTIFIED BY 'Admin123';
  CREATE USER 'devuser'@'%' IDENTIFIED BY 'DevPass123';
  GRANT ALL PRIVILEGES ON *.* TO 'devuser'@'%';
  FLUSH PRIVILEGES;
"

Network Security Configuration

Configure firewald for application ports:

firewall-cmd --permanent --add-port=8080/tcp --add-port=3306/tcp
firewall-cmd --reload
firewall-cmd --list-ports

Application Publication

Prepare database schema:

mysql -udevuser -pDevPass123 -e "CREATE DATABASE IF NOT EXISTS webapp CHARACTER SET utf8mb4;"
mysql -udevuser -pDevPass123 webapp < /opt/deploy/schema.sql

Deploy web archive:

systemctl stop tomcat
rm -rf /srv/tomcat/current/webapps/ROOT*
cp /opt/deploy/application.war /srv/tomcat/current/webapps/ROOT.war
systemctl start tomcat
Tags: Linux

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.