[命令] CentOS Linux & RHEL 命令 YUM (管理软件和软件源)

内容一: 帮助文档相关

1.1 显示 YUM 帮助信息

# yum help

1.2 显示 YUM 子选项的帮助信息

# yum help <option>

或者:

# yum <option> help

内容二:软件相关

2.1 安装软件

2.1.1 交互式
# yum install <software>
2.1.2 非交互式
# yum -y install <software>

或者:

# yum install <software> -y

2.2 删除软件

2.2.1 交互式
# yum remove <software>
2.2.2 非交互式
# yum -y remove <software>

或者:

# yum remove <software> -y

2.3 升级软件

2.3.1 升级软件
2.3.1.1 交互式
# yum update <software>
2.3.1.2 非交互式
# yum -y update <software>

或者:

# yum update <software> -y
2.3.2 升级所有软件
2.3.2.1 升级所有软件
2.3.2.1.1 交互式
# yum update
2.3.2.1.2 非交互式
# yum -y update

或者:

# yum update -y
2.3.2.2 升级除某软件外的所有软件
2.3.2.2.1 交互式
# yum update --exclude=<software>
2.3.2.2.2 非交互式
# yum -y update --exclude=<software>

或者:

# yum update --exclude=<software> -y
2.3.2.3 显示所有可以升级的软件
# yum check-update

2.4 显示软件

2.4.1 显示软件
2.4.1.1 显示软件
# yum list all | grep <software>
2.4.1.2 显示软件详细信息
# yum info | grep <software>
2.4.2 显示所有软件
# yum list all

内容三:软件组相关

3.1 安装软件组

3.1.1 交互式
# yum groupinstall <group>
3.1.2 非交互式
# yum -y groupinstall <group>

或者:

# yum groupinstall <group> -y

3.2 删除软件组

3.2.1 交互式
# yum groupremove <group>
3.2.2 非交互式
# yum -y groupremove <group>

或者:

# yum groupremove <group> -y

3.3 显示所有可用软件组

# yum group list

内容四:安全相关

4.1 Errata

4.1.1 Errata
4.1.1.1 安装 Errata
4.1.1.1.1 交互式
# yum update --advisory=<errata>
4.1.1.1.2 非交互式
# yum -y update --advisory=<errata>

或者:

# yum update --advisory=<errata> -y
4.1.1.2 显示 Errata 的详细信息
# yum updateinfo <errata>
4.1.2 所有 Errata
4.1.2.1 安装所有 Errata
4.1.2.1.1 交互式
# yum update-minimal --security
4.1.2.1.2 非交互式
# yum -y update-minimal --security

或者:

# yum update-minimal --security -y
4.1.2.2 显示所有 Errata 和相关软件版本
# yum updateinfo list
4.1.2.3 显示所有 Errata 和相关的 CVE
# yum updateinfo info security

4.2 CVE

4.2.1 CVE
4.2.1.1 安装 CVE
4.2.1.1.1 交互式
# yum update --cve <CVE>
4.2.1.1.2 非交互式
# yum -y update --cve <CVE>

或者:

# yum update --cve <CVE> -y
4.2.2 所有 CVE
4.2.2.1 显示所有 CVE 和相关软件版本
# yum updateinfo list cves
4.2.2.2 显示所有 CVE 和相关的 Errata
# yum updateinfo info security

4.2 安全补丁

4.2.1 安全补丁
4.2.1.1 安装安全补丁
4.2.1.1.1 交互式
# yum update <security patch>
4.2.1.1.2 非交互式
# yum -y update <security patch>

或者:

# yum update <security patch> -y
4.2.2 所有安全补丁
4.2.2.1 安装所有安全补丁
4.2.2.1.1 交互式
# yum update --security
4.2.2.1.2 非交互式
# yum -y update --security

或者:

# yum update --security -y
4.2.2.2 显示所有安全补丁
# yum check-update --security

内容五:软件源相关

5.1 显示所有软件源

# yum repolist 

5.2 缓存软件源列表

5.2.1 缓存所有已启用软件源列表
# yum repolist 
5.2.2 清除所有软件源列表缓存
# yum clean all
5.2.3 保存所有软件源列表缓存
# yum makecache

内容六:软件模块相关 (切换软件可用的版本)

6.1 软件模块相关的格式

6.1.1 显示所有软件模块
# yum module list
6.1.2 重置软件模块
# yum module reset <module>
6.1.3 设置软件模块
# yum module enable <module>:<versione>

6.2 切换软件模块的案例

6.2.1 检测当前软件兼容情况
# yum distro-sync

(注意:需要确保这条命令执行有以后没有报错)

