Linux 更新 yum 源

Siona

Linux 更新 yum 源

1. yum 默认源,安装包失败

# yum 安装失败。。。
# yum install libXext.x86_64
[root@javaNginx program]
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Could not get metalink https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=x86_64 error was
12: Timeout on https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=x86_64: (28, 'Resolving timed out after 30540 milliseconds')
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=extras&infra=stock error was
12: Timeout on http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=extras&infra=stock: (28, 'Resolving timed out after 30539 milliseconds')

默认源,已停止维护。

2. 设置阿里源

# ① 
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

# ② 
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo

3. yum 缓存

# ③
# 可以先清理缓存,然后生成新的缓存
sudo yum clean all && yum makecache

# 或者直接 yum update,
sudo yum update

yum 设置代理

yum 的存在使 Centos 上软件的安装、配置、升级、卸载变得十分的方便, 但是当安装 Centos 的机器是通过代理服务器访问外网的话, yum 的使用就变得无从下手了,以下介绍以下怎样为yum配置代理地址及代理用户, 使在代理上网的环境下亦能享受 yum 带来的方便,而不一定要去进行 make & make install。

用 vi 编辑器打开 yum 配置文件,一般情况下: vi /etc/yum.conf

打开 yum 的配置文件之后,在文件最后加上代理服务器的协议、地址、端口,如果代理服务器需要用户认证话,同时加上认证用户的用户名和密码。

代理服务器不需要认证:加上 proxy=协议://代理服务器地址:端口 (如:proxy=http://192.168.1.1:7890)

代理服务器需要认证用户:加上 proxy=协议://代理服务器地址:端口 (如:proxy=http://192.168.1.1:7890)

                        proxy_username=代理服务器用户名

                        proxy_password=代理服务器密码

保存退出后,就可以使用 yum 轻松的安装软件了。

# 实际操作
vi /etc/yum.conf

# 添加以下命令
proxy=http://192.168.1.1:7890

ESC
:wq
# 即可


# 仅针对当前命令行,有时候不可用,直接用上述修改 yum 配置文件即可。
export https_proxy=http://192.168.1.100:7890 http_proxy=http://192.168.1.100:7890 all_proxy=socks5://192.168.1.100:7890
Last Updated 8/29/2024, 3:09:35 AM