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
-
Upload the CentOS 7 ISO image to the local
bckdirectory, ensuring it matches the version used for installation. -
Create a mount point and perform mounting:
mkdir -p /opt/yum_Centos7
- Mount the ISO image:
mount /opt/bck/CentOS-7-x86_64-DVD-1804.iso /opt/yum_Centos7 -o loop
- 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
- Generate repository cache and test installation:
yum clean all
yum makecache
Remote Offline Repository via Nginx
- 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;
}
}
-
Place files to be served under the HTML directory.
-
Start the Nginx service and access via web browser at IP:port.
-
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
- Rebuild the cache and verify installation:
yum clean all
yum makecache
Creating Offline RPM Packages
- 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
- Modify yum configuration to retain downloaded packages:
sed -i 's/keepcache=0/keepcache=1/g' /etc/yum.conf
- 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
- 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/
- Generate repository metadata:
cd /opt/bck/
createrepo .
- Package the repository for distribution:
cd ..
tar zcf bck_yum.tar.gz bck
- 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