本例子以nginx作為舉例:
CentOS7中 以systemctl 替代了chkconfig 進行服務的管理,
默認在CentOS6 中控制服務開機自啟,是在vim /etc/rc.d/rc.local 這個文件中控制的,
在CentOS7 中該服務基於systemctl管理,
提供rc.local.service, 並通過配置/etc/rc.local該文件進行管理系統啟動時完成相關自動任務。
/usr/lib/systemd/system/rc-local.service 該文件是控制開機自啟的配置文件。配置文件如下:
[Unit]
Description=/etc/rc.d/rc.local Compatibility
ConditionFileIsExecutable=/etc/rc.d/rc.local
After=network.target
[Service]
Type=forking
ExecStart=/etc/rc.d/rc.local start
TimeoutSec=0
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
【Install】為新增內容, multi-user.target 代表3 級別, graphical.target 代表5級別

賦予該文件權限。
systemctl enable rc-local
systemctl status rc-local (查看服務狀態)
Nginx 設置開機自啟:
安裝好nginx之后,測試curl localhost 看是否訪問正常,
通過systemctl status nginx.service 可以查看到控制nginx服務是否加載的配置文件路徑為:/usr/lib/systemd/system/nginx.service
然后systemctl enable nginx.service 該命令啟動nginx服務
systemctl is-enabled nginx.service 查看某個軟件是否開機自啟動
設置了開機自啟后查看狀態的截圖:

以上,設置相關服務開機自啟。
systemctl list-unit-files 列出所有可用單元(服務)
systemctl list-units 列出所有運行中的單元
