
- Linux管理員教程
- 首頁
- CentOS概述
- 基本的CentOS Linux命令
- 檔案/資料夾管理
- 使用者管理
- 配額管理
- Systemd服務啟動和停止
- 使用systemctl進行資源管理
- 使用cgroups進行資源管理
- 程序管理
- 防火牆設定
- 在CentOS Linux中配置PHP
- 在CentOS Linux中設定Python
- 在CentOS Linux中配置Ruby
- 為CentOS Linux設定Perl
- 安裝和配置Open LDAP
- 建立SSL證書
- 安裝Apache Web伺服器CentOS 7
- 在CentOS 7上設定MySQL
- 設定Postfix MTA和IMAP/POP3
- 安裝匿名FTP
- 遠端管理
- CentOS中的流量監控
- 日誌管理
- 備份和恢復
- 系統更新
- Shell指令碼
- 包管理
- 卷管理
- Linux管理員有用資源
- Linux管理員 - 快速指南
- Linux管理員 - 有用資源
- Linux管理員 - 討論
Linux管理員 - 系統更新
CentOS 7系統可以透過三種方式更新:
- 手動
- 自動
- 手動更新主要安全問題並配置自動更新
在生產環境中,建議手動更新生產伺服器。或者至少制定一個更新計劃,以便管理員可以確保對業務運營至關重要的服務。
一個簡單的安全更新可能會導致常用應用程式出現遞迴問題,這需要管理員進行升級和重新配置。因此,在生產環境中安排自動更新之前,請務必先在開發伺服器和桌面進行測試。
手動更新CentOS 7
要更新CentOS 7,我們需要熟悉yum命令。yum用於處理CentOS 7中的軟體包儲存庫。yum是常用的工具,用於:
- 更新CentOS 7 Linux系統
- 搜尋軟體包
- 安裝軟體包
- 檢測並安裝軟體包所需的依賴項
為了使用yum進行更新,您的CentOS伺服器需要連線到網際網路。大多數配置將安裝基本系統,然後使用yum查詢主要的CentOS儲存庫以獲取軟體包中的附加功能並應用系統更新。
我們已經使用yum安裝了一些軟體包。使用yum時,始終需要以root使用者身份執行操作。或者具有root許可權的使用者。因此,讓我們搜尋並安裝一個易於使用的文字編輯器,名為nano。
[root@centos rdc]# yum search nano Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirror.rackspace.com * epel: mirror.chpc.utah.edu * extras: repos.forethought.net * updates: repos.forethought.net ====================================================================== N/S matched: nano ====================================================================== nano.x86_64 : A small text editor nodejs-nano.noarch : Minimalistic couchdb driver for Node.js perl-Time-Clock.noarch : Twenty-four hour clock object with nanosecond precision Name and summary matches only, use "search all" for everything. [root@centos rdc]#
現在,讓我們安裝nano文字編輯器。
[root@centos rdc]# yum install nano Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirror.keystealth.org * epel: pubmirror1.math.uh.edu * extras: centos.den.host-engine.com * updates: repos.forethought.net Resolving Dependencies --> Running transaction check ---> Package nano.x86_64 0:2.3.1-10.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: nano x86_64 2.3.1-10.el7 base 440 k Transaction Summary Install 1 Package Total download size: 440 k Installed size: 1.6 M Is this ok [y/d/N]: y Downloading packages: nano-2.3.1-10.el7.x86_64.rpm | 440 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : nano-2.3.1-10.el7.x86_64 1/1 Verifying : nano-2.3.1-10.el7.x86_64 1/1 Installed: nano.x86_64 0:2.3.1-10.el7 Complete! [root@centos rdc]#
我們已經安裝了nano文字編輯器。在我看來,這種方法比在網站上搜索實用程式並手動執行安裝程式要容易得多。此外,儲存庫使用數字簽名來驗證軟體包,確保它們來自使用yum的受信任來源。管理員有責任在信任新儲存庫時驗證其真實性。這就是為什麼最好謹慎對待第三方儲存庫的原因。
Yum還可以用於刪除軟體包。
[root@centos rdc]# yum remove nano Loaded plugins: fastestmirror, langpacks Resolving Dependencies --> Running transaction check ---> Package nano.x86_64 0:2.3.1-10.el7 will be erased --> Finished Dependency Resolution Dependencies Resolved
現在讓我們檢查更新。
[root@centos rdc]# yum list updates Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirror.keystealth.org * epel: pubmirror1.math.uh.edu * extras: centos.den.host-engine.com * updates: repos.forethought.net Updated Packages NetworkManager.x86_64 1:1.4.0-17.el7_3 updates NetworkManager-adsl.x86_64 1:1.4.0-17.el7_3 updates NetworkManager-glib.x86_64 1:1.4.0-17.el7_3 updates NetworkManager-libnm.x86_64 1:1.4.0-17.el7_3 updates NetworkManager-team.x86_64 1:1.4.0-17.el7_3 updates NetworkManager-tui.x86_64 1:1.4.0-17.el7_3 updates NetworkManager-wifi.x86_64 1:1.4.0-17.el7_3 updates audit.x86_64 2.6.5-3.el7_3.1 updates audit-libs.x86_64 2.6.5-3.el7_3.1 updates audit-libs-python.x86_64
如圖所示,我們有幾十個待安裝的更新。實際上,由於我們尚未配置自動更新,因此大約有100個總更新。因此,讓我們安裝所有待處理的更新。
[root@centos rdc]# yum update Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirrors.usc.edu * epel: pubmirror1.math.uh.edu * extras: repos.forethought.net * updates: repos.forethought.net Resolving Dependencies --> Running transaction check ---> Package NetworkManager.x86_64 1:1.4.0-14.el7_3 will be updated ---> Package NetworkManager.x86_64 1:1.4.0-17.el7_3 will be an update selinux-policy noarch 3.13.1102.el7_3.15 updates 414 k selinux-policy-targeted noarch 3.13.1102.el7_3.15 updates 6.4 M systemd x86_64 21930.el7_3.7 updates 5.2 M systemd-libs x86_64 21930.el7_3.7 updates 369 k systemd-python x86_64 21930.el7_3.7 updates 109 k systemd-sysv x86_64 21930.el7_3.7 updates 63 k tcsh x86_64 6.18.01-13.el7_3.1 updates 338 k tzdata noarch 2017a1.el7 updates 443 k tzdata-java noarch 2017a1.el7 updates 182 k wpa_supplicant x86_64 1:2.021.el7_3 updates 788 k Transaction Summary =============================================================================== Install 2 Packages Upgrade 68 Packages Total size: 196 M Total download size: 83 M Is this ok [y/d/N]:
按下“y”鍵後,CentOS 7的更新將開始。yum更新時通常會經歷以下過程:
- 檢查當前軟體包
- 在儲存庫中查詢已更新的軟體包
- 計算更新軟體包所需的依賴項
- 下載更新
- 安裝更新
現在,讓我們確保我們的系統是最新的:
[root@centos rdc]# yum list updates Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * updates: mirror.compevo.com [root@centos rdc]#
如您所見,沒有列出任何更新。
為YUM配置自動更新
如前所述,在企業環境中,自動更新可能不是首選的安裝方法。讓我們來看一下使用yum配置自動更新的步驟。
首先,我們安裝一個名為yum-cron的軟體包。
[root@centos rdc]# yum -y install yum-cron Install 1 Package Total download size: 61 k Installed size: 51 k Downloading packages: yum-cron-3.4.3-150.el7.centos.noarch.rpm | 61 kB 00:00:01 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : yum-cron-3.4.3-150.el7.centos.noarch 1/1 Verifying : yum-cron-3.4.3-150.el7.centos.noarch 1/1 Installed: yum-cron.noarch 0:3.4.3-150.el7.centos Complete! [root@centos rdc]#
預設情況下,yum-cron只會下載更新,而不會安裝它們。是否自動安裝更新取決於管理員。最大的警告是:某些更新需要系統重新啟動。此外,某些更新可能需要在服務再次執行之前進行配置更改。
更新依賴項可能會在以下情況下產生遞迴問題:
yum建議更新某個庫
該庫僅支援Apache伺服器2.4,但我們有伺服器2.3
我們的電子商務網站依賴於特定版本的PHP
為該庫安裝的新版Apache需要升級PHP
我們的生產Web應用程式尚未使用較新的PHP版本進行測試
除非配置為不升級,否則yum可能會自動升級Apache和PHP,而不會發出通知。
如果所有5種情況都發生,可能會導致從早上的大麻煩到可能的安全漏洞,從而暴露使用者資料。雖然上述示例是一種完美風暴,但我們永遠不想發生這種情況。
管理員需要評估由於更新重新啟動和重新配置可能導致的停機時間而導致的服務恢復時間造成的潛在收入損失的可能性。對於每天數百萬美元的電子商務網站來說,這種做法可能不夠保守。
現在讓我們配置yum-cron來自動安裝系統更新。
[root@centos rdc]# vim /etc/yum/yum-cron.conf # Whether updates should be applied when they are available. Note # that download_updates must also be yes for the update to be applied. apply_updates = yes
我們要將apply_updates = no更改為apply_updates = yes。現在讓我們配置yum-cron的更新間隔。
同樣,是否使用自動更新和按需安裝更新是一把雙刃劍,管理員需要針對每種獨特情況進行考慮。