Centos添加服務設置啟動

  • 創建systemd服務
# vim /etc/systemd/system/node_exporter.service
[Unit]
Description=node_exporter
After=network.target

[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/node_exporter/node_exporter # 需要啟動的文件路徑
Restart=on-failure

[Install]
WantedBy=multi-user.target

[Unit]:設置啟動順序與依賴關系。
[Service]:設置啟動行為
[Install]:是服務安裝的相關設置

  • 服務指令
systemctl daemon-reload        # 重載系統服務,
systemctl enable *.service        # 設置開機啟動
systemctl disable *.service        # 關閉開機啟動
systemctl start *.service        # 啟動服務
systemctl stop *.service        # 停止服務
systemctl restart *.service        # 重啟服務
  • 修改配置文件以后,需要重新加載配置文件,然后重新啟動相關服務。
systemctl daemon-reload        # 重載系統服務,
systemctl restart *.service        # 重啟服務
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容