Friday, November 6, 2009

Creating a CPAN mirror

!!! Research Time....making infrastructure easy...

Probably you have a lot of perl developers in your network and they require to create custom packages for easy deployment. Moreover, you do not want all the developers to get the packages from internet every time because it could consume your bandwidth. The solution for this problem is having a local CPAN mirror. This procedure is pretty simple , but it can take sometime to synchronize the mirror the first time.

First lets have a a server with enough space to store the mirror data. Let say you provision 10GB for CPAN ( CPAN can consume around 7GB).

Synchronize the  CPAN mirror with one of the mirrors available using rsync. I have a separated partition for CPAN mounted on /cpan directory.

 # /usr/bin/rsync -av --delete /cpan

This process can take long time depending on your internet access, so I suggest you to use screen to leave the terminal running.

After the first synchronization , you must make sure that your mirror is updated ( CPAN can have many updates during the day) , so I suggest you to create a cron job that runs everyday at midnight. Edit your crontab and add the following:

#crontab -e

@daily /usr/bin/rsync -av --delete /cpan >/dev/null 2>&1

Now that you have the CPAN mirror copied to the disk, you need to share it on the network. You can use ftp or http, for my case I prefer to use http with Apache. I have Apache already installed for another mirrors so basically I need to give access to the mirror putting a symlink on Apache default directory (/var/www)

# ln -s /cpan /var/www/cpan

Then create a cname on your local DNS for to

Now you have your mirror available on

CPAN client configuration

If your team of developers have already used external CPANs, they will require to modify CPAN to access your local mirror. If it is the first time you are using CPAN, it will be asking you to choose a mirror.

# cpan

cpan shell -- CPAN exploration and modules installation (v1.9402)
Enter 'h' for help.

cpan[1]> o conf

On CPAN, "o conf" will show you the configuration.

cpan[2]> o conf urllist

This command will show you the list of mirrors that you have configured.

cpan[3]> o conf urllist flush

This command will delete any mirror on the list.

 cpan[6]> o conf urllist push /cpan/

This command will add your local mirror to urllist. Finally you need to commit the changes 

cpan[7]> o conf commit

Done ....start using your mirror


No comments:

Post a Comment