# 伺服器架設期末模擬 ## Prepare * 重新建立 Server1, Server2 * 為 Server1 與 Server2 加入網卡 * Server1: * NIC1: NAT * NIC2: Bridge * Server2: * NIC1: NAT * NIC2: Bridge ## 模擬試題 ### 1. 設定 IP 設定如下 IP 資訊後,應能達到下列效果: * 能夠使用 Echo Request/Echo Reply 測試 `fb.me` 並成功確認連線。 * 能夠在 Server1 與 Server2 使用 `172.16.X.0/24` 互 ping 相通。 IP 資訊: * Server1 IP: * NIC1: DHCP * NIC2: IP: 172.16.X.5/24 ![](https://i.imgur.com/JZimxgO.png) * Server2 IP: * NIC1: DHCP * NIC2: IP: 172.16.X.11/24 ![](https://i.imgur.com/V8mi4np.png) ![](https://i.imgur.com/0eo0RKo.png) ![](https://i.imgur.com/jHREaOM.png) * #student$ sudo su - * #[輸入密碼] * #root# nmtui * 變更configuration為manual * 輸入IP * 開啟開機自動連線功能 ![](https://i.imgur.com/sSwy9A8.png) ### 2. 帳號群組與目錄權限 * 在 `Server2` 裡,依下列條件,若需建立帳號,其密碼均設為 `exam`。 * #echo exam | passwd --stdin(鍵盤輸入值) user11 * #echo exam | passwd --stdin(鍵盤輸入值) user12 * #echo exam | passwd --stdin(鍵盤輸入值) boss 1. 系統建立 `/resource/` 目錄 * #mkdir /resource 3. 員工帳號 `user11`, `user12` 為 `staff` 群組 * #groupadd staff * #useradd -g staff user11 * #useradd -g staff user12 5. `boss` 帳號對 `/resource/` 有完整權限 * #useradd boss 7. 員工只能讀取 `/resource/` 目錄 * #ls -lhd /resource/ <--路徑,加d為目錄本身(drwxr) * #chmod 750 /resource/ * #chown boss /resource/ * #chgrp staff /resource/ * #ls -lh * #ls -lhd /resource/ 9. 其它帳號對 `/resource/` 沒有任何權限 ### 3. 日期與校時 * Server1 與 Server2 設定網路校時功能。 * #dnf install -y install -y chrony * Server2 之時區設定為 "美國紐約"。 * #systemctl enable --now chronyd * #timedatectl list-timezones | grep (時區位置) * #timedatectl set-timezone (時區位置) * #chronyc souces(查看時區位置,不能為0) ### 4. 網站與資料庫 * Server2 中完成下列功能: * 建立 `/web/` 資料夾。 * #mkdir /web * 將 `/dev/sdb` 使用 XFS 檔案系統,掛載於 `/web/` 資料夾,並於重新開機後能夠自動掛載。 * #mkfs.minix ^C * #mkfs.xfs /dev/sdb * #bldkid /dev/sdb(UUID) * #vi /etc/fstab * vi--> UUID= /web sfx defaults 0 0 * #mount -a(掛載) * #df (驗證) * 將 phpMyAdmin 工具下載到 `/web/` 中,解開後的目錄重新命名為 `exam-sql`。 * #cd /web/ * #ls -l * #curl -OJL (連結) * #ls * #tar -zxf (下載的檔案) * #ls * #mv (下載的檔案) exam-sql * #ls * 設定 NFS 服務,將 `/web/` 提供讓 `172.16.X.0/24` 僅供唯讀。 * #dnf install nfs-utils * #vi /etc/exports * vi--> /web172.16.(座位號碼).0/24(ro) * 以上所須之服務,必須設定下次重開機後自動啟用。 * #systemctl enable --now nfs-server * #showmount -e localhost * #firewall-cmd --permanent --add-service=nfs * #firewall-cmd --reload * #firewall-cmd --list-all * Server1 完成下列功能: * 提供 MairaDB 服務功能,資料庫 `root` 密碼設定為 `exam`。 * #dnf install -y mariadb-server * #mysql_secure_installaction * #systemctl enable --now mariadb * #ls /var/lib/mysql/ (重設資料庫) * #mysql_secure_installaction * #mysql -u root -p -h localhost * 提供 Apache Web 虛擬站台功能: * 網址:`exam.linux.class` 能夠對應到 `172.16.X.5`. * #dnf install -y htppd * #systemctl enable --now httpd * #vi /etc/hosts * vi-->172.16.(座位號碼).5 exam.linux.class * #ping exam.linux.class * `exam.linux.class` 網站根目錄為 `/var/www/html/exam.linux.class` * #cd /etc/httpd/conf.d/ * #cp /usr/share/doc/httpd/httpd-vhosts.conf./exam.linux.class.conf * #vi exam.linux.class.confi * vi-->ServerAdmin webmaster@dummy-host2.example.com * vi-->%s/dummy-host2.example.com/exam.linux.class/g * vi-->DoucmentRoot "/var/www/html/exam.linux.class" (改) * #mkdir /var/www/html/exam.linux.class * #ls -ld /var/www/html/exam.linux.class (複製貼上可能有問題) * 提供 PHP 功能,並能使用資料庫連線功能。 * #dnf install -y php-fpm php php-gd php-mbs tring php-xml php-json php-mysqli php-pdo * #systemctl enable --now php-fpm * #systmectl restart httpd * 將 `Server2` 中的 NFS `/web/` 分享目錄掛載到 `exam.linux.class` 站台根目錄。 * #mount -t nfs 172.16.x.11:web /var/www/html/exam.linux.class/ * #df -h(檢查) * #cd /var/www/html/exam.linux.class/ * #ls * #curl http://exam.linux.class * #echo hello > index.html(驗證是否正確) * #ls * #curl http://exam.linux.class/index.html * #setsebool -P httpd_use_nfs on(denied的話,貼在裝Apache的Server上面) * 在 Server1 的 Firefox 中輸入: * http://exam.linux.class/exam-sql/ 要能正常顯示。 * http://exam.linux.class/exam-sql/ 要能正確登入 MariaDB 資料庫。 * 以上所須之服務,必須設定下次重開機後自動啟用。 * #cd /etc/ (裝Apache的伺服器) * #vi /etc/fstab * vi-->ip:web/ /var/www/html/exam.linux.class nfs ro 0 0 * #df * #umount /var/www/html/exam.linux.class * #df -h * #mount -a * #df -h