Centos7 yum出现Could not retrieve mirrorlist http://mirrorlist.centos.org/

这篇博客详细介绍了在Linux系统中遇到的网络配置问题及解决方案,包括DNS设置、网络服务启停、文件操作和YUM包管理等。通过实例展示了如何解决域名解析错误、查看和编辑文件内容、管理文件系统以及使用YUM进行软件安装和更新。此外,还涵盖了常用的Linux命令和快捷键,帮助用户更高效地操作Linux环境。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题:

Loaded plugins: fastestmirror, langpacks
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org"


 One of the configured repositories failed (Unknown),
 and yum doesn't have enough cached data to continue. At this point the only
 safe thing yum can do is fail. There are a few ways to work "fix" this:

     1. Contact the upstream for the repository and get them to fix the problem.

     2. Reconfigure the baseurl/etc. for the repository, to point to a working
        upstream. This is most often useful if you are using a newer
        distribution release than is supported by the repository (and the
        packages for the previous distribution release still work).

     3. Run the command with the repository temporarily disabled
            yum --disablerepo=<repoid> ...

     4. Disable the repository permanently, so yum won't use it by default. Yum
        will then just ignore the repository until you permanently enable it
        again or use --enablerepo for temporary usage:

            yum-config-manager --disable <repoid>
        or
            subscription-manager repos --disable=<repoid>

     5. Configure the failing repository to be skipped, if it is unavailable.
        Note that yum will try to contact the repo. when it runs most commands,
        so will have to try and fail each time (and thus. yum will be be much
        slower). If it is a very temporary problem though, this is often a nice
        compromise:

            yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true

Cannot find a valid baseurl for repo: base/7/x86_64

出现原因:
域名解析DNS的问题

解决办法:
设置DNS域名地址

vi  /etc/resolv.conf
#添加如下内容
meserver 8.8.8.8
nameserver 8.8.4.4
重启网络

service network restart

centos7指令大全

