吳宗叡
    • 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

      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.
      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

    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.
    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
    # RHCSA 考古題: https://blog.csdn.net/qq_37789137/article/details/103637904 ## 內部環境 bastion: 172.25.250.254 workstation: 172.25.250.9 servera: 172.25.250.10 serverb: 172.25.250.11 帳號密碼: root / redhat 帳號密碼: student / student ### 重設機器 進到foundation terminal ```shell $ rht-vmctl reset [servername/all] ``` ## 總複習 ### RH124 * p438 主機名稱設定 * 修改主機名稱 * `hostnamectl set-hostname servera.lab.example.com` * p444 網路組態設定 * 新增connection * `nmcli con add con-name [con name] ifname [eth] type ethernet ip4 [ip/24] gw4 [gateway]` * 修改dns server * `nmcli con mod [con name] ipv4.dns [dns server]` * 修改connection autostarted * `nmcli con mod [new con] connection.autoconnect yes` * `nmcli con mod [old con] connection.autoconnect no` * 修改connection添加ip address * `nmcli con mod [con name] +ipv4.addresses [ip/24]` * p378 時區設定/網路時間 * 設定時區 * `timedatectl list-timezone | grep [time-zone name]` * `timedatectl set-timezone [time-zone name]` * 自動校時 * `vi /etc/chrony.conf` 添加`server [server] iburst` * `systemctl restart chronyd` * p384 journalctl/logger * 取得30分鐘前時間 * `date -d "-30 minutes"` * 使用journalctl查看log event * `journalctl --since [start time] --until [end time]` * 添加rsyslog設定以接收登入log * `vi /etc/rsyslog.d/auth-errors.conf` 添加 `authpriv.alert /var/log/auth-errors` * `systemctl restart rsyslog` * 使用logger偽造authpriv.alert log * `logger -p authpriv.alert "Logging test authpriv.alert"` * 使用tail查看log * `tail /var/log/auth-errors` * p233 權限設定 * 設定資料夾群組 * `chown :[group name] [dir]` * 設定gid及使用權限 * `chmod 2770 [dir]` * umask設定使UID大於199且username與groupname相同者umask為007其餘為022 `(umask為減少檔案權限)` * `vi /etc/profile.d/local-umask.sh` * ``` if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then umask 007 else umask 022 fi ``` * P506 yum repo設定(以p506`[EPEL]`為範本) * `yum-config-manager --add-repo="https://content.example.com/rhel8.2/x86_64/dvd/BaseOS"` * `vi content.example.com_rhel8.2_x86_64_dvd_BaseOS.repo` * 加上`gpgcheck = 0` * content.example.com/rhel8.2/x86_64/dvd/ ``` [BaseOS] name= RHEL8-BaseOS baseurl=http://content.example.com/rhel8.2/x86_64/dvd/BaseOS/ enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release [AppStream] name=RHEL8-AppStream baseurl=http://content.example.com/rhel8.2/x86_64/dvd/AppStream enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release ``` * p226 檔案存取權限(特殊權限 g+s) * 設定gid到資料夾 * `chmod g+s [dir]` * 設定umask * `umask 027` * 修改bashrc使預設umask改變 * `echo "umask 007" >> ~/.bashrc` * p472 檔案壓縮 * 壓縮為tar.gz * `tar -czf [file name].tar.gz [dir]` * p200 帳號權限/設定 * 修改使用者密碼最長時效 * `vi /etc/login.defs` 修改 `PASS_MAX_DAYS`欄位 * 新增group * `groupadd -g [group id] [group name]` * 設定administrative權限給group * `vi /etc/sudoers.d/[group name]` * 填寫`%[group name] ALL=(ALL) ALL` * 添加使用者進group * `useradd -G [group name] [username]` * 調整使用者到期時間 * `date -d "+90 days" +%F` * `chage -E [date] [username]` * 調整密碼最長時效 * `chage -M [days] [username]` * 調整使用者首次登入要修改密碼 * `chage -d 0 [username]` * p192 nologin(不讓使用者使用shell) * 設定nologin為特定使用者shell * `usermod -s /sbin/nologin [username]` * 添加使用者時即設定nologin * `useradd -s /sbin/nologin [username]` ### RH134 * p44 user cronjob設定 * 修改cronjob * `crontab -e` * `*/2 08-20 * * Mon-Fri /usr/bin/date >> /home/student/ my_first_cron_job.txt` * 查看cronjob * `crontab -l` * 刪除所有cronjob * `crontab -r` * p409 container相關 * 測試可否連上regisrty * `podman search ubi` * 背景執行container並加入volume(option: `rw`,`z`..) * `podman run -d --name [name] -p [host]:[container] -v [host]:[container]:[option] [image]` * 生成system service * `podman generate systemd --name [container name] --files --new` * 確保user service可在開機時啟動 * `loginctl enable-linger` * `loginctl show-user [name]` * p251 autoFS * 新增主要設定檔(direct) * `vi /etc/auto.master.d/direct.autofs` * `/- /etc/auto.direct` * `# <預設目錄> <資料對應檔>` * 新增資料對應檔(direct) * `vi /etc/auto.direct` * `/external -rw,sync,fstype=nfs4 serverb.lab.example.com:/shares/direct/external` * `# [本地端目錄] [-掛載參數] [伺服器所提供的目錄]` * 新增主要設定檔(indirect) * `vi /etc/auto.master.d/indirect.autofs` * `/internal /etc/auto.indirect` * `# <預設目錄> <資料對應檔>` * 新增資料對應檔(indirect) * `vim /etc/auto.indirect` * `* -rw,sync,fstype=nfs4 serverb.lab.example.com:/shares/indirect/&` * `# [本地端目錄] [-掛載參數] [伺服器所提供的目錄]` * 本地端目錄 "*" 表示 /internal 下的任何次目錄 * enable autoFS.service * `systemctl enable --now autofs` * 重新開機 * `systemctl reboot` * p107 ACL設定 (檔案只有User1沒有rwx權限) * 設定ACL權限給group * `setfacl -Rm g:[group]:rwX [dir]` * `-R`:資料夾下所有, `rwX`:read/write/有條件得execute * 設定ACL權限給user * `setfacl -Rm u:[user]:- [dir]` * `-`:不給任何權限 * 設定default ACL權限給group(之後的檔案資料夾都適用) * `setfacl -m d:g:[group]:rwx [dir]` * `d:`:default * 設定default ACL權限給user(之後的檔案資料夾都適用) * `setfacl -m d:u:[user]:- [dir]` * `d:`:default * 確認ACL設定 * `getfacl [dir]` * p145 selinux設定 * 調整資料夾selinux權限(httpd_sys_content_t為範例) * `semanage fcontext -l | grep http`/`ls -z` * `semanage fcontext -a -t httpd_sys_content_t '[dir](/.*)?'` * `(/.*)?`:資料夾下所有 * `restorecon -Rv [dir]` * p309 selinux port限制設定 * 確認selinux allow port * `semanage port -l | grep http` * 添加port到selinux * `semanage port -a -t http_port_t -p tcp [port]` * 調整防火牆 * `firewall-cmd --permanent --add-port=[port]/tcp` * `firewall-cmd --reload` * p25 Regex (挑出檔案含有特定字串的行) * 利用grep 使用regex * `grep '^[regex]' [file]` * grep -i(忽略大小寫) * `grep -i '[regex]' [file]` * p170 swap * 列出/dev/vdb partition * `parted /dev/vdb print` * 切partition給swap * `parted /dev/vdb mkpart myswap linux-swap 1001MB 1501MB` * `1001MB 1501MB`:從1001切到1501共500MB * 註冊新的partition * `udevadm settle` * 建立swap * `mkswap /dev/vdb2` * 啟動剛建立的swap * `swapon --show` * `swapon /dev/vdb2` * `swapon --show` * 關閉剛建立的swap * `swapoff /dev/vdb2` * `swapon --show` * 修改`/etc/fstab` * `lsblk --fs /dev/vdb2` * `vi /etc/fstab`填入下方 * `UUID=[uuid] swap swap defaults 0 0` * `systemctl daemon-reload` * 啟用所有swap * `swapon -a` * 重新開機 * `systemctl reboot` * p71 tuned設定(電腦模式: 省電/平衡...) * 查看tuned是否啟用 * `systemctl is-enable tuned` * `systemctl is-active tuned` * 安裝 tuned * `yum install tuned` * `systemctl start tuned` * 取得系統推薦模式 * `tuned-adm recommend` * 調整turnd 模式 * `tuned-adm profile powersave` * p191 LVM * 建立磁碟分割表 * `parted /dev/vdb mklabel gpt` * 切partition * `parted /dev/vdb mkpart primary 1MiB 257Mib` * `parted /dev/vdb set 1 lvm on` * 註冊partition * `udevadm settle` * 建立PV * `pvcreate /dev/vdb1` * 建立VG * `vgcreate [VG name] /dev/vdb1` * 建立LV * `lvcreate -n [LV name] -L [size M] [VG name]` * 建立FS * `mkfs.xfs /dev/[VG name]/[LV name]` * 建立資料夾 * `mkdir /data` * 修改`/etc/fstab`新增下方 * `/dev/[VG name]/[LV name] /data xfs defaults 1 2` * `systemctl daemon-reload` * `mount /data` * p207 LV放大 * 建立PV * `pvcreate /dev/vdb2` * 擴大VG * `vgextend [VG name] /dev/vdb2` * 擴大LV * `lvextend -L +[size M] /dev/[VG name]/[LV name]` * `xfs_growfs /storage/data1` * p233 advstorage stratis (重點p235 7.4/p237 11.5) * 安裝stratis相關 * `yum install stratisd stratis-cli` * 啟用stratis * `systemctl enable stratisd` * `systemctl start stratisd` * 新增labpool * `stratis pool create labpool /dev/vdb` * `stratis pool list` * 擴大labpool * `stratis pool add-data labpool /dev/vdc` * `stratis pool list` * 列出block device * `stratis blockdev list` * 建立FS * `stratis filesystem create labpool labfs` * `stratis filesystem list` * 查詢UUID * `lablk --output=UUID /stratis/labpool/labfs` * 修改`/etc/fstab` * `UUID=[UUID] /labstratisvol xfs defaults,x-systemd.requires=stratis.service 0 0` * `systemctl daemon-reload` * 建立vdo volume * `vdo create --name=labvdo --device=/dev/vdd --vdoLogicalSize=50G` * `vdo list` * 建立FS * `mkfs.xfs -K /dev/mapper/labvdo` * 註冊device * `udevadm settle` * 修改`/etc/fstab` * `UUID=[UUID] /labvodvol xfs defaults,x-systemd.requires=vdo.service 0 0` * p278 root密碼忘記重設 * 開機按下`Ctrl+Alt+Del` * 按下`e`進入開機選項 * 到linux開頭行 按下`End`到最後新增`rd.break` * 按下`Ctrl+x` boot * 重新mount /sysroot * `mount -o remount,rw /sysroot` * `chroot /sysroot` * 修改密碼 * `passwd root` * 使/etc/shadow自動帶入selinux * `touch /.autorelabel` * `exit` ## 考古題 ### 機器1(xxx.example.com) 1. 網路配置 | 項目 | 內容 | |:----------- |:--------------- | | Hostname | xxx.example.com | | IP Address | 172.20.10.20 | | subnet mask | 255.255.255.0 | | Gateway | 172.20.10.254 | | DNS | 172.20.10.254 | * `nmtui` * `ip address > 172.20.10.20/24` 2. 配置yum repo >`http://xxx.example.com/BaseOS` 和 `http://xxx.example.com/AppStream` ```shell $ yum-config-manager --add-repo=http://xxx.example.com/BaseOS $ yum-config-manager --add-repo=http://xxx.example.com/AppStream $ vi xxx.example.com_BaseOS.repo #加上gpgcheck = 0 $ vi xxx.example.com_AppStream.repo #加上gpgcheck = 0 ``` 3. 調適SELinux >非標準端口 82 上運行的 Web 服務器在提供內容時遇到問題。根據需要調試並解決問題,使其滿足以下條件: >>1. 系統上的 Web 服務器能夠提供 /var/www/html 中所有現有的 HTML 文件(注:不要刪除或以其他方式改動現有的文件內容) >>2. Web 服務器在端口 82 上提供此內容 >>3. Web 服務器在系統啟動時自動啟動 ```shell $ semanage port -l | grep http $ semanage port -a -t http_port_t -p tcp 82 $ semanage fcontext -l | grep http $ semanage fcontext -m -t httpd_sys_content_t "/var/www/html(/.*)?" $ restorecon -Rv /var/www/html $ systemctl restart httpd ``` 4. 創建用戶 >創建下列用戶、組和組成員資格: >>1.名為 sysmgrs 的組 >>2.用戶 natasha ,作為次要組從屬於 sysmgrs >>3.用戶 harry ,作為次要組還從屬於 sysmgrs >>4.用戶 sarah ,無權訪問系統上的交互式 shell 且不是 sysmgrs 的成員 >>5.natasha 、 harry 和 sarah 的密碼應當都是 123 ```shell $ groupadd sysmgrs $ useradd -G sysmgrs natasha $ useradd -G sysmgrs harry $ useradd -s /sbin/nologin sarah $ passwd natasha $ passwd harry $ passwd sarah ``` 5. 配置cron > 配置 cron 作業,該作業每隔 5 分鐘運行並執行以下命令: logger “EX200 in progress”,以用戶 natasha 身份運行 ```shell $ crontab -e -u natasha ``` ``` */5 * * * * logger "EX200 in progress" ``` 6. 創建協作目錄 >創建具有以下特徵的協作目錄 /home/managers >>/home/managers 的組用權是 sysmgrs >>目錄應當可被 sysmgrs 的成員讀取。寫入和訪問,但任何其他用戶不具這些權限。 (當然,root 用戶有權訪問系統上的所有文件和目錄) >>/home/managers 中創建的文件自動將組所有權設置到 sysmgrs 組 ```shell $ mkdir /home/managers $ chown :sysmgrs /home/managers $ chmod 2770 /home/managers ``` 7. 配置 NTP > 配置您的系统,使其成为 vvv.zzz.example.com 的 NTP 客户端。 ```shell $ systemctl status chronyd $ vim /etc/chrony.conf #添加 server vvv.zzz.example.com iburst $ systemctl restart chronyd ``` 8. 配置 autofs > 配置 autofs ,以按照如下所述自動掛載遠程用戶的主目錄: >>xxx.example.com(172.20.10.20) NFS 導出 /rhel 到您的系統。此文件系統包含為用戶 user1 預配置的主目錄 >>user1 的主目錄是 xxx.example.com:/rhel/user1 >>user1 的主目錄應自動掛載到本地 /rhel 下的 /rhel/user1 >>主目錄必須可供其用戶寫入 >>user1 的密碼是 123 ```shell $ vim /etc/auto.master #添加 /rhel /etc/auto.misc $ vim /etc/auto.misc #添加 user1 -rw xxx.example.com:/rhel/user1 $ systemctl enable autofs $ systemctl start autofs ``` 9. 配置 /var/tmp/fstab 權限 > 將文件 /etc/fstab 複製到 /var/tmp/fstab 。配置 /var/tmp/fstab 的權限以滿足如下條件: >>文件 /var/tmp/fstab 自 root 用戶所有 >>文件 /var/tmp/fstab 屬於組 root >>文件 /var/tmp/fstab 應不能被任何人執行 >>用戶 natasha 能夠讀取和寫入 /var/tmp/fstab >>用戶 harry 無法寫入或讀取 /var/tmp/fstab >>所有其他用戶(當前或未來)能夠讀取 /var/tmp/fstab ```shell $ cp /etc/fstab /var/tmp/fstab $ chmod 774 /var/tmp/fstab $ setfacl -m u:natasha:rw /var/tmp/fstab $ setfacl -m u:harry:- /var/tmp/fstab ``` 10. 配置用戶帳戶 > 配置用戶 user2,其用戶 ID 為 3388。此用戶的密碼應當為 123。 ```shell $ useradd -u 3388 user2 $ passwd user2 ``` 11. 查找文件 > 查找當 user3 所有的所有文件並將其副本放入 /root/dfiles 目錄 ```shell $ mkdir /root/dfiles $ find / -user user3 -exec cp -a {} /root/dfiles \; ``` 12. 查找字符串 > 查找文件 /usr/share/rhel.xml 中包含字符串 re 的所有行。將所有這些行的副本按原始順序放在文件 /root/files 中。 ```shell $ grep re /usr/share/rhel.xml $ grep re /usr/share/rhel.xml > /root/list ``` 13. 創建存檔 > 創建一個名為 /root/books.tar.gz 的 tar 存檔,其應包含 /usr/local 的 tar 存檔,其應包含 /usr/local 的內容。該 tar 存檔必須使用 gzip 進行壓縮。 ```shell $ tar -czf /root/books.tar.gz /usr/local ``` ### 機器2(vvv.example.com) 1. 設置 root 密碼 > 將 vvv 的 root 密碼設置為 123 。您需要獲得系統訪問權限才能進行此操作 ```shell # 開機頁面按e # linux行尾加rd.break # ctrl + x $ mount -o remount,rw /sysroot $ chroot /sysroot $ echo 123 | passwd --stdin root $ touch /.autorelabel $ exit ``` 2. 配置yum repo >`http://xxx.example.com/BaseOS` 和 `http://xxx.example.com/AppStream` ```shell $ yum-config-manager --add-repo=http://xxx.example.com/BaseOS $ yum-config-manager --add-repo=http://xxx.example.com/AppStream $ vi xxx.example.com_BaseOS.repo #加上gpgcheck = 0 $ vi xxx.example.com_AppStream.repo #加上gpgcheck = 0 ``` 3. 調整邏輯卷(LV)大小 >將邏輯卷 vo 及其文件系統的大小調整到 180 MiB。確保文件系統內容保持不變。注:分區大小很少與請求的大小完全相同,因此可以接受範圍為 167 MiB 到 193 MiB 的大小 ```shell $ df -h $ vgdisplay myvol $ lvextend -L 180M /dev/myvol/vo $ resize2fs /dev/myvol/vo ``` 4. 添加交換分區(swap) > 向您的系統添加一個額外的交換分區 567MiB 。交換分區應在系統啟動時自動掛載。不要刪除或以任何方式改動系統上的任何現有交換分區。 ```shell $ parted /dev/vdb print $ parted /dev/vdb mkpart myswap linux-swap 1001MB 1568MB $ udevadm settle $ mkswap /dev/vdb2 $ vim /etc/fstab # /dev/vdb2 swap swap defaults 0 0 $ swapon -a ``` 5. 創建邏輯卷(LV) >根據如下要求,創建新的邏輯卷: >>邏輯捲取名為 np ,屬於 npgroup 卷組,大小為 45 個擴展塊(PE) >>npgroup 卷組中邏輯卷的擴展塊大小應當為 20 MiB >>使用 ext3 文件系統格式化新邏輯卷。該邏輯卷應在系統啟動時自動掛載到 /mnt/np 下 ```shell $ parted /dev/vdb print $ parted /dev/vdb mkpart primary 1569MB 3000MB $ parted /dev/vdb mkpart set 3 lvm on $ udevadm settle $ pvcreate /dev/vdb3 $ vgcreate -s 20M npgroup /dev/vdb3 $ lvcreate -l 45 -n np npgroup $ mkfs.ext3 /dev/npgroup/np $ mkdir /mnt/np $ vim /etc/fstab # /dev/npgroup/np /mnt/np ext3 defaults 1 2 $ mount -a ``` 6. 創建 VDO 卷 >根據如下要求,創建新的 VDO 卷: >>使用未分區的磁盤 >>該卷的名稱為 vdoname >>該卷的邏輯大小為 80G >>該卷使用 xfs 文件系統格式化 >>該卷掛載到 /vbark下 ```shell $ lsblk $ yum install vdo $ vdo create --name=vdoname --device=/dev/vdc --vdoLogicalSize=80G $ mkfs.xfs -K /dev/mapper/vdoname $ udevadm settle $ mkdir /vbark $ vim /etc/fstab $ #添加 /dev/mapper/vdoname /vbark xfs defaults,x-systemd.requires=vdo.service 0 0 $ mount -a ``` 7. 配置系統調優 >為您的系統選擇建議的 tuned 配置集並將它設為默認設置 ```shell $ tuned-adm recommend $ tuned-adm profile virtual-guest(tuned-adm recommend結果) ``` ### 純題目 #### 機器1(xxx.example.com) 1. 網路配置 | 項目 | 內容 | |:----------- |:--------------- | | Hostname | xxx.example.com | | IP Address | 172.20.10.20 | | subnet mask | 255.255.255.0 | | Gateway | 172.20.10.254 | | DNS | 172.20.10.254 | 2. 配置yum repo >`http://xxx.example.com/BaseOS` 和 `http://xxx.example.com/AppStream` 3. 調適SELinux >非標準端口 82 上運行的 Web 服務器在提供內容時遇到問題。根據需要調試並解決問題,使其滿足以下條件: >>1. 系統上的 Web 服務器能夠提供 /var/www/html 中所有現有的 HTML 文件(注:不要刪除或以其他方式改動現有的文件內容) >>2. Web 服務器在端口 82 上提供此內容 >>3. Web 服務器在系統啟動時自動啟動 4. 創建用戶 >創建下列用戶、組和組成員資格: >>1.名為 sysmgrs 的組 >>2.用戶 natasha ,作為次要組從屬於 sysmgrs >>3.用戶 harry ,作為次要組還從屬於 sysmgrs >>4.用戶 sarah ,無權訪問系統上的交互式 shell 且不是 sysmgrs 的成員 >>5.natasha 、 harry 和 sarah 的密碼應當都是 123 5. 配置cron > 配置 cron 作業,該作業每隔 5 分鐘運行並執行以下命令: logger “EX200 in progress”,以用戶 natasha 身份運行 6. 創建協作目錄 >創建具有以下特徵的協作目錄 /home/managers >>/home/managers 的組用權是 sysmgrs >>目錄應當可被 sysmgrs 的成員讀取。寫入和訪問,但任何其他用戶不具這些權限。 (當然,root 用戶有權訪問系統上的所有文件和目錄) >>/home/managers 中創建的文件自動將組所有權設置到 sysmgrs 組 7. 配置 NTP > 配置您的系统,使其成为 vvv.zzz.example.com 的 NTP 客户端。 8. 配置 autofs > 配置 autofs ,以按照如下所述自動掛載遠程用戶的主目錄: >>xxx.example.com(172.20.10.20) NFS 導出 /rhel 到您的系統。此文件系統包含為用戶 user1 預配置的主目錄 >>user1 的主目錄是 xxx.example.com:/rhel/user1 >>user1 的主目錄應自動掛載到本地 /rhel 下的 /rhel/user1 >>主目錄必須可供其用戶寫入 >>user1 的密碼是 123 9. 配置 /var/tmp/fstab 權限 > 將文件 /etc/fstab 複製到 /var/tmp/fstab 。配置 /var/tmp/fstab 的權限以滿足如下條件: >>文件 /var/tmp/fstab 自 root 用戶所有 >>文件 /var/tmp/fstab 屬於組 root >>文件 /var/tmp/fstab 應不能被任何人執行 >>用戶 natasha 能夠讀取和寫入 /var/tmp/fstab >>用戶 harry 無法寫入或讀取 /var/tmp/fstab >>所有其他用戶(當前或未來)能夠讀取 /var/tmp/fstab 10. 配置用戶帳戶 > 配置用戶 user2,其用戶 ID 為 3388。此用戶的密碼應當為 123。 11. 查找文件 > 查找當 user3 所有的所有文件並將其副本放入 /root/dfiles 目錄 12. 查找字符串 > 查找文件 /usr/share/rhel.xml 中包含字符串 re 的所有行。將所有這些行的副本按原始順序放在文件 /root/files 中。 13. 創建存檔 > 創建一個名為 /root/books.tar.gz 的 tar 存檔,其應包含 /usr/local 的 tar 存檔,其應包含 /usr/local 的內容。該 tar 存檔必須使用 gzip 進行壓縮。 #### 機器2(vvv.example.com) 1. 設置 root 密碼 > 將 vvv 的 root 密碼設置為 123 。您需要獲得系統訪問權限才能進行此操作 2. 配置yum repo >`http://xxx.example.com/BaseOS` 和 `http://xxx.example.com/AppStream` 3. 調整邏輯卷(LV)大小 >將邏輯卷 vo 及其文件系統的大小調整到 180 MiB。確保文件系統內容保持不變。注:分區大小很少與請求的大小完全相同,因此可以接受範圍為 167 MiB 到 193 MiB 的大小 4. 添加交換分區(swap) > 向您的系統添加一個額外的交換分區 567MiB 。交換分區應在系統啟動時自動掛載。不要刪除或以任何方式改動系統上的任何現有交換分區。 5. 創建邏輯卷(LV) >根據如下要求,創建新的邏輯卷: >>邏輯捲取名為 np ,屬於 npgroup 卷組,大小為 45 個擴展塊(PE) >>npgroup 卷組中邏輯卷的擴展塊大小應當為 20 MiB >>使用 ext3 文件系統格式化新邏輯卷。該邏輯卷應在系統啟動時自動掛載到 /mnt/np 下 6. 創建 VDO 卷 >根據如下要求,創建新的 VDO 卷: >>使用未分區的磁盤 >>該卷的名稱為 vdoname >>該卷的邏輯大小為 80G >>該卷使用 xfs 文件系統格式化 >>該卷掛載到 /vbark下 7. 配置系統調優 >為您的系統選擇建議的 tuned 配置集並將它設為默認設置 mend結果) ## 上課內容 ### root建立帳號 ```shell $useradd user1 $passwd user1 -> 輸入密碼 ``` ### User變更密碼 ```shell $passwd -> 輸入現在密碼 -> 輸入修改後密碼 ``` ### root修改User密碼 ```shell $passwd user1 -> 輸入密碼 ``` ### 修改時間 ```shell $date -s 2022-04-23 $date -s 15:30:00 $clock -w (同步時間到系統電子錶) ``` ### 檔案格式查詢 ```shell $file [filename] ``` ### commandline文字刪除 ctrl + U 刪除位置前所有 ctrl + k 刪除位置後所有 ### ls -l 詳細說明 `drwxr-xr-x. 2 student student 6 Sep 1 2020 Desktop` * 第一碼 ``` -: 一般檔案 d: 目錄 l: Soft Link b: 設備檔 c: 設備檔 s: Unix Domain Socket p: pipline ``` * rwd後的 `.` ACL權限 * `.`後的數字 第一碼為d: 目錄下還有多少目錄 其他: 檔案有多少Hard Link * 數字後的使用者名稱 擁有者 所屬的group ### 查看檔案詳細資料 ```shell $stat /etc/hosts File: /etc/hosts Size: 659 Blocks: 8 IO Block: 4096 regular file Device: fc03h/64515d Inode: 16808187 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Context: system_u:object_r:net_conf_t:s0 Access: 2022-04-24 09:53:07.957599472 +0800 Modify: 2022-04-24 09:53:07.950599617 +0800 Change: 2022-04-24 09:53:07.951599596 +0800 Birth: - ``` ## chapter2 ### cp 複製 保留檔案原始屬性(-p) ``` cp -p source directory ``` 複製目錄(-r) ``` cp -r -p source-directory directory ``` 複製soft link(-d) 不加的話會直接複製原檔案 ``` cp -d soft-link directory ``` 強大指令`-a`(-p,-r,-d和而為一) ``` cp -a source directory ``` ### mv 移動 移動目錄(-r) ``` mv -r source-directory directory ``` ### rm 刪除 不再確認刪除(-f) ``` rm -f target ``` 刪除目錄(-r) ``` rm -rf target-directory ``` ## chapter5 ### input redirect ``` tr a-z A-Z < file ``` ### vi shortkey ``` i : 游標 前方 插入 字元 a : 游標 後方 插入 字元 O : 游標 上方 插入 空白行 o : 游標 下方 插入 空白行 del : 刪除一個字元 dd : 刪除一行 3dd : 刪除三行 yy : 複製 一行 p : 在游標 下方 貼上 P : 在游標 上方 貼上 3yy : 複製 三行 :1 : 移動 游標 到檔案的 第 1 行 :N : 移動 游標 到檔案的 第 N 行 :$ : 移動 游標 到檔案的 最行一行 ctrl + g: 顯示 游標 在檔案的 行 跟 列 的位置 u : 上一步 ctrl + r: 下一步 /String : 搜尋 字串 n : 向下搜尋 N : 向上搜尋 :w : 存檔 然後繼續編輯 :wq! : 存檔 然後結束 vi :q! : 不存檔結束 vi :1,$s/[Cc]at/Dog/g : 以正規表示式 搜尋 取代 字串 ``` ### 變數 ```shell $VARIABLE="variable" => shell 變數 $export VARIABLE="variable" => 環境變數 ``` ### shell ![](https://i.imgur.com/Ie4hvOy.png) ## chapter6 ### UserNum | | User | Group | | ------- | ---------- | ----------- | | 0 | root | root | | 1~200 | SystemUser | SystemGroup | | 201~999 | SystemUser | SystemGroup | | >=1000 | user | group | ==1~200: 服務為RedHat提供== ==201~999: 服務非RedHat提供== SystemUser/SystemGroup 當初漏洞服務使用root造成竊取 ### user添加附屬群組 ```shell $usermod -G group1 group2 => override $usermod -aG group1 group2 => append ``` ## chapter7 ### 使用者權限 | user | group | other | user | group | | | ---- | ----- | ----- | ---- | ----- | ---- | | rwx | rwx | rwx | root | root | file | ----權限由左至右查看----> ### 查看目錄權限 沒加-d 會查看目錄下檔案 ```shell $ls -ld folder ``` ### 更變使用者 * 檔案 ```shell rwx rwx rwx root root file $chown user1 file => 更變持有者 $chgrp user1 file => 更變持有群組 $chown user1:user1 file => 兩者都更變 ``` * 目錄 ```shell drwx rwx rwx root root dir $chown -R user1 dir => 更變持有者 $chgrp -R user1 dir => 更變持有群組 $chown -R user1:user1 dir => 兩者都更變 ``` ### 更變存取權限 * 檔案 ```shell r_x r__ rw_ root root file ─┐ rwx r_x __x root root file ←┘ $chmod u+w,g+x,o-rw+x file $chmod u=rwx,g=rx,o=x file $chmod 751 file ``` * 目錄 ```shell $chmod -R 751 dir/ ``` ### 檔案建立與刪除權限 ``` ABC rwx rwx r_x ├a1 rwx rwx rwx ├a2 ___ rwx ___ ``` * 使用者為other不可刪除任意檔案 * 使用者為user/group可刪除任意檔案 檔案建立與刪除與否在於上層folder w權限 ## chapter7 ### process signals * 1: Hangup * 9: Kill * 15: Terminate * 18: Continue * 10: Stop ## chapter10 ### ssh ![](https://i.imgur.com/baNdzSM.png) ### 利用key登入 ```shell $ssh-keygen => 生成key ``` 1. 單一指令 ```shell $ssh -i key.pub root@serverb => 使用key登入 ``` 2. 直接登入 ```shell $ssh-copy-id -i key.pub root@serverb => 將key塞入目標電腦 $ssh root@serverb => 目標電腦認key ``` ## chapter13 ### scp * 複製後屬性會不同 ```shell $scp root@serverb:/etc/passwd . => 從serverb複製/etc/passwd回來 $scp -r root@serverb:/home . => 用root身分執行從serverb複製/home回來 $scp /etc/passwd root@serverb:/tmp => 複製/etc/passwd到serverb $scp -r /home root@serverb:/tmp => 用root身分執行複製/home到serverb ``` ### rsync * 與ssh功能相同但屬性會維持 ```shell $rsync -av root@serverb:/etc/passwd . => 從serverb複製/etc/passwd回來 $rsync -av root@serverb:/home . => 從serverb複製/home回來 $rsync -avHAX root@serverb:/home . => 盡量使用-avHAX保留最原始檔案 $rsync -av /home /tmp => 本機目錄複製 ``` * 額外參數 * `-H`: 保留Hard Link * `-A`: 保留ACLs * `-X`: 保留SELinux * `--progress`: 顯示進度 ### sftp ```shell $sftp root@serverb => 登入到serverb sftp $get file => 下載file ``` ## chapter? ### LVM * 列出PV * `pvscan` * 建立PV * `pvcreate /dev/sda1` 以partition為單位 * `pvcreate /dev/sdb` 以設備為單位 * 查看PV狀態 * `pvdisplay /dev/sda1` * `pvdisplay /dev/sdb` * 列出VG * `vgscan` * 建立VG(-s 指定PE大小,可不填寫) * `vgcreate -s [?M] vg0 /dev/sda1 /dev/sdb` * 查看VG狀態 * `vgdisplay vg0` * 列出LV * `lvscan` * 建立LV * `lvcreate -L 200M -n lv1 vg0` 以容量為單位 * `lvcreate -l 13 -n lv2 vg0` 以PE為單位 * 查看LV狀態 * `lvdisplay /dev/vg0/lv1` * 格式化LV * `nkfs.ext4 /dev/vg0/lv1` * `nkfs.xfs /dev/vg0/lv2` * 建立mount資料夾 * `mkdir /mnt/lv1` * `mkdir /mnt/lv2` * 修改 `/etc/fstab` ``` /dev/vg0/lv1 /mnt/lv1 ext4 defaults 1 2 /dev/vg0/lv2 /mnt/lv2 xfs defaults 1 2 ``` * 檢查mount * `mount -a` ### 擴大LV * 建立PV * `pvcreate /dev/sdc` * 擴大VG * `vgextend vg0 /dev/sdc` * 擴大LV * `lvextend -L +100M /dev/vg0/lv1` 擴大100M * `lvextend -L 100M /dev/vg0/lv1` 擴大到100M * `lvextend -l +7 /dev/vg0/lv1` 擴大7個PE * `lvextend -l 12 /dev/vg0/lv1` 擴大到12個PE * 擴大File System * `resize2fs /dev/vg0/lv1` 擴大ext4 * `xfs_growfs /dev/vg0/lv1` 擴大xfs * 檢視File System * `df -h` ### 移除LVM * 移除LV * `unmount /dev/vg0/lv1` * `lvremove /dev/vg0/lv1` * 編輯`/etc/fstab` 移除lv相關 * `rm -rf /mnt/lv1` * 移除VG * `vgremove /dev/vg0` * 移除PV * `pvremove /dev/sda1` ### 移除parted * `parted /dev/sda rm 1` * `cat /proc/partitions` ### container * container to be systemd service ``` 2 mkdir -p ~/.config/containers/ 3 cp /tmp/containers-services/registries.conf ~/.config/containers/ 4 podman search ubi 5 mkdir -p ~/webcontent/html/ 6 echo "Hello World" > ~/webcontent/html/index.html 7 podman login registry.lab.example.com 8 podman run -d --name myweb -p 8080:8080 -v ~/webcontent:/var/www:Z registry.lab.example.com/rhel8/httpd-24:1-105 9 curl http://localhost:8080/ 10 mkdir -p ~/.config/systemd/user/ 11 cd ~/.config/systemd/user/ 12 ls 13 podman generate systemd --name myweb --files --new 14 ls 15 vi container-myweb.service 16 clear 17 podman stop myweb 18 podman rm myweb 19 ls 21 systemctl --user daemon-reload 22 ls 23 ystemctl --user enable container-myweb 24 systemctl --user enable container-myweb 25 systemctl --user start container-myweb 26 curl http://127.0.0.1:8080 27 systemctl --user stop container-myweb 28 systemctl --user start container-myweb 29 curl http://127.0.0.1:8080 ``` * Add a new network bridge ``` 16 nmcli connection add con-name br0 type bridge ifname br0 ipv4.method manual ipv4.addresses 172.25.250.9/24 ipv4.gateway 172.25.250.254 ipv4.dns 172.25.250.254 17 nmcli connection add con-name eth0 type bridge-slave ifname eth0 master br0 19 nmcli connection delete "Wired connection 1" ``` * lxc ``` dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm yum install lxc lxc-templates vi /etc/lxc/default.conf >> lxc.net.0.link = br0 lxc-create -n rockylinux -t download -- --keyserver keyserver.ubuntu.com lxc-ls -f lxc-start -n rockylinux lxc-attach -n rockylinux passwd lxc-console -n rockylinux lxc-copy -n rockylinux -N web man 5 lxc.container.conf lxc-destroy -n web lxc-top ```

    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

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    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