centos设置yum
# Centos7配置yum本地代理
公司内部服务器不允许上网,安装好Linux系统后需要在线安装一些软件时无法使用在线安装,此时可借助内部可以上网的电脑或服务进行代理访问。当然可以可以通过安装本地yum服务或者使用下载离线安装包进行安装。
# 1.验证服务器是否可以在线安装
执行yum安装尝试安装一个软件如下载软件wget
[root@Q6 ~]# yum install wget
已加载插件:fastestmirror
Determining fastest mirrors
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was
14: curl#7 - "Failed to connect to 2604:1380:2001:d00::3: 网络不可达"
One of the configured repositories failed (未知)
1
2
3
4
5
6
2
3
4
5
6
网络不可达说明服务器无法通过yum方式安装,此时可以下载离线安装包方式,或者设置本地局域网代理
# 2.搭建Nginx环境
选择一台可以上网的服务器; proxy_pass 地址,使用系统Linux系统预设baserul地址部分,Nginx片段代码
server {
listen 38111;
location / {
proxy_pass http://mirrors.aliyun.com/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
此处配置的是阿里云代理,可以配置默认的centos下载源
设置好代理,可以访问一下是否可以正常使用 [http://192.168.1.2:38111/centos/7/os/x86_64/repodata/repomd.xml]访问出现下图说明代理正常
# 3.Linux Yum文件修改
系统yum文件/ect/yum.repos.d/CentOS-Base.repo
# 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&infra=$infra
#baseurl=http://mirror.centos.org/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&infra=$infra
#baseurl=http://mirror.centos.org/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&infra=$infra
#baseurl=http://mirror.centos.org/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&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
备份文件,以防止修改错误无法还原
文件修改如下:采用域名部分替换成Nginx地址
# 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 - 192.168.1.2:38111
failovermethod=priority
baseurl=http://192.168.1.2:38111/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://192.168.1.2:38111/centos/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates - 192.168.1.2:38111
failovermethod=priority
baseurl=http://192.168.1.2:38111/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://192.168.1.2:38111/centos/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - 192.168.1.2:38111
failovermethod=priority
baseurl=http://192.168.1.2:38111/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://192.168.1.2:38111/centos/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - 192.168.1.2:38111
failovermethod=priority
baseurl=http://192.168.1.2:38111/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://192.168.1.2:38111/centos/RPM-GPG-KEY-CentOS-7
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - 192.168.1.2:38111
failovermethod=priority
baseurl=http://192.168.1.2:38111/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://192.168.1.2:38111/centos/RPM-GPG-KEY-CentOS-7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# 4.更新centos本地yum
文件修改成功后执行以下命令,清空软件源,重新生成缓存
#yum clean all
#yum makecache
# 运行结果
[root@Q6 yum.repos.d]# yum clean all
已加载插件:fastestmirror
正在清理软件源: base extras updates
Cleaning up list of fastest mirrors
[root@Q6 yum.repos.d]# yum makecache
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/10): base/7/x86_64/group_gz | 153 kB 00:00:00
(2/10): base/7/x86_64/primary_db | 6.1 MB 00:00:01
(3/10): base/7/x86_64/filelists_db | 7.2 MB 00:00:02
(4/10): extras/7/x86_64/primary_db | 247 kB 00:00:00
(5/10): extras/7/x86_64/other_db | 148 kB 00:00:00
(6/10): base/7/x86_64/other_db | 2.6 MB 00:00:01
(7/10): extras/7/x86_64/filelists_db | 277 kB 00:00:01
(8/10): updates/7/x86_64/filelists_db | 8.7 MB 00:00:02
(9/10): updates/7/x86_64/other_db | 1.0 MB 00:00:00
(10/10): updates/7/x86_64/primary_db | 16 MB 00:00:04
元数据缓存已建立
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 5.测试验证
[root@Q6 home]# yum install wget
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 wget.x86_64.0.1.14-18.el7_6.1 将被 安装
--> 解决依赖关系完成
依赖关系解决
====================================================================================================================
Package 架构 版本 源 大小
====================================================================================================================
正在安装:
wget x86_64 1.14-18.el7_6.1 base 547 k
事务概要
====================================================================================================================
安装 1 软件包
总下载量:547 k
安装大小:2.0 M
Is this ok [y/d/N]: y
Downloading packages:
警告:/var/cache/yum/x86_64/7/base/packages/wget-1.14-18.el7_6.1.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY
wget-1.14-18.el7_6.1.x86_64.rpm 的公钥尚未安装
wget-1.14-18.el7_6.1.x86_64.rpm | 547 kB 00:00:00
从 http://192.168.1.2:38111/centos/RPM-GPG-KEY-CentOS-7 检索密钥
导入 GPG key 0xF4A80EB5:
用户ID : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
指纹 : 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
来自 : http://192.168.1.2:38111/centos/RPM-GPG-KEY-CentOS-7
是否继续?[y/N]:y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : wget-1.14-18.el7_6.1.x86_64 1/1
验证中 : wget-1.14-18.el7_6.1.x86_64 1/1
已安装:
wget.x86_64 0:1.14-18.el7_6.1
完毕!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
验证没有问题!
更新于: 2022/05/24 23:55:22