一、常用命令
1.文件与目录操作
命令	解析
cd /home	进入 ‘/home’ 目录
cd ..	返回上一级目录
cd ../..	返回上两级目录
cd -	返回上次所在目录
cp file1 file2	将file1复制为file2
cp -a dir1 dir2	复制一个目录
cp -a /tmp/dir1 .	复制一个目录到当前工作目录(.代表当前目录)
ls	查看目录中的文件
ls -a	显示隐藏文件
ls -l	显示详细信息
ls -lrt	按时间显示文件(l表示详细列表,r表示反向排序,t表示按时间排序)
pwd	显示工作路径
mkdir dir1	创建 ‘dir1’ 目录
mkdir dir1 dir2	同时创建两个目录
mkdir -p /tmp/dir1/dir2	创建一个目录树
mv dir1 dir2	移动/重命名一个目录
rm -f file1	删除 ‘file1’
rm -rf dir1	删除 ‘dir1’ 目录及其子目录内容
2.查看文件内容
命令	解析
cat file1	从第一个字节开始正向查看文件的内容
head -2 file1	查看一个文件的前两行
more file1	查看一个长文件的内容
tac file1	从最后一行开始反向查看一个文件的内容
tail -3 file1	查看一个文件的最后三行
vi file	打开并浏览文件
3.文本内容处理
命令	解析
grep str /tmp/test	在文件 ‘/tmp/test’ 中查找 “str”
grep ^str /tmp/test	在文件 ‘/tmp/test’ 中查找以 “str” 开始的行
grep [0-9] /tmp/test	查找 ‘/tmp/test’ 文件中所有包含数字的行
grep str -r /tmp/*	在目录 ‘/tmp’ 及其子目录中查找 “str”
diff file1 file2	找出两个文件的不同处
sdiff file1 file2	以对比的方式显示两个文件的不同
vi file	
操作	解析
i	进入编辑文本模式
Esc	退出编辑文本模式
:w	保存当前修改
:q	不保存退出vi
:wq	保存当前修改并退出vi
4.查询操作
命令	解析
find / -name file1	从 ‘/’ 开始进入根文件系统查找文件和目录
find / -user user1	查找属于用户 ‘user1’ 的文件和目录
find /home/user1 -name *.bin	在目录 ‘/ home/user1’ 中查找以 ‘.bin’ 结尾的文件
find /usr/bin -type f -atime +100	查找在过去100天内未被使用过的执行文件
find /usr/bin -type f -mtime -10	查找在10天内被创建或者修改过的文件
locate *.ps	寻找以 ‘.ps’ 结尾的文件,先运行 ‘updatedb’ 命令
find -name ‘*.[ch]’ | xargs grep -E ‘expr’	在当前目录及其子目录所有.c和.h文件中查找 ‘expr’
find -type f -print0 | xargs -r0 grep -F ‘expr’	在当前目录及其子目录的常规文件中查找 ‘expr’
find -maxdepth 1 -type f | xargs grep -F ‘expr’	在当前目录中查找 ‘expr’
5.压缩、解压
命令	解析
bzip2 file1	压缩 file1
bunzip2 file1.bz2	解压 file1.bz2
gzip file1	压缩 file1
gzip -9 file1	最大程度压缩 file1
gunzip file1.gz	解压 file1.gz
tar -cvf archive.tar file1	把file1打包成 archive.tar(-c: 建立压缩档案;-v: 显示所有过程;-f: 使用档案名字,是必须的,是最后一个参数)
tar -cvf archive.tar file1 dir1	把 file1,dir1 打包成 archive.tar
tar -tf archive.tar	显示一个包中的内容
tar -xvf archive.tar	释放一个包
tar -xvf archive.tar -C /tmp	把压缩包释放到 /tmp目录下
zip file1.zip file1	创建一个zip格式的压缩包
zip -r file1.zip file1 dir1	把文件和目录压缩成一个zip格式的压缩包
unzip file1.zip	解压一个zip格式的压缩包到当前目录
unzip test.zip -d /tmp/	解压一个zip格式的压缩包到 /tmp 目录
6.yum安装器
命令	解析
yum -y install [package]	下载并安装一个rpm包
yum localinstall [package.rpm]	安装一个rpm包,使用你自己的软件仓库解决所有依赖关系
yum -y update	更新当前系统中安装的所有rpm包
yum update [package]	更新一个rpm包
yum remove [package]	删除一个rpm包
yum list	列出当前系统中安装的所有包
yum search [package]	在rpm仓库中搜寻软件包
yum clean [package]	清除缓存目录(/var/cache/yum)下的软件包
yum clean headers	删除所有头文件
yum clean all	删除所有缓存的包和头文件
7.网络相关
命令	解析
ifconfig eth0	显示一个以太网卡的配置
ifconfig eth0 192.168.1.1 netmask 255.255.255.0	配置网卡的IP地址
ifdown eth0	禁用 ‘eth0’ 网络设备
ifup eth0	启用 ‘eth0’ 网络设备
iwconfig eth1	显示一个无线网卡的配置
iwlist scan	显示无线网络
ip addr show	显示网卡的IP地址
8.系统相关
命令	解析
su -	切换到root权限(与su有区别)
shutdown -h now	关机
shutdown -r now	重启
top	罗列使用CPU资源最多的linux任务 (输入q退出)
pstree	以树状图显示程序
man ping	查看参考手册(例如ping 命令)
passwd	修改密码
df -h	显示磁盘的使用情况
cal -3	显示前一个月,当前月以及下一个月的月历
cal 10 1988	显示指定月,年的月历
date –date ‘1970-01-01 UTC 1427888888 seconds’	把一相对于1970-01-01 00:00的秒数转换成时间
二、XSheel 5相关操作
1.窗体快捷键
命令	解析
Ctrl + u	删除光标之前到行首的字符
Ctrl + k	删除光标之前到行尾的字符
Ctrl + c	取消当前行输入的命令,相当于Ctrl + Break
Ctrl + a	光标移动到行首(ahead of line),相当于通常的Home键
Ctrl + e	光标移动到行尾(end of line)
Ctrl + f	光标向前(forward)移动一个字符位置
Ctrl + b	光标往回(backward)移动一个字符位置
Ctrl + l	清屏,相当于执行clear命令
Ctrl + r	显示:号提示,根据用户输入查找相关历史命令(reverse-i-search)
Ctrl + w	删除从光标位置前到当前所处单词(word)的开头
Ctrl + t	交换光标位置前的两个字符
Ctrl + y	粘贴最后一次被删除的单词
Ctrl + Alt + d	显示桌面
Alt + b	光标往回(backward)移动到前一个单词
Alt + d	删除从光标位置到当前所处单词的末尾
Alt + F2	运行
Alt + F4	关闭当前窗口
Alt + F9	最小化当前窗口
Alt + F10	最大化当前窗口
Alt + Tab	切换窗口
Alt + 左键	移动窗口(或在最下面的任务栏滚动鼠标滑轮)
当你在Linux系统上使用yum工具安装软件包时,遇到"Could not retrieve mirrorlist http://mirrorlist.centos.org"这样的错误,通常意味着yum无法从CentOS官方镜像列表获取可用的软件包源。这可能是由于以下几个原因: 1. **网络连接问题**:检查你的网络是否稳定,或者尝试重启路由器、清空DNS缓存。 2. **镜像站点不可达**:CentOS镜像地址可能暂时无法访问,你可以更换到其他的镜像源,比如国内的阿里云、清华大学等提供的镜像。 3. **防火墙限制**:确认系统防火墙或安全软件是否阻止了对特定网址的访问,如有需要,可以临时关闭或者添加规则允许访问。 4. **yum配置文件问题**:检查`/etc/yum.conf` 或者 `/etc/yum.repos.d/` 中的mirrors设置,看是否有正确的URL。 5. **时间同步问题**:确保系统的日期和时间与互联网的时间保持一致,因为一些服务器可能会基于时间戳验证请求。 解决这个问题的一个通用步骤是编辑yum的配置文件,更新或添加一个有效的镜像源。例如: ```bash sudo vi /etc/yum.repos.d/CentOS-Mirrors.list ``` 然后替换原有的镜像URL为可用的镜像,如: ``` [base] name=CentOS-$releasever - Base mirrorlist=https://mirrors.aliyun.com/repo/CentOS-\$releasever/$basearch/ enabled=1 gpgcheck=1 ``` 保存并关闭文件后,运行命令让yum更新新的配置: ```bash sudo yum makecache fast ``` 接着再次尝试安装软件包: ```bash sudo yum install [package-name] ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值