Have you ever needed/wanted to set up a single Red Hat Enterprise Linux server to sync all you servers to for package updates? 32 and 64 bit machines pointing to the same server? Different distros on the same server? Here’s how…
This tutorial is for setting up mrepo only. It’s the first part of setting up a Spacewalk instance to mirror RHN. If you’ve already completed this, go on to Part Two…(coming soon)
Part One: Setting up a mrepo server to mirror RHN’s Satellite repositories.
The repo server should be running RHEL/CentOS 5.X. RHEL 6/CentOS6 is not compatible with these instructions, as they have changes the way the RHPL scripts work in 6, and thus breaks Spacewalk on 6. This may be fixed in the future, but as of early 2012, it’s not yet a practical option.
You’ll need a modest server, probably something with at least a 2Ghz processor and 2Gb RAM. My setup uses a (Virtual) Xeon X5650 @ 2.67GHz and 4GB RAM on a VMWare instance. Honestly, it’s probably overkill, but it’s good enough. Depending on how many different distros and versions you plan on mirroring, space could be a problem. Plan on 6Gb per version, 10Gb if you plan on hosting the DVD ISOs as well. If you have 32 and 64 bit versions of RHEL 3,4,5 and 6, that’s ~50Gb, and ~75Gb if you want DVDs. If you want separate CentOS repos, add more. (But Centos can be configured to pull RHEL repos, as well…so it’s not necessary. Suse/Debian/Fedora will need their own repos though.)
In my setup, I have lvm’d disks totaling 80GB (lvm makes it easier to add space later by adding disk slices to the Volume Group/Logical Volume.) I have that 80GB mounted to /var/www- which is where I will keep the served repo cache and sources.
I am assuming you have your server configured to run apache, and have any security questions addressed as your policy dictates. IPTables/other firewall configured to allow traffic, network connectivity, SELinux configured to taste. I can’t offer help configuring those, as those settings are all highly dependent on you particular environment and installation.
You’ll need to attach to the RHN or CentOS repos and install the following packages:
Createrepo-0.4.5 or better. Current RH-sanctioned release is createrepo-0.4.11-3.el5
Mrepo-0.8 or better. Current RH-sanctioned version is mrepo-0.8.7-1.el5.rf.
Spacewalk. Current RH-sanctioned version is 1.6, but it is not available in the normal RHEL channels- it is available in a repository on RH’s servers, though- http://spacewalk.redhat.com/yum/
(You’ll need to add it to your current repos. An install guide is available at https://fedorahosted.org/spacewalk/wiki/HowToInstall )
You’ll also need a database. Spacewalk supports Oracle(10g, 11g, or the free XE) or PostgreSQL. It’s your call on which to use. Oracle costs real money; Oracle XE is free, but severely restricted, which makes a production repo less practical, but not impossible; and PostgreSQL is free, but mildly limited in capabilities. RH warns that monitoring is not likely to work in Spacewalk with Postgre, there may be other functions that don’t work perfectly, too, but if your goal is just a production package repository, it’s a good free alternative to Oracle. (I may provide another post just to discuss these differences…)
Procedure for setting up repositories and sync –
Here’s where you’re going to have to think this through. You’re going to need to change and create a few files.
Files to edit:
/etc/mrepo.conf (First step)
/etc/httpd/conf/httpd.conf (Second step)
Files to create:
Source Directory (Third step)
Repodata Directory (Third step)
SystemIDs and UUID (Fourth step)
Mrepo.conf.d config files (Fifth step)
1.) Let us assume, for the sake of this exercise, you are going to host 4 repos- 32 and 64 bit versions of RHEL4 and RHEL5. There will be one mrepo.conf file, two mrepo.cond.d files (one for each distro- RHEL4 and RHEL5), and four each for repodata and source directories (2 RHEL4’s and 2 RHEL5’s, 32 and 64bit versions, respectively). For every different distro, you’ll need one conf.d file, and for each architecture, you’ll need one repo and src directory. So for a set up with 3 distros (RHEL4,5 & 6) and 3 Archs (386,x64, and Alpha), your 1,2,and 4 each becomes 1,3,and 9 each, capisce? First thing is to edit the /etc/mrepo.conf file.
srcdir = /var/www/mrepo_sources
wwwdir = /var/www/mrepo
confdir = /etc/mrepo.conf.d
arch = i386 x86_64
rhnlogin = RHNUsername:RHNPassword
Note the location of the src and www dirs. You can call these anything you want, and put them anywhere, so long as you have space and remember what you called them. Note next the arch= line. I have my server set to sync to i386 and x86_64. There is a pretty wide assortment of options here if you have interesting architectures.
Config other options as fits you network, but this is all the info that’s necessary. Adding an email addy to the mailto line is a good idea, too.
2.) Next we need to edit 3 lines in the /etc/httpd/conf/httpd.conf file.
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
# If this is not set to valid DNS name for your host, server-generated
# redirections will not work. See also the UseCanonicalName directive.
# If your host doesn’t have a registered DNS name, enter its IP address here.
# You will have to access it by its address anyway, and this will make
# redirections work in a sensible way.
ServerName hostname.domain.com:80 <<THIS LINE, make it your FQDN, so apache starts cleanly
…couple lines below…
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
DocumentRoot “/var/www/mrepo” <<THIS LINE, make it match your wwwdir in mrepo.conf
…couple lines below…
# This should be changed to whatever you set DocumentRoot to.
<Directory “/var/www/mrepo”> <<THIS LINE, make it match your wwwdir in mrepo.conf
3.) Next we need to set up our repo and source directories. The naming on these is important. The directories and mrepo.conf.d files (that we’ll create later) have to match. In our case we have four of each. In my case I’ve named them:
These are empty directories. In the case of our example her, you need each of those four in A.)the srcdir in the first line of your mrepo.conf, and B.) in the wwwdir of said file.
Redhat requires a UUID on your machine to sync up, and you’ll need to generate one.
Now create /etc/sysconfig/rhn/up2date-uuid (yes, that’s up2date….its a legacy file. Don’t worry about it)
[root@hostname]# vi /etc/sysconfig/rhn/up2date-uuid
[root@hostname]# cat /etc/sysconfig/rhn/up2date-uuid
uuid[comment]=Universally Unique ID for this server
rhnuuid=12345678-123a-1abc-a123-1ab2c34567d8 <<This needs to match the uuidgen output above…
4.) Now we need to generate a RHN systemid for each of these directories we just made, so that Red Hat can sync each directory to a separate repo. Note the release names are specific to Red Hat naming conventions…and that each line is either 32 or 64 in arch and in folder name.
gensystemid -u NAME -p PASS –release=4ES –arch=i386 /var/www/mrepo/rhel4es-i386/
gensystemid -u NAME -p PASS –release=4ES –arch=x86_64 /var/www/mrepo/rhel4es-x86_64/
gensystemid -u NAME -p PASS –release=5Server –arch=x86_64 /var/www/mrepo/rhel5s-x86_64/
gensystemid -u NAME -p PASS –release=5Server –arch=i386 /var/www/mrepo/rhel5s-i386
And we need to copy those system id’s to the source dir, as well. You can modify and run this block… (make sure you are in the wwwdir to run this, in this case /var/www/mrepo…)
for i in rhel4es-i386 rhel5s-i386 rhel4es-x86_64 rhel5s_x86-64; do cp /var/www/mrepo/$i/systemid /var/www/mrepo_sources/$i/.; done
5.) Lastly, we need to set up the /etc/mrepo.conf.d/conf files.
for i in rhel4es rhel5s; do touch /etc/mrepo.conf.d/$i.conf; done
Next, to populate those files. You can find samples in /usr/share/doc/mrepo*/dists/. You’ll need to set your architecture here- you can have multiple archs on the same line, separated by a space.
name = Red Hat Enterprise Server $release ($arch)
release = 5
#arch = i386 x86_64 ia64 ppc s390 s390x
arch = i386 x86_64
metadata = repomd repoview
### Additional repositories
updates = rhns:///rhel-$arch-server-5
vt = rhns:///rhel-$arch-server-$repo-5
supplementary = rhns:///rhel-$arch-server-$repo-5
fastrack = rhns:///rhel-$arch-server-$repo-5
hts = rhns:///rhel-$arch-server-$repo-5
rhn-tools = rhns:///$repo-rhel-$arch-server-5
### RPMforge repository
rpmforge = rsync://apt.sw.be/pub/freshrpms/pub/dag/redhat/el$release/en/$arch/RPMS.dag/
rpmforge = ftp://apt.sw.be/pub/dag/pub/redhat/el$release/en/$arch/RPMS.dag/
rpmforge = http://apt.sw.be/redhat/el$release/en/$arch/RPMS.dag/
Here is where you can add additional repos, if you want to add aftermarket ones.
6.) Now it’s time to turn it up and sync. Start apache and mrepo, and set them to automatically start, then sync. This will take a very long time. If you’re doing this from a VM, you might be best to log into the console, and start the sync from there, so you can still use the machine. If you’re using a terminal, you can backgroub the process by appending a “&” to the end of the sync command (an `fg` command brings it back to the front if you need it.)
service httpd start
service mrepo start
chkconfig httpd on
chkconfig mrepo on
Now your repo is complete! On to Spacewalk Setup…