1 / 55

第九章 系統管理工作

第九章 系統管理工作. 學習目標 了解系統管理的目的 系統管理工作項目 會建立大量帳號與設定密碼 設定與管理磁碟配額 quota 備份系統必要檔案 設定時區與系統時間 設定系統排程工作. 章節大綱. 9-1 setup 管理工作. 9-4 設定系統排程工作. 9-2 壓縮檔案 - 備份. 9-5 磁碟配額設定. 9-3 設定系統時間與時區. 備註:可依進度點選小節. 系統管理工作. 管理者主要的工作 確保系統正常運作 降低系統失效機率 風險預先做好準備 系統設定正確,如時間、防火牆、網路介面等

lloyd
Download Presentation

第九章 系統管理工作

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 第九章 系統管理工作 學習目標 了解系統管理的目的 系統管理工作項目 會建立大量帳號與設定密碼 設定與管理磁碟配額quota 備份系統必要檔案 設定時區與系統時間 設定系統排程工作

  2. 章節大綱 9-1setup管理工作 9-4 設定系統排程工作 9-2 壓縮檔案-備份 9-5 磁碟配額設定 9-3 設定系統時間與時區 備註:可依進度點選小節

  3. 系統管理工作 • 管理者主要的工作 • 確保系統正常運作 • 降低系統失效機率 • 風險預先做好準備 • 系統設定正確,如時間、防火牆、網路介面等 • 定期備份系統重要檔案與目錄

  4. 9-1setup管理工具 Fedora Linux提供的系統管理工具 系統時區 系統開機欲啟用的服務 網路卡設定 防火牆 系統帳號

  5. 9-1setup管理工具

  6. 9-1setup管理工具

  7. 9-1setup管理工具防火牆設定

  8. 9-2 壓縮檔案-備份 先把零散檔案包裹成一個檔案 再壓縮包裹檔案成為壓縮檔

  9. 9-2 壓縮檔案-備份 [root@proj ~]# touch testfile [root@proj ~]# ll testfile* -rw-r--r-- 1 root root 0 12月 28 13:45 testfile [root@proj ~]# gzip testfile [root@proj ~]# ll testfile* -rw-r--r-- 1 root root 29 12月 28 13:45 testfile.gz • 壓縮檔案gzip • Linux的檔案壓縮工具 • 壓縮後的副檔名是.gz • 原檔案會被壓縮檔取代

  10. 9-2 壓縮檔案-備份 [root@proj ch9]# gunzip testfile.gz [root@proj ch9]# ll testfile* -rw-r--r-- 1 root root 0 12月 28 13:54 testfile • 解壓縮gz檔 • 使用gunzip指令

  11. 9-2 壓縮檔案-備份 [root@proj ~]# touch testfile [root@proj ~]# ll testfile -rw-r--r-- 1 root root 0 12月 28 13:49 testfile [root@proj ~]# zip -r testfile.zip testfile adding: testfile (stored 0%) [root@proj ~]# ll testfile* -rw-r--r-- 1 root root 0 12月 28 13:49 testfile -rw-r--r-- 1 root root 148 12月 28 13:49 testfile.zip • 壓縮檔案zip • 非Linux系統使用時(如Windows),可以使用zip指令將檔案壓縮為zip格式 • zip指令壓縮檔案時,使用-r選項指定壓縮後的檔案名稱

  12. 9-2 壓縮檔案-備份 [root@proj ~]# unzip testfile.zip Archive: testfile.zip replace testfile? [y]es, [n]o, [A]ll, [N]one, [r]ename: y extracting: testfile [root@proj ~]# ll testfile* -rw-r--r-- 1 root root 0 12月 28 13:49 testfile -rw-r--r-- 1 root root 148 12月 28 13:49 testfile.zip 解壓zip檔

  13. 9-2 壓縮檔案-備份 • 包裹(集合)多個檔案tar • 將多個零散的檔案包裹成為一個檔案 • 利用選項-c產生新的包裹檔案 • -v觀看指令進度 • -f指定包裹檔案的名稱 • 最後再加上欲打包零散檔案的檔名 • tar -cvf fileall.tar file1 file2 file3 • 使用星號指令多個符合的檔名 • tar -cvf fileall.tar file*

  14. 9-2 壓縮檔案-備份 [root@proj ch9]# tar -cvf myetc.tar /etc [root@proj ch9]# ll myetc.tar -rw-r--r-- 1 root root 13731840 12月 28 14:06 myetc.tar • 使用tar打包整個目錄 • 把/etc裏所有檔案打包為myetc.tar

  15. 9-2 壓縮檔案-備份 [root@proj ch9]# tar -xvf myfiles.tar file1 file2 file3 • 打開(解包)tar包裹檔 • tar指令的選項x可以用來打開包裹檔

  16. 9-2 壓縮檔案-備份 • 利用tar指令壓縮檔案 • 選項-x可以將已打包的包裹檔內的檔案解開至目前目錄下 • tar -xvf fileall.tar • 測試列出包裹檔裏的檔案清單 • tar -tvf fileall.tar • 利用tar指令打包並壓縮檔案 • tar -czvf myfiles.tar.gz file*

  17. 9-2 壓縮檔案-備份 • tgz格式 • 簡化tar.gz的名稱 • 以tar -xzvf tgz檔就可以解開 • 壓縮指令: • tar -czvf myfiles.tgz file* • 解壓縮指令: • tar -xzvf myfiles.tgz

  18. 9-2 壓縮檔案-備份 • bzip2格式 • 一種新的壓縮格式 • 也經常在網路上流通交換 • 用bz2格式壓縮 • [root@proj ch9]# bzip2 file1 • [root@proj ch9]# ls -l file1* • -rw-r--r-- 1 root root 14 12月 28 14:01 file1.bz2 • (原file1檔被file1.bz2取代) • bz2格式解壓縮 • [root@proj ch9]# bunzip2 file1.bz2 • [root@proj ch9]# ls -l file1* • -rw-r--r-- 1 root root 0 12月 28 14:01 file1 • (原壓縮檔file1.bz2被解開的file1取代)

  19. 9-2 壓縮檔案-備份 • 備份系統目錄 • 良好的備份習慣,能在系統發生問題時,回復至前次備份的正常狀態 • 系統設定檔目錄/etc • 使用者家目錄/home • 使用者電子郵件資料/var/spool/

  20. 9-3 設定系統時間與時區 • 「硬體時間」是由電腦內BIOS(或CMOS)內所負責 • 由主機板電池供 • 關機時亦持續運作 • 「系統時間」由Linux作業系統所負責 • 系統開機時讀取硬體時間後,便由Linux管理系統時間

  21. 9-3 設定系統時間與時區 • 時區檔案 • 全球時間依地點分為24個時區 • 台灣地區時區為格林威治標準時間加上8小時 • Linux系統時區檔案位於/etc/localtime • 在/usr/share/zoneinfo/目錄下存放了各個國家與地區所屬的時區檔案 • 更換系統時區,可複製/usr/share/zoneinfo/內的檔案,覆蓋/etc/localtime

  22. 9-3 設定系統時間與時區 • date日期時間指令 • 可用來顯示或設定Linux系統日期與時間 • [root@fc ~]# date • 五2月 20 00:04:30 CST 2009 • 加上參數,要求date指令依指定方式顯示格式 • [root@fc ~]# date +%Y%M%d • 20090220

  23. 9-3 設定系統時間與時區 • date指令格式 • %Y :取得年份 • %m 取得月份 • %d 取得當月的日 • %H 取得時 • %M 取得分 • %S 取得秒

  24. 9-3 設定系統時間與時區 • 活用date指令

  25. 9-3 設定系統時間與時區 • 網路校時協定(NTP)更新系統時間 • NTP架構是以分層(Stratum)校時 • 由第一層(Stratum 1)標準時間的NTP伺服器往下提供第二層NTP伺服器校時

  26. 9-3 設定系統時間與時區 • 網路校時協定(NTP) • 國家頻率與時間標準實驗室(http://www.stdtime.gov.tw)提供了第二層伺服器共五部 • time.stdtime.gov.tw • clock.stdtime.gov.tw • tick.stdtime.gov.tw • tock.stdtime.gov.tw • watch.stdtime.gov.tw

  27. 9-3 設定系統時間與時區 • 網路校時協定(NTP) • 利用ntpdate指令,可連接至NTP伺服器進行校時 • [root@fc ~]# ntpdate watch.stdtime.gov.tw • 1 Mar 20:02:15 ntpdate[17554]: adjust time server 220.130.158.54 offset -0.000263 sec • ntpdate指令更新的是系統的軟體時間,還需要以指令hwclock -w將系統時間寫入硬碟時間 • [root@fc ~]# hwclock –w(將系統時間寫入硬體時間) • [root@fc ~]# hwclock -r(再讀取看看是否已改變了?) • 西元2009年03月01日 (週日) 20時04分11秒 -0.078051 seconds

  28. 9-3 設定系統時間與時區 • NTP的重要性 • 架構較複雜的服務系統往往需要多台伺服器完成系統的需求 • 如果些主機的時間有差異,各主機紀錄資料的時間會出現不同步的問題 • 日後在追蹤日誌時會造成資料的錯誤

  29. 9-4 設定系統排程工作 • crond服務會持續檢視系統的排程工作檔案與時間 • 訂定的時間去執行指定的排程工作 • Linux的排程工作檔案是/etc/crontab • 記載了排程工作的細節

  30. 9-4 設定系統排程工作 • 排程工作檔案/etc/crontab

  31. 9-4 設定系統排程工作 • /etc/crontab • crontab檔案內容的最後四行是系統預設訂定的四個分類 • 每小時、每天、每星期與每月 • 特定時間的表示法使用分、時、日、月、星期

  32. 9-4 設定系統排程工作 • /etc/crontab • 除了這五個時間定義外,另外有星號“*”與除號“/”可以用來指定特定時間 • 8月15日早上9點29分: • 29 9 15 8 * • 每個月的10日,下午5點正 • 0 17 10 * * • 每個星期六的零晨4時正 • 0 4 * * 6

  33. 9-5 磁碟配額設定 • 利用Linux的磁碟配額(quota)來限制使用者的磁碟空間用量 • 在使用到一定空間量時,適時提醒使用者已經超出範圍 • 設定磁碟配額必須針對磁碟分割區(Partition) • 檔案系統佔用的空間(disk space) • 檔案的數目(number of files) • 磁碟配額可針對使用者(user)與群組(group)

  34. Quota Limits • Block Limit 容量限制 • 1 block = 1024 bytes • Soft Limit:使用空間限額,超過此值便算是超用 • Hard Limit:使用空間嚴格上限;使用空間可以暫時超過 soft limit,但是絕對不可以超過 hard limit

  35. Quota Limits • File Limit 檔案數量限制 • 檔案數目(i-node number) • Soft Limit:使用檔案數目限額,超過此值便算是超用 • Hard Limit使用檔案數目嚴格上限;檔案數目可以暫時超過 soft limit,但是絕對不可以超過 hard limit

  36. Quota Limits • Soft Time Limit • 使用 quota 超過 soft limit 之後,可以暫時再多用一些,但是又超過 grace period(寬限期) 之後,便不能再超用 • 使用者必須在一定期限內減少檔案空間用量至soft值以下 • 管理者修改寬限期時間限定 • edquota -t

  37. 9-5 磁碟配額設定 • 磁碟配額設定步驟 • 開機掛載分割區設定檔/etc/fstab • 產生quota設定檔 • 掃描磁碟並產生配額設定檔 • 設定個別使用者配額 • 驗證與測試 • 複製配額設定至另一個使用者

  38. Quota 相關檔案與指令 • /etc/fstab File system configuration • quotas Binary quota file at the root of each file system • /usr/sbin/edquota Quota 編輯器 • /usr/sbin/quotacheck File system quota consistency checker • /usr/sbin/quotaon Turn file system quota on/off

  39. 9-5 磁碟配額設定 • 磁碟配額報表 • 使用repquota 指令得到配額報表 • -a :對所有已掛載的檔案系統進行配額統計 • -v :包含未掛載的檔案系統 • -g :產生群組(group) 的配額統計報表 • -u :產生使用者(user) 的配額統計報表,為預設值 • -s :包含完整的統計資訊

  40. 如何設定 quota ? 編輯 /etc/fstab 加入 quota 選項 以 quotacheck 產生 quotas 檔案 以 edquota 指令設定 quota

  41. 開啟 quota 功能 修改 /etc/fstab 啟動 group quota 管理:grpquota 啟動 user quota 管理:usrquota 將檔案系統掛載選項 defaults 改成defaults,usrquota,grpquota

  42. 重新掛載檔案系統 • 修改 /etc/fstab 後執行 quotacheck,可以不重新開機!只要 remount 即可:mount -o remount 設定quota的檔案系統 • 如果執行 mount –o remount 失敗: • /etc/fstab 設定錯誤!請檢查是否拼寫錯誤。注意 defaults,usrquota,grpquota逗點之間不可空格! • 修改妥當後,再試一次! • 某些行程已經鎖住檔案系統: • 必須重開機(/etc/fstab 設定錯誤,將無法開機)

  43. 產生 quota 檔案 # quotacheck -guvamScanning /dev/md3 [/home] donequotacheck: Checked 10110 directories and 73997 files # ls -l /home -rw------- 1 root root 7168 10月 21 16:31 aquota.group -rw------- 1 root root 7168 10月 21 16:31 aquota.user quota.user:記載 user quota 的限制 quota.group:記載 group quota 的限制

  44. 設定 quota • 設定使用者磁碟配額指令:edquota [-p proto_user] username設定帳號 username 的 quota • -p   proto_user將 proto_user 的 quota 設定複製給 username

  45. 設定 quota • 設定群組磁碟配額指令:edquota -g groupname設定群組 groupname 的 quota • edquota -gp proto_group groupname將 proto_group 的 quota 設定複製給 groupname

  46. 設定 quota • 設定寬限期指令: • 設定使用寬限期edquota -t • 設定群組寬限期edquota –gt

  47. 啟動 quota • quotaon -guva • g: group 群組 • u: user 使用者 • v: 詳細資訊, Display a message for each file system where quotas are turned on. • a: All automatically mounted non-NFS file systems in /etc/fstab with quotas will have their quotas turned on

  48. 停用 quota • quotaoff –guva • 修改 quota 參數後,應停止 quota 再啟動 quota • quotaoff -guva • quotaon -guva

  49. 檢視 quota 報告 • quota 檢視自己帳號的 quota 報告 • quota -g檢視自己群組的 quota 報告 • 檢視系統的 quota 報告,下列指令必須以 root 的身份執行 • repquota [-v] [-g] [-u] -a • repquota [-v] [-g] [-u] filesys ...

  50. Quota 練習 以下列指令轉換身份成為管理員$ su - 以下列指令建立帳號 test# adduser test 以下列指令建立帳號 test2# adduser -g test test2 修改 /etc/fstab,將 / 的 mount option 改為 defaults,grpquota,usrquota 產生 quota 檔案

More Related