Skip to content

Instantly share code, notes, and snippets.

@istar0me
Created October 30, 2018 02:25
Show Gist options
  • Save istar0me/3b62b3d513a7375bde9ae7a01672cc72 to your computer and use it in GitHub Desktop.
Save istar0me/3b62b3d513a7375bde9ae7a01672cc72 to your computer and use it in GitHub Desktop.
  • 第 9 週正常上課,第 10 週期中考
  • 期中考考課本每章節後面的選擇題,轉換成簡答題的形式(約 20 ~ 25 題)

C14 系統服務與排程

  • 在 CentOS, readhat, fedora 環境下
    • http 伺服器稱作 httpd(apache)
    • 啟動伺服器指令:systemctl start httpd
  • 而在 ubuntu 環境下
    • http 伺服器稱作 apache(apache2)
    • 啟動伺服器指令:systemctl start apache2
  • 在 Docker 輕量化環境下,可能沒有 systemctl 之類的指令
    • 因此可以改採用 /etc/init.d/apache2 start/etc/init.d/ssh start 等指令

服務管理

init vs. systemd

  • 傳統:init
    • 缺點:序列(Serial)式啟動,因此較花時間
  • 新一代:systemd
    • 優點:沒有相依性的程式能夠並發(concurrent)式啟動,因而加快開機速度
    • 具有彈性
  • 這兩種服務管理系統的 process id 皆為 1
  • ps -aux | grep systemd:查看 systemd 的行程狀態
  • pstree:查看行程間的關聯性(樹狀結構),能看到 systemd 為樹狀的根
  • 補充:在行程中,有一個服務稱作 dhclient,dhclient:dhcp 客戶端
    • dhclient + 介面卡名稱:要一個可能的 IP,以及相關的設定

Unit(服務) vs. Target(標的)

  • 每個服務都是一個 Unit
  • 描述服務間的依賴性(如啟動服務時,是否要先啟動另一個服務才能執行;或服務關閉時,須執行甚麼動作)
  • systemd 相關檔案存放在 /usr/lib/systemd/system
[user@pc1 system]$ cat /usr/lib/systemd/system/vsftpd.service
[Unit]
Description=Vsftpd ftp daemon # 描述, daemon:後台程序
After=network.target # 代表須先執行 network 此服務

[Service]
Type=forking
ExecStart=/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf # 執行服務的路徑

[Install]
WantedBy=multi-user.target
  • 指令 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf 等同於 systemctl start vsftpd,會將 vsftpd 服務開啟
    • 如果在完整的環境下,一般會建議採用 systemctl 指令
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment