Skip to content

Setting Up a Local Musicbrainz Mirror

rembo10 edited this page Apr 8, 2012 · 26 revisions

Introduction

This guide will show you how to set up your own local musicbrainz mirror from scratch, optionally using nginx as the frontend, although this is probably not necessary if your only connecting to it from a few machines.

It assumes you'll be using Debian Linux, but you can substitute most of the apt-get commands with your package manager of choice.

The official install guide from musicbrainz can be found here: https://github.com/metabrainz/musicbrainz-server/blob/master/INSTALL

Prerequisites

  1. UNIX-based operating system (here we'll be using Debian 6.0)
  2. Git
  3. Perl (at least v5.0)
  4. PostgreSQL (using v8.4 here but replace the version below with the latest available for your distro)
  5. Memcached

To grab all the prerequisites in one go, issue this command: sudo apt-get install build-essential git-core libssl-dev libxml2-dev libpq-dev libexpat1-dev libdb-dev memcached libexpat-dev postgresql-8.4 postgresql-server-dev-8.4 postgresql-contrib liblocal-lib-perl libossp-uuid-perl libicu-dev

Installation and Setup

  1. Set up a musicbrainz user with a home in /home/musicbrainz

  2. Git clone the latest musicbrainz-server: cd /home/musicbrainz git clone git://git.musicbrainz.org/musicbrainz-server.git musicbrainz-server cd musicbrainz-server

  3. Modify DBDefs.pm to run as a slave cp lib/DBDefs.pm.default lib/DBDefs.pm nano lib/DBDefs.pm Set MB_SERVER_ROOT to /home/musicbrainz/musicbrainz-server Set REPLICATION_TYPE to { RT_SLAVE }

  4. Install carton: sudo cpan Carton

  5. Install dependencies: carton install --deployment

Create the database

  1. Install PostgreSQL Extensions: cd postgresql-musicbrainz-unaccent make sudo make install cd ..

  2. Build collate extension: cd postgresql-musicbrainz-collate make sudo make install cd ..

  3. Set up PostgreSQL authentication Edit pg_hba.conf to allow all local connections: # TYPE DATABASE USER CIDR-ADDRESS METHOD local all all trust For IPv4/IPv6 local connections, you can make the same changes.

  4. Create the database: carton exec ./admin/InitDb.pl -- --createdb --clean

  5. Grab the latest dumps from: ftp://ftp.musicbrainz.org/pub/musicbrainz/data/fullexport/ "To get going, you need at least the mbdump.tar.bz2, mbdump-editor.tar.bz2 and mbdump-derived.tar.bz2 archives, but you can grab whichever dumps suit your needs. Assuming the dumps have been downloaded to /tmp/dumps/ you can import them with:

         carton exec ./admin/InitDb.pl -- --createdb --import /tmp/dumps/mbdump*.tar.bz2 --echo
    
  6. Start the server! Just run: carton exec -- plackup -Ilib -r

Visiting http://yourip:5000 should bring up the mirror.

Set up Headphones to access your local mirror

This part is easy :-)

Just select "custom" as your musicbrainz mirror on the config page and enter in "localhost" (if the server is running on your machine), or the ip address if it is on another machine, and the correct port (5000 by default). You can change the sleep interval between requests - for example musicbrainz.org requires a 1 second sleep between requests, but if it's your local machine you can lower this to 0.

Hit 'Save Changes' and Headphones will start using your local mirror!

Post-Installation Notes

  1. You'll want to grab hourly updates from musicbrainz, which requires setting up a cron job to run, 10 minutes past the hour: carton exec -- ./admin/replication/LoadReplicationChanges

  2. A handy script by Munger at #musicbrainz-devel on freenode allows you to start/stop the server and run hourly replication changes: http://paste.pocoo.org/raw/555245/

Save it as /usr/bin/mbcontrol (chmod a+x to make it executable) Usage: mbcontrol start (start the server) mbcontrol stop (stop the server) mbcontrol hourly (load the replication changes)

To have in run as a cronjob every hour, you can run: crontab -e and stick this line in at the end: 10 * * * * /usr/bin/mbcontrol hourly (This will make it run 10 minutes past every hour)

Clone this wiki locally