Topic: Icecast Streaming Jukebox
This RTFM will show you how to setup a streaming MP3 server - so you can connect to it with the likes of xmms / mplayer and listen to your favorite music no matter where you are. Though this guide is primarily based upon a NetBSD setup, only the pkgsrc usage and default config file locations should be the differences.
In this example I will be setting up a streaming server for my fav. rock group ThirdDay
Basic Intro - yes, you should read this!
Before I begin, it's important that you understand the principle of the setup that we are about to create.
The streaming server relies on two parts working together. The first is the server itself (icecast2 in our case), which listens to connections from xmms/mplayer and streams the music to them. The second is the client, which "plays" the music for the server to stream. There are many different "clients" - some of which require live feeds from the soundcard to work. In this senario I will be using "ices", mp3 version which reads a list of mp3 files (it's playlist) and plays them one after another endlessly.
Installing the needed software
As a fan of pkgsrc, here's the quick and easy way to install the bits of software we need:
# cd /usr/pkgsrc/audio/icecast # make install clean clean-depends # cd /usr/pkgsrc/audio/ices-mp3 # make install clean clean-depends
Setting up the server - Icecast
Let me first state that the Icecast server will be chrooted as it's a supported feature. The chroot is /var/chroot/icecast
The config is incredibly straight forward and resides in /usr/pkg/etc/icecast/icecast.xml and very few changes are necessary. To save you any pain, here's the "clean" version of my setup (If you do copy my file, please make an effort to change the usernames and passwords for security!):
<icecast> <limits> <clients>100</clients> <sources>2</sources> <threadpool>5</threadpool> <queue-size>524288</queue-size> <client-timeout>30</client-timeout> <header-timeout>15</header-timeout> <source-timeout>10</source-timeout> <burst-on-connect>1</burst-on-connect> <burst-size>65535</burst-size> </limits> <authentication> <source-password>letmein</source-password> <relay-password>letmein</relay-password> <admin-user>admin</admin-user> <admin-password>hackme</admin-password> </authentication> <hostname>localhost</hostname> <listen-socket> <port>8000</port> </listen-socket> <fileserve>1</fileserve> <paths> <basedir>/var/chroot/icecast</basedir> <logdir>log//</logdir> <webroot>/web</webroot> <adminroot>/admin</adminroot> <pidfile>/var/chroot/icecast/icecast.pid</pidfile> <alias source="/" dest="/status.xsl"/> </paths> <logging> <accesslog>access.log</accesslog> <errorlog>error.log</errorlog> <loglevel>2</loglevel> </logging> <security> <chroot>1</chroot> <changeowner> <user>icecast</user> <group>icecast</group> </changeowner> </security> </icecast>
You'll notice the "changeowner" section, the user and group are automagically created on NetBSD and pkgsrc. If you're on another OS you will need to create these manually.
Next, based upon my config above, you need to copy the admin section and web page section to the chrooted area. This is done as follows:
# cp -R /usr/pkg/share/icecast/web /var/chroot/icecast # cp -R /usr/pkg/share/icecast/admin /var/chroot/icecast
Next, we ensure that the permissions are all correct
chown -R icecast:icecast /var/chroot/icecast
Start the server
With NetBSD you can do the following:
# cp /usr/pkg/share/examples/rc.d/icecast /usr/pkg/etc/rc.d/icecast # echo 'icecast=YES' >> /etc/rc.conf # /usr/pkg/etc/rc.d/icecast start
The server is now up and ready for connections - but there's currently no music to stream...
Setting up the client - ices-mp3
Ices also has a config file /usr/pkg/etc/icecast/ices.conf Here's the setup I used:
<?xml version="1.0"?> <ices:Configuration xmlns:ices="http://www.icecast.org/projects/ices"> <Playlist> <File>/var/chroot/icecast/ices/thirddaylist.txt</File> <Randomize>0</Randomize> <Type>builtin</Type> <Module>ices</Module> </Playlist> <Execution> <Background>1</Background> <Verbose>0</Verbose> <BaseDirectory>/var/chroot/icecast/ices</BaseDirectory> </Execution> <Stream> <Server> <Hostname>localhost</Hostname> <Port>8000</Port> <Password>letmein</Password> <Protocol>http</Protocol> </Server> <Mountpoint>/thirdday</Mountpoint> <Name>ThirdDay</Name> <Genre>Contemporary Christian Rock</Genre> <Description>ThirdDay all day</Description> <URL>http://www.thirdday.com/</URL> <Public>0</Public> <Bitrate>128</Bitrate> <Reencode>0</Reencode> <Channels>2</Channels> </Stream> </ices:Configuration>
Important things to note are:
"Name" - the name of the stream, and what appears on xmms, etc.
"Mountpoint" - the URL location (I'll explain this in a moment)
"Public" - set this to "1" and the Internet streaming servers get informed about your stream by icecast - so leave it at "0" for private
"File" - in the playlist section defines the file with the list of mp3 file locations
Next we need to create the directory ices will use:
# mkdir /var/chroot/icecast/ices # chown icecast:icecast /var/chroot/icecast/ices
Now you can list all the mp3 files that are to be played and repeated. In my setup, it's the file /var/chroot/icecast/ices/thirddaylist.txt and it looks something like this:
/usr/music/thirdday/come together.mp3 /usr/music/thirdday/thief.mp3
As the ices client is NOT chrooted, the location of mp3 files is not limited to /var/chroot/icecast
Start the client
In order to keep things tidy we will run the client as the same user. We do this with the following command:
# /usr/bin/su -m icecast -c "/usr/pkg/bin/ices-mp3"
the command can also be added to /etc/rc.local to ensure the client starts when the system reboots.
IMPORTANT WEB LINKS
I will assume all connections are made to localhost for consistency, but "localhost" can be replaced with the server name if connecting over a LAN/WAN/Internet. Now, let the fun begin...
based upon the setup above you can do the following:
listen to the stream directly (using the mountpoint we defined in the ices.conf file):
connect to the server status page with a browser as follows:
This option also provides a nice graphic link to the m3u file by the name of the mountpoint
connect to the server admin setup
you can control client connections, see who's connected, etc. The admin username and password is what's defined in your config file /use/pkg/etc/icecast/icecast.xml - so scroll up if you blindly copied my example config file!
That's up to you... stream it over the net if you want, and listen to it wherever you go...
-- Copyright BSDnexus