How to Install Airsonic Media Server on CentOS 7


Introduction

Airsonic is an open-source web-based media server that allows users to manage, stream, and share their audio and video files. It is a versatile and powerful tool, with support for various media formats, as well as integration with third-party services like Last.fm and Tidal. In this article, we will guide you through process of installing Airsonic on a CentOS 7 system.

Prerequisites

Before starting, ensure that you have −

  • A CentOS 7 system with root or sudo access.

  • A stable internet connection.

  • Basic knowledge of command line.

Step 1: Update Your System

First, update your CentOS 7 system to latest version by running following commands −

sudo yum update
sudo yum upgrade

Step 2: Install Java

Airsonic requires Java to run, so we need to install it first. Install OpenJDK 11 package by running following commands −

sudo yum install java-11-openjdk

To confirm that Java has been installed, run following command −

java -version

Step 3: Create a Dedicated User for Airsonic

For security purposes, it is recommended to create a separate user to run Airsonic service. Use following command to create a new user named 'airsonic' −

sudo useradd -r -m -U -d /opt/airsonic -s /sbin/nologin airsonic

Step 4: Download and Configure Airsonic

Download latest Airsonic standalone WAR file from official GitHub repository −

sudo wget https://github.com/airsonic/airsonic/releases/download/v10.6.2/airsonic.war -P /opt/airsonic

Adjust permissions for downloaded file −

sudo chown airsonic: /opt/airsonic/airsonic.war

Create a new systemd service file for Airsonic −

sudo nano /etc/systemd/system/airsonic.service

Paste following content into file −

[Unit]
Description=Airsonic Media Server
After=remote-fs.target network.target

[Service]
User=airsonic
Group=airsonic
Environment="JAVA_OPTS=-Xmx700m"
ExecStart=/usr/bin/java $JAVA_OPTS -Dairsonic.home=/opt/airsonic -Dserver.context-path=/airsonic -Dserver.port=8080 -jar /opt/airsonic/airsonic.war
SuccessExitStatus=143

[Install]
WantedBy=multi-user.target

Save file and exit text editor.

Step 5: Start and Enable Airsonic Service

Start Airsonic service with following command −

sudo systemctl start airsonic

Enable Airsonic to start at boot −

sudo systemctl enable airsonic

Step 6: Configure Firewall

If you have a firewall enabled on your system, add a rule to allow incoming traffic on default Airsonic port (8080) −

sudo firewall-cmd --permanent --add-port=8080/tcp
sudo firewall-cmd --reload

Step 7: Access Airsonic Web Interface

Open your web browser and navigate to http://your_server_IP:8080/airsonic. You will see Airsonic login page. Use default username 'admin' and password 'admin' to log in. Make sure to change default password immediately after logging in for first time to ensure security.

Step 8: Configure Airsonic

After logging in, you will be presented with Airsonic dashboard. Here, you can customize settings, add media folders, and configure transcoding options.

To add media folders, go to 'Settings' > 'Media Folders' and click 'Add media folder' button. Provide path to your media folder and choose a folder type (Music or Video). Click 'Save' to add folder.

To configure transcoding options, go to 'Settings' > 'Transcoding'. Airsonic comes with preconfigured transcoding settings for various media formats, but you can customize them according to your needs.

Adjust settings for media scanner, network, and security, as needed. Make sure to click 'Save' after making any changes.

Step 9: Enjoy Your Airsonic Media Server

With everything set up, you can now use Airsonic to stream, manage, and share your media files. You can access your Airsonic server from any device with a web browser, including smartphones, tablets, and computers.

Step 10: Configure Reverse Proxy (Optional)

If you want to access Airsonic using a domain name or subdomain, you can set up a reverse proxy using a web server such as Nginx or Apache. In this example, we will use Nginx.

Install Nginx

sudo yum install epel-release
sudo yum install nginx

Start and enable Nginx

sudo systemctl start nginx
sudo systemctl enable nginx

Create a new Nginx server block configuration file

sudo nano /etc/nginx/conf.d/airsonic.conf

Paste following content into file, replacing yourdomain.com with your domain or subdomain −

server {
   listen 80;
   server_name yourdomain.com;

   location / {
      proxy_pass http://localhost:8080/airsonic/;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
   }
}

Save file and exit text editor.

Reload Nginx to apply changes

sudo systemctl reload nginx

Update your DNS settings to point your domain or subdomain to your server's IP address.

Step 11: Secure Your Airsonic Server with SSL (Optional)

To protect your data and enhance security of your Airsonic server, it is highly recommended to use HTTPS. One way to achieve this is by obtaining a free SSL certificate from Let's Encrypt.

Install Certbot and Nginx plugin

sudo yum install certbot python2-certbot-nginx

Run Certbot to obtain and install SSL certificate

sudo certbot --nginx -d yourdomain.com

Follow on-screen instructions to complete SSL certificate setup. Once completed, your Airsonic server will be accessible via HTTPS.

Step 12: Enable Automatic SSL Renewal (Optional)

Let's Encrypt SSL certificates are valid for 90 days. To automate renewal process, create a cron job to run Certbot renewal command regularly.

Open crontab file

sudo crontab -e

Add following line to file −

0 2 * * * /usr/bin/certbot renew --quiet

This will run renewal command every day at 2 AM. If certificate is close to its expiration date, Certbot will automatically renew it.

By following these additional steps, you can further enhance functionality and security of your Airsonic media server. With a reverse proxy, SSL certificate, and automatic certificate renewal, you can enjoy a more secure and user-friendly experience while streaming and sharing your media files.

Step 13: Install and Configure a Database (Optional)

By default, Airsonic uses an embedded H2 database to store its data. However, you can improve performance and reliability of your Airsonic server by using an external database like PostgreSQL or MySQL/MariaDB. In this example, we will install and configure PostgreSQL.

Install PostgreSQL

sudo yum install postgresql-server postgresql-contrib

Initialize PostgreSQL database

sudo postgresql-setup initdb

Start and enable PostgreSQL service

sudo systemctl start postgresql
sudo systemctl enable postgresql

Create a new PostgreSQL user and database for Airsonic

sudo -i -u postgres
createuser airsonic
createdb -O airsonic airsonicdb
exit

Edit PostgreSQL configuration file to allow local connections

sudo nano /var/lib/pgsql/data/pg_hba.conf

Find following lines −

host    all    all      127.0.0.1/32      ident
host    all    all      ::1/128           ident

Replace ident with md5 −

host    all    all      127.0.0.1/32      md5
host    all    all      ::1/128           md5

Save file and exit text editor.

Restart PostgreSQL service

sudo systemctl restart postgresql

Update Airsonic service file to use PostgreSQL database −

sudo nano /etc/systemd/system/airsonic.service

Modify Environment and ExecStart lines as follows

Environment="JAVA_OPTS=-Xmx700m -Dspring.datasource.url=jdbc:postgresql://localhost:5432/airsonicdb -Dspring.datasource.username=airsonic -Dspring.datasource.password=your_password"
ExecStart=/usr/bin/java $JAVA_OPTS -Dairsonic.home=/opt/airsonic -Dserver.context-path=/airsonic -Dserver.port=8080 -Dspring.profiles.active=legacy -jar /opt/airsonic/airsonic.war

Replace your_password with a strong password for Airsonic PostgreSQL user.

Save file and exit text editor.

Restart Airsonic service

sudo systemctl restart airsonic

Step 14: Configure Third-Party Integrations (Optional)

Airsonic supports integration with various third-party services like Last.fm, Tidal, and Google Drive. To configure these integrations, follow steps below −

  • Last.fm − Go to 'Settings' > 'Personal' and enter your Last.fm username and password in 'Last.fm Scrobbling' section. Click 'Save' to enable scrobbling.

  • Tidal − Go to 'Settings' > 'Network' and enter your Tidal API token in 'Tidal Settings' section. Click 'Save' to enable Tidal integration.

  • Google Drive − Go to 'Settings' > 'Media Folders' and click 'Add media folder' button. Choose 'Google Drive' as folder type and follow on-screen instructions to authenticate and authorize access to your Google Drive account.

With these additional steps, you can further enhance capabilities of your Airsonic media server. By using an external database, you can improve performance and reliability, while third-party integrations allow you to connect your server to popular services like Last.fm, Tidal, and Google Drive.

Conclusion

In this article, we have walked you through process of installing and configuring an Airsonic media server on CentOS 7. With Airsonic, you can effortlessly stream your music and videos, share your media library with friends and family, and enjoy your content on any device.

Updated on: 10-May-2023

204 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements