Configuring YUM Repository Sources

Setting Up YUM Repositories

Online Repository Configuration

Alibaba Cloud Repository

 curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
 sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
 yum install epel-release -y
 yum clean all
 yum makecache

Huawei Cloud x86 Server Mirror

 mkdir -p /etc/yum.repos.d/repo_bak/
 mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/repo_bak/
 curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.myhuaweicloud.com/repo/CentOS-Base-7.repo
 yum clean all
 yum makecache

Offline Local Repository

  1. Upload the CentOS 7 ISO image to the local bck directory, ensuring it matches the version used for installation.

  2. Create a mount point and perform mounting:

 mkdir -p /opt/yum_Centos7
  1. Mount the ISO image:
 mount /opt/bck/CentOS-7-x86_64-DVD-1804.iso /opt/yum_Centos7 -o loop
  1. Configure the repository:
 cat > /etc/yum.repos.d/Centos7_bck.repo <<EOF
 [local]
 name=local
 baseurl=file:///opt/yum_Centos7
 enabled=1
 gpgcheck=0
 EOF
  1. Generate repository cache and test installation:
 yum clean all
 yum makecache

Remote Offline Repository via Nginx

  1. Install Nginx on the first machine (192.168.150.129) and modify its configuration:
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;

events {
    worker_connections 1024;
}

http {
    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    log_format main '$remote_addr - $remote_user [$time_local] "$request" '
                    '$status $body_bytes_sent "$http_referer" '
                    '"$http_user_agent" "$http_x_forwarded_for"';

    access_log /var/log/nginx/access.log main;

    sendfile on;
    keepalive_timeout 65;

    include /etc/nginx/conf.d/*.conf;
}

Configuration for default site:

server {
    listen 80;
    listen [::]:80;
    server_name localhost;

    location / {
        root /usr/share/nginx/html;
        autoindex on;
        autoindex_exact_size on;
    }

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }
}
  1. Place files to be served under the HTML directory.

  2. Start the Nginx service and access via web browser at IP:port.

  3. On the second machine (192.168.150.128), configure the repository:

 cat > /etc/yum.repos.d/Centos7_bck.repo <<EOF
 [local]
 name=local
 baseurl=http://192.168.150.129:80
 enabled=1
 gpgcheck=0
 EOF
  1. Rebuild the cache and verify installation:
 yum clean all
 yum makecache

Creating Offline RPM Packages

  1. Set up an online repository in the test environment:
 cd /etc/yum.repos.d/
 mkdir bck
 mv CentOS-* bck/

 curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
 sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
 yum install epel-release -y
 yum clean all
 yum makecache
  1. Modify yum configuration to retain downloaded packages:
 sed -i 's/keepcache=0/keepcache=1/g' /etc/yum.conf
  1. Install required packages:
 yum install autoconf bash-completion bind-utils cifs-utils createrepo dstat expect ftp gcc gcc-c++ glibc iotop lrzsz lsof make net-tools nfs-utils openssl openssl-devel openvpn pam-devel pcre-devel python2-pip rsync screen sysstat tcpdump telnet tree unzip vim wget yum-utils zip haveged
  1. Move installed RPMs to a backup directory:
 mkdir -p /opt/bck
 find /var/cache/yum/x86_64/7/ -name "*.rpm" | xargs -I {} mv {} /opt/bck/
  1. Generate repository metadata:
 cd /opt/bck/
 createrepo .
  1. Package the repository for distribution:
 cd ..
 tar zcf bck_yum.tar.gz bck
  1. On-site operatinos upon receiving the archive:
 # Extract archive to /opt
 tar zxmf bck_yum.tar.gz 

 # Backup existing repositories
 mkdir -p /etc/yum.repos.d/bck
 mv /etc/yum.repos.d/CentOS-* /etc/yum.repos.d/bck/

 # Create new local repository
 cat > /etc/yum.repos.d/bck_yum.repo <<EOF
 [local]
 name=local
 baseurl=file:///opt/bck
 enabled=1
 gpgcheck=0
 EOF

 # Rebuild cache and install packages
 yum clean all
 yum makecache
 yum install autoconf bash-completion bind-utils cifs-utils createrepo dstat expect ftp gcc gcc-c++ glibc iotop lrzsz lsof make net-tools nfs-utils openssl openssl-devel openvpn pam-devel pcre-devel python2-pip rsync screen sysstat tcpdump telnet tree unzip vim wget yum-utils zip haveged --skip-broken

Tags: Yum repository Linux centos Offline

Posted on Wed, 24 Jun 2026 18:15:48 +0000 by phpmania1