Creating Local CentOS Repository
In many Linux distros, package management tools are utilized for getting new packages and their dependencies. They are also used for In environments that has many boxes, updating packages and installing new packages may lead tremendous bandwidth consumption. In order to avoid this, it is possible to create a local CentOS Repository and add it all the machines. By using this ability, all other machines can get packages locally, means without consuming any bandwidth from outside Internet connection.
Since traffic inside a network for a limited time for updates does not lead to a problem for many local networks, it results in a observable gain in bandwidth usage of Internet connection. Especially, when local network and number of boxes getting bigger, the ratio is becoming more and more profitable.
After knowing why and when it is important to employ a local repo; in this post, we will discuss how to create one. For this purpose, we will create a local CentOS repo.
- A web server – A web server is required to serve the repo files. You can use one which you want, such as Apache or Nginx.
- Disk space – Disk space depends on your need and repo configuration. If you want to make a local repo that includes many repositories, you should have larger disk space. For a default CentOS repository, >=20GB disk space is enough.
2. Install Required Packages
We need two packages to create a repository. Firstly, we need to synchronize our local repo with CentOS repos. There is a program called reposync which has a name looks like rsync. Actually, it works in the same way as rsync does. To install it:
Yum-utils package contains reposync.
Now we can run reposync command. By default, it will sync the repos that current machine has in /etc/yum.repos.d directory. It will take a while depending your connection and status of repositories.
Firstly, we should create a directory for our new repo. For simplicity, Apache’s default source directory is used for this purpose:
After creating the directory, we can go there and run the reposync command as follows:
As a reminder, this will likely take a long time that is enough for a coffee break or more. After completing this stage, now we have all of the packages in our local repo. You can take a look at the directories that created from reposync.
After synchronizing the repos, we have required package files and we should make a repo from them. This is possible with creating a database of our packages. We will use createrepo command for this.
Firstly, install createrepo package:
After installing it, run the new command in the directory we used for getting packages:
This will take a short time. However, it depends on some factors such as your package count and processor speed. Afterwards, you are ready to add your new repository to your boxes.
3. Access Your New Repo
After running these commands, now we have our local repository. The address of this repo depends on your selection of the folder that reposync was run. If you followed this document one-by-one with no difference, it will be http://IP/CentOS6Repo and if you have a domain, you can also reach the repo with http://domain/CentOS6Repo like http://gu.ray.kim/CentOS6Repo.
4. Final Words
Next entry will cover how to activate that repo on other machines which is very easy and quick to make. We will have another post about creating repos which includes some details and additional preferences about creating and managing repos, updating them etc.