-
Notifications
You must be signed in to change notification settings - Fork 600
Setting Up a Local Musicbrainz Mirror
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
- UNIX-based operating system (here we'll be using Debian 6.0)
- Git
- Perl (at least v5.0)
- PostgreSQL (using v8.4 here but replace the version below with the latest available for your distro)
- 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
-
Set up a musicbrainz user with a home in /home/musicbrainz
-
Git clone the latest musicbrainz-server:
cd /home/musicbrainz
git clone git://git.musicbrainz.org/musicbrainz-server.git musicbrainz-server
cd musicbrainz-server
-
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 } -
Install carton:
sudo cpan Carton
-
Install dependencies:
carton install --deployment
-
Install PostgreSQL Extensions:
cd postgresql-musicbrainz-unaccent
make
sudo make install
cd ..
-
Build collate extension:
cd postgresql-musicbrainz-collate
make
sudo make install
cd ..
-
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. -
Create the database:
carton exec ./admin/InitDb.pl -- --createdb --clean
-
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
-
Start the server! Just run:
carton exec -- plackup -Ilib -r
Visiting http://yourip:5000 should bring up the 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!
-
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
-
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)