[命令] Linux 命令 hdparm (测试硬盘读取速度)

 # hdparm -Ttv /dev/sda

/dev/sda:
 multcount     = 128 (on)
 IO_support    =  1 (32-bit)
 readonly      =  0 (off)
 readahead     = 1024 (on)
 geometry      = 8354/255/63, sectors = 134217728, start = 0
 Timing cached reads:   7304 MB in  2.00 seconds = 3658.90 MB/sec
 Timing buffered disk reads: 612 MB in  3.01 seconds = 203.07 MB/sec

(补充:这里以测试 /dev/sda 硬盘的读取速度为例)

[命令] Linux 命令 sensors 的使用 (显示系统硬件温度)

步骤一:安装 sensors 命令

如果是 RHEL & Rocky Linux:

# yum install lm_sensors

如果是 openSUSE & SLES:

# zypper install lm_sensors

步骤二:检测硬件

2.1 分别选择要检测的区域

# sensors-detect

(补充:此命令是交互式的,当需要确定要检测的区域时,如果要检测则可以按下 “y” 键再按下 “回车” 键或者直接按下 “回车” 键,如果不检测则可以按下 “n” 键)

2.2 检测所有区域

# sh -c "yes|sensors-detect"

(注意:此命令会直接检测所有区域,不会再有选择的机会)

步骤三:显示系统硬件温度

# sensors

[步骤] KVM 虚拟机模板的创建 (Rocky Linux 8 版)

注意:

在创建 KVM 虚拟机之前要先安装 KVM 并创建 KVM 虚拟网络

镜像准备:

在 Rocky Linux 官网上下载安装系统所需要的镜像:

https://rockylinux.org/download

正文:

步骤一:理解创建 KVM 虚拟机模板的目的

主要用于批量克隆出新的 KVM 机器,节约创建新虚拟机的时间

步骤二:为这个虚拟机创建硬盘文件

2.1 创建硬盘文件

(只在真机上执行以下步骤)

# qemu-img create -f qcow2 /var/lib/libvirt/images/rockylinux8.qcow2 10G

(补充:这里以创建 10G 大小的 rockylinux8.qcow2 硬盘文件为例)

2.2 确认硬盘文件已创建

(只在真机上执行以下步骤)

# ls /var/lib/libvirt/images/ | grep rockylinux8.qcow2

(补充:这里以显示 rockylinux8.qcow2 硬盘文件为例)

步骤三:使用 KVM 和刚刚创建的硬盘文件新安装一台虚拟机

3.1 启动 KVM 的 virt-manager

(只在真机上执行以下步骤)

# virt-manager

3.2 在 virt-manager 上的左上角点击文件之后点击 “新建虚拟机”

(只在真机上执行以下步骤)

(步骤略)

3.2.1 选择以本地安装介质的方式安装系统

(只在真机上执行以下步骤)

(图:1)
3.2.2 选择安装系统的系统镜像

(只在真机上执行以下步骤)

(图:2)

(补充:这里以使用 Rocky-8.5-x86_6-dvd1.iso 系统镜像为例)

3.2.3 设置内存大小和 CPU 核心数

(只在真机上执行以下步骤)

(图:3)

(补充:这里以设置 2048 MiB 内容和 2 核 CPU 为例)

3.2.4 选择用刚刚创建的硬盘文件来安装系统

(只在真机上执行以下步骤)

(图:4)

(补充:这里以使用 rockylinux8.qcow2 硬盘文件为例)

3.2.5 给虚拟机命名并选择虚拟网络

(只在真机上执行以下步骤)

(注意:虚拟网络必须提前创建好)

(图:5)

(补充:这里以将虚拟机命名为 rockylinux8 并使用 0 网络为例)

3.2.6 开始安装系统

(只在真机上执行以下步骤)

(图:6)
3.2.7 选择系统语言

(只在真机上执行以下步骤)

(图:7)
3.2.8 之后进行系统配置界面

(只在真机上执行以下步骤)

需要手动配置的地方有四个:
1) “INSTALLATION DESTINATION”
2) “KDUMP”
3) “SOFTWARE SELECTION”
4) “Root Password”
分别点击以后就可以配置了

3.2.8.1 通过 “INSTALLATION DESTINATION” 对硬盘进行分区

(只在真机上执行以下步骤)

(补充:完成后点击左上角的 “DONE”)

(注意:只分一个分区,只设置一个挂载点挂载到根 “/”,使用标准硬盘类型,硬盘格式设置为 XFS)

(图:8)
(图:9)
3.2.8.2 取消 “KDUMP”

(只在真机上执行以下步骤)

(补充:完成后点击左上角的 “DONE”)

(图:10)
3.2.8.3 选择最小化安装系统

(只在真机上执行以下步骤)

