The package icecast2 can be used to broadcast an audio stream in multiple formats (OGG, mp3, etc.) to lot of people via HTTP.

Purpose

This allows to have an URL that can be used in an HTML5 video player or in VLC or in lot of other audio players.

Installation

In operating systems based on Debian, the icecast2 package can be installed in this way:

su --login
apt update
apt install icecast2 

Or if you prefer with sudo you can install icecast2 in this way:

sudo apt update
sudo apt install icecast2 

As default the server is already running on port 8000.

Configuration

Check this file:

/etc/icecast2/icecast.xml

One of the important parts are the "source-password" that is the password of the "source" user that can be used to send audio stream to a mountpoint.

Test

If you want to do an audio stream test, you can use butt.

Multiple processes

If for some reasons you need an additional icecast2 process, you can create a dedicated systemd service, setting a dedicated Unix user and a dedicated configuration file.

Note that this is NOT needed to just have multiple audio mountpoints since Icecast2 supports infinite mountpoints. This is useful if you want two completely separate processes with two very different configuration files and admin credentials etc.

For example, save this as my-custom-icecast2-user.service in /etc/systemd/system:

[Unit]
Documentation=man:systemd-sysv-generator(8)
Description=Custom Icecast2 streaming media server
Before=multi-user.target
Before=graphical.target
After=remote-fs.target
After=network-online.target
Wants=network-online.target

[Service]
User=my-custom-icecast2-user
Group=my-custom-icecast2-user
Type=exec
ExecStart=/usr/bin/icecast2 -c /etc/icecast2/icecast-custom.xml

[Install]
WantedBy=multi-user.target

Then you can activate it doing:

# create a dedicated user
adduser --system my-custom-icecast2-user

# create a stub configuration file
cp /etc/icecast2/icecast.xml /etc/icecast2/icecast-custom.xml

# create a custom log directory
mkdir /var/log/icecast2-custom

# fix permissions on the log directory
chown my-custom-icecast2-user: /var/log/icecast2-custom

Stuff that you may need to change from /etc/icecast2/icecast-custom.xml. Change the port from 8000 to another one:

<port>8002</port>

Also change the default logdir from /var/log/icecast2 to something else:

<logdir>/var/log/icecast2-custom</logdir>

Then activate your service:

systemctl daemon-reload
systemctl enable my-custom-icecast2-user.service
systemctl start  my-custom-icecast2-user.service

HTTPs

If you have your own domain and you want to add SSL support to Icecast to have https://example.com/ and see Icecast, you may probably want to use the apache2 webserver and the tool certbot to make a simple and scalable frontend webserver listening on port 80 and 443. Installation:

apt install apache2 certbot

Then copy something like this in /etc/apache2/sites-available/example.com.conf:

<virtualhost *:443>

  ServerName example.com

  # this path is unuseful and used only for Let's Encrypt's temporary files during the renewal process
  DocumentRoot /var/www/html

  # send all traffic to Icecast in plaintext
  <Location "/">
    ProxyPass        http://localhost:8000/
    ProxyPassReverse http://localhost:8000/
  </Location>

  # these files are served from /var/www/html to serve Let's Encrypt temporary files
  <Location "/.well-known/acme-challenge">
    ProxyPass !
  </Location>

  <IfFile /etc/letsencrypt/live/example.com/cert.pem>
    SSLEngine on
    SSLCertificateFile      /etc/letsencrypt/live/example.com/cert.pem
    SSLCertificateKeyFile   /etc/letsencrypt/live/example.com/privkey.pem
    SSLCertificateChainFile /etc/letsencrypt/live/example.com/chain.pem
  </IfFile>

</virtualhost>

<VirtualHost *:80>
  ServerName example.com

  Redirect / https://example.com/
</VirtualHost>

Then:

a2ensite example.com.conf

a2enmod ssl
a2enmod proxy_http

apache2ctl configtest

systemctl restart apache2

Then create the SSL certificate with Let's Encrypt and restart again the webserver on success:

letsencrypt certonly --domain example.com --webroot --webroot-path /var/www/html

systemctl restart apache2

Now you should be ready to visit this URL and see Icecast:

https://example.com/


Note: this page is available under Creative Commons zero (public domain) by Valerio Bozzolan and Debian contributors. All contributions are welcome.