【Linux基础之yum源】centos配置本地yum源

本文档提供了两种场景下的CentOS YUM源搭建流程,包括基于Windows的YUM源搭建和基于Linux 7.2的YUM源搭建。详细介绍了如何通过Nginx配置本地YUM源以及如何在服务器集群中进行YUM源配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

适用场景

服务器主机无法直接连接互联网。

centos系统rpm包及镜像下载地址

【rpm包下载地址】

centos7.3 http://vault.centos.org/7.3.1611/os/x86_64/Packages/

centos7.2 http://vault.centos.org/7.2.1511/os/x86_64/Packages/

centos7.1 http://vault.centos.org/7.1.1503/os/x86_64/Packages/

centos7.0 http://vault.centos.org/7.0.1406/os/x86_64/Packages/

centos6.9 http://mirrors.shuosc.org/centos/6.9/os/x86_64/Packages/

centos6.8 http://vault.centos.org/6.8/os/x86_64/Packages/

centos6.7 http://vault.centos.org/6.7/os/x86_64/Packages/

centos6.6 http://vault.centos.org/6.6/os/x86_64/Packages/

centos6.5 http://vault.centos.org/6.5/os/x86_64/Packages/

【镜像下载地址】

centos7.3 http://vault.centos.org/7.3.1611/isos/x86_64/

centos7.2 http://vault.centos.org/7.2.1511/isos/x86_64/

centos7.1 http://vault.centos.org/7.1.1503/isos/x86_64/

centos7.0 http://vault.centos.org/7.0.1406/isos/x86_64/

centos6.9 http://mirrors.shuosc.org/centos/6.9/isos/x86_64/

centos6.8 http://vault.centos.org/6.8/isos/x86_64/

centos6.7 http://vault.centos.org/6.7/isos/x86_64/

centos6.6 http://vault.centos.org/6.6/isos/x86_64/

centos6.5 http://vault.centos.org/6.5/isos/x86_64/

1.基于window的yum源搭建流程

适用场景:

本机可以直连服务器(互通)

1.下载nginx安装包

#下载地址
http://nginx.org/download/nginx-1.12.2.zip

2.解压配置

unzip nginx-1.12.2.zip

3.配置nginx,并制作启动、关闭脚本

#配置文件
server {
    listen       1234;
    server_name  localhost;
    location /6.5 {
        alias E:\yum\6.5;
        autoindex  on;
    }
    location /6.6 {
        alias E:\yum\6.6;
        autoindex  on;
    }
    location /6.7 {
        alias E:\yum\6.7;
        autoindex  on;
    }
    location /6.8 {
        alias E:\yum\6.8;
        autoindex  on;
    }
    location /6.9 {
        alias E:\yum\6.9;
        autoindex  on;
    }
    location /7.0 {
        alias E:\yum\7.0;
        autoindex  on;
    }
    location /7.1 {
        alias E:\yum\7.1;
        autoindex  on;
    }
    location /7.2 {
        alias E:\yum\7.2;
        autoindex  on;
    }
    location /7.3 {
        alias E:\yum\7.3;
        autoindex  on;
    }
    location /7.4 {
        alias E:\yum\7.4;
        autoindex  on;
    }
}

#启动脚本
@echo off
cd D:\Program Files (x86)\nginx-1.12.2\
start /b .\nginx.exe 
pause

#关闭脚本
@echo off
cd D:\Program Files (x86)\nginx-1.12.2\
.\nginx.exe -s stop
pause

4.下载任意版本镜像(以7.3为例)

#需下载DVD版或者Everything版本,如果是centos6只需挂载CD1
挂载镜像,将包里的Packages、repodata复制到E:\yum\7.4文件夹下(没有创建)

5.启动nginx、配置远程机器yum

