Introduction
There are lots of reasons why you might want to host your own RPM repository. A few reasons up front:
- Speed: Performing a yum (or dnf) update from one of your locally hosted repositories is much faster than checking the ones on the internet!
- Cost: If you run a business, then you know bandwidth can be expensive. If Linux is the operating system your developers and/or employees use, then hosting the repository internally means they won’t waste bandwidth each time one of them performs a system update. You’ll have downloaded everything once, and provided a central controlled share point they can apply all of their updates from.
- Retention: Over time, your successfully deployed systems will age and the packages that were once readily available for it may be a lot harder to acquire! Sometimes it’s a good thing to create and manage your own internal repository so that you always have access to the exact RPMs you used to deploy/create your development environment with. This is especially the case for that one rare day that arises requiring you to go back and debug a legacy system of yours. If the packages are already available to you locally; you should have no problem reproducing any detected problems since you’ll be able to reconstruct their environment exactly.
- Mock: I love this tool; mock allows you to dynamically generate different distributions of CentOS/Fedora (new and old) allowing you to build your applications to test them in it. You simply create a mock environment of the distribution of interest. In this new environment, you can do whatever it was you wanted to, then you can easily blow it away when you’re done. The best part about mock is that it allows you to build/test things without hauling in all of the development libraries into your native working environment. Quite frankly, I couldn’t have hosted or tested half of the things I do in all my blogs and my repository without it. Mock generates it’s ‘throw/away’ environments by connection to a yum repository and setting itself up. If you host your own repositories, it can greatly speed up this process.
- Consistency: If everyone in your department were to reference the same rpm repository instead of one of the hundreds of mirrors available on the internet, you would consistently be hosting and sharing the same packages internally with your team. This is fantastic in a software development environment where everyone should be using the same packages anyway. This isn’t to say that all public CentOS mirrors are different, but they do go up and down from time to time. They also all synchronize themselves with whatever the latest and greatest at different times too.
- Mirrors: Even if you just host your own mirror publicly, you’d be doing the Linux community good! You’d become another server of the hundreds already out there providing a source for free software! Your efforts would offload network congestion others face and speed up everyone’s Linux experience.
- Custom Media: Hosting your own RPM packages can grant you the power to build your own custom media. You can accomplish the same task without hosting internally, but it’s much (,much) slower! This will make for a great topic in another blog though since this process is a topic of it’s own. I do however explain how to host your own custom repositories in this blog though!
Local Hosting Environment
The whole hosting process will take up some disk-space… 150GB or so if you decide to host everything I identify here. Nothing major, but worth noting for those with smaller disk drives.
The first thing you need to do is decide where you’ll host everything from. I will use the following directories for this blog entry:
Directory |
Details |
/var/share/repo |
The location we’ll host the repository from. |
/var/share/isos |
The location we’ll store our ISO image files in. |
First let’s make sure our directories exist:
1 2 3 4 5 6 7 | [ ! -d /var/share/repo ] && \
mkdir -p var /share/repo
[ ! -d /var/share/isos ] && \
mkdir -p var /share/isos
|
You’ll want to have the following tools on hand as well if you plan on hosting your own repositories:
1 2 3 4 5 | yum install -y rsync lftp
yum install -y createrepo yum-utils find
|
Repository Hosting
The next few sections focus on the following repositories; you may or may not need them all. So feel free to just use what you need.
Note: The blog utilizes the lftp tool for all of the synchronization, but the rsync command is also documented in the comments if you prefer that route as well. It’s also worth noting that you can re-run these mirror commands again and again to keep your local repository updated with the latest.
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | pushd /var/share/isos
wget http: //mirror .csclub.uwaterloo.ca /centos/5 .11 /isos/x86_64/CentOS-5 .11-x86_64-bin-DVD-1of2.iso \
-O /var/share/isos/CentOS-5 .11-x86_64-DVD1.iso
wget http: //mirror .csclub.uwaterloo.ca /centos/5 .11 /isos/x86_64/CentOS-5 .11-x86_64-bin-DVD-2of2.iso \
-O /var/share/isos/CentOS-5 .11-x86_64-DVD2.iso
mkdir dvd1
mkdir dvd2
mount -o loop,ro CentOS-5.11-x86_64-DVD1.iso dvd1
mount -o loop,ro CentOS-5.11-x86_64-DVD2.iso dvd2
[ ! -d /var/share/repo/centos/5 .11 /x86_64/os ] && \
mkdir -p /var/share/repo/centos/5 .11 /x86_64/os
[ ! -d /var/share/repo/centos/5 .11 /x86_64/updates ] && \
mkdir -p /var/share/repo/centos/5 .11 /x86_64/updates
[ ! -d /var/share/repo/centos/5 .11 /x86_64/extras ] && \
mkdir -p /var/share/repo/centos/5 .11 /x86_64/extras
[ ! -d /var/share/repo/centos/5/x86_64/epel ] && \
mkdir -p /var/share/repo/centos/5/x86_64/epel
pushd /var/share/repo/centos/5/x86_64
ln -snf ../.. /5 .11 /x86_64/os os
ln -snf ../.. /5 .11 /x86_64/updates updates
ln -snf ../.. /5 .11 /x86_64/extras extras
popd
pushd /var/share/repo/centos/5 .11 /x86_64
ln -snf ../.. /5/x86_64/epel epel
popd
rsync -av --ignore-existing dvd1/ /var/share/repo/centos/5 .11 /x86_64/os/
rsync -av --ignore-existing dvd2 /CentOS/ /var/share/repo/centos/5 .11 /x86_64/os/Packages/
umount dvd1
umount dvd2
rmdir dvd1
rmdir dvd2
popd
lftp mirror.csclub.uwaterloo.ca -e "mirror --verbose /centos/5.11/updates/x86_64/ /var/share/repo/centos/5.11/x86_64/updates"
lftp mirror.csclub.uwaterloo.ca -e "mirror --verbose /centos/5.11/extras/x86_64/ /var/share/repo/centos/5.11/x86_64/extras"
lftp mirror.csclub.uwaterloo.ca -e "mirror --verbose /fedora/epel/5/x86_64/ /var/share/repo/centos/5/x86_64/epel"
|
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | pushd /var/share/isos
wget http: //mirror .csclub.uwaterloo.ca /centos/5 .11 /isos/i386/CentOS-5 .11-i386-bin-DVD-1of2.iso \
-O /var/share/isos/CentOS-5 .11-i386-DVD1.iso
wget http: //mirror .csclub.uwaterloo.ca /centos/5 .11 /isos/i386/CentOS-5 .11-i386-bin-DVD-2of2.iso \
-O /var/share/isos/CentOS-5 .11-i386-DVD2.iso
mkdir dvd1
mkdir dvd2
mount -o loop,ro CentOS-5.11-i386-DVD1.iso dvd1
mount -o loop,ro CentOS-5.11-i386-DVD2.iso dvd2
[ ! -d /var/share/repo/centos/5 .11 /i386/os ] && \
mkdir -p /var/share/repo/centos/5 .11 /i386/os
[ ! -d /var/share/repo/centos/5 .11 /i386/updates ] && \
mkdir -p /var/share/repo/centos/5 .11 /i386/updates
[ ! -d /var/share/repo/centos/5 .11 /i386/extras ] && \
mkdir -p /var/share/repo/centos/5 .11 /i386/extras
[ ! -d /var/share/repo/centos/5/i386/epel ] && \
mkdir -p /var/share/repo/centos/5/i386/epel
pushd /var/share/repo/centos/5/i386
ln -snf ../.. /5 .11 /i386/os os
ln -snf ../.. /5 .11 /i386/updates updates
ln -snf ../.. /5 .11 /i386/extras extras
popd
pushd /var/share/repo/centos/5 .11 /i386
ln -snf ../.. /5/i386/epel epel
popd
rsync -av --ignore-existing dvd1/ /var/share/repo/centos/5 .11 /i386/os/
rsync -av --ignore-existing dvd2 /CentOS/ /var/share/repo/centos/5 .11 /i386/os/Packages/
umount dvd1
umount dvd2
rmdir dvd1
rmdir dvd2
popd
lftp mirror.csclub.uwaterloo.ca -e "mirror --verbose /centos/5.11/updates/i386/ /var/share/repo/centos/5.11/i386/updates"
lftp mirror.csclub.uwaterloo.ca -e "mirror --verbose /centos/5.11/extras/i386/ /var/share/repo/centos/5.11/i386/extras"
lftp mirror.csclub.uwaterloo.ca -e "mirror --verbose /fedora/epel/5/i386/ /var/share/repo/centos/5/i386/epel"
|
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | pushd /var/share/isos
wget http: //mirror .its.dal.ca /centos/6 .8 /isos/x86_64/CentOS-6 .8-x86_64-bin-DVD1.iso \
-O /var/share/isos/CentOS-6 .8-x86_64-DVD1.iso
wget http: //mirror .its.dal.ca /centos/6 .8 /isos/x86_64/CentOS-6 .8-x86_64-bin-DVD2.iso \
-O /var/share/isos/CentOS-6 .8-x86_64-DVD2.iso
mkdir dvd1
mkdir dvd2
mount -o loop,ro CentOS-6.8-x86_64-DVD1.iso dvd1
mount -o loop,ro CentOS-6.8-x86_64-DVD2.iso dvd2
[ ! -d /var/share/repo/centos/6 .8 /x86_64/os ] && \
mkdir -p /var/share/repo/centos/6 .8 /x86_64/os
[ ! -d /var/share/repo/centos/6 .8 /x86_64/updates ] && \
mkdir -p /var/share/repo/centos/6 .8 /x86_64/updates
[ ! -d /var/share/repo/centos/6 .8 /x86_64/extras ] && \
mkdir -p /var/share/repo/centos/6 .8 /x86_64/extras
[ ! -d /var/share/repo/centos/6/x86_64/epel ] && \
mkdir -p /var/share/repo/centos/6/x86_64/epel
pushd /var/share/repo/centos/6/x86_64
ln -snf ../.. /6 .8 /x86_64/os os
ln -snf ../.. /6 .8 /x86_64/updates updates
ln -snf ../.. /6 .8 /x86_64/extras extras
popd
pushd /var/share/repo/centos/6 .8 /x86_64
ln -snf ../.. /6/x86_64/epel epel
popd
rsync -av --ignore-existing dvd1/ /var/share/repo/centos/6 .8 /x86_64/os/
rsync -av --ignore-existing dvd2 /Packages/ /var/share/repo/centos/6 .8 /x86_64/os/Packages/
umount dvd1
umount dvd2
rmdir dvd1
rmdir dvd2
popd
lftp mirror.csclub.uwaterloo.ca -e "mirror --verbose /centos/6.8/updates/x86_64/ /var/share/repo/centos/6.8/x86_64/updates"
lftp mirror.csclub.uwaterloo.ca -e "mirror --verbose /centos/6.8/extras/x86_64/ /var/share/repo/centos/6.8/x86_64/extras"
lftp mirror.csclub.uwaterloo.ca -e "mirror --verbose /fedora/epel/6/x86_64/ /var/share/repo/centos/6/x86_64/epel"
|
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | pushd /var/share/isos
wget http: //mirror .its.dal.ca /centos/6 .8 /isos/i386/CentOS-6 .8-i386-bin-DVD1.iso \
-O /var/share/isos/CentOS-6 .8-i386-DVD1.iso
wget http: //mirror .its.dal.ca /centos/6 .8 /isos/i386/CentOS-6 .8-i386-bin-DVD2.iso \
-O /var/share/isos/CentOS-6 .8-i386-DVD2.iso
mkdir dvd1
mkdir dvd2
mount -o loop,ro CentOS-6.8-i386-DVD1.iso dvd1
mount -o loop,ro CentOS-6.8-i386-DVD2.iso dvd2
[ ! -d /var/share/repo/centos/6 .8 /i386/os ] && \
mkdir -p /var/share/repo/centos/6 .8 /i386/os
[ ! -d /var/share/repo/centos/6 .8 /i386/updates ] && \
mkdir -p /var/share/repo/centos/6 .8 /i386/updates
[ ! -d /var/share/repo/centos/6 .8 /i386/extras ] && \
mkdir -p /var/share/repo/centos/6 .8 /i386/extras
[ ! -d /var/share/repo/centos/6/i386/epel ] && \
mkdir -p /var/share/repo/centos/6/i386/epel
pushd /var/share/repo/centos/6/i386
ln -snf ../.. /6 .8 /i386/os os
ln -snf ../.. /6 .8 /i386/updates updates
ln -snf ../.. /6 .8 /i386/extras extras
popd
pushd /var/share/repo/centos/6 .8 /i386
ln -snf ../.. /6/i386/epel epel
popd
rsync -av --ignore-existing dvd1/ /var/share/repo/centos/6 .8 /i386/os/
rsync -av --ignore-existing dvd2 /Packages/ /var/share/repo/centos/6 .8 /i386/os/Packages/
umount dvd1
umount dvd2
rmdir dvd1
rmdir dvd2
popd
lftp mirror.csclub.uwaterloo.ca -e "mirror --verbose /centos/6.8/updates/i386/ /var/share/repo/centos/6.8/i386/updates"
lftp mirror.csclub.uwaterloo.ca -e "mirror --verbose /centos/6.8/extras/i386/ /var/share/repo/centos/6.8/i386/extras"
lftp mirror.csclub.uwaterloo.ca -e "mirror --verbose /fedora/epel/6/i386/ /var/share/repo/centos/6/i386/epel"
|
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | pushd /var/share/isos
[ ! -d /var/share/isos/ ] && mkdir -p /var/share/isos/
wget http: //mirror .its.dal.ca /centos/7 .2.1511 /isos/x86_64/CentOS-7-x86_64-Everything-1511 .iso \
-O /var/share/isos/CentOS-7 .2.1511-x86_64-Everything.iso
[ ! -d /var/share/repo/centos/7 .2 /x86_64/os ] && \
mkdir -p /var/share/repo/centos/7 .2 /x86_64/os
[ ! -d /var/share/repo/centos/7 .2 /x86_64/updates ] && \
mkdir -p /var/share/repo/centos/7 .2 /x86_64/updates
[ ! -d /var/share/repo/centos/7 .2 /x86_64/extras ] && \
mkdir -p /var/share/repo/centos/7 .2 /x86_64/extras
[ ! -d /var/share/repo/centos/7/x86_64/epel ] && \
mkdir -p /var/share/repo/centos/7/x86_64/epel
pushd /var/share/repo/centos/7/x86_64
ln -snf ../.. /7 .2 /x86_64/os os
ln -snf ../.. /7 .2 /x86_64/updates updates
ln -snf ../.. /7 .2 /x86_64/extras extras
popd
pushd /var/share/repo/centos/7 .2 /x86_64
ln -snf ../.. /7/x86_64/epel epel
popd
mount -o loop,ro /var/share/isos/CentOS-7 .2.1511-x86_64-Everything.iso \
/var/share/repo/centos/7 .2 /x86_64/os
sed -i -e '/CentOS-7\.2\.1511-x86_64-Everything\.iso/d' /etc/fstab
echo '/var/share/isos/CentOS-7.2.1511-x86_64-Everything.iso /var/share/repo/centos/7.2/x86_64/os iso9660 loop,ro,auto 0 0' >> /etc/fstab
lftp mirror.csclub.uwaterloo.ca -e "mirror --verbose /centos/7.2.1511/updates/x86_64/ /var/share/repo/centos/7.2/x86_64/updates"
lftp mirror.csclub.uwaterloo.ca -e "mirror --verbose /centos/7.2.1511/extras/x86_64/ /var/share/repo/centos/7.2/x86_64/extras"
lftp mirror.csclub.uwaterloo.ca -e "mirror --verbose /fedora/epel/7/x86_64/ /var/share/repo/centos/7/x86_64/epel"
|
Web Hosting
Once you’ve got your repositories mirrored, you need to host them. Here is the easiest way to do so:
If you’re (planning on) using NginX, then the following will get you going:
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 | yum install nginx -y
systemctl enable nginx.service
systemctl start nginx.service
cat << _EOF > /etc/nginx/default .d /repo .conf
location /repo/ {
alias /var/share/repo/ ;
autoindex on;
}
_EOF
systemctl reload nginx.service
|
Now you should be able to access your website by visiting the server you set this up on with /repo as the path. ie: http://localhost/repo
SELinux
Users running SELinux in enforcing mode will want to do the following so that they’re repository can be hosted properly:
1 2 3 | semanage fcontext -a -t httpd_sys_content_t '/var/share/repo(/.*)?'
|
YUM Repositories
Now we’ll want to update our servers around our office, or maybe just on this PC we’re using to point to our new repositories. Here is probably the easiest way:
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | pushd /etc/yum .repo.d/
sed -e 's/^\(enabled\)=.*/\1=0/g' \
fedora*.repo centos*.repo epel*.repo &> /dev/null
popd
MYREPOADDR=localhost
cat << _EOF > /etc/yum .repo.d /centos .internal.repo
[internal-base]
name=CentOS \$releasever - \$basearch - Base
baseurl=http: // $MYREPOADDR /repo/centos/ \$releasever/\$basearch /os/
enabled=1
priority=1
gpgcheck=0
skip_if_unavailable=False
[internal-updates]
name=CentOS \$releasever - \$basearch - Updates
failovermethod=priority
baseurl=http: // $MYREPOADDR /repo/centos/ \$releasever/\$basearch /updates/
enabled=1
priority=1
gpgcheck=0
skip_if_unavailable=True
[internal-extras]
name=CentOS \$releasever - \$basearch - Extras
failovermethod=priority
baseurl=http: // $MYREPOADDR /repo/centos/ \$releasever/\$basearch /extras/
enabled=1
priority=1
gpgcheck=0
skip_if_unavailable=True
[internal-epel]
name=CentOS \$releasever - \$basearch - Internal EPEL
failovermethod=priority
baseurl=http: // $MYREPOADDR /repo/centos/ \$releasever/\$basearch /epel/
enabled=1
priority=1
gpgcheck=0
skip_if_unavailable=True
_EOF
|
You can easily take the examples provided here and alter them for other repositories you wish to host.
Custom Repositories
Perhaps you’re picking and choosing RPMs from a ton of different sources, or you’re building your own. It’s a good idea not to touch the repositories we’re already mirroring. Leave them exactly the way they are. However, you can create your own repository instead that you can place your personal collection of rpms in:
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | [ ! -d /var/share/repo/centos/7/x86_64/custom ] && \
mkdir -p /var/share/repo/centos/7/x86_64/custom
pushd /var/share/repo/centos/7 .2 /x86_64
ln -snf ../.. /7/x86_64/custom custom
popd
cp my.awesome.application-1.0.0-1.x86_64.rpm
[ -d /var/share/repo/centos/7/x86_64/custom/repodata ] && \
rm -rf /var/share/repo/centos/7/x86_64/custom/repodata
repomanage -o /var/share/repo/centos/7/x86_64/custom/repodata | \
xargs rm -f
|
The next step requires us to generate a comps file. These are XML files that define details of our repository. You can get complicated and define it yourself if you like, but to make things simple, you can just use this script i wrote which will generate one on the fly based on the directory you specify it to parse:
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | #!/bin/sh
REPODIR=$1
if [ -z "$REPODIR" ]; then
echo "You must specify a repository directory to scan (containing rpms)."
exit 1
fi
if [ ! -d "$REPODIR" ]; then
echo "You must specify a repository directory to scan (containing rpms)."
exit 1
fi
pushd $REPODIR &> /dev/null && REPODIR=$( pwd ) && popd &> /dev/null
ID= "custom"
NAME= "Core"
DESC= "Custom Built Packages"
COMPSFILE=comps-$ID.xml
COMPSDIR=$REPODIR /repodata
COMPS=$COMPSDIR/$COMPSFILE
[ -d $COMPSDIR ] && rm -rf $COMPSDIR
[ ! -d $COMPSDIR ] && mkdir -p $COMPSDIR
FILES=$( find -L $REPODIR -mindepth 1 -maxdepth 1 - type f -name "*.rpm" - exec basename {} \;)
cat << _EOF > "$COMPS"
<?xml version= "1.0" encoding= "UTF-8" ?>
<!DOCTYPE comps PUBLIC "-//REDHAT//DTD Comps info//EN" "comps.dtd" >
<comps>
<group>
< id >$ID< /id >
<name>$NAME< /name >
<description>$DESC< /description >
<default>True< /default >
<uservisible>True< /uservisible >
<packagelist>
_EOF
for FILE in $FILES; do
PFILE=$(rpm -qp "$REPODIR/$FILE" --nosignature --queryformat= "%{NAME}" 2> /dev/null )
cat << _EOF >> "$COMPS"
<packagereq type = "default" >$PFILE< /packagereq >
_EOF
done
cat << _EOF >> "$COMPS"
< /packagelist >
< /group >
<category>
< id >$ID< /id >
<name>$NAME< /name >
<display_order>99< /display_order >
<grouplist>
<groupid>$ID< /groupid >
< /grouplist >
< /category >
< /comps >
_EOF
createrepo -d -q -g $COMPS $REPODIR
|
Place the script file above into your /usr/bin directory if you like (called updaterepo) and call it on any directory you want to turn into a repository from then on:
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | chmod 775 /bin/updaterepo
[ ! -d /var/share/repo/centos/7/x86_64/custom ] &&
mkdir -p /var/share/repo/centos/7/x86_64/custom
updaterepo /var/share/repo/centos/7/x86_64/custom
[code]
You're done ! Now you can update your <strong> /etc/yum .repos.d/< /strong > to include this new location with each yum call you make ! Just use the other examples already provided in this blog as a template!
<h1>Mock< /h1 >
<a href= "https://github.com/rpm-software-management/mock/wiki" target= "_blank" >Mock< /a > is a fantastic tool for RPM management. It 's also a great tool for someone who just wants to test and see if they' re code will run on another platform. You could almost think of Mock as a poor man 's <a href="https://linuxcontainers.org/" target="_blank">Linux Container</a> which are pretty popular these days. Mock isn' t as contained, but it can accomplish the same feat and is even faster since it doesn't have the (Linux) container overhead.
Mock is set up as follows:
[code lang= "bash" ]
yum install -y mock
usermod -a -G mock [User name]
|
Just like that’ you’re now ready to create mock environments. Now by default, mock is configured to fetch it’s information from the external repositories on the internet. But it’s configuration is really easy to get ahold of and update. Check out the /etc/mock directory.
You can now edit the mock environment you wish to host and optionally update the repositories to point to your own. For example, pick a file like /etc/mock/epel-7-x86_64.cfg which is used to generate a 64-bit Enterprise Linux (RedHat/CentOS) 7.x environment.
You’ll see entries like this which will look very familiar (it’s a yum/dnf configuration file entry just like the ones identified above). You can comment out the mirrorlist entry and swap it with your own local repository.
... ...
[base]
name=BaseOS
# comment out the mirrorlist reference:
# mirrorlist=http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os
# point to our own local repository instead:
baseurl=http://localhost/repo/centos/7/x86_64/os/
failovermethod=priority
gpgkey=file:///usr/share/distribution-gpg-keys/centos/RPM-GPG-KEY-CentOS-7
gpgcheck=1
[updates]
name=updates
enabled=1
# comment out the mirrorlist reference:
# mirrorlist=http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=updates
# point to our own local repository instead:
baseurl=http://localhost/repo/centos/7/x86_64/updates/
failovermethod=priority
gpgkey=file:///usr/share/distribution-gpg-keys/centos/RPM-GPG-KEY-CentOS-7
gpgcheck=1
[extras]
name=extras
enabled=1
# comment out the mirrorlist reference:
# mirrorlist=http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=extras
# point to our own local repository instead:
baseurl=http://localhost/repo/centos/7/x86_64/extras/
failovermethod=priority
gpgkey=file:///usr/share/distribution-gpg-keys/centos/RPM-GPG-KEY-CentOS-7
gpgcheck=1
[epel]
name=epel
# comment out the mirrorlist reference:
# mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-7&arch=x86_64
# point to our own local repository instead:
baseurl=http://localhost/repo/centos/7/x86_64/updates/
failovermethod=priority
gpgkey=file:///usr/share/distribution-gpg-keys/epel/RPM-GPG-KEY-EPEL-7
gpgcheck=1
... ...
You can also just copy and paste one of the config files to another and change it around. Add repositories, remove some; the config file for mock is really straight forward if you use another as a template.
Mock is pretty straight forward to use. You just need to pass it in the environment you’re using with each call you make to it.
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | mock -r epel-7-x86_64 --init
mock - v -r epel-7-x86_64 install hostname vi
mock - v -r epel-7-x86_64 --shell
mock - v -r epel-7-x86_64 --rebuild awesome.application-v2.0.0-1.fc24.src.rpm \
--resultdir=awesome.app
|
Credit
If you like what you see and wish to copy and paste this HOWTO, please reference back to this blog post at the very least. It’s really all I ask.
Sources
- Mock: A fantastic development tool that allows you to dynamically generate a fully functional development environment for a CentOS/Red Hat/Fedora distribution of your choice. It allows you to keep development libraries out of your native (working) environment keeping things clean.
- Some good repositories worth mirroring (in no particular order):
- CentOS 5.x, 6.x and 7.x: Here is a list of all of the mirrors you can sync from.
- Extra Packages for Enterprise Linux (EPEL): CentOS/Red Hat users shouldn’t be without this one. It has tons of the building blocks you might need to reconstruct things with.
- NuxRef: Yes… my repository; I mean why not, right?
- Fedora: Bleeding edge distributions don’t stick around long. After a year or so, you’ll be hard-pressed to find RPMs. It might be wise to mirror the distribution you’re using if you don’t plan on upgrading anytime soon. There is enough information in this blog to mirror a Fedora repository if you want to do so.