/etc/systemd/system和/lib/systemd/system的區別


 

搬運文

1.1 [/usr]/lib/systemd/system/ (軟件包安裝的單元)

The expectation is that /lib/systemd/system is a directory that should only contain systemd unit files which were put there by the package manager (YUM/DNF/RPM/APT/etc).

1.2 /etc/systemd/system/(系統管理員安裝的單元, 優先級更高)

Files in /etc/systemd/system are manually placed here by the operator of the system for ad-hoc software installations that are not in the form of a package. This would include tarball type software installations or home grown scripts.

2. 優先級

systemd的使用大幅提高了系統服務的運行效率, 而unit的文件位置一般主要有三個目錄:

1
2
3
4
5
6
7
8
9
10
Table 1.  Load path when running in system mode (--system).
┌────────────────────────┬─────────────────────────────┐
│Path │ Description │
├────────────────────────┼─────────────────────────────┤
│/etc/systemd/system │ Local configuration │
├────────────────────────┼─────────────────────────────┤
│/run/systemd/system │ Runtime units │
├────────────────────────┼─────────────────────────────┤
│/lib/systemd/system │ Units of installed packages │
└────────────────────────┴─────────────────────────────┘

這三個目錄的配置文件優先級依次從高到低,如果同一選項三個地方都配置了,優先級高的會覆蓋優先級低的。

系統安裝時,默認會將unit文件放在/lib/systemd/system目錄。如果我們想要修改系統默認的配置,比如nginx.service,一般有兩種方法:

  1. /etc/systemd/system目錄下創建nginx.service文件,里面寫上我們自己的配置。
  2. /etc/systemd/system下面創建nginx.service.d目錄,在這個目錄里面新建任何以.conf結尾的文件,然后寫入我們自己的配置。推薦這種做法。

/run/systemd/system這個目錄一般是進程在運行時動態創建unit文件的目錄,一般很少修改,除非是修改程序運行時的一些參數時,即Session級別的,才在這里做修改。

參考:https://www.dazhuanlan.com/2020/03/14/5e6cb299378a9/

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM