Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Establishing a Java Runtime Environment on Linux: Offline Deployment of Tomcat and Database Services

Tech May 9 3

JDK Runtime Installation and Path Configuration

Verify the current system state to avoid duplicate installations. Check for pre-existing JVM binaries:

java -version
javac -version

If no suitable OpenJDK or Oracle JDK is present, transfer the distribution archive to the server workspace. Extract the archive into a dedicated runtime location rather than scattering files across the system root.

TARGET_RUNTIME="/usr/lib/jvm/custom-jre"
ARCHIVE_PATH="/var/tmp/jdk-distribution.tar.gz"

sudo mkdir -p "$TARGET_RUNTIME"
sudo tar -xzf "$ARCHIVE_PATH" -C "$TARGET_RUNTIME" --strip-components=1

Define environment bindings at the system level to ensure all sessions inherit the runtime paths. Append the following definitions to /etc/profile.d/custom-java.sh:

export JRE_BASE="$TARGET_RUNTIME"
export JRE_BIN="${JRE_BASE}/bin"
export JRE_LIB="${JRE_BASE}/lib"
export CLASSPATH=".:${JRE_LIB}"
export SYSTEM_PATH="${JRE_BIN}:/usr/sbin:/usr/bin:$PATH"
export PATH="$SYSTEM_PATH"
unset JRE_BASE JRE_BIN JRE_LIB CLASSPATH SYSTEM_PATH

Apply the changes immediately without requiring a session reboot:

source /etc/profile
java -version

Apache Tomcat Server Initialization and Bootstrapping

Extract the servlet container archive to a controlled application directory. Adjust version identifiers as needed for your specific build.

WEBAPP_ROOT="/srv/tomcat-installs/v8_5"
TARBALL_SRC="/var/tmp/apache-tomcat-release.tar.gz"

sudo tar -xzf "$TARBALL_SRC" -C "/srv/" --strip-components=1
mv "/srv/apache-tomcat-*" "$WEBAPP_ROOT"

Launch the daemon using the built-in controller located in the binary partition:

cd "$WEBAPP_ROOT/bin"
./start-catalina.sh

Expose the default HTTP interface through the host firewall. Ensure traffic is permitted on the standard connector port before routing external requests.

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

To guarantee automatic service resurrection after kernel panics or scheduled reboots, configure a legacy init wrapper. Relocate the native launcher and inject system directives:

cp "$WEBAPP_ROOT/bin/catalina.sh" /etc/init.d/web-container
chmod +x /etc/init.d/web-container

cat <<EOF >> /etc/init.d/web-container
JAVA_INSTALLATION="$TARGET_RUNTIME"
TOMCAT_INSTANCE="$WEBAPP_ROOT"
EOF

# Register service metadata
sed -i '1 i #\chkconfig: 2345 70 30\n#\description: Servlet Container Service' /etc/init.d/web-container
chkconfig --add web-container

Validate persistence by executing a cold reboot sequence. The init hierarchy will invoke the registered hook upon reaching multi-user targets.

MariaDB Purge and Oracle MySQL Deployment

Cleanse legacy database remnants that conflict with modern distributions. Identify and strip conflicting libraries:

rpm -qa | grep mariadb-libs
rpm -e --nodeps $(rpm -qa | grep mariadb-libs)

Prepare an isolated storage zone for the relational engine packages. Decompress the bundled repository and execute dependency resolution sequentially:

MYSQL_DEPLOY="/srv/database/mysql-57-bundle"
BUNDLE_SRC="/var/tmp/mysql-official-rpms.tar"

sudo mkdir -p "$MYSQL_DEPLOY"
tar -xf "$BUNDLE_SRC" -C "$MYSQL_DEPLOY"

cd "$MYSQL_DEPLOY"
rpmlist=("mysql-community-common" "mysql-community-libs" "mysql-community-client" "mysql-community-server")
for pkg in "${rpmlist[@]}"; do
  sudo rpm -ivh ${pkg}-5.7.35-1.el7.x86_64.rpm
done

Transition to runtime management via the unified service controller:

systemctl daemon-reload
systemctl start mysqld.service
systemctl enable mysqld.service

Retrieve the ephemeral authentication credential generated during initialization. Strip restrictive password complexity policies and establish permanent credentials:

TEMP_AUTH=$(grep 'temporary password' /var/log/mysqld.log | tail -n1 | awk '{print $NF}')
mysql -u root -p"$TEMP_AUTH" <<SQL_END
SET GLOBAL validate_password.policy = LOW;
SET GLOBAL validate_password.length = 4;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'SecurePass1';
FLUSH PRIVILEGES;
EXIT;
SQL_END

Permit network connections from external clients by modifying socket bindings and adjusting host restrictions. Open the relational protocol port within the perimeter defense layer:

mysql -u root -p'SecurePass1' <<SQL_SEC
CREATE DATABASE app_workflow_db;
GRANT ALL ON app_workflow_db.* TO 'deployer'@'%' IDENTIFIED BY 'AppFlow456';
FLUSH PRIVILEGES;
EXIT;
SQL_SEC

firewall-cmd --permanent --add-service=mysql
firewall-cmd --reload

Enterprise Application Packaging and Runtime Binding

Provision the target schema inside the database cluster. Import legacy DDL/DML dumps to initialize table structures and seed reference data.

Halt the servlet processor to release locked archive locks and prevent corruption during file swaps:

cd "$WEBAPP_ROOT/bin"
./shutdown-catalina.sh

Navigate to the document root partition designated for hot-swappable archives. Resolve the absolute path context:

cd "$WEBAPP_ROOT/webapps"
realpath .

Transfer the compiled .war artifact into this directory via secure file transfer protocols.

Reactivate the processing engine to trigger automatic unpacking and classloading:

./startup-catalina.sh

Route client traffic through the designated virtual host endpoint. Append the context path identifier followed by administrative credentials to complete the handshake:

http://<host_ip>:8080/<context-path>/login

Monitor background execution streams via journalctl or log partitions to verify successful module injection and health checks.

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.