今天安装服务器环境碰到一个问题yum命令安装GCC等环境报错找不到镜像(服务器是政府给的,可能是为了安全很多东西都要自己配置包括hosts)
1.首先保障服务器能通外网
这里ping一下mirrors.ustc.edu.cn 这个地址也是一会yum镜像的地址(中科大)
ping mirrors.ustc.edu.cn
可能会报错
ping: unknown host mirrors.ustc.edu.cn
2.修改hosts文件
进入/etc/hosts 修改 加入以下两行
202.141.176.110 mirrors.ustc.edu.cn
208.100.23.71 vault.centos.org
reboot命令 重启服务器
ping通进入下一步
3.卸载重装yum安装包
rpm -qa|grep yum
# 移除
rpm -e yum-*
# 下载
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-34.el7.noarch.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget http://vault.centos.org/7.2.1511/os/x86_64/Packages/yum-3.4.3-132.el7.centos.0.1.noarch.rpm
# 安装
rpm -ivh yum-*
4.配置/etc/yum.repos.d/ 配置文件
cd /etc/yum.repos.d/
# 备份
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
修改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
baseurl=https://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=https://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=https://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
修改完成后最终要的三步
yum clean all
rm -rf /var/cache/yum/
yum makecache
5.测试
尝试安装GCC等
yum install gcc gcc-c++ gcc-g77
成功!!