Wednesday, April 24, 2013

Setup Local Centos (Or Any Linux Flavor) Local Repository Mirror

Since I have started using the Linux CentOS operating system, I have created a number of servers. When I do updates on these servers, all of the servers went straight out to the internet to retrieve their updates. Besides being a time consuming process, it was eating up a large amount of bandwidth.

This got me thinking
"Hey, Microsoft has a server service (WSUS) that downloads all of the updates for every product that they make. Can I create a local repository on my network that all of my CentOS servers get their updates from?"
After looking around on good for a couple of hours, I found the answer. The answer is "Yes, you can setup a local repository on your network."

Here is what I did to set up a local repository.

  1. I downloaded and installed the minimal version of CentOS 6.4.
    * The nice thing I just found out about version 6.4 is that the Hyper-V drivers are included now, so no more downloading and installing the Linux Integration Components. That saves a great deal of time.
  2. After the install finished, I set SELINUX to disabled and turned off the firewall and did a reboot. I know this is not the wisest thing to do, but hey, the only thing the server is doing is updating other servers.
    - To disable SELINUX, open /etc/selinux/config, change "SELINUX=enforcing" to "SELINUX=disabled"
    - To disable the firewall, type "chkconfig iptables off" and "chkconfig ip6tables off"
    - Type "reboot" to restart the server.
  3. Install http, php, and rsync. This will set the server up as a web server. You will use rsync to download a copy of a public repository to your local repository server.
    - Type "yum install -y http php rsync"
  4. Now, configure the http service to start on bootup and start the http service.
    - Type "chkconfig --level 345 httpd on" for bootup
    - Type "service httpd start" to start the service
  5. Now, create a folder in the web server directory to keep all the update files. Because I may have different flavors of Linux in the future, I created a directory called "repo" with a sub-directory of "centos", then the different versions
    - Type "mkdir /var/www/html/repo"
  6. Next, sync your local repository with a public one. To save on space, I excluded the isos.
    * If you want to include them, keep in mind that each version of CentOS you want to keep locally, you will need about 20GB of space.
    - Type "rsync --progress -av --delete --delete-excluded --exclude "local*" --exclude "isos" rsync:// /var/www/html/repo/centos/6.4/"
  7. Because of how the repo works, we need to make a sym link from the 6.4 folder like this:
    ln -s /var/www/html/repo/centos/6.4/ /var/www/html/repo/centos/6
  8. On the client computer (the ones needing updates) you need to edit the /etc/yum.repo.d/CentOS-Base.repo
    - Remove the comment mark (#) from all of the baseurl and comment out the mirrorlist.
    - Under baseurl, change "" to the IP address of your repository server and add "/repo". Here is how mine looks: "baseurl=$releasever/os/$basearch/"
  9. Once you have made those changes and saved the file, we need to clear out the old settings. To do this type "yum clean all". 
  10. After you clear out the settings, do a "yum update" and you will see that the client computer/server is now going to your local repository for its updates. 
Once I finished setting up my local repository, I was able to update four servers in less than 10 minutes and one was a newly created server. That is a lot faster than the 30 minutes each server took before. 

No comments:

Post a Comment