Create Local Repos
If you have downloaded, created, or rebuilt RPM packages locally (as explained in TipsAndTricks/YumAndRPM "Get set up for rebuilding packages while not being root") you may want a place to put them so they are accessible from all the machines on your local net.
Note: For a single package or a stand-alone end-user system, don't go through all the overhead of building a formal NFS export and package repository - just use either:
[root@server1 ~]# yum --nogpgcheck localinstall packagename.arch.rpm
or the older and simpler approach for an unsigned package:
[root@server1 ~]# rpm -Uvh packagename.arch.rpm
One benefit of the rpm based approach, is that a developer can incrementally solve dependencies, and rpm will suggest what the next needed package must provide, and one can build up a 'just enough' solution:
[root@server1 ~]# rpm -Uvh package1.arch.rpm package2.arch.rpm ...
Use of a yum repo adds additional benefits, as yum can resolve dependencies and automatically satisfy them from available repositories.
The following procedure will explain how to set up an NFS share containing a repository of locally built/rebuilt/downloaded packages and access them in a uniform manner from other systems of the same distro version. One can follow a similar procedure to enable local mirrors of os, updates, etc. avoiding downloading from external mirror servers, and controlling availability of updates to local machines until they have been tested.
- The example will cover i386 for CentOS4. A similar approach can be followed for other architectures and versions. One can also use other means of providing access to the repo, such as a HTTPd and/or an FTP server. Convention on command-line sections: # means run as root, $ means run as a user - builduser in the example.
- First create directory structure on the server, say server1:
[root@server1 ~]# mkdir -p /share/CentOS/4/local/i386/RPMS
- If createrepo is not already installed, as it will not be by default, install it.
[root@server1 ~]# yum install createrepo
- Build a spiffy new set of packages from foo-188.8.131.52-1.el4.src.rpm (or alternately get packages from another trusted source).
[builduser@server1 ~]$ rpmbuild --rebuild /path/to/srpm/foo-184.108.40.206-1.el4.src.rpmThis creates (for example)
/home/builduser/rpmbuild/RPMS/foo-220.127.116.11-1.el4.i386.rpm /home/builduser/rpmbuild/RPMS/foo-devel-18.104.22.168-1.el4.i386.rpm /home/builduser/rpmbuild/RPMS/foo-docs-22.214.171.124-1.el4.i386.rpm
- Move the files to the repo and create metadata:
[root@server1 ~]# mv /home/builduser/rpmbuild/RPMS/foo* /share/CentOS/4/local/i386/RPMS [root@server1 ~]# chown -R root.root /share/CentOS/4/local [root@server1 ~]# createrepo /share/CentOS/4/local/i386 [root@server1 ~]# chmod -R o-w+r /share/CentOS/4/local
- Note: Steps 3 and 4 are repeated as new packages are added to the repo.
- Create /etc/yum.repos.d/local.repo
Warning: The example assumes yum-plugin-protectbase plugin (see PackageManagement/Yum/ProtectBase) is installed, and that you want your repo to be enabled by default, protected, and allowed to replace core packages. It also assumes your packages are not GPG-signed. Another, arguably superior, alternative is to use PackageManagement/Yum/Priorities.
[local] name=CentOS-$releasever - local packages for $basearch baseurl=file:///share/CentOS/$releasever/local/$basearch enabled=1 gpgcheck=0 protect=1
- For HTTP or FTP repos the baseurl line must be changed accordingly.
- Install packages on the server to test the repo. Can be removed later if not required on server.
[root@server1 ~]# yum install foo foo-devel foo-docs
- Export the directory via NFS - if not already on a shared directory. (May also need to install and start NFS, and/or reboot if you have not been using it. The procedure for that is left as an exercise for the student.) Change the IP address to suit your local network. Use "rw" and address 'root_squash' issues, rather than "ro" if you want the share to be writable from suitably privileged machines.
[root@server1 ~]# echo "/share 192.168.1.0/24(ro,async)' >>/etc/exports [root@server1 ~]# exportfs -r
- Log on to a client machine (e.g. client1) as root and set up the NFS mount and yum configuration.
The autofs package may be required (yum install autofs) for the example to work as shown. An alternative would be to create /share and NFS mount /share in /etc/fstab. The example assumes you have ssh/scp working for root. You will need either a working DNS with local host names, or /etc/hosts set up with IP addresses and hostnames.
[root@client1 ~]# scp server1:/etc/yum.repos.d/local.repo /etc/yum.repos.d/ [root@client1 ~]# ln -s /net/server1/share /share
- Test the setup - should be able to see the repo.
[root@client1 ~]# ls /share/CentOS/4/local
- Install packages on client.
[root@client1 ~]# yum install foo foo-devel foo-docs
Repeat the last three steps for additional clients as required.
This page created and maintained by PhilSchaffner. Other Wiki contributors are invited to make corrections, additions, or modifications.