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

相关文章

Spring事务传播机制最佳实践

《Spring事务传播机制最佳实践》Spring的事务传播机制为我们提供了优雅的解决方案,本文将带您深入理解这一机制,掌握不同场景下的最佳实践,感兴趣的朋友一起看看吧... 目录1. 什么是事务传播行为2. Spring支持的七种事务传播行为2.1 REQUIRED(默认)2.2 SUPPORTS2

Java中的雪花算法Snowflake解析与实践技巧

《Java中的雪花算法Snowflake解析与实践技巧》本文解析了雪花算法的原理、Java实现及生产实践,涵盖ID结构、位运算技巧、时钟回拨处理、WorkerId分配等关键点,并探讨了百度UidGen... 目录一、雪花算法核心原理1.1 算法起源1.2 ID结构详解1.3 核心特性二、Java实现解析2.

MySQL 中 ROW_NUMBER() 函数最佳实践

《MySQL中ROW_NUMBER()函数最佳实践》MySQL中ROW_NUMBER()函数,作为窗口函数为每行分配唯一连续序号,区别于RANK()和DENSE_RANK(),特别适合分页、去重... 目录mysql 中 ROW_NUMBER() 函数详解一、基础语法二、核心特点三、典型应用场景1. 数据分

MySQL追踪数据库表更新操作来源的全面指南

《MySQL追踪数据库表更新操作来源的全面指南》本文将以一个具体问题为例,如何监测哪个IP来源对数据库表statistics_test进行了UPDATE操作,文内探讨了多种方法,并提供了详细的代码... 目录引言1. 为什么需要监控数据库更新操作2. 方法1:启用数据库审计日志(1)mysql/mariad

深度解析Spring AOP @Aspect 原理、实战与最佳实践教程

《深度解析SpringAOP@Aspect原理、实战与最佳实践教程》文章系统讲解了SpringAOP核心概念、实现方式及原理,涵盖横切关注点分离、代理机制(JDK/CGLIB)、切入点类型、性能... 目录1. @ASPect 核心概念1.1 AOP 编程范式1.2 @Aspect 关键特性2. 完整代码实

MySQL 用户创建与授权最佳实践

《MySQL用户创建与授权最佳实践》在MySQL中,用户管理和权限控制是数据库安全的重要组成部分,下面详细介绍如何在MySQL中创建用户并授予适当的权限,感兴趣的朋友跟随小编一起看看吧... 目录mysql 用户创建与授权详解一、MySQL用户管理基础1. 用户账户组成2. 查看现有用户二、创建用户1. 基

Spring Boot 实现 IP 限流的原理、实践与利弊解析

《SpringBoot实现IP限流的原理、实践与利弊解析》在SpringBoot中实现IP限流是一种简单而有效的方式来保障系统的稳定性和可用性,本文给大家介绍SpringBoot实现IP限... 目录一、引言二、IP 限流原理2.1 令牌桶算法2.2 漏桶算法三、使用场景3.1 防止恶意攻击3.2 控制资源

springboot项目中整合高德地图的实践

《springboot项目中整合高德地图的实践》:本文主要介绍springboot项目中整合高德地图的实践,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一:高德开放平台的使用二:创建数据库(我是用的是mysql)三:Springboot所需的依赖(根据你的需求再

SpringBoot3应用中集成和使用Spring Retry的实践记录

《SpringBoot3应用中集成和使用SpringRetry的实践记录》SpringRetry为SpringBoot3提供重试机制,支持注解和编程式两种方式,可配置重试策略与监听器,适用于临时性故... 目录1. 简介2. 环境准备3. 使用方式3.1 注解方式 基础使用自定义重试策略失败恢复机制注意事项

MySQL MCP 服务器安装配置最佳实践

《MySQLMCP服务器安装配置最佳实践》本文介绍MySQLMCP服务器的安装配置方法,本文结合实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下... 目录mysql MCP 服务器安装配置指南简介功能特点安装方法数据库配置使用MCP Inspector进行调试开发指