美文网首页
【Linux基础之yum源】centos配置本地yum源

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

作者: 微凉哇 | 来源:发表于2017-12-29 18:59 被阅读161次

    适用场景

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

    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
    

    相关文章

      网友评论

          本文标题:【Linux基础之yum源】centos配置本地yum源

          本文链接:https://www.haomeiwen.com/subject/virwgxtx.html