(补充:完成后点击左上角的 “DONE”)

(图:11)
3.2.8.4 设置 root 密码

(只在真机上执行以下步骤)

(图:12)
3.2.9 之后点击右下角的 “Begin installation”

(只在真机上执行以下步骤)

(图:13)
3.2.10 安装完成后重启

(只在真机上执行以下步骤)

(图:14)
3.2.11 在安装系统的过程中需要注意的内容总结

(只在真机上执行以下步骤)

1) 一定要使用刚刚创建的 /var/lib/libvirt/images/rockylinux8.qcow2 作为安装虚拟机的硬件文件
2) 虚拟机网络 “0” 要提前创建好
3) 只分一个分区,只设置一个挂载点挂载到根 “/”,使用标准硬盘,硬盘格式是 XFS
4) 取消 “KDUMP”
5) 选择最小化安装系统
6) 设置 root 密码

步骤四:进入新创建虚拟机修改配置

4.1 修改网卡个性化设置

4.1.1 修改网卡配置文件

(只在虚拟机上执行以下步骤)

# vi /etc/sysconfig/network-scripts/ifcfg-enp1s0

将全部内容修改如下:

TYPE=Ethernet
BOOTPROTO=dhcp
NAME=enp1s0
DEVICE=enp1s0
ONBOOT=yes
4.1.2 使修改的网卡配置生效

(只在虚拟机上执行以下步骤)

# reboot

4.2 禁用 SELinux

(只在虚拟机上执行以下步骤)

# vi /etc/selinux/config

将全部内容修改如下:

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

4.3 禁用空路由

(只在虚拟机上执行以下步骤)

# vi /etc/sysconfig/network

将全部内容修改如下:

# Created by anaconda
NOZEROCONF="yes"

4.4 添加 Console 配置

4.4.1 修改 grub 内核配置文件

(只在虚拟机上执行以下步骤)

# vi /etc/default/grub

将全部内容修改如下:

GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL="serial console"
GRUB_SERIAL_COMMAND="serial --unit=1 --speed=115200"
GRUB_CMDLINE_LINUX="biosdevname=0 net.ifnames=0 console=tty0 console=ttyS0,115200n8"
GRUB_DISABLE_LINUX_UUID="true"
GRUB_ENABLE_LINUX_LABEL="true"
GRUB_DISABLE_RECOVERY="true"
4.4.2 使修改的 grub 内核配置生效

(只在虚拟机上执行以下步骤)

# grub2-mkconfig -o grub

4.5 将系统自动挂载的硬盘从使用 UUID 换成硬件路径

4.5.1 显示根 “/” 分区的 UUID

(只在虚拟机上执行以下步骤)

# blkid
/dev/sda1: UUID="e76ed189-6d0f-49d5-8586-c5aae4bdc9b5" TYPE="xfs" PARTUUID="3d8377ef-01"

(补充:这里的 UUID 是: e76ed189-6d0f-49d5-8586-c5aae4bdc9b5)

4.5.2 在自动挂载文件里将根 “/” 分区的 UUID 换成硬件路径

(只在虚拟机上执行以下步骤)

# vi /etc/fstab

将以下内容:

......
UUID=e76ed189-6d0f-49d5-8586-c5aae4bdc9b5 /                   xfs     defaults        0 0

(补充:这里的 UUID 是: e76ed189-6d0f-49d5-8586-c5aae4bdc9b5)

修改为:

/dev/sda1 /                   xfs     defaults        0 0

4.6 删除不用的程序

(只在虚拟机上执行以下步骤)

# yum -y remove firewalld-* python-firewall

4.7 对虚拟系统进行升级

(只在虚拟机上执行以下步骤)

# yum -y update

4.8 进行分区扩展

4.8.1 安装分区扩展软件

(只在虚拟机上执行以下步骤)

# yum install -y cloud-utils-growpart
4.8.2 给开机自启配置文件相应的权限
# chmod 755 /etc/rc.local
4.8.3 设置开机自动扩容根 “/” 目录

(只在虚拟机上执行以下步骤)

# vi /etc/rc.local

添加以下内容:

......
/usr/bin/growpart /dev/sda1
/usr/sbin/xfs_growfs /

4.9 修改虚拟机系统的名称

(只在虚拟机上执行以下步骤)

# vi /etc/hostname

将全部内容修改如下:

rockylinux8

4.10 启用 serial 服务实现通过 virsh console 命令控制虚拟机

(只在虚拟机上执行以下步骤)

# systemctl start serial-getty@ttyS0
# systemctl enable serial-getty@ttyS0

4.11 清除虚拟系统的历史命令

(只在虚拟机上执行以下步骤)

# history -c

4.12 关闭虚拟机

(只在虚拟机上执行以下步骤)

# poweroff

