In this tutorial I describe how to set up a CentOS 6.6 Yum Repository. All you need to do is copy/paste 2 shell scripts and execute them. Once that's done, you copy a .repo file to your Yum Clients. That's all. I work with only x86_64 version only.
If you need a more thorough explanation on how to set up a local Yum Repo, please follow my 4-part series on setting up a local yumrepo .
One minute video demo to show how easily you can create a yumrepo from scratch using my scripts. Obviously the whole process takes days to complete due to 10GB of data to download from a CentOS mirror server. By using my 2 scripts, the actual time you need to spend typing in front of your screen will be less than a few minutes. Watch in 720p if possible.
Some terms to know. I just came up with these for my own use.
- yumrepo: Usually known as Yum Repository. It's a place that contains rpms. A yumrepo can be accessed via http or ftp. I use http.
- Yumserver: It's a CentOS server that hosts rpms for yumclients to download when yum command is issued on the yumclient.
- Yumclient: Any CentOS server that downloads rpms from a yumrepo is a yumclient. Even a yumserver itself is a yumclient as it downloads rpms from a yumrepo.
Setting up Yumrepo for CentOS 6.6
Have a CentOS 6.6 server ready with about 100GB of storage space. A CentOS 6.6 Yum Repository with minimal RPMs (no i386 or ISO files) needs only about 14GB of storage. However you need about 12GB of extra space to shuffle files around. And having extra storage space allows adding additional Yum Repositories later with minimal disruption so I recommend starting out with about 100GB of storage space.
Assuming the new yumserver's hostname is yumserver01. If you use IP and not DNS for internal servers, replace update URL with correct IP.
- From your PC, ssh into your new yumserver.
- On your new yumserver, create 2 directories as root
- Download CentOS 6.6 x86_64 ISO files (both DVD1 and DVD2) to /root/isos/. You will need about 6GB of space.
- Download yum-scripts.zip and unzip the content (2 scripts) to /root/bin/. You should see the 2 scripts in /root/bin/.
- Ensure root owns the ISO files.
- Ensure root owns the scripts and they are executable.
- Execute yum-create-server-centos6.6.sh as root. It will take about 10-30min to complete.
- Following folder will be created and RPMs from the 2 ISO files will be copied in.
- A link, 6, is created. It points to 6.6
- Use a web browser and test browsing http://yumserver01/yumrpms/centos6.6/6/os/x86_64/. Replace yumserver01 with your own FQDN or IP address of yumserver. You should see a webpage showing list of files and fodlers.
- You should also see this file on yumserver01: /root/bin/66.repo. The file should have following.
- If the yumserver01 is to be accessed via IP (ex: 192.168.1.20), in 66.repo replace the 4 instances of yumserver01 with the IP.
- Now you just need to execute the 2nd script for the new yumrepo to be fully functional. Note that it will take days for the script to complete due to 10GB of data to rsync down. Hence you should start the script with & option at the end.
- The script, yum-rsync-minimal-centos6.6.sh, will always generate a short log at /root/logs/yum-rsync-minimal-centos6.6-yyyymm.log" Note all logs from each month will be kept in 1 log file. You should see following 4 lines AFTER yum-rsync-minimal-centos6.6.sh has finished running.
- Now the new yumrepo centos6.6 is fully functional.
[[email protected] ~]# mkdir isos bin
[[email protected] ~]# ls -lh /root/isos/ total 5.6G -rw-r--r-- 1 root root 4.4G Feb 26 13:24 CentOS-6.6-x86_64-bin-DVD1.iso -rw-r--r-- 1 root root 1.3G Mar 18 10:02 CentOS-6.6-x86_64-bin-DVD2.iso
[[email protected] ~]# ls /root/bin/ | sort yum-create-server-centos6.6.sh yum-rsync-minimal-centos6.6.sh
[[email protected] ~]# chown -R root:root /root/isos
[[email protected] ~]# chown -R root:root /root/bin [[email protected] ~]# chmod 750 -R /root/bin
[[email protected] ~]# du -hs /data/www/yumrpms/centos6.6/6.6/os/x86_64 5.8G /data/www/yumrpms/centos6.6/6.6/os/x86_64
[[email protected] ~]# ls -lh /data/www/yumrpms/centos6.6/ total 8.0K lrwxrwxrwx 1 apache apache 3 Mar 23 08:04 6 -> 6.6 drwxrwxr-x 11 apache apache 4.0K Oct 19 21:36 6.6
# 66.repo # Change hostname to IP if you do not have DNS for local machines. [base] name=CentOS-$releasever - Base baseurl=http://yumserver01/yumrpms/centos6.6/$releasever/os/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=&arch=&repo=os #baseurl=http://mirror.centos.org/centos//os// gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6 #released updates [updates] name=CentOS-$releasever - Updates baseurl=http://yumserver01/yumrpms/centos6.6/$releasever/updates/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=&arch=&repo=updates #baseurl=http://mirror.centos.org/centos//updates// gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6 #additional packages that may be useful [extras] name=CentOS-$releasever - Extras baseurl=http://yumserver01/yumrpms/centos6.6/$releasever/extras/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=&arch=&repo=extras #baseurl=http://mirror.centos.org/centos//extras// gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-$releasever - Plus baseurl=http://yumserver01/yumrpms/centos6.6/$releasever/centosplus/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=&arch=&repo=centosplus #baseurl=http://mirror.centos.org/centos//centosplus// gpgcheck=1 enabled=0 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6 #END of file
... baseurl=http://192.168.1.20/yumrpms/centos6.6/$releasever/os/$basearch/ ...
[[email protected] ~]# yum-rsync-minimal-centos6.6.sh &
[[email protected] ~]# more /root/logs/yum-rsync-minimal-centos6.6-201503.log Fri Mar 27 12:01:02 UTC 2015 Rsync and createrepo commands started 2015-03-27.12-09: Rsync was executed successfully. 2015-03-27.12-48: Createrepo was executed successfully. [[email protected] ~]#
Testing yumrepo centos6.6 with a yumclient
Using CentOS 6.6 server named 'lab01' as yumclient.
- yumserver01: copy yumserver01:/root/bin/66.repo --> lab01:/etc/yum.repos.d/66.repo.
- lab01: rename /etc/yum.repos.d/CentOS-Base.repo --> /etc/yum.repos.d/CentOS-Base.repo.orig.
- lab01: list files in /etc/yum.repos.d/ and you should see following:
- Run yum clean all and yum -y update
- As lab01 downloads the RPMs, you can tail httpd access_log on yumserver01 and you should see the files being downloaded.
[[email protected] ~]# ls /etc/yum.repos.d/ | sort 66.repo CentOS-Base.repo.orig CentOS-Debuginfo.repo CentOS-fasttrack.repo CentOS-Media.repo ...
[[email protected] ~]# yum clean all ... [[email protected] ~]# yum update ...
[[email protected] ~]# tail -f /var/log/httpd/access_log ...
Use yumupdate.sh on yumclients
Remember that in some cases, /etc/yum.repos.d/CentOS-Base.repo is recreated after running "yum update" (like when CentOS is upgraded from 6.5 --> 6.6). You should not leave CentOS-Base.repo in if you are using a local yumrepo server. Hence, I created a script to run "yum update" on my CentOS servers. The script will rename CentOS-Base.repo if found before and after. It also reboots the server if the kernel is updated.
- Create /root/bin/yumupdate.sh with following:
- Log is kept in /root/logsyum/yyyymmdd-hhmm.log.
#!/bin/bash NowDate=`date "+%Y%m%d-%H%M"` LogsYum="/root/logsyum" LogFile="yum-update-$NowDate.log" mkdir -p $LogsYum 2> /dev/null mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.$NowDate 2> /dev/null yum clean all yum -y update 2>&1 | tee $LogsYum/$LogFile KernelTest=$(grep -ic "kernel" $LogsYum/$LogFile) if [ $KernelTest -ge 1 ]; then echo "# Kernel updated" >> $LogsYum/$LogFile mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.$NowDate 2> /dev/null reboot exit 0 else echo "# Kernel NOT updated." >> $LogsYum/$LogFile mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.$NowDate 2> /dev/null exit 0 fi
Keep yumrepo centos6.6 in sync
New RPMs are often released to fix bugs or add features. Thus you need to remember to keep your yumrepo synced with latest RPMs. To do so, set cronjob to run yum-rsync-minimal-centos6.6.sh once every few days. You could get more sophisticated and have it send out email alert if RPMs are downloaded, prompting you to run yumupdate on your fleet of CentOS servers.
As mentioned at the beginning of this webpage, you can also follow my 4-part series on setting up a local yumrepo if you need more details.