Tuesday 24 September 2013

Setup local repo with Centos 6

SOURCE: http://someideas.net/redhat/centos/setup-local-repository-centos-64


Since I'm doing a lot of test I decided to create a vmachine with local repository so by that way I'm not downloading the same packages over and over..

1. Install required software.

a. Install CentOS Base.
b. Install apache
yum install httpd
Once is installed we need to create folder structure, in my case CentOS 6.4 x64:
mkdir -p /var/www/html/CentOS/6/os/x86_64/Packages
mkdir -p /var/www/html/CentOS/6/updates/x86_64/Packages

2. The Base + Update Repository

Select an rsync mirror for updates from CentOS Mirror List, I'm in Spain so:
rsync://rsync.cica.es/CentOS/
then the command will be:
rsync -avrt rsync://rsync.cica.es/CentOS/6.4/os/x86_64/Packages/ --exclude=debug/ /var/www/html/CentOS/6/os/x86_64/Packages/
rsync -avrt rsync://rsync.cica.es/CentOS/6.4/updates/x86_64/Packages/ --exclude=debug/ /var/www/html/CentOS/6/updates/x86_64/Packages/
Create .repo file:
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo-BACKUP
vi /etc/yum.repos.d/CentOS-Base.repo
[base.local]
name=CentOS-$releasever - Base
baseurl=http://centoslocalrepo/CentOS/$releasever/os/$basearch/
gpgcheck=0 [update.local]
name=CentOS-$releasever - Updates
baseurl=http://centoslocalrepo/CentOS/$releasever/updates/$basearch/
gpgcheck=0

3. Create Repo

createrepo -v /var/www/html/CentOS/6/os/x86_64
createrepo -v /var/www/html/CentOS/6/updates/x86_64

4. Final details + client machines

in order to add my local repo to all my CentOS machines I have to make some cosmetic changes:
* in server:
vi /etc/sysconfig/iptables
and add http access:
[...]
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 80 -j ACCEPT
[...]
service iptables restart
service httpd start
chkconfig httpd on
cp /etc/yum.repos.d/CentOS-Base.repo /var/www/html/
* in clients:
cd /etc/yum.repos.d/
mv CentOS-Base.repo CentOS-Base.repo-BACKUP
curl -O centoslocalrepo/CentOS-Base.repo
so everything is done, except for 1 thing, updates
for this I have to create a simple script and add to cron that launches rsync and createrepo, so:
touch /opt/rh/localrepoupdate
chmod +x /opt/rh/localrepoupdate
vi /opt/rh/localrepoupdate
#!/bin/bash
rsync -avrt rsync://rsync.cica.es/CentOS/6.4/updates/x86_64/Packages/ --exclude=debug/ /var/www/html/CentOS/6/updates/x86_64/Packages/
createrepo -v /var/www/html/CentOS/6/updates/x86_64
and
then add to cron weekly /opt/rh/localrepoupdate and that's it!

5. Create clone local repository

rsync -avrt centoslocalrepo:/var/www/html/CentOS/6/os/x86_64/ /var/www/html/CentOS/6/os/x86_64/
rsync -avrt centoslocalrepo:/var/www/html/CentOS/6/updates/x86_64/ /var/www/html/CentOS/6/updates/x86_64/

link1: http://www.unixmen.com/setup-local-yum-repository-on-centos-rhel-scientific-linux-6-4/
link2: http://www.howtoforge.com/creating_a_local_yum_repository_centos

No comments: