Ubuntu18.04突然不能更新apt源?实践出真理ack比grep香太多了!

2024-01-20 14:30

本文主要是介绍Ubuntu18.04突然不能更新apt源?实践出真理ack比grep香太多了!,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

喵哥好久不更新了,前段时间一直忙于秋招,然后就是实验室搬家。最近这两天搞了一个服务器玩玩,总算遇到了一个不错的素材。

乍看标题,似乎莫名其妙,其实是在解决更新apt源失败的问题过程中得出的经验之谈。这篇博客可能会比较“松散”,因为这里主要是说明解决问题的过程,算是一个记录,方便后面复习。

1、问题描述

在搭建服务器的过程中,使用wget下载文件,或是apt install安装软件,或是apt update更新apt源都失败。具体如下图:

遇到这种问题简直要搞死人,想做的事情都做不了,服务器基本就没啥用了。这种情况持续了四五天,我也是在这四五天里一直在尝试各种解决方案。

2、尝试的解决方案

2.1修改apt源

最早发现这个问题是在安装软件的时候,当时以为是用的apt源有问题,所以就去/etc/apt/sources.list.d/sources.list里修改了apt源,当然在修改前需要做好备份:

sudo cp /etc/apt/sources.list.d/sources.list /etc/apt/sources.list.d/sources.list.bak
sudo vim /etc/apt/sources.list.d/sources.list

阿里源:

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

中科大源:

deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

163源:

deb http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse

清华源:

deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

可是修改了sources.list文件后,没法去更新apt源。喵哥想到因为每次都是尝试去连接192.168.187.145,有可能跟DNS服务器有关。

2.2修改DNS服务器

修改DNS服务器是在/etc/resolv.conf里,但是这里修改的DNS会在服务器重启,或者执行 resolvconf -u 后会变为默认的设置。那么在哪设置默认的DNS呢?

可以在/etc/resolvconf/resolv.conf.d/base里面添加:

nameserver 223.5.5.5
nameserver 223.6.6.6
nameserver 8.8.8.8
nameserver 8.8.4.4

 

然后执行 resolvconf -u去刷新/etc/resolv.conf。

然而,这么尝试了还是行不通。第一次我放弃了,我把服务器给重置了,然后又重新开始配置服务器。

但是,第二次配置服务器的时候又遇到这个问题,总不能一直重置服务器吧。

3、解决方案

因为不管是wget下载文件,还是apt安装软件、更新apt源,都是尝试去连接192.168.187.145这个IP,所以这个应该跟系统中的某个地方的设置有关,但是在哪呢?

喵哥第一反应是用grep 去找

grep 192.168.187.145 /

但是用grep在全局查找实在是太慢了,不想等。记得前段时间看到ack,ag比grep快很多,于是就用ack去尝试搜索:

ack 192.168.187.145 /

发现快很多,一下就出了结果:

 

可以看到,在/root/.zshrc中有一行代理设置用到了这个IP,难怪。。。

找到后就简单了,注释掉这一行就好了。

附1:ack的用法

ack --help-types             # 打印所有type类型
ack "include|RTSP" .        # ack 'pattern1|pattern2|pattern3' 可以搜索含有 pattern1 或者 pattern2 或者 pattern3 的行
ack-grep hello
ack-grep -i hello
ack-grep -v hello             # 反向选择,即过滤掉含 hello 的行
ack-grep -w hello
ack-grep -Q 'hello*'
ack -f --html                # 打印类型是html的文件,不做具体的搜索,相当于find命令,html类型的文件大致包含: .html, .htm.  使用 ack -f --html -w index 方式是不对的,不能同时搜文件和文件内容。
ack -w --type=nojs css     #查找不是js类型之外的其它文件,只要该文件含有单词css
ack -n "(^9999)|(^000)"    #这种正则表达式和grep的类似,这里只是查找文件,不进入子目录进行递归(-n),它显示含有以9999或者000开头的行
ack -g log --cc         # -g代表只搜索文件(会递归进子目录),这里的意思是搜索c类型的文件,其文件名相对路径含有字符log,输入如 *log*.c  *log*.h 这样的文件。 ack -g log --cc -w aa,这样使用是不对的,不能同时搜文件和文件内容。ack --type-add=html:ext:shtml,xhtml   #只影响当前的命令,必须配合搜索命令一起使用,如:ack --type-add=html:ext:shtml,xhtml --html -w body,或者 ack --type-add=html:ext:shtml,xhtml -f --html
echo "--type-add=html:ext:shtml,xhtml" >> ~/.ackrc     #这个可以将增加某类型的类型定义保存起来,以后每次使用ack都会生效。--type-set=example:is:example.txt     # 这个是改变或新建某类型的类型文件。
echo "--type-set=bashcnf:match:/.bash(rc|_profile)/" >> ~/.ackrc     #这个是用正则式来定义类型参数,定义里一个叫bashcnf的类型,该类型匹配 .bashrc 或 .bash_profile 两个文件。
ack 'string1|string2'     #搜索string1或string2.

