Creating a small local YUM and Pip repository


I was on this situation: My team had to work at the customer side (he gave us access to a part of his infrastructure), and the working servers (Staging cluster) didn’t have Internet access. As you can see, the working servers only allowed incoming connections, and all servers runned CentOS 7.

I had to install packages from EPEL repository and from Pip repository, and I knew which packages my team required -because I’m the sysadmin- and the servers have 20GB to store shared files. (It means that servers have defined partitions for libraries, database, datablocks and user’s home.)

On Jump server I installed the package for EPEL repository

yum install -y
yum makecache fast

YUM (EPEL) repository

The customer isolated the servers on Staging cluster but allowed access to local mirrors to install official packages. And my team needed python-pip that is provided by EPEL repository.

I installed the required packages for the first part on Jump server

yum install -y createrepo yum-utils

I used a directory to store all downloaded packages

mkdir /opt/epel

Here’s the trick for a minimal repository: download only the required packages with their required dependencies that exist only on EPEL

for URL in `yumdownloader --resolve --urls python-pip | grep 'http.*epel'` ; do wget -P /opt/epel ${URL} ; done

Next step was creating a package database for the repository and moving the content to one server on Staging cluster

createrepo /opt/epel
scp -r /opt/epel <server foo>:/var/www/html/

The second part was on a server on Staging cluster. As you noted, I moved the repository content to /var/www/html because Apache serves this directory by default

yum install -y httpd

And then, I created a YUM’s repository configuration that was copied to each server on Staging cluster. The file is /etc/yum.repos.d/epel.repo and has this content

name=EPEL $releaseserver - $basesearch Local

Pip repository

I strongly recommend installing Pip packages inside a virtual environment instead inside of the whole OS.

First, I installed Pip and pip2py in the Jump server

yum install -y python-pip
pip install pip2pi

I created the local Pip repository and copied the /opt/pip directory to /var/www/html on a server at Staging cluster

mkdir /opt/pip
pip install --download /opt/pip <package name>
dir2pi /opt/pip
scp -r /opt/pip <server foo>:/var/www/html/

Then, to use the local Pip repository I used the following file in ${HOME}/.pip/pip.conf

index-url = http://your.domain.lan/pip/simple

(If Pip still using the official repository, start a new session.)