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.
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.
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.
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.
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.
ColumnsNo header row, so no names in the file49 named columns from the feature specattack_cat14 distinct values: blanks, trailing spaces, Backdoor and Backdoors10 classes, blanks mapped to Normalsport, dsportSome ports stored as hex strings, such as 0x000bDecimal integersct_ftp_cmdBlank on non-FTP rows, typed as a stringZero, typed as an integerRow count2,539,7392,539,739, none droppedEvery fix lives in a single CREATE TABLE AS SELECT, and I checked the clean table’s row count against the raw one.
Compatibility mattered as much as capacity.
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.
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.
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.
JAVA_HOME → Java 8export JAVA_HOME=…java-11JAVA_HOME → Java 8export JAVA_HOME=${JAVA_HOME:-…java-11}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.
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.
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.
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.
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.
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.
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.
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.