許家偉
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # [Linux 基礎訓練 - 期末考練習](https://linux.vbird.org/linux_basic_train/centos8/practice2.php) ###### tags: `家教` ## 作業之一 (不提供學生答案,僅提供教師參考答案) 作業硬碟一般操作說明: - 開啟雲端虛擬機器前,請務必確認你開啟的硬碟是『practice1』,否則就會做錯題目 - 若要使用圖形界面,請務必使用 student 身份登入,若需要切換身份,再啟用終端機處理。 - 若有簡答題需要使用中文,請自行以第一堂課的動作自行處理輸入法安裝。 - 每部虛擬機器均有獨特的網卡位址,請勿使用他人硬碟上傳,否則計分為 0 分。 - 每位同學均有自己的 IP 尾數,請先向老師詢問您的 IP 尾數,才可以進行作業上傳。 - 最終上傳作業結果,請務必使用 root 身份上傳。 - 進入作業硬碟後,先用 root 身份執行 vbird_book_setup_ip , 執行流程請參考:vbird_book_setup_ip 作業當中,某些部份可能為簡答題~若為簡答題時,請將答案寫入 /home/student/ans.txt 當中,並寫好正確題號,方便老師訂正答案。 請注意,檔名寫錯將無法上傳! --- ## 重要注意事項: - 若發生底下的問題,則此次練習為 0 分 - root 設定密碼錯誤 - IP 設定錯誤 - 預設出現圖形界面 (如果開機不是純文字界面,也是 0 分) - 若無法傳送成績,此次考試亦為 0 分 - 某些題目是具有連續性的,因此請看懂題目後再進行。 --- ### 切換到圖形介面 systemctl isolate graphical.target ### 切換到文字介面 systemctl isolate multi-user.target ### vim使用 ![](https://i.imgur.com/oh8rj8f.jpg) ## 開始考試的練習 -- VM 1: 系統設定與操作部份 這個系統預設的 root 密碼為 myCentOS8,預設的 student 密碼為 mystdgo,是可以直接登入的,無須救援 root 密碼。 這個系統需要的是一些正確的設定,以符合系統的運作! 不是題目:請使用 [vbird_book_setup_ip](https://linux.vbird.org/linux_basic_train/centos8/unit00.php?unit=setip) 設定好你的學號資料。 ### 1.系統初始化設定 #### A. 我需要每次開機都可以預設的進入純文字界面而非現行的圖形界面,可以節省許多不必要的資源浪費。 - 在系統自己開機後,預設會跑進純文字界面,沒有圖形界面的意思。 - 你在操作時,依舊可以『暫時』切換到圖形界面,沒有特別要求你一定要在文字界面答題。 ``` systemctl set-default multi-user.target ``` #### B. 請設定好這部主機的網路參數成為如下狀態 (全對才給分): - 刪除原有的網路連線名稱,建立名為『 mynetwork 』的連線名稱,且使用到可對外的乙太網路界面。 - 需要開機就自動啟動這個連線 - 網路參數的設定方式為手動設定 - 網際網路位址 IP address 為: 192.168.251.XXX (XXX 為上課時,老師給予的號碼) - 子網路遮罩 netmask 為: 255.255.255.0 - 通訊閘 Gateway 為: 192.168.251.254 - 領域名稱伺服器 DNS server 位址為: 172.16.200.254 以及 120.114.100.1 這兩個 - 主機名稱:請設定為 wwwXXX.book.vbird (其中 XXX 為上課時,老師給予的號碼) ```shell= nmcli connection delete ens3 nmcli connection add con-name mynetwork ifname ens3 type ethernet nmcli connection show nmcli connection modify mynetwork \ connection.autoconnect yes \ ipv4.method manual \ ipv4.addresses 192.168.251.85/24 \ ipv4.gateway 192.168.251.254 \ ipv4.dns "172.16.200.254 120.114.100.1" nmcli connection up mynetwork hostnamectl set-hostname www85.book.vbird ``` #### C. 針對 YUM 的軟體倉儲設定,你有底下的兩組軟體倉儲位址,請設定好所需要的環境 (全對才給分): - http://ftp.ksu.edu.tw/FTP/Linux/CentOS/8/AppStream/x86_64/os/ - http://ftp.ksu.edu.tw/FTP/Linux/CentOS/8/BaseOS/x86_64/os/ ```bash= # 發現 /etc/yum.repos.d/ 底下的倉儲庫遺失 須先把檔案補齊 # 開啟瀏覽器到 https://github.com/Msiciots/yum.repos.d 下載 wget https://github.com/Msiciots/yum.repos.d/archive/refs/heads/main.zip unzip main.zip cp ./yum.repos.d-main/* /etc/yum.repos.d vim /etc/yum.repos.d/CentOS-AppStream.repo ### baseurl=http://ftp.ksu.edu.tw/FTP/Linux/CentOS/8/AppStream/x86_64/os/ ### vim /etc/yum.repos.d/CentOS-Base.repo ### baseurl=http://ftp.ksu.edu.tw/FTP/Linux/CentOS/8/BaseOS/x86_64/os/ ### ``` 如果沒網路無法下載 github 檔案: ```bash= # A. 從 http://ftp.ksu.edu.tw 去找到三個 URL,然後修改底下的資料,共分三個檔案喔! vim /etc/yum.repos.d/CentOS-AppStream.repo ### [AppStream] name=CentOS-$releasever - AppStream #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=AppStream&infra=$infra baseurl=http://ftp.ksu.edu.tw/FTP/CentOS/8/AppStream/x86_64/os/ gpgcheck=1 enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial ### vim /etc/yum.repos.d/CentOS-Base.repo ### [BaseOS] name=CentOS-$releasever - Base #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=BaseOS&infra=$infra baseurl=http://ftp.ksu.edu.tw/FTP/CentOS/8/BaseOS/x86_64/os/ gpgcheck=1 enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial ### vim /etc/yum.repos.d/CentOS-Extras.repo ### [extras] name=CentOS-$releasever - Extras #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra baseurl=http://ftp.ksu.edu.tw/FTP/CentOS/8/extras/x86_64/os/ gpgcheck=1 enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial ### # B. 清除快取! yum clean all # C. 進行 yum update 看看 yum update ``` ###複製### #### D. 時區與時間及網路校時功能設計: - 你系統的時間好像怪怪的,時區與時間好像都錯亂了!請改回台北的時區與時間。 - 請使用網路校時 (chronyd) 的方式,使用貴校 ntp.ksu.edu.tw 作為伺服器,主動更新你的系統時間。 且系統啟動之後,會持續網路校時以取得最正確的時間。(若貴校並無 NTP 伺服器,則以 time.stdtime.gov.tw 作為來源) ``` # 查看時間 timedatectl timedatectl set-timezone Asia/Taipei yum -y install chrony vim /etc/chrony.conf ### server ntp.ksu.edu.tw iburst ### systemctl enable chronyd systemctl start chronyd chronyc tracking ``` ![](https://i.imgur.com/sbGAI49.png) #### E.系統的自動更新機制: - 請至少升級核心 (kernel) 到最新版本,且升級完畢後,需要重新開機為宜 - 這部主機需要作為未來開發軟體之用,因此需要安裝一個『 RPM 開發工具 』的軟體群組,請安裝他。 - 請設定每天凌晨 3 點自動背景進行全系統更新。 ```bash= yum -y update kernel && reboot # 查看 group yum grouplist yum groupinstall "RPM Development Tools" vim /etc/crontab ### 0 3 * * * root yum -y update ### systemctl restart crond systemctl status crond ``` ### 2.帳號與權限控管方面的問題,包括新建帳號、帳號相關權限設定等 #### A.管理員的一般帳號設定: - 請讓 student 可以順利使用自己的密碼操作 sudo 指令 ``` visudo ### # 輸入 :98 可以跳到98行 root ALL=(ALL) ALL <==找到這一行,大約在 98 行左右 student ALL=(ALL) ALL <==這一行是你要新增的! ### ``` #### B.帳號鎖定功能: - 有個名為 alex 的帳號,他的密碼為 mygodhehe ,這個帳號有點怪異,因此身為管理員的你,得要將該帳號暫時鎖定。 - 意思是說,這個帳號的所有資源都不變,但是該帳號無法順利使用密碼登入的意思(密碼鎖定) ``` # 這行會鎖定密碼 passwd -l alex # 查看密碼資訊 passwd -S alex ``` #### C.特殊系統帳號建置:建立一個名為 mysys1 的系統帳號,且這個系統帳號 - 不需要家目錄 - 不具備可互動的 shell - 不需要密碼 ![](https://i.imgur.com/BHo9l9Z.png) ``` useradd -M -s /sbin/nologin mysys1 ``` #### D.預設帳號的權限屬性設定: - 建立新用戶時,新用戶的家目錄應該都會出現一個名為 newhtml 的子目錄存在 - 新帳號登入時,預設將會『 rm='rm -i' 』『 cp='cp -i' 』『 mv='mv -i' 』這三個命令別名存在。 ``` mkdir /etc/skel/newhtml vim /etc/skel/.bashrc ### alias rm='rm -i' alias cp='cp -i' alias mv='mv -i' ### ``` #### 跳過 E.特殊帳號管理的需求: - 讓 /home 這個目錄支援使用者與群組的 Quota 磁碟配額功能 - 增加一個名為 examgroup 的群組 http://linux.vbird.org/linux_basic/0420quota.php#the_quota ![](https://i.imgur.com/mMXHav5.png) ``` vim /etc/fstab ### /dev/mapper/centos-home /home xfs defaults,usrquota,grpquota 0 0 ### groupadd examgroup ``` #### F.特殊帳號建立的需求:請寫一隻名為 /root/users/addusers.sh 的腳本,這個腳本將用來處理特殊帳號的建置。 你應該使用 for…do…done 迴圈的方式來建立這隻腳本,而 for 迴圈內的程式碼,請依序使用如下的方式來建置妥當 - 建立帳號時的相關參數設計: - 帳號名稱為: examuser11 ~ examuser30 共 20 個帳號 - 建立帳號時,每個帳號都要加入一個名為 examgroup 的次要群組支援 - 每個帳號的全名說明就是該帳號的名稱 - 每個帳號的密碼均為 myPassWord - 並且每個帳號首次登入系統時,都會被強迫要求更改密碼 (chage ??) - 每個帳號在 /home 的 Quota 為 soft --> 120MB, hard --> 150MB - 修改每位帳號家目錄 (例如 examuser11 家目錄在 /home/examuser11/ ) 的權限成為 drwx--x--x 的模樣 - 腳本建置完畢後,請務必執行一次,以確定帳號可以順利被建立! ```bash= mkdir /root/users vim /root/users/addusers.sh ``` in /root/users/addusers.sh ```bash= #!/bin/bash groupadd examgroup for i in {11..30} do useradd -G examgroup -c "examuser${i}" examuser${i} echo "myPassWord" | passwd --stdin examuser${i} chage -d 0 examuser${i} xfs_quota -x -c "limit -u bsoft=120M bhard=150M myuser${i}" /home chmod -R 711 /home/examuser${i} done ``` ```bash= chmod 777 /root/users/addusers.sh ``` #### 有問題 寫作 G.群組共用目錄的功能:請建立一個名為 /data/myexam 的目錄,這個目錄的權限設定是這樣的: - 於 examgroup 群組內的用戶權限: - 該目錄可以讓 examgroup 的用戶具有完整的權限 - 而其他人不具備任何權限 - 在該目錄底下新建的資料(不論檔案還是目錄),新資料的擁有群組都會是 examgroup - 關於 examuser30 與 student 這兩個帳號的特定要求: - 因為 examuser30 帳號被盜,因此 examuser30 針對 /data/myexam 設定為不具備任何權限 - 因為 student 是管理員的一般帳號,該帳號也需要查詢 /data/myexam 目錄下的資訊。 - 請讓 student 可以讀、進入該目錄,但不可以寫入該目錄。 - 未來在此目錄底下新建的任何資料,預設 student 都具有讀與進入目錄的權限(沒有寫入的權限喔!)。 ```bash= mkdir /data/myexam chmod -R 770 /data/myexam chgrp -R examgroup /data/myexam ``` ```bash= setfacl -m u:examuser30:--- /data/myexam setfacl -m d:u:student :rx /data/myexam # 查看權限設定 getfacl /data/myexam ``` ### 3.系統基本操作,包括系統備份、自動化腳本、時間自動更新等機制 #### A.尋找特殊權限的檔名資料: - 找出在/usr/bin, /usr/sbin 目錄下,具有 s 或 t 等特殊權限的檔名 (SUID/SGID/SBIT) - 將這些檔名連同權限,以類似 ll 輸出的資訊,將訊息輸出到 /data/findperm.txt 檔案中 ```bash= find /usr/bin -type f \( -perm -4000 -o -perm -2000 -o -perm -1000 \) -exec ls -al {} >> /data/findperm.txt \; find /usr/sbin -type f \( -perm -4000 -o -perm -2000 -o -perm -1000 \) -exec ls -al {} >> /data/findperm.txt \; ``` #### B.找尋 IP 參數輸出: - 使用『 ip addr show 』這個指令,將輸出訊息中,含有 inet 關鍵字的,但不能含有 inet6 關鍵字,一整列輸出 - 將上述的結果轉輸出到 /data/mynetwork.txt 檔案中。 ```bash= ip addr show | grep inet | grep -v "inet6" > /data/mynetwork.txt ``` #### C.系統備份腳本製作:由於系統上面有非常多的重要資料必須要進行備份,因此我們想要使用一支 script 來進行備份的動作,且將該 script 定時執行: - 請撰寫一隻名為 /root/backup_system.sh 的腳本,來進行備份的工作 - 需要備份的目錄有:/etc, /home, /var/spool/mail/, /var/spool/cron/, /var/spool/at/, /var/lib/,腳本的內容為: - 第一行一定要宣告 shell 喔! - 自動判斷 /backups 目錄是否存在,若不存在則 mkdir 建立她,若存在則不進行任何動作 - 設計一個名為 mysource 的變數,變數內容以空格隔開所需要備份的目錄 - 設計一個名為 mytarget 的變數,該變數為 tar 所建立的檔名,檔名命名規則 /backups/mysys_20xx_xx_xx.tar.gz , 其中 20xx_xx_xx 為西元年、月、日的數字,該數字依據你備份當天的日期由 date 自行取得。 - 開始利用 tar 來備份 - 請注意,撰寫完畢之後,一定要立刻執行一次該腳本!確認實際有建立 /backups 以及相關的備份資料喔! ```bash= touch /root/backup_system.sh chmod 777 /root/backup_system.sh ``` in /root/backup_system.sh ```bash= #!/bin/bash [ ! -d "/backups" ] && mkdir /backups mysource="/etc /home /var/spool/mail/ /var/spool/cron/ /var/spool/at/ /var/lib/" y=(date +%y) m=(date +%m) d=(date +%d) mytarget="/backups/mysys_20${y}_${m}_${d}.tar.gz" tar -zpcv -f ${mytarget} ${mysource} ``` #### D.定期備份功能:排定上述的備份指令在每個星期 6 的凌晨 2 點進行這個備份的動作,且這個script在執行的時候: - 備份指令執行的過程請使用資料流重導向將過程完整的儲存在 /backups/backup.log 這個檔案中(包括正確與錯誤資訊) - 使用 NI值 10 來執行此指令。 ```bash= vim /etc/crontab ### 0 2 * * 6 root nice -n 10 /root/backup_system.sh > /backups/backup.log ### ``` #### E.我的 /usr/sbin/setquota 這個檔案不小心刪除了,該如何救回來?(可以使用 rpm 去追蹤是哪個軟體提供的檔案後,移除再安裝該軟體即可完成此題目。) ```bash= rpm -qf /usr/sbin/setquota yum remove [軟體] yum install [軟體] ``` #### https 沒開 F.服務的管理部份,以 httpd 為例: - 讓你的 Linux 成為 http 以及 https 支援兩者的網頁伺服器 - 每次開機都會主動的喚醒這個伺服器功能 - Internet 應該要能夠連線到你的 http 以及 https 埠口服務 - 當輸入 http://localhost 時,可以看到的是你的 (1)姓名與 (2)學號 - 注意:上課提到的服務建置五個步驟! ```bash= yum install httpd vim /var/www/html/index.html ### (1)姓名: 陳俊仲 (2)學號: A080C101 ### systemctl start httpd systemctl enable httpd ``` 開啟 https (port 443) 參考:https://www.techrepublic.com/article/how-to-enable-https-on-apache-centos/ ```bash= yum install mod_ssl openssl openssl genrsa -out ca.key 2048 openssl req -new -key ca.key -out ca.csr openssl x509 -req -days 365 -in ca.csr -signkey ca.key -out ca.crt cp ca.crt /etc/pki/tls/certs cp ca.key /etc/pki/tls/private/ca.key cp ca.csr /etc/pki/tls/private/ca.csr vim /etc/httpd/conf.d/ssl.conf ### SSLCertificateFile /etc/pki/tls/certs/localhost.crt > SSLCertificateFile /etc/pki/tls/certs/ca.crt SSLCertificateKeyFile /etc/pki/tls/private/localhost.key > SSLCertificateKeyFile /etc/pki/tls/private/ca.key ### systemctl restart httpd # 查看 port 與 服務 netstat -ptunl ``` #看到enter ![Uploading file..._46z76ykt3]() ### 4.腳本建立與系統管理 #### A.特殊原因,例如電力固定維護的關機情境問題: - 你的系統將在 7 月的 20 號 08:00 進行關機的歲修工作,請以『單次』工作排程來設計關機的動作 (poweroff) ```bash= at 08:00 2021-07-20 > poweroff > (Ctrl+D) ``` #### B.系統開機的通知訊息: - 系統開機之後,會自動寄出一封 email 給 root,說明系統開機了。 - 指令可以是『 echo "reboot new" | mail -s 'reboot message' root 』 - 請注意,這個動作必須是系統『自動於開機完成後就動作』,而不需要使用者或管理員登入喔!(hint: rc.local) ![](https://i.imgur.com/mNRzGHy.png) ```bash= vim /etc/rc.d/rc.local ### echo “reboot new” | mail -s ‘reboot message’ root ### chmod a+x /etc/rc.d/rc.local; ll /etc/rc.d/rc.local systemctl daemon-reload systemctl list-dependencies multi-user.target | grep rc-local ``` #### C.為了方便大家使用 ps 外帶的參數來查詢系統的程序,因此管理員建立一隻名為 /usr/local/bin/myprocess 的腳本讓大家方便使用,腳本內容主要為: - 第一行一定要宣告 shell 為 bash 才行; - 主要僅執行『 /bin/ps -Ao pid,user,cpu,tty,args 』 - 這隻腳本必須要讓所有人都可以執行才行! in /usr/local/bin/myprocess ```bash= #!/bin/bash /bin/ps -Ao pid,user,cpu,tty,args ``` ```bash= chmod a+x /usr/local/bin/myprocess ``` #### D.寫一隻名為 /usr/local/bin/myans.sh 的腳本,這隻腳本的執行結果會這樣: - 腳本內第一行一定要宣告 shell 為 bash - 當執行 myans.sh true 時,螢幕會輸出『 Answer is true 』,且訊息為預設的 Standard output - 當執行 myans.sh false 時,螢幕會輸出『 Answer is false 』,且訊息輸出到 starndard error output - 當外帶參數不是 true 也不是 false 時,螢幕會輸出『 Usage: myans.sh true|false 』 - 這隻腳本必須要讓所有人都可以執行才行! in /usr/local/bin/myans.sh ```bash= #!/bin/bash arg=${1} if [ "${arg}" == "true" ]; then echo "Answer is true"; elif [ "${arg}" == "false" ]; then echo "Answer is false" 1>&2; else echo "Usage: myans.sh true|false"; fi ``` ```bash= chmod a+x /usr/local/bin/myans.sh ``` ### 5.基礎檔案管理與檔案系統維護: #### A.打包檔案的格式錯誤問題: - 你的系統中有個檔名 /root/mybackup 的檔案,這個檔案原本是備份系統的資料,但副檔名不小心寫錯了! - 請將這個檔案修訂成為比較正確的副檔名 (例如 /root/mybackup.txt 之類的模樣) - 並且將該檔案在 /srv/testing/ 目錄中解開這個檔案的內容。 ```bash= # 查看檔案型態 file /root/mybackup mv /root/mybackup /root/mybackup.tar.xz cd /root mkdir /srv/testing tar -xvf mybackup.tar.xz -C /srv/testing ``` #### B.LVM 彈性容量變化的效果: - 目前的系統中, /home 應該使用的是 LVM 的維護模式。請找出 /home 所在的 VG 剩餘容量 - 將 VG 所有剩餘容量通通提供給 /home 使用,因此整個 /home 的容量將會放大很多。 - 在目前的系統中,掛載在 /home 的LVM格式資料,請將它的容量變成 - 且這個目錄內的資料並不會消失(無須重新格式化的意思)。 ```bash= # 查看 LV 容量 lvscan # 查看 vg 的剩餘容量 vgdisplay # 將剩餘 vg 容量給 /home lvresize -l +1280 /dev/centos/home # 查看修改後 LV 容量 lvscan ``` ### 6.完成上述所有的題目後,請重新開機,並請在開機後 10 分鐘內執行上傳腳本,否則系統不允許你上傳喔! 作業結果傳輸:請以 root 的身分執行 vbird_book_check_unit 指令上傳作業結果。 正常執行完畢的結果應會出現【XXXXXX_aa:bb:cc:dd:ee:ff_unitNN】字樣。若需要查閱自己上傳資料的時間, 請在作業系統上面使用瀏覽器查詢: http://192.168.251.254 檢查相對應的課程檔案。 相關流程請參考: [vbird_book_check_unit](https://linux.vbird.org/linux_basic_train/centos8/unit00.php?unit=unitck) ## 開始考試的練習 -- VM 2: 系統救援與檔案系統部份 ### 0.不是題目: - 這個系統容量比較小,而且預設在文字界面 - 這個系統目前已經沒有圖形界面,所以你無法進入圖形界面。 - 若你想要使用圖形界面操作系統,可能需要安裝 yum groupinstall GNOME 才行。 - 同樣的,預設界面一定要是純文字界面才可以! ### 1.這部主機真的怪怪的,之前的管理員似乎在這部主機上面進行一些測試,追問之下有一些可能發生的原因,問題還不只一個。 請依據底下可能發生原因的問題予以克服,最終讓系統可以直接以 root 登入! (hint: 千萬不要忘記 .autorelabel 的動作!) #### A.系統救援 - 1 :核心相關資料錯誤造成的問題 - 原因:因為要測試核心開機功能,結果不小心將 initramfs 檔案刪除掉了,所以應該是無法順利開機。 - 建議救援方式:使用原版光碟處理,請進入系統救援的模式,並依據系統既有的核心版本,將 initramfs 重建 - 注意:(1)重建時,應考慮 grub2 的原本設定檔 (可能會在哪裡?),以找到正確的檔名,方可順利成功開機喔。 (2)你可以使用任何一個 CentOS 8.x 的光碟做救援,但是需要注意不同的核心版本的問題! ![](https://i.imgur.com/YY61LYp.png) ![](https://i.imgur.com/nEbKFt8.jpg) ![](https://i.imgur.com/t8qm9Z4.jpg) ![](https://i.imgur.com/4Wak6JT.jpg) 順利登入 rescue linux 模式 ```bash= chroot /mnt/sysimg # 查看 /boot/loader/entries 之下的 .conf 檔案 # initrd 後面接 .img 名稱 # version 後面接 [核心版本 ex:4.18.0-147.el8.x86_64] cd /boot # 將 /lib/modules 下的系統核心模組檔案建成 img 檔 dracut -v initramfs-4.18.0-147.el8.x86_64.img 4.18.0-147.el8.x86_64 ``` #### B.系統救援 - 2 :管理員手滑造成的 root 屬性問題 - 原因:因為幫用戶設定屬性,結果不小心『可能』修改到 root 這個帳號的相關屬性資料。 - 救援恢復的要求: (1)root 密碼恢復到 myCentOS8;(2)root 登入時可順利取得 bash shell 參考 http://linux.vbird.org/linux_basic/0510osloader.php#solution_init 在開機參數加入 init=/bin/bash, 進到系統選單頁面案`e` ![](https://i.imgur.com/n4MMYqm.png) ```bash= mount -o remount,rw / echo "myCentOS8" | passwd --stdin root /sbin/usermod -s /bin/bash root ``` 將系統重新啟動 #### C.系統救援 - 3 :LVM 隨便刪除造成的錯誤 - 原因:在發生此錯誤之前,似乎曾經將系統的 LVM swap 刪除,是否如此造成系統錯誤還不得而之。 - 建議救援方式:不要使用光碟,使用核心支援的維護模式,查看一下開機選單的內容是否正確。 - 注意:在順利登入系統之後,你或許需要 (1)重建 grub 選單以及 (2)修改 /etc/fstab 檔案,以處理 swap 產生的問題 - 注意:刪除 swap 為正常的行為,所以,請不要重建 lvm 的 swap 裝置!從選單去處理! 利用救援光碟進入硬碟檔案系統 ``` # 移除原本Swap掛載 vim /etc/fstab ``` ![](https://i.imgur.com/zqsu0gP.png) ``` vim /etc/default/grub ### 移除與 centos/swap 有關的參數 GRUB_CMDLINE_LINUX="rd.lvm.lv=centos/root crashkernel=auto rhgb quiet systemd.unit=multi-user.target" ### # 重新編譯設定檔案 grub2-mkconfig -o /boot/grub2/grub.cnf ``` 使用硬碟開機即可進入系統 #### D.不是題目:在使用 root 正確登入系統之後,請使用 vbird_book_setup_ip 設定好你的學號與網路。 ### 2.系統初始化功能: #### A.針對 YUM 的軟體倉儲設定,你有底下的兩組軟體倉儲位址,請設定好所需要的環境 (全對才給分): http://ftp.ksu.edu.tw/FTP/Linux/CentOS/8/AppStream/x86_64/os/ http://ftp.ksu.edu.tw/FTP/Linux/CentOS/8/BaseOS/x86_64/os/ ```bash= # 發現 /etc/yum.repos.d/ 底下的倉儲庫遺失 須先把檔案補齊 # 開啟瀏覽器到 https://github.com/Msiciots/yum.repos.d 下載 wget https://github.com/Msiciots/yum.repos.d/archive/refs/heads/main.zip unzip main.zip cp ./yum.repos.d-main/* /etc/yum.repos.d vim /etc/yum.repos.d/CentOS-AppStream.repo ### baseurl=http://ftp.ksu.edu.tw/FTP/Linux/CentOS/8/AppStream/x86_64/os/ ### vim /etc/yum.repos.d/CentOS-Base.repo ### baseurl=http://ftp.ksu.edu.tw/FTP/Linux/CentOS/8/BaseOS/x86_64/os/ ### ``` 如果沒網路無法下載 github 檔案: ```bash= # A. 從 http://ftp.ksu.edu.tw 去找到三個 URL,然後修改底下的資料,共分三個檔案喔! vim /etc/yum.repos.d/CentOS-AppStream.repo ### [AppStream] name=CentOS-$releasever - AppStream #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=AppStream&infra=$infra baseurl=http://ftp.ksu.edu.tw/FTP/CentOS/8/AppStream/x86_64/os/ gpgcheck=1 enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial ### vim /etc/yum.repos.d/CentOS-Base.repo ### [BaseOS] name=CentOS-$releasever - Base #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=BaseOS&infra=$infra baseurl=http://ftp.ksu.edu.tw/FTP/CentOS/8/BaseOS/x86_64/os/ gpgcheck=1 enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial ### vim /etc/yum.repos.d/CentOS-Extras.repo ### [extras] name=CentOS-$releasever - Extras #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra baseurl=http://ftp.ksu.edu.tw/FTP/CentOS/8/extras/x86_64/os/ gpgcheck=1 enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial ### # B. 清除快取! yum clean all # C. 進行 yum update 看看 yum update ``` #### B.系統升級行為 - 只針對 kernel 升級即可 - 升級完畢請立刻重新開機,且使用新核心 ```bash= yum -y update kernel && reboot ``` #### C.關於開機選單調整 - timeout時間設定為 15 秒, - 預設所有的核心參數都會加入 noapic 及 noacpi 兩個參數 - 開機選單多一個回到MBR的設定,選單名稱內亦須包含『 MBR 』字樣,且選單位於最後一個位置 - 開機選單在最後多一項可以進入圖形界面模式,這個圖形界面請使用原有的核心版本 (不是剛剛升級的核心版本), 且title必須含有『 mygraphical 』的字樣才行! ```bash= vim /etc/default/grub ### GRUB_TIMEOUT=15 ... GRUB_CMDLINE_LINUX=".... noapic noacpi " ### vim /etc/grub.d/40_custom ### menuentry 'Go to MBR' --id 'mbr' { insmod chain set root=(hd0) chainloader +1 } ### cp /boot/loader/entries/[核心檔案名].conf /boot/loader/entries/custom.conf vim /boot/loader/entries/custom.conf ### title mygraphical version 4.18.0-147.el8.x86_64 linux /vmlinuz-4.18.0-147.el8.x86_64 initrd /initramfs-4.18.0-147.el8.x86_64.img $tuned_initrd options $kernelopts $tuned_params systemd.unit=graphical.target id centos-20191204215851-4.18.0-147.el8.x86_64 grub_users $grub_users grub_arg --unrestricted grub_class kernel ### grub2-mkconfig -o /boot/grub2/grub.cfg ``` ### 3.檔案系統方面的處理,包含分割(注意primary, extended, logical的限制)、格式化、掛載等 #### A.軟體磁碟陣列管理:目前的系統有個出現磁碟出問題而快要損毀 (degrade) 的軟體磁碟陣列,找出並修復好該系統。 - 該磁碟似乎已經被拔除一個 partition - 找出系統中具有的跟 RAID 內的 partition 容量相同,且沒有被使用的 partition,那就是這個 RAID 缺乏的磁碟槽 (假設已經被修理好了) - 請將該磁碟槽加入原本的系統中,以救援這個磁碟陣列 (讓他變成 clean 的狀態,改變 degraded 的困擾) ``` # 查看 raid, state 存在 degraded mdadm --detail /dev/md5 mdadm --manage /dev/md5 --add /dev/vda4 # 重新查看 raid, state 以變回 clean mdadm --detail /dev/md5 ``` #### B.記憶體置換容量的處理: - 目前這個系統裡面似乎所有的 swap 通通被刪除了!不過這樣實在不太好。 - 建立大型檔案,檔名為 /myswap.img,容量大概是 1G 即可。 - 將上述檔案格式化成為 swap - 每次開機這個 swap 都會主動被系統所使用。 參考 http://linux.vbird.org/linux_basic/0230filesystem.php#swapfile ```bash= dd if=/dev/zero of=/myswap.img bs=1M count=1024 mkswap /myswap.img swapon /myswap.img # 查看Swap是否啟用 swapon -s vim /etc/fstab ### /myswap.img swap swap defaults 0 0 ### ``` #### C.LVM 的建立與 VDO 的應用 - 將目前這個系統當中的所有剩餘容量建立成為單一分割槽,並且將 system ID 設定為 LVM - 利用上面這個分割槽,建立一個名為 thevg 的 VG ,且 PE 容量為 8M - 將 thevg 的所有容量通通給予名為 thelv 的 lv,所以最終會出現 /dev/thevg/thelv 的裝置。 - 將 /dev/thevg/thelv 加入到 VDO 的支援,建立名為如下的 VDO 裝置 - VDO 名稱為 thevdo - VDO 虛擬容量為 20G - 裝置使用 /dev/thevg/thelv - 將 VDO 裝置格式化成為 XFS 檔案系統 - 此裝置開機後會立刻掛載到 /data/vmdata 目錄下 ```bash= gdisk /dev/vda # 一連串建立 partion 的動作 ``` ![](https://i.imgur.com/H10YqBg.png) ```bash= # 讓系統更新剛剛新建的分割槽資訊 partprobe # 查看分割槽是否出現 lsblk # 開始建立 lvm pvcreate /dev/vda6 vgcreate -s 8M thevg /dev/vda6 # 查看全部 PE 數量 vgdisplay thevg lvcreate -n thelv -l 903 thevg # 查看全部 LVM lvdisplay /dev/thevg/thelv # 安裝 vdo 服務軟體 yum install vdo kmod-kvdo systemctl restart vdo systemctl enable vdo # 建立 VDO vdo create --name=thevdo --vdoLogicalSize=20G \ > --device=/dev/thevg/thelv --deduplication enabled --compression enabled # 查看 vdo 狀態 vdostats --human-readable # 格式化成 xfs mkfs.xfs /dev/mapper/thevdo # 設定開機自動掛載 vim /etc/fstab ### /dev/mapper/thevdo /data/vmdata xfs defaults,x-systemd.requires=vdo.service 0 0 ### # 查看是否成功掛載 df -Th /data/vmdata ``` #### D.LVM 與 stratisd 的應用 - 將 centos 這個 VG 的剩餘容量,給予一個名為 thepool 的 LVM 裝置,最終會有 /dev/centos/thepool 裝置存在。 - 將 thepool 加入到名為 lvmpool 的儲存池 (thin pool) 當中 - 建立 thefs 檔案系統,並且開機會掛載到 /data/mypool 目錄下。 - 上述掛載最好使用 UUID 來處理! 安裝 stratis ```bash= yum install -y stratisd stratis-cli systemctl start stratisd systemctl enable stratisd ``` ```bash= # 查看 VG:centos 的剩餘容量 vgdisplay centos lvcreate -n thepool -l 1792 centos stratis pool create lvmpool /dev/centos/thepool stratis filesystem create lvmpool thefs stratis filesystem list # 查看 thefs 的 uuid 輸入上面結果的 Device 位置 blkid /dev/stratis/lvmpool/* # 設定開機自動掛載 vim /etc/fstab ### UUID=[剛剛查詢到的uuid] /data/mypool xfs defaults,x-systemd.requires=stratisd.service 0 0 ### # 查看是否成功掛載 df -Th /data/mypool ``` ### 4.系統效能處理: #### A.請改用『 throughput-performance 』來動態調整系統效能 ```bash= tuned-adm profile throughput-performance tuned-adm active ``` #### B.調整核心參數,讓每次開機都會修改成為底下這樣: - /proc/sys/vm/dirty_ratio 改成 40 - /proc/sys/vm/dirty_background_ratio 改成 5 - /proc/sys/vm/swappiness 改成 10 ```bash= vim /etc/sysctl.d/mycentos.conf ### vm.dirty_ratio = 40 vm.dirty_background_ratio = 5 vm.swappiness = 10 ### sysctl -p /etc/sysctl.d/mycentos.conf ``` #### 5.完成上述所有的題目後,請重新開機,並請在開機後 10 分鐘內執行上傳腳本,否則系統不允許你上傳喔! 作業結果傳輸:請以 root 的身分執行 vbird_book_check_unit 指令上傳作業結果。 正常執行完畢的結果應會出現【XXXXXX_aa:bb:cc:dd:ee:ff_unitNN】字樣。若需要查閱自己上傳資料的時間, 請在作業系統上面使用瀏覽器查詢: http://192.168.251.254 檢查相對應的課程檔案。 相關流程請參考: [vbird_book_check_unit](https://linux.vbird.org/linux_basic_train/centos8/unit00.php?unit=unitck)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully