搭建http yum源:

注:

1、我是在1台Ubuntu上搭建的http (因为我同时也要做Ubuntu的本地软件源)

2、CentOS的yum包需先在1台CentOS上createrepo


在1台CentOS服务器里先把ISO Packages里的包拷出来

mkdir /iso

mount -o loop CentOS-7-x86_64-DVD-2009.iso /iso

mkdir /space/yum

rsync -av --progress /iso/Packages/* /space/yum/

createrepo -d /space/yum/ (这步一定要做,会生成repodata目录)

在1台Ubuntu上搭建http

mkdir -p /space/mirror/centos7.9

安装apache2

apt-get install apache2

vi /etc/apache2/sites-enabled/000-default.conf

<VirtualHost *:8080> (默认为80)

DocumentRoot /space/mirror (默认为/var/www/html)

:wq

vi /etc/apache2/ports.conf

Listen 8080

:wq

vi /etc/apache2/apache2.conf

<Directory /space/mirror/>

Options Indexes FollowSymLinks

AllowOverride None

Require all granted

</Directory>

:wq

service apache2 restart

访问:http://ip:8080 (先确保apache可以正常访问)

安装nginx:

apt-get install nginx

vi /etc/nginx/sites-enabled/default

upstream apt-mirror {

server 127.0.0.1:8080;

}

server {

root /space/mirror;

......


 location /centos7.9/ {
    proxy_pass http://xxx.ming.com/centos7.9/yum/;
    proxy_redirect off;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;
   }

}

:wq

vi /etc/nginx/nginx.conf

http {

......

    client_header_buffer_size 512k;
    large_client_header_buffers 4 512k;
    client_max_body_size 100m;

}

:wq

service nginx restart

访问:http://xxx.ming.com/centos7.9 (确保能正常访问)

CentOS客户端设置:

vi /etc/yum.repos.d/CentOS-Base.repo

[base]

name=CentOS-$releasever - Base

baseurl=http://xxx.ming.com/centos7.9/

gpdcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

:wq

验证:

yum update

yum install xxx