# 6/4 NASA 機房實做 [toc] ## 目的 讓同學熟悉架設實體機、機櫃滑軌、櫃頂交換器設定 ## 約法三章 - 每組灌好系統搬回機房、上機架後,不可在機房逗留。 - **一旦上機架,就不可再卸下。請確認你的 switch 和網路設定都正確後,再上機架,免得連不上去而 GG**。 - **各組須於 12:10 前把機器搬回機房,不管是否已設定完畢**(除非有非抗拒理由,否則本次實驗零分) - 助教當天會發 switch 登入帳密及各組使用者帳密,CentOS 使用者及 IPMI 管理者請按照此帳密設定 ### 分組 **[分組、座位、 IP 分配表](https://docs.google.com/spreadsheets/d/18bky0x3gyNQEfnvn02oIm2Hq3gDE1WkyAWHenlWQHJU/edit?usp=sharing)** ### 行前準備 - [ ] 灌好的 CentOS 7 開機隨身碟([教學](https://wiki.archlinux.org/index.php/USB_flash_installation_media)) * 請使用此 ISO:http://free.nchc.org.tw/centos/7.5.1804/isos/x86_64/CentOS-7-x86_64-DVD-1804.iso - [ ] 每組至少有兩台筆電,可以接上伺服器確認網路功能 ### 上課流程 * 9:10 ~ 9:20 數習中心宣傳 * 9:20 ~ 9:40 課程說明 * 9:40 ~ 10:00 帶隊到 R215 機房搬自己的伺服器 * 10:00 ~ 12:10 安裝伺服器、搬回 R215 裝回去 ### 評分標準 1. `curl [your server ip]/` 回傳正確內容 2. 是否可以透過 IPMI 遠端拿到機器 console ## Step-by-step #### 灌系統 * [ ] 延長線接上電源 * [ ] 插上 VGA 螢幕線、鍵盤 * [ ] 開機進入 BIOS system configuration,確認 IPMI 功能有開、把 IPMI 設好(或是直接用 `ipmitool` 設定,見下) * [ ] 把開機隨身碟插上去 * [ ] 重開機後選擇使用隨身碟開機安裝 (**Dell 1950 按 `F11`、IBM x3550 按 `F12`**) - [ ] 依照助教要求設定使用者帳密(root 密碼隨便你) * [ ] 裝 `ipmitool` 和 `httpd` 套件 * [ ] 設定 console (給 IPMI 使用) * [ ] 設定網路 * [ ] 用 `ipmitool` 再次確認 IPMI 有設對 * [ ] 設定 web server * [ ] 用自己的筆電分別接兩個網路孔,再三確認網路會動 * [ ] 搬進機房、上滑軌、接網路線、開機 * [ ] 測試(web server、IPMI、ssh 登入) #### 設定網路 * [ ] 登入 switch,開啟 access vlan 7 * [ ] 用筆電接上伺服器第一個網路孔,確認 IPMI 連的上 * [ ] 用筆電接上伺服器第二個網路孔,確認網路介面卡設定正確 ## 細節 ### 網路位置 :::danger **請登入 csie WiFi 或工作站,才能連到 172 網段的機器** ::: #### Switch * A04 Switch IP:`172.16.127.1` (A, B, C, D 組) * A05 Switch IP:`172.16.127.2` (E, F, G 組) #### Server & IPMI * IP subnet:`172.16.127.0/24` (請看上面分配表) * Net mask:`255.255.0.0` * Default Gateway:`172.16.0.1` ### 設定 switch 每組有2個 port,分別供 IPMI 和 CentOS 使用。IP 都屬於系上 vlan 7 網段,所以要把 switch 的 `access vlan 7` 打開,才能通(**不需要設 vlan tag**) ##### SSH 登入 switch: ``` ssh nasa2018@172.16.127.1 # A04 ssh nasa2018@172.16.127.2 # A05 ``` ##### 設定 interface 以 port 1 為例(各組請使用分配到的 port): ``` A-04# conf t A-04(config)# int Gi1/0/1 A-04(config-if)# switchport mode access A-04(config-if)# switchport access vlan 7 A-04(config-if)# exit A-04(config)# exit ``` 用 show 指令檢查設定是否正確: ``` A-04# sh ru int Gi1/0/1 Current configuration : 88 bytes ! interface GigabitEthernet1/0/1 switchport access vlan 7 switchport mode access end ``` ### 裝 `ipmitool` 和 `httpd` ``` bash yum --disablerepo=\* --enablerepo=c7-media \ install httpd ipmitool ``` ### 設定 Console 為了讓 IPMI 拿的到 serial console,你必須讓 kernel 開機時開啟 `ttyS1`: 把 `/etc/default/grub` 中`GRUB_CMDLINE_LINUX` 和 `GRUB_TERMINAL` 改成: ``` GRUB_CMDLINE_LINUX="console=ttyS1,115200 console=tty0" GRUB_TERMINAL="console serial" ``` 加上 `GRUB_SERIAL_COMMAND`: ``` GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=1 --word=8 --parity=no --stop=1" ``` :smirk: **改完一定要跑 `grub2-mkconfig -o /boot/grub2/grub.cfg`** ### 設定網路 把伺服器 IP 設定在**第二張**網卡(第二個網路孔)(第一張網卡由 IPMI 使用了)。 - 設定助教指定給每組的那個 IP - 設定 static IP:[自己看教學](https://www.howtoforge.com/linux-basics-set-a-static-ip-on-centos) - 設好後,把你的筆電接上**第二個**網路孔,手動設固定 IP,看可不可以 ping 到伺服器 筆電設定固定 IP 可以用: - Linux:`sudo ip a add 172.16.127.10/24 dev eth0` (改成你這組的 IP) - Windows:[教學](http://blog.xuite.net/yh96301/blog/52288002-Windows+7%E8%A8%AD%E5%AE%9A%E7%B6%B2%E8%B7%AF%E9%80%A3%E7%B7%9A%E7%82%BA%E5%9B%BA%E5%AE%9AIP) ### 設定 web server - 先安裝 `httpd` (上面有寫怎麼裝) - `/var/www/html/index.html` 的內容是: ``` NASA--[組別代號] ``` 例如我是 C 組的話,內容就是 ``` NASA--C ``` - `sudo systemctl enable httpd` - `sudo systemctl start httpd` - 確認成功:`curl localhost/` (回傳上面那個檔案的內容) - 順便讓 ssh server 自動開起來:`sudo systemctl enable sshd`,如果你 IPMI 爛掉的話,還有機會可以登入 ### IPMI IPMI 讓你可以遠端操作伺服器電源、拿 console…,很強大。我們要設定正確的網路位置和管理者帳密,才連的上去 - 管理者名稱:`nasa` - 管理者密碼:每組不一樣,助教直接給 - IP 位置:一定要設助教給的那個喔 有兩種方法可以設定 IPMI,第一種是在 BIOS 設定,第二種是在 CentOS 上用 `ipmitool` 設定。**二選一即可。** #### 在 BIOS 設定 IPMI 開機後,IBM x3550 按 `F1` 進入 *System Setup*,選擇 *Advanced Setup* -> *BMC Settings* -> *BMC Network Configuration* 和 *User Account Settings*。 Dell 1950 則等到 BIOS 後半段按 `Ctrl-e` 進入 *Remote Access Setup*。 #### 在 CentOS 設定 IPMI 載入 kernel module: ``` modprobe ipmi_msghandler modprobe ipmi_devintf modprobe ipmi_si ``` - [設定網路](https://www.thomas-krenn.com/en/wiki/Configuring_IPMI_under_Linux_using_ipmitool#LAN_Configuration) - [設定管理者](https://www.thomas-krenn.com/en/wiki/Configuring_IPMI_under_Linux_using_ipmitool#User_Configuration) - 網路有設對嗎:`sudo ipmitool lan print 1` - 管理者有設對嗎:` sudo ipmitool user list 1` - 設好後,把你的筆電接上**第一個**網路孔,手動設固定 IP,看可不可以 ping 到伺服器 #### 遠端透過 IPMI 連上伺服器 1. 把你的密碼寫在某個檔案 `[password file]` 2. 可以連嗎:`ipmitool -I lanplus -A MD5 -U nasa -H [IPMI IP] -f [password file] power status` 3. 可以拿 console 嗎:`ipmitool -I lanplus -A MD5 -U nasa -H [IPMI IP] -f [password file] sol activate` 4. 如果不行的話,可以 ssh 進去看看。如果連 ssh 都不行的話,你就 GG 了。所以,一定要確保所有流程都正確後,才上機架