【Linux使用】Centos 7 YUM仓库配置文件代理服务器设置

版权声明:转载必须保留原出处,没有书面许可不可用于商用目的, https://blog.csdn.net/qq_43401808/article/details/89226962

系统信息

[tony@tony-compute1 ~]$ cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[tony@tony-compute1 ~]$ uname -a
Linux tony-compute1 3.10.0-957.10.1.el7.x86_64 #1 SMP Mon Mar 18 15:06:45 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

所有仓库都位于外网,访问都通过代理服务器时

修改/etc/yum.conf,在[main]节下添加代理服务器设置。

[tony@tony-compute1 ~]$ sudo vim /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
...distroverpkg=centos-release
<font color=red>proxy=http://$user:$password@$proxy:$port</font>

注意:代理服务器必须是一个URL格式,即以http://,ftp://,https://,socks4://,socks4a://,socks5://,socks5h://开头,否则会得到如下错误:

Options error: Error parsing “proxy = ‘user:password@proxy:8888’”:
URL must be http, ftp, https, socks4, socks4a, socks5 or socks5h not “”

部分仓库在内网,部分仓库在外网,代理服务器设置

事实上,代理服务器的设置是可以按仓库分别设定的。

如果大多数仓库访问都在外网,则在yum.conf中设置代理服务器,对于放置在内网的仓库,则设置为不使用代理服务器。具体步骤如下:

  • 在/etc/yum.conf中设置主代理服务器,参看上文
  • 在/etc/yum.repos.d目录找到仓库配置文件(以.repo后缀结尾的都是仓库配置文件),不使用代理服务器的仓库配置下面都加上proxy=_none_设置。
    例如
[tony@tony-controller yum.repos.d]$ cat CentOS-Base.repo
[base]
baseurl = http://linux-ftp.local/pub/mirrors/centos/$releasever/os/$basearch
enabled = 1
gpgcheck = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
name = CentOS-$releasever - Base
proxy=_none_

[updates]
baseurl = http://linux-ftp.local/pub/mirrors/centos/$releasever/updates/$basearch/
enabled = 1
gpgcheck = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
name = CentOS-$releasever - Updates
proxy=_none_

[extras]
baseurl = http://linux-ftp.local/pub/mirrors/centos/$releasever/extras/$basearch/
enabled = 1
gpgcheck = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
name = CentOS-$releasever - Extras
proxy=_none_

[centosplus]
baseurl = http://linux-ftp.local/pub/mirrors/centos/$releasever/centosplus/$basearch/
enabled = 1
gpgcheck = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
name = CentOS-$releasever - Plus
proxy=_none_

反过来,如果大部分仓库在内网,则默认不使用代理服务器,对于需要代理服务器的仓库则单独设置;甚至对于不同的仓库可以分别设置使用不同的代理服务器。

猜你喜欢

转载自blog.csdn.net/qq_43401808/article/details/89226962