# Red Hat Enterprise Linux Developer
###### tags: `Linux` `Red hat`
This note covers the basic usage of Linux and Red hat features
## :memo: Markdown Outline
[ToC]
### Step 1: Fedora & Red hat Enterprise Linux & Rocky Linux

### Step 2: Linux
Applications | Development Tools
------------- OS system API --------------
Runtime Library
------------- System Call ----------------
Operating System kernel
------------- Hardware Spec --------------
Hardware
- Linux Command Type:
```shell=
Command name [command parameter] [command object]
long type: man --help
short type: man -h
```
- first: check linux system name
```c=
cat /etc/redhat-release
ex: Red Hat Enterprise Linux release 8.4 (Ootpa)
```
Red Hat Enterprise Linux 8 is distributed through two main repositories:
- BaseOS
- AppStream
Modules are collections of packages representing a logical unit: an application, a language stack, a database, or a set of tools. These packages are built, tested, and released together.
Red Hat Enterprise Linux repository
> repository file is created in the /etc/yum.repos.d/ directory
Use the yum | dnf utility to manage package operations
- Searching information about packages
- Installing packages
- Updating packages
- Removing packages
- Checking the list of currently available repositories
- Adding or removing a repository
- Enabling or disabling a repository
### RPM (Red hat Packet Management)
:bulb: **Table**
| Description | Command |
| ----------------------------------- |:---------------------------------- |
| 安裝套件 | rpm -ivh filename.rpm |
| 更新版本 | rpm -Uvh filename.rpm |
| 解除安裝 | rpm -e filename.rpm |
| 查詢相關訊息 | rpm -qpi filename.rpm |
| 列出檔案訊息 | rpm -qpl filename.rpm |
| 查詢其RPM格式 | rpm -qf filename |
-i : 代表安裝
-v : 顯示訊息
-h : 安裝進度
```shell=
Install: rpm -ivh filename.rpm
Update: rpm -Uvh filename.rpm
Uninstall: rpm -e filename.rpm
search and information: rpm -qpi filename.rpm
below: rpm -qpl filename.rpm
command type: rpm -qf filename
```
```shell=
yum repolist all
yum list all
yum info package name
yum install package name
yum reinstall package name
yum update package name
yum remove package name
yum clean all
yum check-update
yum grouplist
```
RPM YUM: RPM 是為了簡化安裝的複雜度,而 Yum 套件倉庫是為了解決軟體包之間的依賴關係。
- systemctl status service
```shell=
ex: systemctl status
● redhat8
State: running
Jobs: 0 queued
Failed: 0 units
Since: Wed 2021-09-08 07:30:55 EDT; 4h 17min ago
CGroup: /
├─user.slice
│ └─user-1000.slice
│ ├─user@1000.service
│ │ ├─gvfs-goa-volume-monitor.service
│ │ │ └─7842 /usr/libexec/gvfs-goa-volume-monitor
│ │ ├─xdg-permission-store.service
│ │ │ └─7803 /usr/libexec/xdg-permission-store
│ │ ├─xdg-document-portal.service
│ │ │ └─8558 /usr/libexec/xdg-document-portal
│ │ ├─tracker-store.service
│ │ │ └─8205 /usr/libexec/tracker-store
│ │ ├─xdg-desktop-portal.service
│ │ │ └─8529 /usr/libexec/xdg-desktop-portal
│ │ ├─evolution-calendar-factory.service
│ │ │ ├─8041 /usr/libexec/evolution-calendar-factory
│ │ │ └─8109 /usr/libexec/evolution-calendar-factory-subprocess -->
│ │ ├─pulseaudio.service
```
- man (help)
- echo (print string or value)
```shell=
format: echo "[ string | '$'var ]"
ex: echo linux-how-are-you
linux-how-are-you
```
- date (print system time) | timedatectl (more information)
```shell=
format: date [option] ["format"]
ex: date "+%Y-%m-%d %H:%M:%S"
2021-09-08 10:58:46
```
- reboot (need root #)
- poweroff (need root #)
- wget
```shell=
fotmat: wget [option] address
ex: wget https://ftp.gnu.org/gnu/gcc/gcc-4.6.4/gcc-4.6.4.tar.gz
```
- ps (check process status)
```shell=
format: ps [option]
ex: ps -aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.2 261592 7624 ? Ss 9月01 0:27 /usr/lib/s
root 2 0.0 0.0 0 0 ? S 9月01 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? I< 9月01 0:00 [rcu_gp]
root 4 0.0 0.0 0 0 ? I< 9月01 0:00 [rcu_par_g
root 6 0.0 0.0 0 0 ? I< 9月01 0:00 [kworker/0
root 9 0.0 0.0 0 0 ? I< 9月01 0:00 [mm_percpu
root 10 0.0 0.0 0 0 ? S 9月01 0:06 [ksoftirqd
root 11 0.0 0.0 0 0 ? I 9月01 1:24 [rcu_sched
root 12 0.0 0.0 0 0 ? S 9月01 0:00 [migration
root 13 0.0 0.0 0 0 ? S 9月01 0:00 [watchdog/
...
```
- top (Task Manager)
```shell=
format: top
ex: top
top - 11:07:20 up 6 days, 22:59, 1 user, load average: 0.82, 1.27, 1.21
Tasks: 277 total, 1 running, 276 sleeping, 0 stopped, 0 zombie
%Cpu(s): 5.2 us, 1.0 sy, 0.0 ni, 92.8 id, 0.7 wa, 0.3 hi, 0.1 si, 0.0 st
MiB Mem : 3649.6 total, 425.2 free, 1921.6 used, 1302.9 buff/cache
MiB Swap: 3972.0 total, 1939.1 free, 2032.9 used. 1064.5 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
552390 redhat 20 0 20.7g 355004 146876 S 14.0 9.5 9:51.39 chrome
4297 redhat 20 0 637992 41656 22924 S 4.0 1.1 8:14.11 gnome-terminal-
2488 redhat 20 0 4893404 263936 41228 S 3.0 7.1 80:54.08 gnome-shell
2357 redhat 9 -11 2297160 7640 5408 S 2.7 0.2 41:34.33 pulseaudio
27290 redhat 20 0 17.0g 23012 21788 S 1.0 0.6 11:32.52 chrome
26754 redhat 20 0 16.8g 221088 103192 S 0.7 5.9 53:16.07 chrome
```
- pidof (search process PID)
```shell=
format: pidof [option] process_name
ex: pidof sshd
55525
```
- kill (Terminate the service of the specified pid)
```shell=
format: kill [option] pid
ex: kill 55525
```
- killall (Terminate all processes corresponding to a service with a specified name)
```shell=
format: killall [option] process-name
ex: killall httpd
```
- ifconfig
```shell=
format: ifconfig [network-device] [option]
ex: ifconfig
```
- uname (check kernel system version)
```shell=
format: uname [option]
ex: uname -a
Linux redhat8 4.18.0-305.12.1.el8_4.x86_64 #1 SMP Mon Jul 26 08:06:24 EDT 2021 x86_64 x86_64 x86_64 GNU/Linux
```
- uptime (View system load information)
```shell=
format: uptime
11:50:03 up 19 min, 1 user, load average: 1.09, 1.23, 1.22
```
- free (Memory usage information)
```shell=
format: free [-h]
ex: free -h
total used free shared buff/cache available
Mem: 3.6Gi 2.0Gi 309Mi 384Mi 1.2Gi 949Mi
Swap: 3.9Gi 150Mi 3.7Gi
```
- who (View the information of the user terminal currently logged in to the host)
```shell=
format: who [option]
ex: who
redhat tty2 2021-09-08 11:32 (tty2)
```
- last (View all system login records)
```shell=
format: last [option]
ex:
```
- history
- sosreport
### Working directory related
- pwd
- cd
```c=
```
- ls (equivalent to the DOS DIR)
```c=
ls -a
ls /home
```
### File editing commands
- cat
```c=
cat <filename>
```
- string
- more
- head
- tail
- tr
- wc
- stat
- cut
- diff
### File directory management commands
- touch
- mkdir
- cp
- mv
- rm
- dd
- file
- tar
- find
- grep
- awk
-
### stdin stdout
- stdin (0): default fome keyboard
- stdout (1): default to moniter
- stderr (2): default to moniter
### Linux command
修改文件的第一步是了解存在哪些文件。使用ls查看當前目錄的內容
```shell=
ls
```
使用 cat 命令快速檢查此文件中的內容。 cat 命令是“concatenate”的縮寫
```shell=
cat
```
您可以通過重定向 echo 命令的輸出來完成引用。下面的命令使用附加重定向運算符 (>>) 將 echo 命令的輸出寫入文件 quote.txt 的末尾。
```shell=
echo "makes it seem more manageable." >> quote.txt
```
''>>'' 操作符允許您從命令行添加文件,在 shell 腳本中特別有用。當命令有很長的輸出並且您想在文本編輯器中查看該輸出時,您也可以使用它
注意:您可能還會遇到 > 重定向運算符。 此運算符將輸出寫入文件,如果文件已存在,則覆蓋該文件。 相比之下,>> 運算符會將輸出附加到指定的文件中。 輸入運算符 (<) 會將數據作為輸入重定向到運算符之前調用的任何內容。 管道操作符 ( | )
有些文件足夠大,用 cat 顯示它們的內容是不切實際的。一個常見的例子是日誌文件,它通常包含大量信息。
由於 tail 僅顯示文件的最後十行,因此它對於查看日誌文件中的最近條目特別有用。查看引導日誌的最後十行。
```shell=
[root@246c49df4e87 ~]# tail /var/log/boot.log
Starting Enable periodic update of entitlement certificates....
Starting Permit User Sessions...
Starting Network Manager Wait Online...
Starting Hostname Service...
[ OK ] Started Enable periodic update of entitlement certificates..
[ OK ] Started OpenSSH server daemon.
[ OK ] Started Permit User Sessions.
[ OK ] Started Command Scheduler.
Starting Hold until boot process finishes up...
Starting Terminate Plymouth Boot Screen...
```
如果您想查看整個文件,像less 或view 這樣的文本查看器將顯示整個文件。
包管理器是安裝、更新和刪除軟體的程序。手動執行這些操作會很乏味並且容易出錯。將這些功能捆綁到一個工具中,可為用戶提供更流暢的體驗。
YUM 具有更多的實用性,因為它在安裝、刪除或更新軟體時執行依賴項解析。接下來的步驟將舉例說明如何使用 YUM 來簡化包管理
使用 yum 安裝網絡分析應用程序 Wireshark。 此應用程序可用於對進出系統的網絡數據包進行故障排除。 這個功能對於這個實驗室來說並不重要,選擇這個應用程序只是因為它可以作為即將到來的示例的一個很好的測試對象。
```shell=
yum install -y wireshark
Updating Subscription Management repositories.
Red Hat Enterprise Linux 8 for x86_64 - BaseOS (RPMs) 42 MB/s | 41 MB 00:00
Red Hat Enterprise Linux 8 for x86_64 - AppStream (RPMs) 33 MB/s | 37 MB 00:01
Last metadata expiration check: 0:00:01 ago on Mon 20 Dec 2021 04:02:17 PM EST.
Dependencies resolved.
===============================================================================================================
Package Arch Version Repository Size
===============================================================================================================
Installing:
wireshark x86_64 1:2.6.2-14.el8 rhel-8-for-x86_64-appstream-rpms 3.6 M
Installing dependencies:
flac-libs x86_64 1.3.2-9.el8 rhel-8-for-x86_64-appstream-rpms 217 k
glx-utils x86_64 8.4.0-5.20181118git1830dcb.el8 rhel-8-for-x86_64-appstream-rpms 44 k
gsm x86_64 1.0.17-5.el8 rhel-8-for-x86_64-appstream-rpms 37 k
gstreamer1-plugins-bad-free x86_64 1.16.1-1.el8 rhel-8-for-x86_64-appstream-rpms 1.8 M
libasyncns x86_64 0.8-14.el8 rhel-8-for-x86_64-appstream-rpms 32 k
libdvdnav x86_64 5.0.3-8.el8 rhel-8-for-x86_64-appstream-rpms 61 k
libdvdread x86_64 5.0.3-9.el8 rhel-8-for-x86_64-appstream-rpms 75 k
libevdev x86_64 1.10.0-1.el8 rhel-8-for-x86_64-appstream-rpms 44 k
libgudev x86_64 232-4.el8 rhel-8-for-x86_64-baseos-rpms 33 k
libinput x86_64 1.16.3-2.el8 rhel-8-for-x86_64-appstream-rpms 217 k
libsmi x86_64 0.4.8-23.el8 rhel-8-for-x86_64-appstream-rpms 2.4 M
libsndfile x86_64 1.0.28-10.el8_4.1 rhel-8-for-x86_64-appstream-rpms 193 k
libsrtp x86_64 1.5.4-8.el8 rhel-8-for-x86_64-appstream-rpms 282 k
libwacom x86_64 1.6-3.el8 rhel-8-for-x86_64-appstream-rpms 42 k
libwacom-data noarch 1.6-3.el8 rhel-8-for-x86_64-appstream-rpms 104 k
libxkbcommon-x11 x86_64 0.9.1-1.el8 rhel-8-for-x86_64-appstream-rpms 25 k
mtdev x86_64 1.1.5-12.el8 rhel-8-for-x86_64-appstream-rpms 24 k
openal-soft x86_64 1.18.2-7.el8 rhel-8-for-x86_64-appstream-rpms 394 k
pcre2-utf16 x86_64 10.32-2.el8 rhel-8-for-x86_64-baseos-rpms 229 k
pulseaudio-libs x86_64 14.0-2.el8 rhel-8-for-x86_64-appstream-rpms 681 k
pulseaudio-libs-glib2 x86_64 14.0-2.el8 rhel-8-for-x86_64-appstream-rpms 30 k
qt5-qtbase x86_64 5.15.2-3.el8 rhel-8-for-x86_64-appstream-rpms 3.6 M
qt5-qtbase-common noarch 5.15.2-3.el8 rhel-8-for-x86_64-appstream-rpms 41 k
qt5-qtbase-gui x86_64 5.15.2-3.el8 rhel-8-for-x86_64-appstream-rpms 6.1 M
qt5-qtdeclarative x86_64 5.15.2-2.el8 rhel-8-for-x86_64-appstream-rpms 4.2 M
qt5-qtmultimedia x86_64 5.15.2-2.el8 rhel-8-for-x86_64-appstream-rpms 881 k
soundtouch x86_64 2.0.0-3.el8 rhel-8-for-x86_64-appstream-rpms 76 k
webrtc-audio-processing x86_64 0.3-9.el8 rhel-8-for-x86_64-appstream-rpms 297 k
wireshark-cli x86_64 1:2.6.2-14.el8 rhel-8-for-x86_64-appstream-rpms 17 M
xcb-util x86_64 0.4.0-10.el8 rhel-8-for-x86_64-appstream-rpms 22 k
xcb-util-image x86_64 0.4.0-9.el8 rhel-8-for-x86_64-appstream-rpms 21 k
xcb-util-keysyms x86_64 0.4.0-7.el8 rhel-8-for-x86_64-appstream-rpms 16 k
xcb-util-renderutil x86_64 0.3.9-10.el8 rhel-8-for-x86_64-appstream-rpms 19 k
xcb-util-wm x86_64 0.4.1-12.el8 rhel-8-for-x86_64-appstream-rpms 32 k
xdg-utils noarch 1.1.2-5.el8 rhel-8-for-x86_64-appstream-rpms 84 k
Transaction Summary
===============================================================================================================
Install 36 Packages
Total download size: 43 M
Installed size: 176 M
Downloading Packages:
(1/36): libgudev-232-4.el8.x86_64.rpm 145 kB/s | 33 kB 00:00
(2/36): xdg-utils-1.1.2-5.el8.noarch.rpm 345 kB/s | 84 kB 00:00
(3/36): pcre2-utf16-10.32-2.el8.x86_64.rpm 905 kB/s | 229 kB 00:00
(4/36): xcb-util-image-0.4.0-9.el8.x86_64.rpm 99 kB/s | 21 kB 00:00
(5/36): xcb-util-wm-0.4.1-12.el8.x86_64.rpm 115 kB/s | 32 kB 00:00
(6/36): flac-libs-1.3.2-9.el8.x86_64.rpm 704 kB/s | 217 kB 00:00
(7/36): libdvdnav-5.0.3-8.el8.x86_64.rpm 271 kB/s | 61 kB 00:00
(8/36): libsrtp-1.5.4-8.el8.x86_64.rpm 1.5 MB/s | 282 kB 00:00
(9/36): xcb-util-keysyms-0.4.0-7.el8.x86_64.rpm 82 kB/s | 16 kB 00:00
(10/36): libdvdread-5.0.3-9.el8.x86_64.rpm 403 kB/s | 75 kB 00:00
(11/36): xcb-util-0.4.0-10.el8.x86_64.rpm 104 kB/s | 22 kB 00:00
(12/36): xcb-util-renderutil-0.3.9-10.el8.x86_64.rpm 92 kB/s | 19 kB 00:00
(13/36): libasyncns-0.8-14.el8.x86_64.rpm 177 kB/s | 32 kB 00:00
(14/36): gsm-1.0.17-5.el8.x86_64.rpm 199 kB/s | 37 kB 00:00
(15/36): openal-soft-1.18.2-7.el8.x86_64.rpm 1.6 MB/s | 394 kB 00:00
(16/36): mtdev-1.1.5-12.el8.x86_64.rpm 143 kB/s | 24 kB 00:00
(17/36): gstreamer1-plugins-bad-free-1.16.1-1.el8.x86_64.rpm 7.6 MB/s | 1.8 MB 00:00
(18/36): libxkbcommon-x11-0.9.1-1.el8.x86_64.rpm 123 kB/s | 25 kB 00:00
(19/36): webrtc-audio-processing-0.3-9.el8.x86_64.rpm 1.5 MB/s | 297 kB 00:00
(20/36): glx-utils-8.4.0-5.20181118git1830dcb.el8.x86_64.rpm 195 kB/s | 44 kB 00:00
(21/36): soundtouch-2.0.0-3.el8.x86_64.rpm 387 kB/s | 76 kB 00:00
(22/36): libsmi-0.4.8-23.el8.x86_64.rpm 12 MB/s | 2.4 MB 00:00
(23/36): pulseaudio-libs-glib2-14.0-2.el8.x86_64.rpm 142 kB/s | 30 kB 00:00
(24/36): pulseaudio-libs-14.0-2.el8.x86_64.rpm 2.5 MB/s | 681 kB 00:00
(25/36): libsndfile-1.0.28-10.el8_4.1.x86_64.rpm 797 kB/s | 193 kB 00:00
(26/36): libevdev-1.10.0-1.el8.x86_64.rpm 169 kB/s | 44 kB 00:00
(27/36): wireshark-2.6.2-14.el8.x86_64.rpm 9.6 MB/s | 3.6 MB 00:00
(28/36): qt5-qtbase-common-5.15.2-3.el8.noarch.rpm 205 kB/s | 41 kB 00:00
(29/36): libwacom-data-1.6-3.el8.noarch.rpm 616 kB/s | 104 kB 00:00
(30/36): wireshark-cli-2.6.2-14.el8.x86_64.rpm 24 MB/s | 17 MB 00:00
(31/36): libinput-1.16.3-2.el8.x86_64.rpm 799 kB/s | 217 kB 00:00
(32/36): libwacom-1.6-3.el8.x86_64.rpm 192 kB/s | 42 kB 00:00
(33/36): qt5-qtdeclarative-5.15.2-2.el8.x86_64.rpm 13 MB/s | 4.2 MB 00:00
(34/36): qt5-qtmultimedia-5.15.2-2.el8.x86_64.rpm 2.9 MB/s | 881 kB 00:00
(35/36): qt5-qtbase-5.15.2-3.el8.x86_64.rpm 15 MB/s | 3.6 MB 00:00
(36/36): qt5-qtbase-gui-5.15.2-3.el8.x86_64.rpm 15 MB/s | 6.1 MB 00:00
---------------------------------------------------------------------------------------------------------------
Total 13 MB/s | 43 MB 00:03
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : gsm-1.0.17-5.el8.x86_64 1/36
Installing : libasyncns-0.8-14.el8.x86_64 2/36
Running scriptlet: libasyncns-0.8-14.el8.x86_64 2/36
Installing : libdvdread-5.0.3-9.el8.x86_64 3/36
Running scriptlet: libdvdread-5.0.3-9.el8.x86_64 3/36
Installing : xcb-util-0.4.0-10.el8.x86_64 4/36
Installing : libgudev-232-4.el8.x86_64 5/36
Installing : xcb-util-image-0.4.0-9.el8.x86_64 6/36
Running scriptlet: xcb-util-image-0.4.0-9.el8.x86_64 6/36
Installing : libdvdnav-5.0.3-8.el8.x86_64 7/36
Running scriptlet: libdvdnav-5.0.3-8.el8.x86_64 7/36
Installing : libwacom-data-1.6-3.el8.noarch 8/36
Installing : libwacom-1.6-3.el8.x86_64 9/36
Installing : libevdev-1.10.0-1.el8.x86_64 10/36
Installing : libsmi-0.4.8-23.el8.x86_64 11/36
Running scriptlet: libsmi-0.4.8-23.el8.x86_64 11/36
Running scriptlet: wireshark-cli-1:2.6.2-14.el8.x86_64 12/36
Installing : wireshark-cli-1:2.6.2-14.el8.x86_64 12/36
Running scriptlet: wireshark-cli-1:2.6.2-14.el8.x86_64 12/36
Installing : soundtouch-2.0.0-3.el8.x86_64 13/36
Running scriptlet: soundtouch-2.0.0-3.el8.x86_64 13/36
Installing : glx-utils-8.4.0-5.20181118git1830dcb.el8.x86_64 14/36
Installing : webrtc-audio-processing-0.3-9.el8.x86_64 15/36
Running scriptlet: webrtc-audio-processing-0.3-9.el8.x86_64 15/36
Installing : libxkbcommon-x11-0.9.1-1.el8.x86_64 16/36
Installing : mtdev-1.1.5-12.el8.x86_64 17/36
Running scriptlet: mtdev-1.1.5-12.el8.x86_64 17/36
Installing : libinput-1.16.3-2.el8.x86_64 18/36
Running scriptlet: libinput-1.16.3-2.el8.x86_64 18/36
Installing : openal-soft-1.18.2-7.el8.x86_64 19/36
Installing : xcb-util-renderutil-0.3.9-10.el8.x86_64 20/36
Running scriptlet: xcb-util-renderutil-0.3.9-10.el8.x86_64 20/36
Installing : xcb-util-keysyms-0.4.0-7.el8.x86_64 21/36
Running scriptlet: xcb-util-keysyms-0.4.0-7.el8.x86_64 21/36
Installing : libsrtp-1.5.4-8.el8.x86_64 22/36
Running scriptlet: libsrtp-1.5.4-8.el8.x86_64 22/36
Installing : flac-libs-1.3.2-9.el8.x86_64 23/36
Installing : libsndfile-1.0.28-10.el8_4.1.x86_64 24/36
Running scriptlet: libsndfile-1.0.28-10.el8_4.1.x86_64 24/36
Installing : pulseaudio-libs-14.0-2.el8.x86_64 25/36
Installing : pulseaudio-libs-glib2-14.0-2.el8.x86_64 26/36
Installing : gstreamer1-plugins-bad-free-1.16.1-1.el8.x86_64 27/36
Installing : xcb-util-wm-0.4.1-12.el8.x86_64 28/36
Running scriptlet: xcb-util-wm-0.4.1-12.el8.x86_64 28/36
Installing : xdg-utils-1.1.2-5.el8.noarch 29/36
Installing : pcre2-utf16-10.32-2.el8.x86_64 30/36
Installing : qt5-qtbase-common-5.15.2-3.el8.noarch 31/36
Running scriptlet: qt5-qtbase-5.15.2-3.el8.x86_64 32/36
Installing : qt5-qtbase-5.15.2-3.el8.x86_64 32/36
Running scriptlet: qt5-qtbase-5.15.2-3.el8.x86_64 32/36
Installing : qt5-qtbase-gui-5.15.2-3.el8.x86_64 33/36
Installing : qt5-qtdeclarative-5.15.2-2.el8.x86_64 34/36
Installing : qt5-qtmultimedia-5.15.2-2.el8.x86_64 35/36
Installing : wireshark-1:2.6.2-14.el8.x86_64 36/36
Running scriptlet: wireshark-1:2.6.2-14.el8.x86_64 36/36
Verifying : libgudev-232-4.el8.x86_64 1/36
Verifying : pcre2-utf16-10.32-2.el8.x86_64 2/36
Verifying : xdg-utils-1.1.2-5.el8.noarch 3/36
Verifying : xcb-util-wm-0.4.1-12.el8.x86_64 4/36
Verifying : flac-libs-1.3.2-9.el8.x86_64 5/36
Verifying : xcb-util-image-0.4.0-9.el8.x86_64 6/36
Verifying : libdvdnav-5.0.3-8.el8.x86_64 7/36
Verifying : libsrtp-1.5.4-8.el8.x86_64 8/36
Verifying : xcb-util-keysyms-0.4.0-7.el8.x86_64 9/36
Verifying : xcb-util-0.4.0-10.el8.x86_64 10/36
Verifying : libdvdread-5.0.3-9.el8.x86_64 11/36
Verifying : xcb-util-renderutil-0.3.9-10.el8.x86_64 12/36
Verifying : libasyncns-0.8-14.el8.x86_64 13/36
Verifying : gsm-1.0.17-5.el8.x86_64 14/36
Verifying : openal-soft-1.18.2-7.el8.x86_64 15/36
Verifying : mtdev-1.1.5-12.el8.x86_64 16/36
Verifying : gstreamer1-plugins-bad-free-1.16.1-1.el8.x86_64 17/36
Verifying : libxkbcommon-x11-0.9.1-1.el8.x86_64 18/36
Verifying : webrtc-audio-processing-0.3-9.el8.x86_64 19/36
Verifying : glx-utils-8.4.0-5.20181118git1830dcb.el8.x86_64 20/36
Verifying : soundtouch-2.0.0-3.el8.x86_64 21/36
Verifying : libsmi-0.4.8-23.el8.x86_64 22/36
Verifying : pulseaudio-libs-14.0-2.el8.x86_64 23/36
Verifying : pulseaudio-libs-glib2-14.0-2.el8.x86_64 24/36
Verifying : libsndfile-1.0.28-10.el8_4.1.x86_64 25/36
Verifying : libevdev-1.10.0-1.el8.x86_64 26/36
Verifying : wireshark-cli-1:2.6.2-14.el8.x86_64 27/36
Verifying : wireshark-1:2.6.2-14.el8.x86_64 28/36
Verifying : qt5-qtbase-common-5.15.2-3.el8.noarch 29/36
Verifying : libinput-1.16.3-2.el8.x86_64 30/36
Verifying : libwacom-data-1.6-3.el8.noarch 31/36
Verifying : qt5-qtdeclarative-5.15.2-2.el8.x86_64 32/36
Verifying : qt5-qtmultimedia-5.15.2-2.el8.x86_64 33/36
Verifying : libwacom-1.6-3.el8.x86_64 34/36
Verifying : qt5-qtbase-5.15.2-3.el8.x86_64 35/36
Verifying : qt5-qtbase-gui-5.15.2-3.el8.x86_64 36/36
Installed products updated.
Installed:
flac-libs-1.3.2-9.el8.x86_64 glx-utils-8.4.0-5.20181118git1830dcb.el8.x86_64
gsm-1.0.17-5.el8.x86_64 gstreamer1-plugins-bad-free-1.16.1-1.el8.x86_64
libasyncns-0.8-14.el8.x86_64 libdvdnav-5.0.3-8.el8.x86_64
libdvdread-5.0.3-9.el8.x86_64 libevdev-1.10.0-1.el8.x86_64
libgudev-232-4.el8.x86_64 libinput-1.16.3-2.el8.x86_64
libsmi-0.4.8-23.el8.x86_64 libsndfile-1.0.28-10.el8_4.1.x86_64
libsrtp-1.5.4-8.el8.x86_64 libwacom-1.6-3.el8.x86_64
libwacom-data-1.6-3.el8.noarch libxkbcommon-x11-0.9.1-1.el8.x86_64
mtdev-1.1.5-12.el8.x86_64 openal-soft-1.18.2-7.el8.x86_64
pcre2-utf16-10.32-2.el8.x86_64 pulseaudio-libs-14.0-2.el8.x86_64
pulseaudio-libs-glib2-14.0-2.el8.x86_64 qt5-qtbase-5.15.2-3.el8.x86_64
qt5-qtbase-common-5.15.2-3.el8.noarch qt5-qtbase-gui-5.15.2-3.el8.x86_64
qt5-qtdeclarative-5.15.2-2.el8.x86_64 qt5-qtmultimedia-5.15.2-2.el8.x86_64
soundtouch-2.0.0-3.el8.x86_64 webrtc-audio-processing-0.3-9.el8.x86_64
wireshark-1:2.6.2-14.el8.x86_64 wireshark-cli-1:2.6.2-14.el8.x86_64
xcb-util-0.4.0-10.el8.x86_64 xcb-util-image-0.4.0-9.el8.x86_64
xcb-util-keysyms-0.4.0-7.el8.x86_64 xcb-util-renderutil-0.3.9-10.el8.x86_64
xcb-util-wm-0.4.1-12.el8.x86_64 xdg-utils-1.1.2-5.el8.noarch
Complete!
```
注意: -y 選項將在安裝過程中自動對任何提示回答是。在您自己的系統上安裝軟體時,使用此選項不是最佳做法,但它對於簡化本實驗室中的某些操作很有用。
此安裝生成大量輸出,因此這裡是每個部分含義的高級摘要。第一部分顯示了必須作為 Wireshark 依賴項安裝的所有包:
```shell=
Arch Version Repository Size
===================================================================
Installing:
wireshark
x86_64 1:2.6.2-12.el8 rhel-8-for-x86_64-appstream-rpms 3.7 M
Installing dependencies:
flac-libs
```
輸出的下一部分顯示每個依賴包的驗證狀態。在這種情況下,YUM 確保其他 36 個包是最新的。
```shell=
Verifying : libgudev-232-4.el8.x86_64 35/36
Verifying : pcre2-utf16-10.32-2.el8.x86_64 36/36
Installed products updated.
```
輸出的最後一部分是為支持 Wireshark 的安裝而安裝的所有軟體包的列表。
```shell=
Installed:
flac-libs-1.3.2-9.el8.x86_64
glx-utils-8.4.0-5.20181118git1830dcb.el8.x86_64
gsm-1.0.17-5.el8.x86_64
...
Complete!
```
您可以使用 yum list 命令驗證此安裝:
```shell=
yum list wireshark
Updating Subscription Management repositories.
Last metadata expiration check: 0:04:47 ago on Mon 20 Dec 2021 04:02:17 PM EST.
Installed Packages
wireshark.x86_64 1:2.6.2-14.el8 @rhel-8-for-x86_64-appstream-rpms
```
這顯示了 YUM 的強大,因為單個命令將無縫地進行安裝。接下來您將看到如何使用 yum 更新和刪除軟體包。
list 子命令可用於找出系統上哪些軟件包具有可用更新。
```shell=
yum list updates
Updating Subscription Management repositories.
Last metadata expiration check: 0:06:46 ago on Mon 20 Dec 2021 04:02:17 PM EST.
Available Upgrades
ModemManager-glib.x86_64 1.10.8-4.el8 rhel-8-for-x86_64-baseos-rpms
NetworkManager.x86_64 1:1.32.10-4.el8 rhel-8-for-x86_64-baseos-rpms
NetworkManager-libnm.x86_64 1:1.32.10-4.el8 rhel-8-for-x86_64-baseos-rpms
NetworkManager-team.x86_64 1:1.32.10-4.el8 rhel-8-for-x86_64-baseos-rpms
NetworkManager-tui.x86_64 1:1.32.10-4.el8 rhel-8-for-x86_64-baseos-rpms
alsa-lib.x86_64 1.2.5-4.el8 rhel-8-for-x86_64-appstream-rpms
apr.x86_64 1.6.3-12.el8 rhel-8-for-x86_64-appstream-rpms
authselect.x86_64 1.2.2-3.el8 rhel-8-for-x86_64-baseos-rpms
authselect-libs.x86_64 1.2.2-3.el8 rhel-8-for-x86_64-baseos-rpms
bash.x86_64 4.4.20-2.el8 rhel-8-for-x86_64-baseos-rpms
bind-export-libs.x86_64 32:9.11.26-6.el8 rhel-8-for-x86_64-baseos-rpms
binutils.x86_64 2.30-108.el8_5.1 rhel-8-for-x86_64-baseos-rpms
buildah.x86_64 1.22.3-2.module+el8.5.0+12582+56d94c81 rhel-8-for-x86_64-appstream-rpms
ca-certificates.noarch 2021.2.50-80.0.el8_4 rhel-8-for-x86_64-baseos-rpms
chkconfig.x86_64 1.19.1-1.el8 rhel-8-for-x86_64-baseos-rpms
chrony.x86_64 4.1-1.el8 rhel-8-for-x86_64-baseos-rpms
cockpit.x86_64 251.1-1.el8 rhel-8-for-x86_64-baseos-rpms
cockpit-bridge.x86_64 251.1-1.el8 rhel-8-for-x86_64-baseos-rpms
...
```
此系統上的許多軟體包都有可用的更新。使用 yum update 指定包名稱將限制此操作僅查找該包。
注意:如果你想確保你的整個系統都是最新的,運行 yum update 而不帶任何其他參數會為你係統上的所有軟體包(包括 YUM 本身)應用更新。
對於此示例,只需更新 bash 包。出於本實驗的目的,再次使用 -y 選項自動對任何提示說"是"。
```shell=
yum update -y bash
Updating Subscription Management repositories.
Last metadata expiration check: 0:11:01 ago on Mon 20 Dec 2021 04:02:17 PM EST.
Dependencies resolved.
========================================================================================================
Package Architecture Version Repository Size
========================================================================================================
Upgrading:
bash x86_64 4.4.20-2.el8 rhel-8-for-x86_64-baseos-rpms 1.5 M
Transaction Summary
========================================================================================================
Upgrade 1 Package
Total download size: 1.5 M
Downloading Packages:
bash-4.4.20-2.el8.x86_64.rpm 6.0 MB/s | 1.5 MB 00:00
--------------------------------------------------------------------------------------------------------
Total 5.9 MB/s | 1.5 MB 00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Upgrading : bash-4.4.20-2.el8.x86_64 1/2
Running scriptlet: bash-4.4.20-2.el8.x86_64 1/2
Cleanup : bash-4.4.19-14.el8.x86_64 2/2
Running scriptlet: bash-4.4.19-14.el8.x86_64 2/2
Verifying : bash-4.4.20-2.el8.x86_64 1/2
Verifying : bash-4.4.19-14.el8.x86_64 2/2
Installed products updated.
Upgraded:
bash-4.4.20-2.el8.x86_64
Complete!
```
注意:您有時會看到子命令 upgrade 與 update 可互換使用。 這兩個子命令之間的區別在於 upgrade 將從系統中刪除任何過時的包。 通常,YUM 的配置是這些子命令都將執行升級操作。
刪除包遵循相同的簡單主題。
```shell=
yum remove -y httpd
Updating Subscription Management repositories.
Dependencies resolved.
========================================================================================================
Package Arch Version Repository Size
========================================================================================================
Removing:
httpd x86_64 2.4.37-39.module+el8.4.0+9658+b87b2deb @rhel-8-for-x86_64-appstream-rpms 4.3 M
Removing dependent packages:
mod_ssl x86_64 1:2.4.37-39.module+el8.4.0+9658+b87b2deb
@rhel-8-for-x86_64-appstream-rpms 266 k
Removing unused dependencies:
apr x86_64 1.6.3-11.el8 @rhel-8-for-x86_64-appstream-rpms 260 k
apr-util x86_64 1.6.1-6.el8 @rhel-8-for-x86_64-appstream-rpms 230 k
apr-util-bdb x86_64 1.6.1-6.el8 @rhel-8-for-x86_64-appstream-rpms 12 k
apr-util-openssl x86_64 1.6.1-6.el8 @rhel-8-for-x86_64-appstream-rpms 20 k
httpd-filesystem noarch 2.4.37-39.module+el8.4.0+9658+b87b2deb @rhel-8-for-x86_64-appstream-rpms 400
httpd-tools x86_64 2.4.37-39.module+el8.4.0+9658+b87b2deb @rhel-8-for-x86_64-appstream-rpms 195 k
mailcap noarch 2.1.48-3.el8 @rhel-8-for-x86_64-baseos-rpms 71 k
mod_http2 x86_64 1.15.7-3.module+el8.4.0+8625+d397f3da @rhel-8-for-x86_64-appstream-rpms 394 k
redhat-logos-httpd
noarch 84.4-1.el8 @rhel-8-for-x86_64-baseos-rpms 7.7 k
Transaction Summary
========================================================================================================
Remove 11 Packages
Freed space: 5.7 M
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Running scriptlet: mod_ssl-1:2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64 1/1
Erasing : mod_ssl-1:2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64 1/11
Running scriptlet: mod_ssl-1:2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64 1/11
Running scriptlet: httpd-2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64 2/11
Erasing : httpd-2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64 2/11
Running scriptlet: httpd-2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64 2/11
Erasing : mailcap-2.1.48-3.el8.noarch 3/11
Erasing : httpd-filesystem-2.4.37-39.module+el8.4.0+9658+b87b2deb.noarch 4/11
Running scriptlet: httpd-filesystem-2.4.37-39.module+el8.4.0+9658+b87b2deb.noarch 4/11
Erasing : redhat-logos-httpd-84.4-1.el8.noarch 5/11
Erasing : httpd-tools-2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64 6/11
Erasing : apr-util-1.6.1-6.el8.x86_64 7/11
Running scriptlet: apr-util-1.6.1-6.el8.x86_64 7/11
Erasing : apr-1.6.3-11.el8.x86_64 8/11
Running scriptlet: apr-1.6.3-11.el8.x86_64 8/11
Erasing : apr-util-bdb-1.6.1-6.el8.x86_64 9/11
Erasing : apr-util-openssl-1.6.1-6.el8.x86_64 10/11
Erasing : mod_http2-1.15.7-3.module+el8.4.0+8625+d397f3da.x86_64 11/11
Running scriptlet: mod_http2-1.15.7-3.module+el8.4.0+8625+d397f3da.x86_64 11/11
Verifying : apr-1.6.3-11.el8.x86_64 1/11
Verifying : apr-util-1.6.1-6.el8.x86_64 2/11
Verifying : apr-util-bdb-1.6.1-6.el8.x86_64 3/11
Verifying : apr-util-openssl-1.6.1-6.el8.x86_64 4/11
Verifying : httpd-2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64 5/11
Verifying : httpd-filesystem-2.4.37-39.module+el8.4.0+9658+b87b2deb.noarch 6/11
Verifying : httpd-tools-2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64 7/11
Verifying : mailcap-2.1.48-3.el8.noarch 8/11
Verifying : mod_http2-1.15.7-3.module+el8.4.0+8625+d397f3da.x86_64 9/11
Verifying : mod_ssl-1:2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64 10/11
Verifying : redhat-logos-httpd-84.4-1.el8.noarch 11/11
Installed products updated.
Removed:
apr-1.6.3-11.el8.x86_64
apr-util-1.6.1-6.el8.x86_64
apr-util-bdb-1.6.1-6.el8.x86_64
apr-util-openssl-1.6.1-6.el8.x86_64
httpd-2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64
httpd-filesystem-2.4.37-39.module+el8.4.0+9658+b87b2deb.noarch
httpd-tools-2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64
mailcap-2.1.48-3.el8.noarch
mod_http2-1.15.7-3.module+el8.4.0+8625+d397f3da.x86_64
mod_ssl-1:2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64
redhat-logos-httpd-84.4-1.el8.noarch
Complete!
```
大量輸出顯示了有關作為此事務的一部分刪除了哪些相關 RPM 的信息。
使用 list 子命令確認軟體包已被卸載:
```shell=
yum list httpd
Updating Subscription Management repositories.
Last metadata expiration check: 0:13:59 ago on Mon 20 Dec 2021 04:02:17 PM EST.
Available Packages
httpd.x86_64 2.4.37-43.module+el8.5.0+13064+c4b14997 rhel-8-for-x86_64-appstream-rpms
```
該軟體包現在列為可用而不是已安裝。下一步將帶您了解 yum 歷史,它提供了一些更強大的工具來回滾包事務。
#### Using yum history to roll back a transaction
history 子命令提供最近 yum 事務的摘要。
```shell=
yum history
Updating Subscription Management repositories.
ID | Command line | Date and time | Action(s) | Altered
------------------------------------------------------------------------------------------------------
7 | remove -y httpd | 2021-12-20 16:15 | Removed | 11
6 | update -y bash | 2021-12-20 16:13 | Upgrade | 1
5 | install -y wireshark | 2021-12-20 16:02 | Install | 36
4 | install -y gcc llvm-libs gcc-c++ cpp binutils b | 2021-06-09 20:16 | Install | 13
3 | install -y buildah podman wget vim emacs git su | 2021-06-09 20:15 | Install | 216
2 | install -y rsync | 2021-06-09 20:13 | Install | 1
1 | | 2021-06-09 16:07 | Install | 428 EE
[root@049e11dcfd5f ~]# yum history
Updating Subscription Management repositories.
ID | Command line | Date and time | Action(s) | Altered
--------------------------------------------------------------------------------------------------------
7 | remove -y httpd | 2021-12-20 16:15 | Removed | 11
6 | update -y bash | 2021-12-20 16:13 | Upgrade | 1
5 | install -y wireshark | 2021-12-20 16:02 | Install | 36
4 | install -y gcc llvm-libs gcc-c++ cpp binutils bas | 2021-06-09 20:16 | Install | 13
3 | install -y buildah podman wget vim emacs git sudo | 2021-06-09 20:15 | Install | 216
2 | install -y rsync | 2021-06-09 20:13 | Install | 1
1 | | 2021-06-09 16:07 | Install | 428 EE
```
輸出在第一列中包含事務 ID,這是您在執行回滾時引用事務歷史記錄中特定位置的方式。
如果您錯誤地安裝或更新包,此子命令對於回滾事務也很有用,因為它會清除與包關聯的所有依賴項。將系統狀態回滾到卸載 httpd 之前:
```shell=
yum -y history rollback 6
Updating Subscription Management repositories.
Last metadata expiration check: 0:16:23 ago on Mon 20 Dec 2021 04:02:17 PM EST.
Dependencies resolved.
=======================================================================================================
Package Arch Version Repository Size
=======================================================================================================
Installing:
httpd x86_64 2.4.37-39.module+el8.4.0+9658+b87b2deb rhel-8-for-x86_64-appstream-rpms 1.4 M
Installing dependencies:
apr x86_64 1.6.3-11.el8 rhel-8-for-x86_64-appstream-rpms 125 k
apr-util x86_64 1.6.1-6.el8 rhel-8-for-x86_64-appstream-rpms 105 k
apr-util-bdb x86_64 1.6.1-6.el8 rhel-8-for-x86_64-appstream-rpms 25 k
apr-util-openssl x86_64 1.6.1-6.el8 rhel-8-for-x86_64-appstream-rpms 27 k
httpd-filesystem noarch 2.4.37-39.module+el8.4.0+9658+b87b2deb rhel-8-for-x86_64-appstream-rpms 38 k
httpd-tools x86_64 2.4.37-39.module+el8.4.0+9658+b87b2deb rhel-8-for-x86_64-appstream-rpms 106 k
mailcap noarch 2.1.48-3.el8 rhel-8-for-x86_64-baseos-rpms 39 k
mod_http2 x86_64 1.15.7-3.module+el8.4.0+8625+d397f3da rhel-8-for-x86_64-appstream-rpms 154 k
mod_ssl x86_64 1:2.4.37-39.module+el8.4.0+9658+b87b2deb
rhel-8-for-x86_64-appstream-rpms 134 k
redhat-logos-httpd
noarch 84.4-1.el8 rhel-8-for-x86_64-baseos-rpms 29 k
Transaction Summary
=======================================================================================================
Install 11 Packages
Total download size: 2.2 M
Installed size: 5.7 M
Downloading Packages:
(1/11): mailcap-2.1.48-3.el8.noarch.rpm 170 kB/s | 39 kB 00:00
(2/11): apr-util-openssl-1.6.1-6.el8.x86_64.rpm 98 kB/s | 27 kB 00:00
(3/11): apr-util-bdb-1.6.1-6.el8.x86_64.rpm 116 kB/s | 25 kB 00:00
(4/11): apr-util-1.6.1-6.el8.x86_64.rpm 491 kB/s | 105 kB 00:00
(5/11): apr-1.6.3-11.el8.x86_64.rpm 513 kB/s | 125 kB 00:00
(6/11): httpd-filesystem-2.4.37-39.module+el8.4.0+9658+b87b2deb.noarch 179 kB/s | 38 kB 00:00
(7/11): mod_http2-1.15.7-3.module+el8.4.0+8625+d397f3da.x86_64.rpm 649 kB/s | 154 kB 00:00
(8/11): httpd-2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64.rpm 4.9 MB/s | 1.4 MB 00:00
(9/11): httpd-tools-2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64.rpm 536 kB/s | 106 kB 00:00
(10/11): mod_ssl-2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64.rpm 587 kB/s | 134 kB 00:00
(11/11): redhat-logos-httpd-84.4-1.el8.noarch.rpm 20 kB/s | 29 kB 00:01
-------------------------------------------------------------------------------------------------------
Total 1.5 MB/s | 2.2 MB 00:01
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : apr-1.6.3-11.el8.x86_64 1/11
Running scriptlet: apr-1.6.3-11.el8.x86_64 1/11
Installing : apr-util-bdb-1.6.1-6.el8.x86_64 2/11
Installing : apr-util-1.6.1-6.el8.x86_64 3/11
Running scriptlet: apr-util-1.6.1-6.el8.x86_64 3/11
Installing : apr-util-openssl-1.6.1-6.el8.x86_64 4/11
Running scriptlet: httpd-filesystem-2.4.37-39.module+el8.4.0+9658+b87b2deb.noarch 5/11
Installing : httpd-filesystem-2.4.37-39.module+el8.4.0+9658+b87b2deb.noarch 5/11
Installing : httpd-tools-2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64 6/11
Installing : redhat-logos-httpd-84.4-1.el8.noarch 7/11
Installing : mailcap-2.1.48-3.el8.noarch 8/11
Installing : mod_http2-1.15.7-3.module+el8.4.0+8625+d397f3da.x86_64 9/11
Installing : httpd-2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64 10/11
Running scriptlet: httpd-2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64 10/11
Installing : mod_ssl-1:2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64 11/11
Running scriptlet: httpd-2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64 11/11
Running scriptlet: mod_ssl-1:2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64 11/11
Verifying : mailcap-2.1.48-3.el8.noarch 1/11
Verifying : redhat-logos-httpd-84.4-1.el8.noarch 2/11
Verifying : apr-util-openssl-1.6.1-6.el8.x86_64 3/11
Verifying : apr-util-bdb-1.6.1-6.el8.x86_64 4/11
Verifying : apr-util-1.6.1-6.el8.x86_64 5/11
Verifying : apr-1.6.3-11.el8.x86_64 6/11
Verifying : httpd-filesystem-2.4.37-39.module+el8.4.0+9658+b87b2deb.noarch 7/11
Verifying : httpd-2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64 8/11
Verifying : mod_http2-1.15.7-3.module+el8.4.0+8625+d397f3da.x86_64 9/11
Verifying : httpd-tools-2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64 10/11
Verifying : mod_ssl-1:2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64 11/11
Installed products updated.
Installed:
apr-1.6.3-11.el8.x86_64
apr-util-1.6.1-6.el8.x86_64
apr-util-bdb-1.6.1-6.el8.x86_64
apr-util-openssl-1.6.1-6.el8.x86_64
httpd-2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64
httpd-filesystem-2.4.37-39.module+el8.4.0+9658+b87b2deb.noarch
httpd-tools-2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64
mailcap-2.1.48-3.el8.noarch
mod_http2-1.15.7-3.module+el8.4.0+8625+d397f3da.x86_64
mod_ssl-1:2.4.37-39.module+el8.4.0+9658+b87b2deb.x86_64
redhat-logos-httpd-84.4-1.el8.noarch
Complete!
```
注意:此處的數字 6 用於指定將系統狀態回滾到事務 ID 6 或刪除 httpd 之前的狀態。 您可以使用其他相對偏移量,例如 last-3,或者您可以使用絕對交易 ID。 例如,yum history rollback 2 將回滾到安裝了 rsync 的事務。
此命令重新安裝了屬於 httpd(包括所有依賴項)的 RPM,將系統狀態恢復到前一個事務之前的狀態。 您可以使用更多子命令來自定義 YUM 的行為方式。 查看此 RHEL 的 YUM 命令備忘單以獲取更多信息。
#### Using RPM to run detailed queries
YUM 是標準的包管理器,但這並不意味著 RPM 已過時。可以使用查詢選項 (-q) 使用 RPM 執行詳細查詢。此步驟將引導您完成有關如何使用此選項的三個示例。
您可以將 -q 選項與列表選項 (-l) 結合使用,以顯示特定軟件包安裝的所有文件。 默認情況下,此信息是隱藏的,以保持軟件包安裝過程簡單,但了解特定文件所在的位置通常很有用。
```shell=
rpm -ql wireshark
/usr/bin/wireshark
/usr/lib/.build-id
/usr/lib/.build-id/80
/usr/lib/.build-id/80/fcff1a01bb50122f9cf3729f98354e136d47e2
/usr/share/appdata/wireshark.appdata.xml
/usr/share/applications/wireshark.desktop
/usr/share/icons/hicolor/128x128/apps/wireshark.png
/usr/share/icons/hicolor/128x128/mimetypes/application-wireshark-doc.png
/usr/share/icons/hicolor/16x16/apps/wireshark.png
/usr/share/icons/hicolor/16x16/mimetypes/application-wireshark-doc.png
/usr/share/icons/hicolor/24x24/apps/wireshark.png
/usr/share/icons/hicolor/24x24/mimetypes/application-wireshark-doc.png
/usr/share/icons/hicolor/256x256/apps/wireshark.png
/usr/share/icons/hicolor/256x256/mimetypes/application-wireshark-doc.png
/usr/share/icons/hicolor/32x32/apps/wireshark.png
/usr/share/icons/hicolor/32x32/mimetypes/application-wireshark-doc.png
/usr/share/icons/hicolor/48x48/apps/wireshark.png
/usr/share/icons/hicolor/48x48/mimetypes/application-wireshark-doc.png
/usr/share/icons/hicolor/64x64/apps/wireshark.png
/usr/share/icons/hicolor/64x64/mimetypes/application-wireshark-doc.png
/usr/share/icons/hicolor/scalable/apps/wireshark.svg
/usr/share/man/man1/wireshark.1.gz
/usr/share/mime/packages/wireshark.xml
```
現在您可以看到 Wireshark 應用程序位於 usr/bin/wireshark。
一些軟體包運行腳本來完成它們的安裝過程。 --scripts 選項可以與 rpm -q 結合使用,以返回特定軟體包的這些安裝後腳本的內容。 Wireshark 實際上沒有任何安裝後腳本,因此請使用 httpd 包嘗試使用此命令。
```shell=
rpm -q --scripts httpd
postinstall scriptlet (using /bin/sh):
if [ $1 -eq 1 ] ; then
# Initial installation
systemctl --no-reload preset httpd.service htcacheclean.service httpd.socket &>/dev/null || :
fi
preuninstall scriptlet (using /bin/sh):
if [ $1 -eq 0 ] ; then
# Package removal, not upgrade
systemctl --no-reload disable --now httpd.service htcacheclean.service httpd.socket &>/dev/null || :
fi
postuninstall scriptlet (using /bin/sh):
# 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 --no-block httpd.service htcacheclean.service >/dev/null 2>&1 || :
```
輸出顯示了一個腳本,該腳本在安裝包時為幕後的 httpd 服務創建預設。
使用 rpm -q 指定 --changelog 將顯示包中最近更改的內容。
```shell=
* Thu May 25 2017 Martin Sehnoutka <msehnout@redhat.com> - 2.2.6-5
- Add triggerin script to remove old alternatives
- Remove appdata.xml as it is provided by upstream now
* Mon May 15 2017 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 2.2.6-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_26_27_Mass_Rebuild
* Mon Apr 24 2017 Martin Sehnoutka <msehnout@redhat.com> - 2.2.6-2
- Build with lua support (resolves: #1259623)
* Fri Apr 21 2017 Martin Sehnoutka <msehnout@redhat.com> - 2.2.6-1
- New upstream release 2.2.6
* Fri Apr 07 2017 Igor Gnatenko <ignatenko@redhat.com> - 2.2.5-2
- Stop patching pkg-config
* Tue Mar 07 2017 Martin Sehnoutka <msehnout@redhat.com> - 2.2.5-1
- New upstream version 2.2.5
```
如果程序突然出現異常,可能與某些關鍵文件沒有正確安裝有關。 rpm 有一個驗證選項 (-V),它將本地文件與包的預期文件進行比較。 從 Wireshark 包中刪除文件以測試此驗證功能:
```shell=
rm -f /usr/share/icons/hicolor/256x256/apps/wireshark.png
```
使用帶有 rpm 的 -V 選項來檢查 Wireshark 的文件狀態。
```shell=
rpm -V wireshark
missing /usr/share/icons/hicolor/256x256/apps/wireshark.png
```
現在您已經看到丟失的文件,重新安裝 Wireshark 包以將其恢復到正確的狀態:
```shell=
yum -y reinstall wireshark
Updating Subscription Management repositories.
Last metadata expiration check: 0:23:23 ago on Mon 20 Dec 2021 04:02:17 PM EST.
Dependencies resolved.
=========================================================================================================
Package Architecture Version Repository Size
=========================================================================================================
Reinstalling:
wireshark x86_64 1:2.6.2-14.el8 rhel-8-for-x86_64-appstream-rpms 3.6 M
Transaction Summary
=========================================================================================================
Total download size: 3.6 M
Installed size: 8.3 M
Downloading Packages:
wireshark-2.6.2-14.el8.x86_64.rpm 13 MB/s | 3.6 MB 00:00
---------------------------------------------------------------------------------------------------------
Total 12 MB/s | 3.6 MB 00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Reinstalling : wireshark-1:2.6.2-14.el8.x86_64 1/2
Cleanup : wireshark-1:2.6.2-14.el8.x86_64 2/2
Running scriptlet: wireshark-1:2.6.2-14.el8.x86_64 2/2
Verifying : wireshark-1:2.6.2-14.el8.x86_64 1/2
Verifying : wireshark-1:2.6.2-14.el8.x86_64 2/2
Installed products updated.
Reinstalled:
wireshark-1:2.6.2-14.el8.x86_64
Complete!
```
檢查wireshark.png是否已經恢復:
```shell=
ls /usr/share/icons/hicolor/256x256/apps/
fedora-logo-icon.png wireshark.png
```
命令 rpm -V 不僅僅用於查找丟失的文件。此命令可以通知用戶自安裝以來是否有任何文件發生更改。要對此進行測試,請在 PAM 包上運行驗證命令。
```shell=
rpm -V pam
S.5....T. c /etc/pam.d/password-auth
S.5....T. c /etc/pam.d/system-auth
```
此查詢返回兩個具有意外條件的文件,password-auth 和 system-auth。 此輸出的第一列告訴您這兩個文件都有意外的大小、校驗和和時間戳。 這兩個文件都是配置文件,所以在安裝後修改它們以適應這個特定係統的目的是有道理的
### yum groupinstall & install
Redhat、Fedora 和 CentOS 安裝程序 (anaconda) 提供了一系列基於圖形或文本的螢幕,以引導用戶完成作業系統安裝過程。其中一個螢幕允許用戶選擇一個或多個軟體包組進行安裝,並可選擇允許添加和刪除單個軟體包。
yum grouplist
```shell=
yum grouplist
Last metadata expiration check: 8:38:49 ago on Tue 21 Dec 2021 12:44:37 PM CST.
Available Environment Groups:
Server
Minimal Install
Workstation
Virtualization Host
Custom Operating System
Installed Environment Groups:
Server with GUI
Installed Groups:
Container Management
Headless Management
Available Groups:
.NET Core Development
RPM Development Tools
Development Tools
Graphical Administration Tools
Legacy UNIX Compatibility
Network Servers
Scientific Support
Security Tools
Smart Card Support
System Tools
```
yum groupinfo
```shell=
yum groupinfo Graphics
Last metadata expiration check: 8:40:15 ago on Tue 21 Dec 2021 12:44:37 PM CST.
Group: Graphics Creation Tools
Description: Software for creation and manipulation of still images.
Default Packages:
gutenprint-plugin
libsane-hpaio
sane-backends-drivers-scanners
sane-frontends
xsane-gimp
Optional Packages:
dcraw
netpbm-progs
```
groupinstall
groupremove
groupupdate
yum install 它安裝單個軟體,以及這個軟體的依賴關係
yum groupinstall 它安裝一個安裝包,這個安裝包包涵了很多單個軟體,以及單個軟體的依賴關係。
### Step 3: GNU Debugger
**GDB capabilities**
A single GDB session can debug the following types of programs:
1. Multithreaded and forking programs
2. Multiple programs at once
3. Programs on remote machines or in containers with the gdbserver utility connected over a TCP/IP network connection
**Debugging requirements**
To debug any executable code, GDB requires debugging information for that particular code:
> For programs developed by you, you can create the debugging information while building the code.
> For system programs installed from packages, you must install their debuginfo packages.
**Attaching GDB to an already running process**
To attach GDB to a program already running as a process:
1. Find the process ID (pid) with the ps command:
> $ ps -C program -o pid h
> $ gdb -p pid
### GDB commands
1. run | r
> 開始執行程序。如果run使用任何參數執行,則這些參數將傳遞給可執行文件,就像程序已正常啟動一樣。使用者通常在設置breakpoint後發出此命令。
3. start
> 開始執行程序,但在程序主函數的開始處停止。如果start使用任何參數執行,則這些參數將傳遞給可執行文件,就像程序一般正常啟動一樣。
4. continue | c
> 從當前狀態繼續執行程序。程序將繼續執行,直到下列情況之一變為真:
- [x] 到達斷點。
- [x] 滿足特定條件。
- [x] 程序接收到一個信號。
- [x] 發生錯誤。
- [x] 程序終止。
5. next | n
> 從當前狀態繼續執行程序,直到到達當前源文件中的下一行代碼。
6. step | s
> 該step命令會在當前源文件中的每個連續代碼行處繼續執行。但是,如果執行當前在包含函式呼叫的源代碼行處時會停止,並且進入到函式裡頭。
7. quit | q
> 終止執行並退出 GDB。
8. print | p
> 顯示給定參數的值。通常,參數是任何復雜性的變量的名稱,從簡單的單個值到結構。參數也可以是在當前語言中有效的表達式,包括程序變量和庫函數的使用,或被測試程序中定義的函數。
9. backtrace | bt
> 顯示用於到達當前執行點的函數調用鏈,或在執行終止之前使用的函數鏈。這對於調查具有難以捉摸的原因的嚴重錯誤(例如分段錯誤)非常有用。
將 ```full``` 選項添加到 ```backtrace``` 命令也會顯示局部變量。
10. info
> 該info命令是一個通用命令,用於提供有關各種項目的信息。它需要一個選項來指定要描述的項目。
- [x] info args命令顯示作為當前選定幀的函數調用的選項。
- [x] info locals命令顯示當前選定幀中的局部變量。
11. help
> 查找相關資訊如何使用。
12. list | l
> 顯示源代碼中程序停止的那一行。此命令僅在程序執行停止時可用。雖然不是嚴格的顯示內部狀態的命令,但list可以幫助用戶了解在程序執行的下一步中內部狀態會發生什麼變化。
### Using GDB breakpoints
通常,只研究一小部分代碼。斷點是告訴 GDB 在代碼中的某個位置停止執行程序的標記。斷點最常與源代碼行相關聯。在這種情況下,放置斷點需要指定源文件和行號。
- To place a breakpoint:
- Specify the name of the source code file and the line in that file:
```shell=
(gdb) br file:line
```
- When file is not present, name of the source file at the current point of execution is used:
```shell=
(gdb) br line
```
- Alternatively, use a function name to put the breakpoint on its start:
```shell=
(gdb) br function_name
```
- A program might encounter an error after a certain number of iterations of a task. To specify an additional condition to halt execution:
```shell=
(gdb) br file:line if condition
Replace condition with a condition in the C or C++ language. The meaning of file and line is the same as above.
```
- To inspect the status of all breakpoints and watchpoints and To remove a breakpoint by using its number as displayed in the output of info br:
```shell=
(gdb) info br
(gdb) delete number
```
- To remove a breakpoint at a given location:
```shell=
(gdb) clear file:line
```
- GDB debugging forking or threaded programs
- Forking is a situation when a program (parent) creates an independent copy of itself (child). Use the following settings and commands to affect what GDB does when a fork occurs:
- ==follow-fork-mode設置控制分叉後 GDB 是跟隨父級還是子級。
fork 之後,調試父進程。這是預設設置。==
```shell=
set follow-fork-mode parent # default
set follow-fork-mode child # fork 之後,調試子進程。
show follow-fork-mode # 顯示當前的設置follow-fork-mode。
```
- The set ==detach-on-fork== setting controls whether the GDB keeps control of the other (not followed) process or leaves it to run.
```shell=
set detach-on-fork on
```
> The process which is not followed (depending on the value of follow-fork-mode) is detached and runs independently. This is the default.
```shell=
set detach-on-fork off
```
> GDB keeps control of both processes. The process which is followed (depending on the value of follow-fork-mode) is debugged as usual, while the other is suspended.
```shell=
show detach-on-fork
```
> Display the current setting of detach-on-fork.
### USING GCC TOOLSET
Red Hat Enterprise Linux 8 introduces GCC Toolset, an Application Stream containing more up-to-date versions of development and performance analysis tools. GCC Toolset is similar to Red Hat Developer Toolset for RHEL 7.
- Red Hat Software Collections
```shell=
subscription-manager list --available # 顯示可用於您的系統的所有訂閱的列表
subscription-manager repos --list # 檢索存儲庫元數據並顯示可用Yum存儲庫的列表
```
### DNF & YUM Tools
DNF 是 Fedora 項目包管理器,可以查詢包的信息,從存儲庫中獲取包,使用自動依賴解析安裝和卸載包,並將整個系統更新為最新的可用軟件包。
DNF 對你正在更新的包執行自動依賴解析,安裝或刪除,因此能夠自動確定,獲取並安裝所有可用的依賴包。
DNF 可以配置新的、額外的存儲庫或包源,還提供了許多增強和擴展其功能的插件。
DNF 能夠執行許多與 RPM 相同的任務,此外,許多命令行選項是相似的,DNF 可以在單台機器或機器組上輕鬆簡單地管理包。
> important [color=#3b75c6]
使用 GPG 簽名的包保護包管理,DNF 通過在 GPG 簽名的包上啟用 GPG(Gnu Privacy Guard;也稱為 GnuPG)簽名驗證來提供安全的包管理,以便為所有包存儲庫(包源)或單個存儲庫打開。啟用簽名驗證後,DNF 將拒絕安裝任何未使用該存儲庫的正確密鑰進行 GPG 簽名的軟件包。這意味著您可以相信您下載並安裝在系統上的RPM包來自可信賴的來源。
您必須具有超級用戶權限才能使用dnf命令在您的系統上安裝、更新或刪除軟體包。 需要使用su或是sudo來獲得超級權限。
Configuring DNF and DNF Repositories
DNF 和相關實用程序的配置文件位於 /etc/dnf/dnf.conf 檔案內。
該文件包含一個強制性的 [main] 的部分,它允許您設置具有全局效果的 DNF 選項,並且還可能包含一個或多個 [repository] 部分,它允許您設置存儲庫特定的選項。
但是,建議在 /etc/yum.repos.d/ 目錄中的新的或現有的 .repo 文件中定義單個存儲庫。
您在 /etc/dnf/dnf.conf 文件的各個 [repository] 部分中定義的值會覆蓋在 [main] 部分中設置的值。
- 通過編輯 /etc/dnf/dnf.conf 配置文件的 [main] 部分來設置全局 DNF 選項
- 通過編輯 /etc/dnf/dnf.conf 中的 [repository] 部分和 /etc/yum.repos.d/ 目錄中的 .repo 文件來為各個存儲庫設置選項
- 使用 /etc/dnf/dnf.conf 中的 DNF 變量和 /etc/yum.repos.d/ 目錄中的文件,以便正確處理動態版本和架構值
- 添加啟用並在命令行上禁用 DNF 存儲庫
- 設置您自己的自定義 DNF 存儲庫
/etc/dnf/dnf.conf 配置文件只包含一個 [main] 部分,雖然該部分中的一些key-value對影響 dnf 的操作方式,但其他部分會影響 DNF 處理存儲庫的方式。
示例 /etc/dnf/dnf.conf 配置文件可能如下所示:
```c=
[main]
gpgcheck=1
installonly_limit=3
clean_requirements_on_remove=true
```
以下是 [main] 部分中最常用的選項:
debuglevel=value
其中 value 是 0 到 10 之間的整數。設置更高的 debuglevel 值會導致 dnf 顯示更詳細的調試輸出。 debuglevel=0 禁用調試輸出,debuglevel=2 是默認值。
exclude=package_name more_package_names
此選項允許您在安裝和更新期間按關鍵字排除軟體包。可以通過引用以空格分隔的包列表來列出要排除的多個包,Shell globs using wildcards (for example, * and ?) are allowed.
gpgcheck=value
其中 value 是以下之一:
0 — 禁用對所有存儲庫中的包進行 GPG 簽名檢查,包括本地包安裝
1 — 對所有存儲庫中的所有包啟用 GPG 簽名檢查,包括本地包安裝。 gpgcheck=1 是默認值,因此所有包的簽名都會被檢查。
如果在 /etc/dnf/dnf.conf 文件的 [main] 部分設置了此選項,則會為所有存儲庫設置 GPG 檢查規則,但是,您也可以為單個存儲庫設置 gpgcheck=value,您可以在一個存儲庫上啟用 GPG 檢查,同時在另一個存儲庫上禁用它。如果 /etc/dnf/dnf.conf 中存在默認值,則在其相應的 .repo 文件中為單個存儲庫設置 gpgcheck=value 會覆蓋默認值。
enabled=value
其中 value 是以下之一:
0 — 執行更新和安裝時,不要將此存儲庫作為包源包含在內。
1 — 將此存儲庫包含為包源。
打開和關閉存儲庫也可以通過將 --set-enabled repo_name 或 --set-disabled repo_name 選項傳遞給 dnf 命令來執行,或通過 PackageKit 實用程序的添加/刪除軟體窗口。
Using DNF Variables
變數只能在 DNF 配置文件的相應部分使用,即 /etc/dnf/dnf.conf 文件和 /etc/yum.repos.d/ 目錄中的所有 .repo 文件。存儲庫變量包括:
$releasever
指的是 DNF 從 RPMDB 中可用信息推導的作業系統的發布版本。
$arch
指系統的 CPU 架構。 $arch 的有效值包括:i586、i686 和 x86_64。
$basearch
指系統的基礎架構。比如i686和i586機器都是i386基礎架構,AMD64和Intel64機器都是x86_64基礎架構。
#### Viewing the Current Configuration
列出所有配置選項及其對應的值,以及存儲庫,執行 dnf config-manager 命令並使用 --dump 選項:
```c=
~]$ dnf config-manager --dump
============================= main ======================================
[main]
alwaysprompt = True
assumeno = False
assumeyes = False
bandwidth = 0
best = False
bugtracker_url = https://bugzilla.redhat.com/enter_bug.cgi?product=Fedora&component=dnf
cachedir = /var/cache/dnf/x86_64/22
[output truncated]
```
#### Adding, Enabling, and Disabling a DNF Repository
設置 [repository Options] 描述了可用於定義 DNF 存儲庫的各種選項。本節說明如何使用 dnf config-manager 命令添加、啟用和禁用存儲庫。
要定義新的存儲庫,您可以將 [repository] 部分添加到 /etc/dnf/dnf.conf 文件,或者到 /etc/yum.repos.d/ 目錄中的 .repo 文件,此目錄中所有文件擴展名為 .repo 的文件都被 DNF 讀取。並且建議在此處而不是在 /etc/dnf/dnf.conf 中定義您的存儲庫。
DNF 存儲庫通常提供自己的 .repo 文件。要將這樣的存儲庫添加到您的系統並啟用它,請以 root 身份運行以下命令
```shell=
dnf config-manager --add-repo repository_url
```
其中 repository_url 是 .repo 文件的鏈接。
ex: 要添加位於 http://www.example.com/example.repo 的存儲庫,請在 shell 提示符下鍵入以下內容:
```shell=
~]# dnf config-manager --add-repo http://www.example.com/example.repo
adding repo from: http://www.example.com/example.repo
```
啟用 DNF 存儲庫 要啟用一個或多個特定存儲庫,請以 root 身份在 shell 提示符下鍵入以下內容:
```shell=
dnf config-manager --set-enabled repository ...
```
其中 repository 是唯一的存儲庫 ID。要顯示當前配置,請添加 --dump 選項。
禁用 DNF 存儲庫 要禁用 DNF 存儲庫,請以 root 身份運行以下命令:
```shell=
dnf config-manager --set-disabled repository ...
```
其中 repository 是唯一的存儲庫 ID。要顯示當前配置,請添加 --dump 選項。
> Leave in-line comments! [color=#3b75c6]
## Linux Package managers: apt & yum, dpkg & rpm
Linux OS 基本上由兩部分組成
- Linux 內核
- 與內核協同工作的軟體包,為我們提供完整的作業系統
這些包可以是應用程序軟體,如文本編輯器、文字處理器等,也可以是 GNU 實用程序,如 bash、cron、dd 等,或者它們可以是與硬體對話的設備驅動程序。除了內核之外的一切都是 Linux 中的一個包。
### Contents of packages
- Binaries or the executable programs
- metadata files containing the version, dependencies, signatures and other relevant information
- documentation and manuals
- configuration files
在 Linux 的早期時代,在我們擁有這些“包管理器”之前,安裝軟體是一個耗時的過程。這個過程是這樣的
- 下載原始程式碼
- 編譯
- 將生成的二進製文件放入適當的 "bin" 文件夾中,以便作業系統在調用時可以找到它
- 將文檔放在“man”文件夾中,以便您可以使用 "man package name" 命令獲取有關包的信息
- 獲取 conf 文件並將它們放在 "/etc/" 文件夾中,以便您可以在需要時更改工具的設置和配置
have more information
https://embeddedinventor.com/a-beginners-introduction-to-linux-package-managers-apt-yum-dpkg-rpm/