← Engineering

Infrastructure report / Network traffic analysis

Building a single-node data stack for intrusion analysis

How I assembled an HDFS, Hive, PostgreSQL, and Spark environment on one Ubuntu server to study a large network traffic dataset, and what the setup taught me about reproducibility.

Research infrastructureHadoop · Hive · SparkProject report
01 / Scope

Make a historical traffic dataset workable on one server.

This project used the UNSW-NB15 dataset for batch analysis of labeled network traffic, as part of a Master’s big data analytics module. The raw CSV was 580.8 MiB with 2,539,739 rows. The module brief estimated about ten million, so I counted the rows in Hive and against the file’s line count, then used the measured figure throughout.

Rows loaded and cleaned
2,539,739
Raw CSV
580.8 MiB
Clean Parquet table
250.6 MiB
8 vCPU · 24 GB RAM
1 server

The practical task was to land that data, give it a queryable schema, clean it into a better storage format, and run repeatable analysis jobs within the limits of a single VPS. The finished stack had four services on one machine. The diagram shows how they talked to each other and which Java runtime each one used.

Runtime map
One Ubuntu 24.04 server · 8 vCPU · 24 GB RAM
Java 11Spark 3.5.3 · local[*]PySpark in a Python 3.12 virtual environment. Runs the analysis jobs across the machine’s cores.
Java 8Hive 3.1.3 metastoreThrift service on port 9083. Metastore only, with no HiveServer2.
PostgreSQL 16Metastore database with 74 tables. The only service managed by systemd.
Java 11HDFS 3.3.6 · single nodeNameNode, DataNode, and SecondaryNameNode with a replication factor of 1. Holds the raw CSV and the Parquet table. No YARN.

Hive was the odd one out: it needed Java 8 while everything else ran on Java 11. The Hive command line and Spark both talked to the metastore directly.

I kept the configuration, operating scripts, analysis code, and a rebuild guide together so the temporary environment could be inspected and recreated. The work centered on a batch data pipeline, rather than live network monitoring.

02 / Data flow

From raw traffic rows to a shared analysis table.

I used a single HDFS DataNode for storage. A Hive external table pointed to the raw CSV in HDFS, so the first queryable layer did not require another copy of the file. A managed Hive table then held cleaned rows as Parquet. Spark jobs read that table through Hive support and ran locally across the machine’s available cores.

Data flow
01 / InputUNSW-NB15 CSVLabeled flows with no header row580.8 MiB · 2,539,739 rows
02 / RawHDFS + external tableunsw_nb15_raw, 49 loosely typed columnsNo second copy
03 / PreparedParquet tableunsw_nb15_clean, cleaned once250.6 MiB · 3 files
04 / AnalysisSpark jobsRead through the Hive metastorelocal[*] · 8 vCPU

PostgreSQL backed the Hive metastore: it stored table metadata, while HDFS held the traffic data. The clean table normalized attack categories and several fields with inconsistent raw representations. That preparation made the later scripts read one stable table instead of repeating cleanup in every job.

What the cleaning step changed
ColumnsNo header row, so no names in the file49 named columns from the feature spec
attack_cat14 distinct values: blanks, trailing spaces, Backdoor and Backdoors10 classes, blanks mapped to Normal
sport, dsportSome ports stored as hex strings, such as 0x000bDecimal integers
ct_ftp_cmdBlank on non-FTP rows, typed as a stringZero, typed as an integer
Row count2,539,7392,539,739, none dropped

Every fix lives in a single CREATE TABLE AS SELECT, and I checked the clean table’s row count against the raw one.

03 / Engineering decisions

Compatibility mattered as much as capacity.

01

Two Java runtimes

Hadoop and Spark used Java 11, while the chosen Hive release needed Java 8. Environment files pinned each process to the right runtime, and a fallback setting stopped Hadoop from overriding Hive’s choice.

02

Local execution

The stack used HDFS for storage and Spark in local mode, without a YARN cluster. A Hive table build initially ran out of JVM heap through the local job runner; the recorded fix raised that process’s heap limit to 4 GB.

03

Repeatable operations

Start, stop, and health-check scripts captured the manual service order. I also kept the configuration files and a fresh-server rebuild sequence, making the temporary environment easier to inspect and reproduce.

Setting the Java version in Hive’s own environment file was not enough. Hive starts its JVM through Hadoop’s launcher script, and that script has its own opinion about Java.

Why the fallback form mattered
Unconditional exportWhat the stock Hadoop environment file did.
hive-env.shJAVA_HOME → Java 8
Hive launches through bin/hadoopThat script sources hadoop-env.sh.
hadoop-env.shexport JAVA_HOME=…java-11
FailsHive runs on Java 11 and stops with a ClassCastException.
Fallback formWhat the setup used.
hive-env.shJAVA_HOME → Java 8
Hive launches through bin/hadoopThat script sources hadoop-env.sh.
hadoop-env.shexport JAVA_HOME=${JAVA_HOME:-…java-11}
WorksJava 8 survives and the metastore listens on port 9083.

Only PostgreSQL ran as a managed service. HDFS and the Hive metastore were started by hand, so the order, and the check between each step, went into a script.

Start order
01 / DatabasePostgreSQLMetastore database, managed by systemdService is active
02 / StorageHDFSstart-dfs.sh, which connects over SSH to localhost3 daemons · 1 live DataNode
03 / MetadataHive metastoreStarted with nohup under Java 8Listening on :9083
04 / VerifyHealth checkSpark to Hive to PostgreSQL, end to endCount is 2,539,739

The version choices were tested against concrete failures, including a Hive/Hadoop library conflict. Recording those incompatibilities beside the working configuration turned a one-off setup into a usable reference. Six of the sixteen I recorded are below.

Failure ledger
ClassCastException on Hive startupHive 3.1.3 depends on the Java 8 class loader model.Install JDK 8 beside JDK 11 and point Hive at it.
NoSuchMethodError when the metastore startsHive bundles Guava 19, which clashes with Hadoop 3.3.Add Guava 27.0-jre and delete the bundled 19.0 jar.
OutOfMemoryError during the table buildWith no YARN, Hive ran jobs in-process on a small default heap.Raise the Hadoop heap limit to 4 GB in hadoop-env.sh.
A 200-byte tarball that tar rejectsOld releases return an HTML 404 page, so wget still “succeeds”.Download from archive.apache.org and check with file.
One attack category missing from a chartpandas reads the string “None” as a missing value.Read the output with keep_default_na turned off.
Scrambled strings from chained CASE WHENA vectorised execution bug reuses byte buffers in Hive 3.1.3.Disable vectorisation for that query and cross-check counts.
04 / Analysis

One prepared table, several questions.

Hive queries and PySpark jobs shared the same cleaned table. Four Hive queries each exercised a family of built-in functions. The Spark scripts split into statistical methods and two classifiers.

Analysis map
Inputunsw_nb15_cleanThe shared Parquet table in Hive
Hive queries
Function-family queriesDate, math, conditional, and string functions over traffic volume, protocols, and connection state
Spark statistics
Descriptive statisticsNormal against attack, with effect sizes
Pearson correlationTen numeric features
Chi-square testsLabel against state group, protocol, service
Sample and density plotsA smaller set for visual inspection
Spark classifiers
Binary random forestNormal against attack, 50 trees, depth 8
Ten-class random forestNormal plus nine attacks, 80 trees, depth 10

The statistical scripts calculate descriptive statistics by traffic label, Pearson correlations between numeric features, and chi-square tests for selected categorical fields. One Hive query found attacks only in hours 0 to 13 of the captures. I treated that as an artefact of how the attack traffic was injected, not as a finding about when attacks happen.

The data is heavily skewed, and that shaped the classifier design. Normal traffic is 87.35% of the rows, while the rarest attack, Worms, has 174.

Class distribution
Normal2,218,45687.35%
Generic215,4818.48%
Exploits44,5251.75%
Fuzzers24,2460.95%
DoS16,3530.64%
Reconnaissance13,9870.55%
Analysis2,6770.11%
Backdoors2,3290.09%
Shellcode1,5110.06%
Worms1740.007%

Bar length is logarithmic. On a linear axis every attack class except Generic would be a sliver.

Both classifiers are Spark MLlib random forests. They use ten numeric features plus three derived categorical ones. The splits are stratified 80/20 with a fixed seed, built with sampleBy and an anti-join so rare classes appear in both sides in proportion. Class weights come from the training split only. One model separates normal from attack traffic, and a binary model trained without the source TTL feature (sttl) checks for a shortcut. The other works across ten traffic categories. A revised ten-class run changes the weighting scheme and keeps the split and main settings comparable.

Reported results
Binary: does removing sttl matter?With sttlWithout sttl
Accuracy98.77%98.62%
ROC AUC0.99930.9990
Ten-class: does the weighting matter?Raw weightsSquare-root weights
Accuracy96.25%97.06%
Macro-F10.4430.536
DoS recall6.4%75.8%

Bars run from 0 to 1. Accuracy barely moves in either comparison, which is the point.

Binary detection was strong, and removing sttl, the feature with the largest effect size between normal and attack traffic (Cohen’s d of about 5), cost only 0.15 points of accuracy. The model’s importance shifted onto other features such as destination load, so it had not learned a single-feature shortcut. In the ten-class run, accuracy of 96 to 97% hid weak results on rare classes. Square-root weights raised macro-F1 and DoS recall, at some cost to Reconnaissance, and a few rare classes stayed weak.

How far to trust these numbers: I chose the revised weighting after seeing the first run’s test results, so its gain is diagnostic, not an unbiased estimate. A stronger claim needs a separate untouched test set or nested validation. Worms has only 41 test examples, so its scores are noisy. Everything here is measured on a split of one synthetic dataset, and strong binary scores do not establish detection performance on a real network.

05 / Lessons

Document the conditions that make a result repeatable.

The hard parts were at the boundaries: Java versions, library compatibility, process environments, and memory limits. A dataset can be small enough for one machine and still expose those failure modes. The runbook, copied configuration, and health checks record the conditions needed to get from a fresh host to a queryable table again.

The original environment was a throwaway coursework machine on a public address, and its network posture showed it. The rebuild guide changes the order of work so the firewall comes before anything starts listening.

Network exposure
As runThe coursework server.
Public internetOne static public address.
No firewallufw was installed but inactive.
Services bound to 0.0.0.0HDFS web and transfer ports, plus the unauthenticated Hive metastore on 9083.
ExposedAdmin ports were reachable from the internet.
Rebuild guideThe documented path for the next server.
Public internetSame public address.
Firewall firstDeny incoming and allow SSH before anything is installed.
Hardened access, supervised servicesNon-root user with key-only SSH, plus systemd units for HDFS and the metastore.
ContainedOnly SSH is reachable by default.

Services were also started manually, so nothing would have survived a reboot. The rebuild guide adds service supervision and moves process files out of a temporary directory. That distinction matters when turning a research setup into a system someone else must operate.

Continue readingAll engineering writing