Linux 快捷命令集合
使用问题
2025-08-05 14:00
701
一、系统换源(国内镜像源,加速包管理)
1. CentOS 系统(yum 换源,以阿里云为例)
# 备份原repo
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
# 下载阿里云源(CentOS 7)
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
# 若为CentOS 8,替换为:
# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo
# 清除缓存并生成新缓存
yum clean all && yum makecache
2. Ubuntu/Debian 系统(apt 换源,以阿里云为例)
# 备份原sources.list
cp /etc/apt/sources.list /etc/apt/sources.list.bak
# 替换为阿里云源(Ubuntu 20.04为例,其他版本需修改"focal"为对应版本代号,如18.04是"bionic")
cat > /etc/apt/sources.list << EOF
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
EOF
# 刷新缓存
apt update
二、系统更新(升级系统组件)
1. CentOS 系统
# 升级所有包(不升级内核)
yum update -y
# 若需升级内核(谨慎,部分服务器可能依赖旧内核)
yum update -y kernel