Linux serverNETWORK ADMINISTRATIONS

How to Create Local Yum Repo on CentOS 7

Step 1: Configure Network Access

yum install httpd

Step 2: Create Yum Local Repository

yum install createrepo

yum install yum-utils

Step 3: Create a Directory to Store the Repositories

mkdir –p /var/www/html/repos/{base,centosplus,extras,updates}

Step 4: Synchronize HTTP Repositories

reposync -g -l -d -m –repoid=base –newest-only –download-metadata –download_path=/var/www/html/repos/

reposync -g -l -d -m –repoid=centosplus –newest-only –download-metadata –download_path=/var/www/html/repos/

reposync -g -l -d -m –repoid=extras –newest-only –download-metadata –download_path=/var/www/html/repos/

reposync -g -l -d -m –repoid=updates –newest-only –download-metadata –download_path=/var/www/html/repos/

Step 5: Create the New Repository

createrepo /var/www/html

Step 6: Setup Local Yum Repository on Client System

mv /etc/yum.repos.d/*.repo /tmp/

Create and edit a new config file:

nano /etc/yum.repos.d/remote.repo

In the new file, enter the command (replacing the IP address with the IP address of your server):

[remote]
name=RHEL Apache
baseurl=http://IP Address
enabled=1
gpgcheck=0

Finally, save the file and exit.
]
Test the Configuration

While still on the client system, run a command to install a package with the yum package manager:

yum install httpd

For NGINX

#yum install nginx -y

#systemctl start nginx
#systemctl enable nginx
#systemctl status nginx

#yum install createrepo yum-utils

#mkdir -p /var/www/html/repos/{base,centosplus,extras,updates}

# reposync -g -l -d -m –repoid=base –newest-only –download-metadata –download_path=/var/www/html/repos/
# reposync -g -l -d -m –repoid=centosplus –newest-only –download-metadata –download_path=/var/www/html/repos/
# reposync -g -l -d -m –repoid=extras –newest-only –download-metadata –download_path=/var/www/html/repos/
# reposync -g -l -d -m –repoid=updates –newest-only –download-metadata –download_path=/var/www/html/repos/

# createrepo -g comps.xml /var/www/html/repos/base/
# createrepo -g comps.xml /var/www/html/repos/centosplus/
# createrepo -g comps.xml /var/www/html/repos/extras/
# createrepo -g comps.xml /var/www/html/repos/updates/

# vim /etc/nginx/conf.d/repos.conf

server {
listen 80;
server_name name or ip for server;
root /var/www/html/repos;
location / {
index index.php index.html index.htm;
autoindex on; #enable listing of directory index
}
}

For Cron Script

#vim /etc/cron.daily/update-localrepos

#!/bin/bash
##specify all local repositories in a single variable
LOCAL_REPOS=”base centosplus extras updates”
##a loop to update repos one at a time
for REPO in ${LOCAL_REPOS}; do
reposync -g -l -d -m –repoid=$REPO –newest-only –download-metadata –download_path=/var/www/html/repos/
createrepo -g comps.xml /var/www/html/repos/$REPO/
done

#chmod 755 /etc/cron.daily/update-localrepos

#vim /etc/yum.repos.d/local-repos.repo

[local-base]
name=CentOS Base
baseurl=http://name or ip of server/base/
gpgcheck=0
enabled=1

[local-centosplus]
name=CentOS CentOSPlus
baseurl=http://name or ip of server/centosplus/
gpgcheck=0
enabled=1

[local-extras]
name=CentOS Extras
baseurl=http://name or ip of server/extras/
gpgcheck=0
enabled=1

[local-updates]
name=CentOS Updates
baseurl=http://name or ip of server/updates/
gpgcheck=0
enabled=1

Test the configuration

#yum repolist
#yum repolist all

source

centos 7

Leave a Reply

Your email address will not be published. Required fields are marked *