附2:.zshrc文件

这个zsh配置文件还不错:

https://download.csdn.net/download/ruibin_cao/11966891

这篇关于Ubuntu18.04突然不能更新apt源?实践出真理ack比grep香太多了!的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/626303

相关文章

虚拟机Centos7安装MySQL数据库实践

《虚拟机Centos7安装MySQL数据库实践》用户分享在虚拟机安装MySQL的全过程及常见问题解决方案,包括处理GPG密钥、修改密码策略、配置远程访问权限及防火墙设置,最终通过关闭防火墙和停止Net... 目录安装mysql数据库下载wget命令下载MySQL安装包安装MySQL安装MySQL服务安装完成

SpringBoot整合(ES)ElasticSearch7.8实践

《SpringBoot整合(ES)ElasticSearch7.8实践》本文详细介绍了SpringBoot整合ElasticSearch7.8的教程,涵盖依赖添加、客户端初始化、索引创建与获取、批量插... 目录SpringBoot整合ElasticSearch7.8添加依赖初始化创建SpringBoot项

Zabbix在MySQL性能监控方面的运用及最佳实践记录

《Zabbix在MySQL性能监控方面的运用及最佳实践记录》Zabbix通过自定义脚本和内置模板监控MySQL核心指标(连接、查询、资源、复制),支持自动发现多实例及告警通知,结合可视化仪表盘,可有效... 目录一、核心监控指标及配置1. 关键监控指标示例2. 配置方法二、自动发现与多实例管理1. 实践步骤

SpringBoot中六种批量更新Mysql的方式效率对比分析

《SpringBoot中六种批量更新Mysql的方式效率对比分析》文章比较了MySQL大数据量批量更新的多种方法,指出REPLACEINTO和ONDUPLICATEKEY效率最高但存在数据风险,MyB... 目录效率比较测试结构数据库初始化测试数据批量修改方案第一种 for第二种 case when第三种

MySQL 迁移至 Doris 最佳实践方案(最新整理)

《MySQL迁移至Doris最佳实践方案(最新整理)》本文将深入剖析三种经过实践验证的MySQL迁移至Doris的最佳方案,涵盖全量迁移、增量同步、混合迁移以及基于CDC(ChangeData... 目录一、China编程JDBC Catalog 联邦查询方案(适合跨库实时查询)1. 方案概述2. 环境要求3.

Linux进程CPU绑定优化与实践过程

《Linux进程CPU绑定优化与实践过程》Linux支持进程绑定至特定CPU核心,通过sched_setaffinity系统调用和taskset工具实现,优化缓存效率与上下文切换,提升多核计算性能,适... 目录1. 多核处理器及并行计算概念1.1 多核处理器架构概述1.2 并行计算的含义及重要性1.3 并

全面掌握 SQL 中的 DATEDIFF函数及用法最佳实践

《全面掌握SQL中的DATEDIFF函数及用法最佳实践》本文解析DATEDIFF在不同数据库中的差异,强调其边界计算原理,探讨应用场景及陷阱,推荐根据需求选择TIMESTAMPDIFF或inte... 目录1. 核心概念:DATEDIFF 究竟在计算什么?2. 主流数据库中的 DATEDIFF 实现2.1

Spring WebFlux 与 WebClient 使用指南及最佳实践

《SpringWebFlux与WebClient使用指南及最佳实践》WebClient是SpringWebFlux模块提供的非阻塞、响应式HTTP客户端,基于ProjectReactor实现,... 目录Spring WebFlux 与 WebClient 使用指南1. WebClient 概述2. 核心依

MyBatis-Plus 中 nested() 与 and() 方法详解(最佳实践场景)

《MyBatis-Plus中nested()与and()方法详解(最佳实践场景)》在MyBatis-Plus的条件构造器中,nested()和and()都是用于构建复杂查询条件的关键方法,但... 目录MyBATis-Plus 中nested()与and()方法详解一、核心区别对比二、方法详解1.and()

Spring Boot @RestControllerAdvice全局异常处理最佳实践

《SpringBoot@RestControllerAdvice全局异常处理最佳实践》本文详解SpringBoot中通过@RestControllerAdvice实现全局异常处理,强调代码复用、统... 目录前言一、为什么要使用全局异常处理?二、核心注解解析1. @RestControllerAdvice2