How to Deploy an AirSonic Media Streaming Server on CentOS 7
AirSonic is an open-source and free media streaming server application. This tutorial will walk you step by step through setting up an AirSonic server on a CentOS 7 system from the ground up.
Prerequisites
- A freshly created CentOS 7 instance, with at least 2GB of RAM. For example, the IPv4 address could be
203.0.113.1
. - A user account with sudo privileges.
- A domain name like
airsonic.example.com
configured to point to your server’s IP address.
Step 1: Initial System Setup
Create a Swap File
To improve the server’s performance, it’s advisable to create a swap file of 2GB (2048MB) on systems with 2GB of physical memory:
sudo dd if=/dev/zero of=/swapfile count=2048 bs=1M
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
free -m
Note: The appropriate swap size may differ depending on the server’s specifications.
Configure Hostname and FQDN
Configuring your server’s hostname and Fully Qualified Domain Name (FQDN) correctly is essential, especially if you plan to enable HTTPS using a Let’s Encrypt SSL certificate.
Use the commands below to set airsonic
as the hostname and airsonic.example.com
as the FQDN:
sudo hostnamectl set-hostname airsonic
cat <
You can confirm the changes using the following:
hostname
hostname -f
Adjust Firewall Settings to Permit Web Traffic
By default, CentOS 7 restricts access to HTTP and HTTPS ports. Use these commands to allow traffic on ports 80 and 443:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo systemctl reload firewalld.service
Add the Repository
Install the EPEL repository and then upgrade the system packages. Once the update is complete, the server will reboot:
sudo yum install -y epel-release
sudo yum -y update && sudo shutdown -r now
Once the machine restarts, log back in with the same sudo user to proceed with further setup.
Step 2: Install OpenJDK Java Runtime Environment (JRE) 8
Start by installing OpenJDK JRE 8 on your CentOS 7 server, then verify the installation:
sudo yum install -y java-1.8.0-openjdk.x86_64
java -version
You should see output similar to this:
openjdk version "1.8.0_171"
OpenJDK Runtime Environment (build 1.8.0_171-8u171-b11-0ubuntu0.18.04.1-b11)
OpenJDK 64-Bit Server VM (build 25.171-b11, mixed mode)
Now, set the JAVA_HOME
environment variable to ensure proper Java configuration:
echo "JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")" | sudo tee -a /etc/profile
source /etc/profile
Step 3: Install AirSonic
There are several ways to deploy AirSonic, but this tutorial uses the method of installing it via the official WAR package.
Create a User and Directory for AirSonic
Create a dedicated group and user for AirSonic, and set up the appropriate directory:
sudo groupadd airsonic
sudo mkdir /var/airsonic
sudo useradd -s /bin/nologin -g airsonic -d /var/airsonic -M airsonic
Download the AirSonic WAR File
Switch to the AirSonic directory and download the latest WAR package:
cd /var/airsonic
sudo wget https://github.com/airsonic/airsonic/releases/download/v10.1.2/airsonic.war
sudo chown -R airsonic:airsonic /var/airsonic
Set Up and Start the AirSonic Service
Next, download the systemd service configuration files and launch the AirSonic service:
sudo wget https://raw.githubusercontent.com/airsonic/airsonic/master/contrib/airsonic.service -O /etc/systemd/system/airsonic.service
sudo wget https://raw.githubusercontent.com/airsonic/airsonic/master/contrib/airsonic-systemd-env -O /etc/sysconfig/airsonic
sudo systemctl daemon-reload
sudo systemctl start airsonic.service
sudo systemctl enable airsonic.service
Note: It’s recommended to review and adjust both systemd unit files on your server according to your environment and preferences.
Step 4: Verify the AirSonic Installation
At this point, AirSonic should be running and listening on port 8080. To check its status, use the command below:
ps -ef|grep airsonic
To access the AirSonic interface via a browser, temporarily open port 8080 in the firewall:
sudo firewall-cmd --permanent --add-port=8080/tcp
sudo systemctl reload firewalld.service
After updating the firewall, open your browser and go to http://203.0.113.1:8080/airsonic
. Log in using the following default credentials:
- Username: admin
- Password: admin
For security reasons, you should update the administrator password right after logging in.
Once you’ve confirmed AirSonic is working, you should close port 8080 again to improve security:
sudo firewall-cmd --permanent --remove-port=8080/tcp
sudo systemctl reload firewalld.service
Step 5: Enable HTTPS with a Let’s Encrypt SSL Certificate
It’s best practice to use HTTPS on every web server for enhanced security. The easiest way to do that is by installing a free Let’s Encrypt SSL certificate using Certbot.
Install Certbot
First, set up the required tools and install Certbot:
sudo yum -y install yum-utils
sudo yum-config-manager --enable rhui-REGION-rhel-server-extras rhui-REGION-rhel-server-optional
sudo yum install -y certbot
Generate an SSL Certificate
Use Certbot to request a certificate for your AirSonic domain:
sudo certbot certonly --standalone --agree-tos --no-eff-email -m admin@example.com -d airsonic.example.com
The SSL certificate and chain will be stored in:
/etc/letsencrypt/live/airsonic.example.com/fullchain.pem
The private key will be saved here:
/etc/letsencrypt/live/airsonic.example.com/privkey.pem
Automate Certificate Renewal
Let’s Encrypt certificates expire every 90 days. To ensure timely renewal, add a cron job that runs daily at noon:
sudo crontab -e
Press I to insert and add the following line:
0 0,12 * * * python -c 'import random; import time; time.sleep(random.random() * 3600)' && certbot renew
Then save and exit by typing:
:wq
This scheduled job will try to renew your Let’s Encrypt certificate twice a day, helping ensure your AirSonic server remains secure and up-to-date.
Step 6: Use Nginx as a Reverse Proxy for AirSonic
Using Nginx offers two major benefits: it lets users visit the AirSonic site without including the port number in the URL, and it allows you to enforce HTTPS security for encrypted connections.
Install Nginx
Begin by installing Nginx through YUM:
sudo yum install -y nginx
Create a Configuration File for AirSonic
Now create an Nginx configuration specifically for the AirSonic service:
cat <
Activate the Nginx Configuration
Restart the Nginx service to apply the new configuration and enable it to start automatically on system boot:
sudo systemctl restart nginx.service
sudo systemctl enable nginx.service
Now you can open a browser and visit http://airsonic.example.com/airsonic
or https://airsonic.example.com/airsonic
to begin using your secure AirSonic web interface.
Conclusion
By following this step-by-step tutorial, you’ve successfully deployed an AirSonic media streaming server on a CentOS 7 system. You’ve configured system basics, installed necessary Java components, set up AirSonic using the WAR package, secured it with a Let’s Encrypt SSL certificate, and enhanced usability by integrating Nginx as a reverse proxy.
Your server is now ready to stream media securely and efficiently over HTTPS. Be sure to periodically check for updates, maintain SSL certificate renewals, and monitor system performance to ensure a smooth streaming experience.