6.2.2 显示所有软件模块
# yum module list | grep podman
container-tools      rhel8 [d]       common [d]                               Most recent (rolling) versions of podman, buildah, skopeo, runc, conmon, runc, conmon, CRIU, Udica, etc as well as dependencies such as container-selinux built and tested together, and updated as frequently as every 12 weeks.
container-tools      1.0             common [d]                               Stable versions of podman 1.0, buildah 1.5, skopeo 0.1, runc, conmon, CRIU, Udica, etc as well as dependencies such as container-selinux built and tested together, and supported for 24 months.                                 
container-tools      2.0             common [d]                               Stable versions of podman 1.6, buildah 1.11, skopeo 0.1, runc, conmon, etc as well as dependencies such as container-selinux built and tested together, and supported as documented on the Application Stream lifecycle page.    
container-tools      3.0             common [d]                               Stable versions of podman 3.0, buildah 1.19, skopeo 1.2, runc, conmon, etc as well as dependencies such as container-selinux built and tested together, and supported as documented on the Application Stream lifecycle page.    
container-tools      4.0             common [d]                               Stable versions of podman 4.0, buildah 1.24, skopeo 1.6, runc, conmon, etc as well as dependencies such as container-selinux built and tested together, and supported as documented on the Application Stream lifecycle page.  

(补充:这里以显示所有和 podman 软件相关的软件模块为例)

6.2.3 设置软件模块
6.2.3.1 重置软件模块
# yum module reset container-tools

(补充:这里以重置 container-tools 软件模块为例)

6.2.3.2 设置软件模块
# yum module enable container-tools:3.0

(补充:这里以设置 container-tools 软件模块版本号为 3.0 为例)

6.2.3.3 显示设置 container-tools 软件模块版本号为 3.0 时 podman 软件的可用版本
# yum list all | egrep ^podman\.x         
podman.x86_64                                           3.0.1-9.module+el8.6.0+14874+64436299                       rhel-8-for-x86_64-appstream-rpms    

(补充:可以看到此时 podman 软件的可用版本是 3.0.1-9)

6.2.4 重置软件模块
6.2.4.1 重置软件模块
# yum module reset container-tools

(补充:这里以重置 container-tools 软件模块为例)

6.2.4.2 显示 container-tools 软件模块没有设置时 podman 软件的可用版本
# yum list all | egrep ^podman\.x
podman.x86_64                                           2:4.0.2-6.module+el8.6.0+14877+f643d2d6                     rhel-8-for-x86_64-appstream-rpms

(补充:可以看到此时 podman 软件的可用版本是 2:4.0.2-6)

内容七:管理相关

7.1 显示 YUM 历史命令

# yum history

7.2 显示 YUM 安装记录

# yum history info

[步骤] SFTP 日志的开启

# vim /etc/sshd/sshd_config

如果是 CentOS Linux & RHEL,将以下内容:

......
Subsystem       sftp    /usr/libexec/openssh/sftp-server
......

修改为:

......
Subsystem       sftp    /usr/libexec/openssh/sftp-server -l INFO
......

如果是 openSUSE & SLE, 将以下内容:

......
Subsystem       sftp    /usr/lib/ssh/sftp-server
......

修改为:

......
Subsystem       sftp    /usr/lib/ssh/sftp-server -l INFO
......

(补充:此时当通过 SFTP 登录系统时,系统日志记录文件 /var/log/messages 里登录记录后面会紧跟一行带 sftp-server 的记录)

[工具] Shell 批量比较服务器所有正在运行进程的变化

介绍

基本信息

作者:朱明宇
名称:批量比较服务器所有正在运行进程的变化
作用:批量比较服务器所有正在运行进程的变化

使用方法

1. 服务器清单 $server_list 每台服务器占用 1 行
2. 在此脚本的分割线内写入相应的内容,并和此脚本放在同一目录下
3. 给此脚本添加执行权限
4. 执行此脚本
5. 此脚本执行完成后,会将运行结果写入当前目录下的 $compare_file 里

脚本分割线里的变量

server_list=server_list.txt #服务器清单
first_time=first_time #存储第一次检结果的目录
second_time=second_time #存储第二次检查结果的目录
compare_file=comparison_results.txt #存储比较结果的文件

注意

此脚本执行前必须要先保证执行本脚本的用户能无密码 ssh 远程这些远程服务器

脚本

#!/bin/bash

####################### Separator ########################

server_list=server_list.txt
first_time=first_time
second_time=second_time
compare_file=comparison_results.txt

####################### Separator ########################

mkdir $first_time &> /dev/null
mkdir $second_time &> /dev/null
echo > $compare_file

read -p "Please input first second or compare now: " choice

check(){
        for server_name in `cat $1`
        do
                ssh -t $server_name "ps -A" | awk '{print $4}' > $2/$server_name
        done
}

compare(){
        for server_name in `cat $1`
        do
                echo $server_name >> $4
                for process in `cat $2/$server_name`
                        do
                        grep $process $3/$server_name &> /dev/null
                        if [ $? -ne 0 ];then
                                echo $process >> $4
                        fi
                done
                echo >> $4
        done
}

if [ $choice == first ];then
        check $server_list $first_time
fi

if [ $choice == second ];then
        check $server_list $second_time
fi

if [ $choice == compare ];then
        compare $server_list $first_time $second_time $compare_file
fi