• nginx代理yum


    适用场景:有多台服务器,但是只有1台服务器可以出公网,此时即可使用如下方式,进行yum代理,解决内网服务器不能yum的尴尬。

    一、首先需要把/etc/yum.repos.d下的文件备份到bak,然后留一个CentOS-Base.repo。编辑这个文件,我使用的是科大的yum源。

    如下代码:

    # CentOS-Base.repo
    #
    # The mirror system uses the connecting IP address of the client and the
    # update status of each mirror to pick mirrors that are updated to and
    # geographically close to the client. You should use this for CentOS updates
    # unless you are manually picking other mirrors.
    #
    # If the mirrorlist= does not work for you, as a fall back you can try the
    # remarked out baseurl= line instead.
    #
    #

    [base]
    name=CentOS-$releasever - Base
    #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
    baseurl=http://mirrors.ustc.edu.cn/centos/$releasever/os/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

    #released updates
    [updates]
    name=CentOS-$releasever - Updates
    # mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
    baseurl=http://mirrors.ustc.edu.cn/centos/$releasever/updates/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

    #additional packages that may be useful
    [extras]
    name=CentOS-$releasever - Extras
    # mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
    baseurl=http://mirrors.ustc.edu.cn/centos/$releasever/extras/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

    #additional packages that extend functionality of existing packages
    [centosplus]
    name=CentOS-$releasever - Plus
    # mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
    baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/centosplus/$basearch/
    gpgcheck=1
    enabled=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

    ################################################################

    二、然后需要编辑内网服务器另一个配置文件:vi /etc/yum.conf       需要注意   proxy=http://172.21.7.20:3621,这里是配置代理的ip和端口,就是可出公网的那台服务器的nginx端口。

    [main]
    cachedir=/var/cache/yum/$basearch/$releasever
    keepcache=0
    debuglevel=2
    logfile=/var/log/yum.log
    exactarch=1
    obsoletes=1
    gpgcheck=1
    plugins=1
    installonly_limit=5
    bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
    distroverpkg=centos-release
    proxy=http://172.21.7.20:3621
    http_caching=none
    # This is the default, if you make this bigger yum won't see if the metadata
    # is newer on the remote and so you'll "gain" the bandwidth of not having to
    # download the new metadata and "pay" for it by yum not having correct
    # information.
    # It is esp. important, to have correct metadata, for distributions like
    # Fedora which don't keep old packages around. If you don't like this checking
    # interupting your command line usage, it's much better to have something
    # manually check the metadata once an hour (yum-updatesd will do this).
    # metadata_expire=90m

    # PUT YOUR REPOS HERE OR IN separate files named file.repo
    # in /etc/yum.repos.d

    ################################################################

    三、设置nginx代理

    在可出公网的那台服务器设置nginx代理:添加如下配置


    server {
    listen 3621;
    #禁用multipart range功能
    max_ranges 1;
    server_name _;
    server_tokens off;
    location / {
    access_log /data3/log1/nginx/mirrors.log;
    proxy_pass http://mirrors.ustc.edu.cn;
    }
    }

    保存,退出,重启nginx。

    此时在内网服务器上执行yum makecache fast,之后内网服务器就可以正常使用yum了,再也不用上传5G的镜像资源挂载了!!!!

  • 相关阅读:
    java类,接口浅谈
    人月神话阅读笔记01
    学习进度条14
    学习进度条13
    每日站立会议10(完结)
    每日站立会议09
    每日站立会议08
    构建之法阅读笔记06(完)
    每日站立会议07
    每日站立会议06
  • 原文地址:https://www.cnblogs.com/yudai/p/10985758.html
Copyright © 2020-2023  润新知