首先得保证虚拟机的网络(network)及ssh配置正确,具体不细说,网上很多教程说的很清楚,一步一步跟着配就行
一般yum普通命令可以用,但是yum install xx的时候就会报错,报错有很多种,我遇到的是镜像的问题,网上有很多说是本地镜像源的问题,建议换源,那源又要下载,下载又要涉及到比如wget之类的下载命令工具,但是偏偏虚拟机上又没有,就造成恶性循环,这会儿上面提到的ssh就派上用场了
镜像文件配置可以参考http://mirrors.163.com/.help/centos.html中的操作,根据自己的centos系统找到合适自己系统的镜像源,当然做这步之前先把原来的那个文件备份好,具体位置应该在/etc/yum.repos.d中,备份操作就不说了,移动、拷贝随你便
下载好镜像文件
接下来使用shell软件连接ssh,到/etc/yum.repos.d文件夹,创建一个CentOS-Base.repo
我的是centos7,就下载7的源,用编辑软件打开,将下面的内容复制到CentOS-Base.repo中,保存退出
vi 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 - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
baseurl=http://mirrors.163.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - 163.com
baseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
然后执行
yum clean all
yum makecache
就搞定了