- 創建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 # 重啟服務