步骤五:在真机上对虚拟机进行清理优化

(只在真机上执行以下步骤)

# sudo virt-sysprep -d rockylinux8

(补充:这里以清理 rockylinux8 虚拟机为例)


注意:如果此命令不存在
1) Rocky Linux 系统的话需要安装 libguestfs-tools
2) openSUSE 系统的话需要安装 guestfs-tools

步骤六:此时就可以将此虚拟机的硬件文件作为模板进行批量克隆虚拟机了

(只在真机上执行以下步骤)

(步骤略)

[命令] 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 --best --allowerasing
2.3.2.2.2 非交互式升级所有软件包时允许删除冲突软件
# yum -y update --best --allowerasing

或者:

# yum update --best --allowerasing -y
2.3.2.3 升级除某软件包外的所有软件包
2.3.2.3.1 交互式升级除某软件包外的所有软件包
# yum update --exclude=<software>
2.3.2.3.2 非交互式升级除某软件包外的所有软件包
# yum -y update --exclude=<software>

或者:

# yum update --exclude=<software> -y
2.3.2.4 使用某 1 个配置文件升级所有软件包
2.3.2.4.1 交互式使用某 1 个配置文件升级所有软件包
# yum ./yum.conf update

(补充:这里以使用 ./yum.conf 配置文件升级所有软件包为例)

2.3.2.4.2 非交互式使用某 1 个配置文件升级所有软件包
# yum -y -c ./yum.conf update

(补充:这里以使用 ./yum.conf 配置文件升级所有软件包为例)

2.3.2.5 显示所有可以升级的软件包
# yum check-update
2.3.2.6 显示所有升级后需要重启才生效的软件包
# dnf needs-restarting --reboothint

2.4 显示软件包

2.4.1 显示软件包
2.4.1.1 显示软件包
# yum list <software>

或者:

# yum list all | grep <software>
2.4.1.2 显示软件包详细信息
# yum info <software>
2.4.1.3 显示软件包的所有可安装版本
# yum list <software> --showduplicate  | sort -r
2.4.1.4 显示软件包来自某一个模块
2.4.1.4.1 显示软件包来自某一个模块的格式
# yum module provides <software>
2.4.1.4.2 显示软件包来自某一个模块的案例
# yum module provides ipa-client
Updating Subscription Management repositories.
Last metadata expiration check: 1:38:12 ago on Fri 26 Jul 2024 08:00:39 AM CST.
ipa-client-4.7.1-11.module+el8+2842+7481110c.x86_64
Module   : idm:DL1:820190227212412:5986f621:x86_64
Profiles : client common
Repo     : rhel-8-for-x86_64-appstream-rpms
Summary  : The Red Hat Enterprise Linux Identity Management system module

......

(补充:从这里的输出结果可以看出 ipa-client 软件包来自 idm 模块,版本是 DL1)

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 交互式安装 Errata
# yum update --advisory=<errata>
4.1.1.1.2 非交互式安装 Errata
# 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 交互式安装所有 Errata
# yum update-minimal --security
4.1.2.1.2 非交互式安装所有 Errata
# 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 交互式安装 CVE
# yum update --cve <CVE>
4.2.1.1.2 非交互式安装 CVE
# 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 显示软件模块
6.1.1.1 显示某个软件库来自某个软件模块
# yum module provides <software>
6.1.1.2 显示所有软件模块
# yum module list
6.1.1.3 显示某个软件模块
# yum module list | grep <software>
6.1.1.4 显示某个软件模块的详细信息
# dnf module info <module>
6.1.1.5 显示某个软件模块的某个模块流的详细信息
# dnf module info <module>:<stream>
6.1.2 重置软件模块
# yum module reset <module>
6.1.3 设置软件模块
# yum module enable <module>:<version>

6.2 切换软件模块的案例

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

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

6.2.2 显示要切换软件模块的软件包属于哪个软件模块
# yum module provides podman

(补充:这里以显示 podman 软件包属于哪个软件模块为例)

6.2.3 显示所有软件模块
# 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.4 设置软件模块
6.2.4.1 重置软件模块
# yum module reset container-tools

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

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

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

或者:

# yum module enable container-tools:rhel8


补充:
1) 这里以设置最新的 container-tools 软件模块版本号为例
2) 当站主在测试这条命令时,最新的 container-tools 软件模块版本号刚好是 3.0

(注意:有些时候只能设置成最新的软件模块版本号后才能升级到最新的软件)

6.2.4.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.5 重置软件模块
6.2.5.1 重置软件模块
# yum module reset container-tools

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

6.2.5.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

7.3 操作回滚

# yum history
# yum history undo <ID>

(补充:上面第 1 条命令会实现操作的 ID 号,在第 2 条命令中写入那个 ID 号就可以取消那次操作)