yum的一些实用小技巧
- yum的历史记录
[root@centos6 ~]# yum history
Loaded plugins: fastestmirror
ID | Login user | Date and time | Action(s) | Altered
-------------------------------------------------------------------------------
6 | root <root> | 2020-08-30 16:49 | Install | 30
5 | root <root> | 2020-08-30 16:48 | Install | 6
4 | root <root> | 2020-07-21 22:58 | I, O, U | 226 EE
3 | root <root> | 2020-07-21 22:42 | I, U | 34
2 | root <root> | 2020-07-21 22:42 | I, U | 6
1 | System <unset> | 2020-07-21 22:12 | Install | 303
history list
history安装系统时间排列,每一次的安装或者卸载都记录一条记录,逐次增加。如果安装的一个软件有很多依赖包,有安装多少个软件,altered都记录。
================================================================================
[root@centos6 ~]# yum history info 2
Loaded plugins: fastestmirror
Invalid history sub-command, use: list, info, summary, repeat, redo, undo, new, rollback, addon, addon-info, stats, statistics, sync, synchronizepkg, pkgs, pkg-list, pkgs-list, package, package-list, packages, packages-list, pkg-info, pkgs-info, package-info, packages-info.
[root@centos6 ~]# yum history info 2
Loaded plugins: fastestmirror
Transaction ID : 2
Begin time : Tue Jul 21 22:42:09 2020
Begin rpmdb : 303:fb8632f6d2bb8f6d0e405d6b2d55159325e1b628
End time : 22:42:10 2020 (1 seconds)
End rpmdb : 308:70e95183ab735de6ad9505b2cd418bef7ed8b2b1
User : root <root>
Return-Code : Success
Command Line : -y install yum-utils deltarpm -q
Transaction performed with:
Updated rpm-4.11.3-25.el7.x86_64 @anaconda
Updated yum-3.4.3-154.el7.centos.noarch @anaconda
Updated yum-plugin-fastestmirror-1.1.31-42.el7.noarch @anaconda
Packages Altered:
Install deltarpm-3.6-3.el7.x86_64 @aliyun
Updated libxml2-2.9.1-6.el7_2.3.x86_64 @anaconda
Update 2.9.1-6.el7.4.x86_64 @aliyun
Dep-Install libxml2-python-2.9.1-6.el7.4.x86_64 @aliyun
Dep-Install python-chardet-2.2.1-3.el7.noarch @aliyun
Dep-Install python-kitchen-1.1.1-5.el7.noarch @aliyun
Install yum-utils-1.1.31-54.el7_8.noarch @updates
history info
yum历史记录的详细信息,包括安装时间,安装的哪些软件,安装时使用的哪个仓库,安装执行的命令等等详细信息。
- 多个仓库引起的冲突的解决
本地仓库和远程仓库可能会有冲突,或者是我有些软件需要从本地cdrom源安装,不想走远程yum源,怎么办?
假设我有三个仓库,仓库名称分别为aliyun,base,file,配置的源分别为阿里云源,centos自带base源,本地cdrom源,
[root@centos6 ~]# yum --disablerepo=file,base,aliyun install httpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* extras: mirrors.aliyun.com
* updates: mirrors.huaweicloud.com
No package httpd available.
并不能安装基本的httpd服务软件,都禁止了嘛,用本地cdrom安装呢?
yum --disablerepo=base,aliyun --enablerepo=file install httpd
- 生成仓库文件的命令
yum-config-manager --add-repo 接具体的网络仓库地址,但有时候,最小化安装后,发现 没有这个命令 yun-config-manager,怎么办?
yum install yum-utils -y ,即可。
- 查询安装的软件有哪些依赖
安装完了某些软件,想知道它到底有哪些软件依赖,怎么办?
yum deplist httpd(假设是看httpd的依赖,会发现输出了一大堆,包括脚本运行时使用到的程序都列出来了)
查询某个bin程序依赖哪些内核库?
ldd /usr/bin/ls(会看到很多内核库哦)
- 查询安装的软件运行了哪些脚本
[root@centos6 ~]# rpm -q --scripts httpd
preinstall scriptlet (using /bin/sh):
# Add the "apache" group and user
/usr/sbin/groupadd -g 48 -r apache 2> /dev/null || :
/usr/sbin/useradd -c "Apache" -u 48 -g apache \
-s /sbin/nologin -r -d /usr/share/httpd apache 2> /dev/null || :
postinstall scriptlet (using /bin/sh):
if [ $1 -eq 1 ] ; then
# Initial installation
systemctl preset httpd.service htcacheclean.service >/dev/null 2>&1 || :
fi
preuninstall scriptlet (using /bin/sh):
if [ $1 -eq 0 ] ; then
# Package removal, not upgrade
systemctl --no-reload disable httpd.service htcacheclean.service > /dev/null 2>&1 || :
systemctl stop httpd.service htcacheclean.service > /dev/null 2>&1 || :
fi
postuninstall scriptlet (using /bin/sh):
systemctl daemon-reload >/dev/null 2>&1 || :
# Trigger for conversion from SysV, per guidelines at:
# https://fedoraproject.org/wiki/Packaging:ScriptletSnippets#Systemd
posttrans scriptlet (using /bin/sh):
test -f /etc/sysconfig/httpd-disable-posttrans || \
/bin/systemctl try-restart httpd.service htcacheclean.service >/dev/null 2>&1 || :
这些脚本都是十分经典的哦,学习这些脚本对shell编程是有好处的。