單純提供一個相對的解答,並不是標準答案!
單純就是個解答的參考,寫完之後再來這邊查查看答案跟你想的一樣不一樣!?
# A. 確認一下,是否已經安裝了 logrotate 軟體? [root@station111 ~]# rpm -qa | grep logrotate logrotate-3.18.0-7.el9.x86_64 rsyslog-logrotate-8.2102.0-105.el9.x86_64 [root@station111 ~]# rpm -q logrotate logrotate-3.18.0-7.el9.x86_64 # 可以使用抓關鍵字的方法處理,如果確定軟體名稱無誤,也能直接查詢! # B. 找出 logrotate 這個軟體內含的檔案檔名 [root@station111 ~]# rpm -ql logrotate /etc/logrotate.conf /etc/logrotate.d /etc/logrotate.d/btmp /etc/logrotate.d/wtmp ...... # C. 找出這個 logrotate 的軟體功能說明 information [root@station111 ~]# rpm -qi logrotate Name : logrotate Version : 3.18.0 Release : 7.el9 Architecture: x86_64 Install Date: Thu 16 Feb 2023 11:44:15 AM CST Group : Unspecified Size : 157349 License : GPLv2+ Signature : RSA/SHA256, Mon 31 Oct 2022 06:04:22 AM CST, Key ID 702d426d350d275d Source RPM : logrotate-3.18.0-7.el9.src.rpm Build Date : Mon 31 Oct 2022 05:59:09 AM CST Build Host : pb-feb99270-ff6c-4b73-b179-ad21d679f096-b-x86-64 Packager : Rocky Linux Build System (Peridot) <releng@rockylinux.org> Vendor : Rocky Enterprise Software Foundation URL : https://github.com/logrotate/logrotate Summary : Rotates, compresses, removes and mails system log files Description : The logrotate utility is designed to simplify the administration of log files on a system which generates a lot of log files. Logrotate allows for the automatic rotation compression, removal and mailing of log files. Logrotate can be set to handle a log file daily, weekly, monthly or when the log file gets to a certain size. Install the logrotate package if you need a utility to deal with the log files on your system. # D. 從既有的檔案去找出該檔案所屬的軟體為何 [root@station111 ~]# rpm -qf /bin/sh bash-5.1.8-6.el9_1.x86_64 # E. 其實沒關係,因為檔名紀錄是在資料庫,與檔案本身有沒有存在無關!所以還是可以查出來: [root@station111 ~]# rpm -qf /etc/crontab crontabs-1.11-27.20190603git.el9.noarch # 之後主要重新安裝一次 (或強制安裝) crontabs 軟體,該檔案就會回復到源有的狀態。 # F. 怎麼知道 chrony 這個軟體的相依軟體與檔案有哪些?可以簡單這樣做: [root@station111 ~]# rpm -qR chrony /bin/sh /bin/sh ....... shadow-utils systemd systemd
# A. 查詢 logrotate 是否被更動過? [root@station111 ~]# rpm -V logrotate # 若不曾被更動過,就不會有任何訊息顯示 # B. 那麼 /etc/crontab 呢? [root@station111 ~]# rpm -qf /etc/crontab crontabs-1.11-27.20190603git.el9.noarch # 先從檔案找到軟體名稱 [root@station111 ~]# rpm -V crontabs S.5....T. c /etc/crontab 再從軟體名稱去檢查有沒有更動過檔案的資訊 # C. 星期天 2:00 進行一次全系統驗證,並儲存 [root@station111 ~]# vim /etc/crontab 0 2 * * 0 root rpm -Va &> /root/rpmv.txt
# A. 找出 ifconfig 這個『指令』的所屬軟體 [root@station111 ~]# yum provides "*bin/ifconfig" net-tools-2.0-0.62.20160912git.el9.x86_64 : Basic networking tools Repo : @System Matched from: Other : *bin/ifconfig # B. 嘗試了解該軟體的功能 [root@station111 ~]# yum info net-tools Installed Packages Name : net-tools Version : 2.0 Release : 0.62.20160912git.el9 Architecture : x86_64 Size : 912 k Source : net-tools-2.0-0.62.20160912git.el9.src.rpm Repository : @System From repo : anaconda Summary : Basic networking tools URL : http://sourceforge.net/projects/net-tools/ License : GPLv2+ Description : The net-tools package contains basic networking tools, : including ifconfig, netstat, route, and others. : Most of them are obsolete. For replacement check iproute package. # C. 列出以 qemu 為開頭的軟體名稱 [root@station111 ~]# yum search qemu ============================= Name & Summary Matched: qemu ============================== ipxe-roms-qemu.noarch : Network boot loader roms supported by QEMU, .rom format libvirt-daemon-driver-qemu.x86_64 : QEMU driver plugin for the libvirtd daemon qemu-ga-win.noarch : Qemus Guest agent for Windows qemu-guest-agent.x86_64 : QEMU guest agent qemu-img.x86_64 : QEMU command line tool for manipulating disk images qemu-kvm.x86_64 : QEMU is a machine emulator and virtualizer .... # D. 找出 qemu-kvm 這個軟體的功能 [root@station111 ~]# yum info qemu-kvm Available Packages Name : qemu-kvm Epoch : 17 Version : 7.0.0 Release : 13.el9_1.2 Architecture : x86_64 Size : 55 k Source : qemu-kvm-7.0.0-13.el9_1.2.src.rpm Repository : appstream Summary : QEMU is a machine emulator and virtualizer URL : http://www.qemu.org/ License : GPLv2 and GPLv2+ and CC-BY Description : qemu-kvm is an open source virtualizer that provides hardware : emulation for the KVM hypervisor. qemu-kvm acts as a virtual : machine monitor together with the KVM kernel modules, and emulates the : hardware for a full system such as a PC and its associated peripherals. # 所以,就是虛擬化功能的軟體喔! # E. 查出到目前為止, yum 進行過什麼行為? [root@station111 ~]# yum history ID | Command line | Date and time | Action(s) | Altered ----------------------------------------------------------------------------------- 3 | install tcsh | 2023-02-26 14:46 | Install | 1 < 2 | | 2023-02-20 14:20 | I, U | 91 > 1 | | 2023-02-16 11:43 | Install | 1190 EE
# a. 用 rpm 查詢 pam-devel 安裝了沒? [root@station111 ~]# rpm -qa | grep pam-devel # b. 用 yum 查詢是否有 pam-devel 軟體? [root@station111 ~]# yum search pam-devel ============================ Name Exactly Matched: pam-devel ============================ pam-devel.x86_64 : Files needed for developing PAM-aware applications and modules for PAM pam-devel.i686 : Files needed for developing PAM-aware applications and modules for PAM # c. 線上直接安裝喔! [root@station111 ~]# yum install pam-devel # d. 使用 rpm 查詢該軟體所屬檔案 [root@station111 ~]# rpm -ql pam-devel /usr/include/security /usr/include/security/_pam_compat.h /usr/include/security/_pam_macros.h .......
# a. 先使用 yum check-update 嘗試分析目前伺服器上有比本機 Linux 還要新的軟體群 [root@station111 ~]# yum check-update NetworkManager.x86_64 1:1.40.0-2.el9_1 baseos NetworkManager-adsl.x86_64 1:1.40.0-2.el9_1 baseos ....... tar.x86_64 2:1.34-6.el9_1 baseos ....... # b. 隨意選擇一個軟體 (例如 tar) 來進行單一軟體的升級 [root@station111 ~]# yum update tar # c. 進行一次全系統升級 [root@station111 ~]# yum update # d. 如果需要每天凌晨 3 點自動背景進行全系統升級,該如何處理? [root@station111 ~]# vim /etc/crontab 0 3 * * * root /bin/yum -y update # 上面的這個 -y 是重點!這樣系統才會自動的輸入 yes 通過!
# a. 將剛剛安裝的 pam-devel 移除掉 [root@station111 ~]# yum remove pam-devel # b. 剛剛已經全系統安裝完畢,請問是否需要重新開機?為什麼? # 答案是『不一定!』如果是一般服務的升級,那只要將服務關閉再啟動,就可以使用最新程式! # 但是,如果是核心,或者是一些基礎函式庫的更新,則最好重新開機! # 尤其是 kernel 的升級,一定要重新開機才能生效!這個可以由 4 個同心圓去理解! [root@station111 ~]# reboot # c. 不知道怎麼辦時,可以透過 needs-restarting -r 來評估看看 [root@station111 ~]# yum install yum-utils [root@station111 ~]# needs-restarting -r No core libraries or services have been updated since boot-up. Reboot should not be necessary. # 有時候,可能會出現如下的資料,那就得要重新開機比較妥當! [root@station111 ~]# needs-restarting -r Core libraries or services have been updated since boot-up: * kernel * linux-firmware Reboot is required to fully utilize these updates. More information: https://access.redhat.com/solutions/27942
# A. 從 http://ftp.ksu.edu.tw 去找到三個 URL,然後修改底下的資料,共分三個檔案喔! [root@station111 ~]# vim /etc/yum.repos.d/rocky.repo [baseos] name=Rocky Linux $releasever - BaseOS #mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=$basearch&repo=BaseOS-$releasever$rltype baseurl=http://ftp.ksu.edu.tw/FTP/Linux/rocky/9/BaseOS/x86_64/os/ gpgcheck=1 enabled=1 countme=1 metadata_expire=6h gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Rocky-9 [appstream] name=Rocky Linux $releasever - AppStream #mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=$basearch&repo=AppStream-$releasever$rltype baseurl=http://ftp.ksu.edu.tw/FTP/Linux/rocky/9/AppStream/x86_64/os/ gpgcheck=1 enabled=1 countme=1 metadata_expire=6h gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Rocky-9 [root@station111 ~]# vim /etc/yum.repos.d/rocky-extras.repo [extras] name=Rocky Linux $releasever - Extras #mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=$basearch&repo=extras-$releasever$rltype baseurl=http://ftp.ksu.edu.tw/FTP/Linux/rocky/9/extras/x86_64/os/ gpgcheck=1 enabled=1 countme=1 metadata_expire=6h gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Rocky-9 # B. 清除快取! [root@station111 ~]# yum clean all # C. 查看一下 baseos 的倉儲資訊 [root@station111 ~]# yum repoinfo baseos Rocky Linux 9 - BaseOS 2.1 MB/s | 1.8 MB 00:00 Rocky Linux 9 - AppStream 6.9 MB/s | 6.8 MB 00:00 Rocky Linux 9 - Extras 10 kB/s | 8.7 kB 00:00 Repo-id : baseos Repo-name : Rocky Linux 9 - BaseOS Repo-status : enabled Repo-revision : 1683217074 Repo-updated : Fri 05 May 2023 12:17:54 AM CST Repo-pkgs : 1,138 Repo-available-pkgs: 1,138 Repo-size : 982 M Repo-baseurl : http://ftp.ksu.edu.tw/FTP/Linux/rocky/9/BaseOS/x86_64/os/ Repo-expire : 21,600 second(s) (last: Sun 07 May 2023 06:06:37 PM CST) Repo-filename : /etc/yum.repos.d/rocky.repo Total packages: 1,138 # D. 進行 yum update 看看 [root@station111 ~]# yum update
# A. 先列出本機上面所有的軟體倉儲 [root@station111 ~]# yum repolist all repo id repo name status appstream Rocky Linux 9 - AppStream enabled appstream-debug Rocky Linux 9 - AppStream - Debug disabled appstream-source Rocky Linux 9 - AppStream - Source disabled baseos Rocky Linux 9 - BaseOS enabled .... # B. 將 extras 這個軟體倉儲設定成為預設關閉 [root@station111 ~]# yum config-manager --disable extras [root@station111 ~]# yum repoinfo extras Repo-id : extras Repo-name : Rocky Linux 9 - Extras Repo-status : disabled Repo-baseurl : http://ftp.ksu.edu.tw/FTP/Linux/rocky/9/extras/x86_64/os/ Repo-expire : 21,600 second(s) (last: unknown) Repo-filename : /etc/yum.repos.d/rocky-extras.repo Total packages: 0 # C. 找到並安裝 epel 軟體 [root@station111 ~]# yum --enablerepo=extras search epel ================================== Name Matched: epel =================================== epel-release.noarch : Extra Packages for Enterprise Linux repository configuration [root@station111 ~]# yum --enablerepo=extras install epel-release # D. 讓 epel 軟體倉儲變成預設是不啟用的 [root@station111 ~]# yum repolist repo id repo name appstream Rocky Linux 9 - AppStream baseos Rocky Linux 9 - BaseOS epel Extra Packages for Enterprise Linux 9 - x86_64 [root@station111 ~]# yum config-manager --disable epel # E. 預設的軟體倉儲是否有 netcdf 軟體查詢 [root@station111 ~]# yum search netcdf # F. 使用 yum --enablerepo=epel 之後,再次查詢有沒有 netcdf?若有,請安裝 [root@station111 ~]# yum --enablerepo=epel search netcdf ============================= Name Exactly Matched: netcdf ============================== netcdf.x86_64 : Libraries for the Unidata network Common Data Form ============================ Name & Summary Matched: netcdf ============================= netcdf-cxx.x86_64 : Legacy netCDF C++ library netcdf-cxx-devel.x86_64 : Development files legacy netCDF C++ library netcdf-cxx-static.x86_64 : Static libraries for legacy netCDF C++ library ..... [root@station111 ~]# yum --enablerepo=epel install netcdf [root@station111 ~]# rpm -ql netcdf | grep bin /usr/bin/nc4print /usr/bin/nccopy /usr/bin/ncdump /usr/bin/ncgen /usr/bin/ncgen3 /usr/bin/ocprint
# A. 檢查一下上述的三個資料中,哪幾個是服務?哪幾個是執行檔? [root@station111 ~]# systemctl status systemd-journald ● systemd-journald.service - Journal Service Loaded: loaded (/usr/lib/systemd/system/systemd-journald.service; static) Active: active (running) since Sun 2023-05-07 16:41:16 CST; 3h 48min ago TriggeredBy: ● systemd-journald-dev-log.socket ● systemd-journald.socket Docs: man:systemd-journald.service(8) man:journald.conf(5) Main PID: 28341 (systemd-journal) Status: "Processing requests..." Tasks: 1 (limit: 10940) Memory: 1.6M CPU: 67ms CGroup: /system.slice/systemd-journald.service └─28341 /usr/lib/systemd/systemd-journald [root@station111 ~]# systemctl status rsyslog ● rsyslog.service - System Logging Service Loaded: loaded (/usr/lib/systemd/system/rsyslog.service; enabled; vendor preset: en Active: active (running) since Sun 2023-05-07 22:59:42 CST; 2h 29min left Docs: man:rsyslogd(8) https://www.rsyslog.com/doc/ Main PID: 747 (rsyslogd) Tasks: 3 (limit: 10940) Memory: 2.8M CPU: 931ms CGroup: /system.slice/rsyslog.service └─747 /usr/sbin/rsyslogd -n [root@station111 ~]# systemctl status logrotate ○ logrotate.service - Rotate log files Loaded: loaded (/usr/lib/systemd/system/logrotate.service; static) Active: inactive (dead) since Sun 2023-05-07 22:59:42 CST; 2h 26min left TriggeredBy: ● logrotate.timer Docs: man:logrotate(8) man:logrotate.conf(5) Main PID: 761 (code=exited, status=0/SUCCESS) CPU: 46ms [root@station111 ~]# cat /usr/lib/systemd/system/logrotate.service ..... [Service] Type=oneshot ExecStart=/usr/sbin/logrotate /etc/logrotate.conf ..... [root@station111 ~]# which logrotate /usr/sbin/logrotate # 所以前面兩個是系統服務,後面一個不是。logrotate 應該是指令而已非服務。 # B. 並檢查服務項目有沒有啟動?而執行檔又是如何執行的? # 如上所示,前面兩個不但開機自動啟動,而且目前是啟動的狀態。 [root@station111 ~]# rpm -qf /usr/sbin/logrotate logrotate-3.18.0-7.el9.x86_64 [root@station111 ~]# rpm -ql logrotate ..... /usr/lib/systemd/system/logrotate.service /usr/lib/systemd/system/logrotate.timer /usr/sbin/logrotate /usr/share/doc/logrotate ..... # 所以 logrotate 是使用 timer 來啟動的指令! [root@station111 ~]# cat /usr/lib/systemd/system/logrotate.timer [Unit] Description=Daily rotation of log files Documentation=man:logrotate(8) man:logrotate.conf(5) [Timer] OnCalendar=daily AccuracySec=1h Persistent=true [Install] WantedBy=timers.target
# 1. 先設定 rsyslogd 的設定檔: # 從 /etc/rsyslog.conf 當中,我們知道 /etc/rsyslog.d/*.conf 可用! [root@station111 ~]# vim /etc/rsyslog.d/admin.conf *.* /var/log/admin.log # 2. 要重新啟動 rsyslog 才行! [root@station111 ~]# systemctl restart rsyslog.service [root@station111 ~]# ll /var/log/admin.log -rw-------. 1 root root 990 5月 7 20:51 /var/log/admin.log # 這個檔案就會被自動生成了!
# A. 不加任何參數與選項,列出所有的日誌資料 [root@station111 ~]# journalctl # B. (1)先用 date 找出日期格式 YYYY-MM-DD 的日期,並以該日期的資訊顯示 log, # 以及(2)僅今天及(3)僅昨天的日誌資料內容 [root@station111 ~]# date +%Y-%m-%d 2023-05-07 [root@station111 ~]# journalctl --since $( date +%Y-%m-%d ) <==當日訊息 -- Logs begin at Mon 2020-05-25 21:33:59 CST, end at Tue 2020-05-26 13:22:42 CST. -- 5月 26 00:00:13 station111.centos systemd[1]: Starting update of the root trust anchor> 5月 26 00:00:13 station111.centos systemd[1]: Started update of the root trust anchor > ..... [root@station111 ~]# journalctl --since today <==當日訊息 [root@station111 ~]# journalctl -S yesterday -U today <==昨日訊息 # C. 只找出 crond.service 的資料,同時只列出最新的 10 筆即可 [root@station111 ~]# journalctl -u crond -n 10 # D. 找出 su, sudo 執行的登錄檔,同時只列出最新的 10 筆即可 [root@station111 ~]# journalctl _COMM=su _COMM=sudo -n 10
[root@station111 ~]# rpm -q logwatch 軟體包 logwatch 尚未安裝 [root@station111 ~]# yum install logwatch
[root@station111 ~]# rpm -ql logwatch | grep etc /etc/cron.daily/0logwatch <==這裡! /etc/logwatch /etc/logwatch/conf ......
[root@station111 ~]# grep -v '#' /etc/cron.daily/0logwatch | grep -v '^$' LOGWATCH_SCRIPT="/usr/sbin/logwatch" OPTIONS="--output mail" $LOGWATCH_SCRIPT $OPTIONS exit 0 [root@station111 ~]# /usr/sbin/logwatch --range today ################### Logwatch 7.5.5 (01/22/21) #################### Processing Initiated: Sun May 7 21:11:32 2023 Date Range Processed: today ( 2023-May-07 ) Period is day. Detail Level of Output: 0 Type of Output/Format: stdout / text Logfiles for Host: station200.rockylinux ################################################################## .... # 預設追蹤的 log 是『昨天 (yesterday) 的項目,但是我們的系統剛剛開機,所以使用 today。 # 另外,如果資訊量太大,我們只需要 sshd 的時候,也可以這樣做: [root@station111 ~]# logwatch --range today --service=sshd --service=cron --service=sudo
# a.1. 從 github 底下去下載最新的 netcdf-c 軟體 [root@station111 ~]# git clone https://github.com/Unidata/netcdf-c.git [root@station111 ~]# cd netcdf-c/ [root@station111 netcdf-c]# # a.2. 由 https://github.com/Unidata/netcdf-c 的 installation 找到 Building NetCDF # 再由該連結最終找到 cmake . 這個準備建立 Makefile 的指令: [root@station111 netcdf-c]# cmake -DCMAKE_PREFIX_PATH=/usr/local [root@station111 netcdf-c]# ll Makefile -rw-r--r--. 1 root root 155083 5月 7 22:44 Makefile # a.3. 開始編譯與安裝 [root@station111 netcdf-c]# make -j [root@station111 netcdf-c]# make install # b. 使用 ncdump -h 確認軟體是否可用即可。 [root@station111 netcdf-c]# type -a ncdump ncdump 是 /usr/local/bin/ncdump ncdump 是 /usr/bin/ncdump [root@station111 netcdf-c]# /usr/local/bin/ncdump -h # 有說明文件就是對了! # c. 理解安裝後,將該軟體移除 [root@station111 netcdf-c]# pwd /usr/local/src/netcdf-c-4.7.4 [root@station111 netcdf-c]# make uninstall # 必需要在原本的編譯原始碼的目錄底下,才可以進行軟體移除的行為喔! [root@station111 netcdf-c]# type -a ncdump ncdump 是 /usr/bin/ncdump
# a.1. 安裝數位簽章,並且安裝軟體倉儲設定檔 [root@station111 ~]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org [root@station111 ~]# yum install https://www.elrepo.org/elrepo-release-9.el9.elrepo.noarch.rpm # a.2. 查詢剛剛裝好的軟體倉儲,並且依據之前的建議,將非正規需要的倉儲關閉 [root@station111 ~]# yum repolist 體庫 ID 軟體庫名稱 appstream Rocky Linux 9 - AppStream baseos Rocky Linux 9 - BaseOS elrepo ELRepo.org Community Enterprise Linux Repository - el9 [root@station111 ~]# yum config-manager --disable elrepo # b. 搜尋並安裝 kernel-ml [root@station111 ~]# yum --enablerepo=elrepo-kernel search kernel-ml =========================== 名稱 精確符合:kernel-ml =========================== kernel-ml.x86_64 : The Linux kernel. (The core of any Linux kernel based : operating system.) .... [root@station111 ~]# yum --enablerepo=elrepo-kernel install kernel-ml # c.1. 查詢是否有新的核心安裝了? [root@station111 ~]# ll /lib/modules drwxr-xr-x. 7 root root 4096 2月 20 14:22 5.14.0-162.12.1.el9_1.0.2.x86_64 drwxr-xr-x. 7 root root 4096 5月 7 16:40 5.14.0-162.23.1.el9_1.x86_64 drwxr-xr-x. 8 root root 4096 2月 16 11:51 5.14.0-162.6.1.el9_1.x86_64 drwxr-xr-x. 7 root root 4096 5月 7 23:51 6.3.1-1.el9.elrepo.x86_64 [root@station111 ~]# uname -r 5.14.0-162.12.1.el9_1.0.2.x86_64 # 最新為 6.3.1 版本,目前則是 5.14.0 版本 # c.2. 進行 reboot!記得開機過程中一定要盯著螢幕!開機時 5 秒選擇 6.3.1 版本核心開機! [root@station111 ~]# reboot [root@station111 ~]# uname -r 6.3.1-1.el9.elrepo.x86_64 # 確定是新版喔! # d. 畢竟是測試,請重新開機,然後挑選原本的舊的核心後,再移除剛剛的核心! [root@station111 ~]# reboot [root@station111 ~]# uname -r 5.14.0-162.23.1.el9_1.x86_64 [root@station111 ~]# rpm -qa | grep kernel-ml kernel-ml-core-6.3.1-1.el9.elrepo.x86_64 kernel-ml-modules-6.3.1-1.el9.elrepo.x86_64 kernel-ml-6.3.1-1.el9.elrepo.x86_64 [root@station111 ~]# yum remove kernel-ml