写在前面:日常维护系统中,如果不是天天接触,难免会忘记一些实用小技巧,本文记录自己使用的小技巧,有新发现时,会长期更新
安装epel和dnf源
# 安装epel
yum -y install epel-release
# 安装dnf,注意需要先安装epel
yum -y install dnf
yum只下载不安装
# centos7下
yum install --downloadonly --downloaddir=/tmp <package-name>
yum指定安装本地rpm包
yum localinstall filename
挂载本地镜像作为yum源
cat /etc/yum.repos.d/baseofbase.repo
[baseofbase]
name=baseofbase
# 镜像目录
baseurl=file:///usr/local/src/centos74
gpgcheck=0
enabled=1
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
修改yum源为阿里源
cd /etc/yum.repos.d
# 备份旧的配置文件:
mv CentOS-Base.repo CentOS-Base.repo.bak
# 下载阿里源的文件
wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
# 清理缓存
yum clean all
# 重新生成缓存
yum makecache
yum更新时不升级Linux内核
RedHat/CentOS/Fedora使用 yum update 更新时,默认会 升级内核 。但有些服务器硬件(特别是组装的机器)在升级内核后,新的内核可能会认不出某些硬件,要重新安装驱动,很麻烦。所以在生产环境中不要轻易的升级内核,除非你确定升级内核后不会出现麻烦的问题。
方法1:修改yum配置
cp /etc/yum.conf /etc/yum.confbak
# 在[main]的最后添加
vim /etc/yum.conf
exclude=kernel*
exclude=centos-release*
方法二、直接在yum的命令后面加上如下的参数
yum --exclude=kernel* update