In this tutorial, we'll learn how to install Apache Traffic Server on AlmaLinux 9 for High-Performance Caching.
Introduction
Apache Traffic Server is an open-source caching proxy server that speeds up web content delivery by storing (caching) frequently accessed data closer to end users. When a user requests a resource—like a web page or a file—Traffic Server checks if it already has a fresh copy in its cache. If it does, it delivers it immediately, avoiding a trip to the origin server. This reduces bandwidth usage, lowers latency, and can dramatically improve page load times.
Using Apache Traffic Server as your caching layer can:
- Reduce server load: Because cached content is served from the proxy instead of hitting your web server every time.
- Improve response times: Serving locally cached data is faster than pulling it from the origin.
- Increase scalability: As your traffic grows, caching helps maintain performance.
In short, if you want to deliver high-speed content to your users, deploying Apache Traffic Server is a powerful solution.
Why Apache Traffic Server Over Other Solutions?
There are many caching and proxy solutions available, like Varnish Cache, Nginx, and Squid. While each has its own advantages, Apache Traffic Server stands out because:
Performance at Scale: Originally used by Yahoo to handle massive traffic, Traffic Server can manage very high levels of concurrency with minimal resource usage.
Flexible Configuration: It provides a robust set of configuration options to tailor caching strategies. Whether you need a straightforward caching setup or a customized approach, Traffic Server can handle it.
Active Development & Community: Backed by the Apache Software Foundation, the project is actively maintained, and the community is responsive to questions and patch requests.
Powerful Plugin System: You can extend functionality easily for logging, compression, or any custom feature your environment requires.
Prerequisites:
Before proceeding, make sure you have the following in place:
- A Fresh AlmaLinux 9 dedicated server or KVM VPS.
- Root or Sudo Privileges: You should have sudo privileges to install packages and make system-wide changes.
Install Apache Traffic Server on AlmaLinux
Step 1: Update Your System
Before installing any new software, update your AlmaLinux 9 packages to their latest versions. Open a terminal and run:
sudo dnf update -y
dnf update -y
refreshes package lists, upgrades existing packages, and automatically confirms the installation of updates.
Reboot if there are kernel or significant library updates:
sudo reboot
Step 2: Check for Apache Traffic Server in Repositories
AlmaLinux 9 is based on RHEL 9, and Apache Traffic Server packages may or may not be included in the default repositories. First, check if it’s available by running:
sudo dnf search trafficserver
If the package trafficserver is found in the search results, proceed with the standard install. If not, you may need to enable additional repositories such as EPEL (Extra Packages for Enterprise Linux) or obtain the official Apache Traffic Server YUM repository.
To enable EPEL, you can run:
sudo dnf install epel-release -y
Then re-check availability:
sudo dnf search trafficserver
You should now see the trafficserver package in the list.
Step 3: Install Apache Traffic Server
Once you’ve confirmed the package is available, install Apache Traffic Server:
sudo dnf install trafficserver -y
During installation, dependencies will be automatically resolved. After the process finishes, you can check if the Traffic Server service is installed and enabled:
systemctl status trafficserver
You should see something like active (running). If it’s not running, start it:
sudo systemctl start trafficserver
sudo systemctl enable trafficserver
Step 3: Understand the Configuration Files
Apache Traffic Server places its configuration files in /etc/trafficserver by default on Ubuntu. These files define how your caching proxy behaves. Three of the most important files are:
1. records.config
This file contains most of the global configuration parameters like network ports, cache settings, and performance tuning. For example, you can define the HTTP port, log levels, and memory limits here.
2. remap.config
This file is crucial if you use Traffic Server as a reverse proxy or to map incoming requests to different servers. If you want a domain to point to a specific backend server or if you’re rewriting URLs, remap.config is the place to do it.
3. storage.config
Defines where Traffic Server stores cached data. You specify disk paths and partition sizes here. It’s a good idea to read through these files (or at least skim them) to get a feel for where different configurations live.
Step 4: Basic Configuration Adjustments
4.1. Listening Port Configuration (records.config
)
By default, Traffic Server might listen on port 8080 for HTTP traffic. If you want it to listen on the standard HTTP port 80, open /etc/trafficserver/records.config in your favorite text editor:
sudo nano /etc/trafficserver/records.config
Look for a line like:
CONFIG proxy.config.http.server_ports STRING 8080
Change it to:
CONFIG proxy.config.http.server_ports STRING 80
Save and exit the file.
4.2. Storage Configuration (storage.config
)
If you want to specify a dedicated disk or partition for caching, you’ll edit /etc/trafficserver/storage.config. The file might look like this by default:
/var/cache/trafficserver 256M
The first path is the directory where your cache will reside. The second value is the maximum size allocated for the cache (in this example, 256 MB
).
To allocate more space or use a different disk/partition, adjust accordingly:
/var/cache/trafficserver 5G
That would allocate 5 GB
of storage in /var/cache/trafficserver
.
4.3. Remap Configuration (remap.config
)
If you want to run Traffic Server as a reverse proxy for a domain—let’s say example.com—and your origin server runs on another internal IP, you’d open /etc/trafficserver/remap.config
and add a line like:
map http://example.com/ http://192.168.1.10/
This tells Traffic Server: “When a request for http://example.com/
comes in, fetch content from http://192.168.1.10/
, and cache it.”
If you have multiple domains or subdomains, you can add more map directives in the same format.
Step 5: Enable and Start Apache Traffic Server
Even though the service likely started upon installation, you might want to ensure it’s set to start on boot:
sudo systemctl enable trafficserver
sudo systemctl start trafficserver
To double-check its status:
systemctl status trafficserver
You’ll see a confirmation that it’s active and running.
Step 6: Testing the Cache
To verify that Apache Traffic Server is working properly, you can do a simple test:
Curl Test:
From your server, run:
curl -I http://localhost/
If Traffic Server is running on port 80, you should see a response header indicating Traffic Server is in use (e.g., Via: http/1.1 traffic_server or something similar
).
Browse Test:
- In a web browser, navigate to your server’s IP or domain (if you have one mapped).
- You should get the website content from your origin server through Traffic Server.
- If you check the response headers, you may see something like X-Cache: HIT once the content is cached.
Check Log Files:
- Logs are typically located in
/var/log/trafficserver
. - Look at
access.log
to see if Traffic Server is handling your requests.
Step 7: Fine-Tuning and Optimization
Cache Rules: By default, Traffic Server follows standard HTTP caching headers. If you want more control, you can enforce custom caching policies via remap.config or by editing caching directives in records.config.
Memory Configuration: Adjust CONFIG proxy.config.cache.ram_cache.size in records.config to control how much RAM is allocated for caching frequently accessed content. More RAM usually means faster response times since memory is faster than disk.
SSL/TLS Handling: If you want Traffic Server to handle HTTPS connections, you’ll need to configure SSL certificates in ssl_multicert.config. This setup is a bit more involved, but it allows Traffic Server to decrypt and cache secure content, then re-encrypt when sending data to clients.
Plugin Extensions: Traffic Server supports plugins that can perform tasks like content filtering, compression, or custom logging. Investigate the plugin.config file to see which plugins are available and how to enable them.
Performance Monitoring: Tools like traffic_ctl, traffic_top, or even standard Linux utilities (like htop and iostat) can help you monitor how Traffic Server is performing and diagnose bottlenecks.
Step 8: Maintaining Apache Traffic Server
Regular Updates:
Keep the software updated by running sudo dnf update
periodically. Check the official Apache Traffic Server documentation for major version releases and upgrade instructions.
Log Rotation:
Ensure that large log files in /var/log/trafficserver
get rotated so they don’t fill up your disk. Ubuntu often configures logrotate by default, but verify or customize /etc/logrotate.d/trafficserver
.
Monitoring Health:
Set up a monitoring system (Nagios, Zabbix, Prometheus, etc.) to keep track of memory usage, CPU load, and network traffic. This will help you spot issues before they become critical.
Backup Configuration:
Regularly back up the files in /etc/trafficserver (especially records.config, remap.config, and storage.config). In case of an accidental misconfiguration, you can quickly revert to a working setup.
Wrap-Up
By installing and properly configuring Apache Traffic Server on AlmaLinux 9, you’ve set up a high-performance caching proxy that can handle large volumes of traffic with minimal resource consumption. This setup will reduce load times, cut down bandwidth usage, and enhance overall user experience.
Remember to:
- Keep an eye on logs for any errors or warnings.
- Regularly update and optimize Traffic Server.
- Experiment with different caching strategies for optimal performance.
With your new caching proxy in place, your users will enjoy faster page loads, and your origin servers will handle more connections with ease. That’s a win-win for both your infrastructure and your visitors. Happy caching!