rm -f /etc/yum.repos.d/*
#如果是centos6的话RPM-GPG-KEY-CentOS-7改为RPM-GPG-KEY-CentOS-6,192.168.1.1为你window端的ip
cat >> /etc/yum.repos.d/c7.repo <<
[c7repo]

name=c7repo

baseurl=http://192.168.1.1:1234/7.3

enabled=1

gpgcheck=1

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

6.远程Linux主机测试yum

#安装telnet测试
rpm -qa|grep telnet
如果存在就卸载
rpm -e telnet

yum clean all
yum -y install telnet

基于Linux7.2的yum源搭建流程

试用场景:
服务器集群间

1.上传系统安装镜像(匹配到小版本,非迷你版)挂载,并设置成开机挂载

mount -o loop ~/CentOS-7-x86_64-DVD-1511.iso /media
echo "mount -o loop ~/CentOS-7-x86_64-DVD-1511.iso /media" >> /etc/rc.local
chmod +x /etc/rc.local

2.配置成本地yum

rm -f /etc/yum.repos.d/*
#如果是centos6的话RPM-GPG-KEY-CentOS-7改为RPM-GPG-KEY-CentOS-6
cat >> /etc/yum.repos.d/c7.repo <<EOF
[c7repo]

name=c7repo

baseurl=file:///media

enabled=1

gpgcheck=1

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

yum clean all

3.安装nginx,配置可以对外提供的yum源,nginx.conf如下

user  root;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    #tcp_nopush     on;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;
    location / {
        root  /media;
        autoindex on;
    }

    }

#启动nginx
/opt/nginx/sbin/nginx
#开机自启动
echo "/opt/nginx/sbin/nginx" >> /etc/rc.local
chmod +x /etc/rc.local

4.使用该yum的客户端主机进行如下配置

#删除或备份其他/etc/yum.repos.d下的其他yum配置文件
rm -f /etc/yum.repos.d/*
#http://192.168.1.1/注意替换
cat >> /etc/yum.repos.d/custom.repo <<EOF
[customrepo]

name=customrepo

baseurl=http://192.168.1.1/ 

enabled=1

gpgcheck=1

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

EOF

5.客户端测试yum

yum clean all
rpm -qa|grep telnet
#有的话卸载
rpm -e telnet

yum -y install telnet
1.查看系统本身存在的版本 rpm -qa | grep yum 2.卸载centos7上存在的yum安装包 rpm -e 包 --nodeps 3.下载yum包(http://mirrors.163.com/centos/7/os/x86_64/Packages/) yum-metadata-parser-1.1.4-10.el7.x86_64 PackageKit-yum-1.0.7-6.el7.centos.x86_64 yum-utils-1.1.31-40.el7.noarch 下方两个一起装 yum-plugin-fastestmirror-1.1.31-40.el7.noarch yum-langpacks-0.4.2-7.el7.noarch yum-3.4.3-150.el7.centos.noarch yum-rhn-plugin-2.0.1-6.el7.noarch 4.安装yum包 rpm -ivh yum* 5.创建配置文件(/etc/yum.repos.d/CentOS-Base.repo) vi /etc/yum.repos.d/CentOS-Base.repo [base] name=CentOS-$releasever - Base - 163.com #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch;=$basearch&repo=os baseurl=http://mirrors.163.com/centos/(系统版本号)7/os/$basearch/ gpgcheck=1 gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 #released updates [updates] name=CentOS-$releasever - Updates - 163.com #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch;=$basearch&repo=updates baseurl=http://mirrors.163.com/centos/7/updates/$basearch/ gpgcheck=1 gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that may be useful [extras] name=CentOS-$releasever - Extras - 163.com #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch;=$basearch&repo=extras baseurl=http://mirrors.163.com/centos/7/extras/$basearch/ gpgcheck=1 gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that extend functionality of existing packages [centosplus] name=$releasever - Plus - 163.com baseurl=http://mirrors.163.com/centos/7/centosplus/$basearch/ gpgcheck=1 enabled=0 gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 每一个baseurl的centos后都改成自己系统的版本号 6.执行命令 yum clean all yum makecache yum install telnet
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值