方法一、寫入rc.local
在/etc/rc.local文件中編輯需要執行的腳本或者命令,我個人習慣用這個,因人而異,有的項目可能需要熱加載配置文件,用服務會更好
#普羅米修斯啟動,需要后面接config配置文件路徑選項 nohup /root/linux_jiankong/prometheus/prometheus --config.file=/root/linux_jiankong/prometheus/prometheus.yml & #node_exporte啟動 nohup /root/linux_jiankong/node_exporter/node_exporter --web.listen-address=:9100 & #啟動influxdb數據庫 influxd -config influxdb.conf #啟動grafana systemctl start grafana-server.service

方法二、設置為服務,使用systemctl來管理
prometheus
- 創建node_exporter組和用戶,用於運行node_exporter和prometheus(也可以不創建,不影響的)
- 創建一個node_exporter.service文件
- 啟動,並配置開機啟動
創建Prometheus組和用戶(非必須步驟)
sudo groupadd -r prometheus sudo useradd -r -g prometheus -s /sbin/nologin -M -c "prometheus Daemons" prometheus
創建services服務文件
如果沒創建prometheus組合用戶,則Service的User就不用寫
cat > /etc/systemd/system/prometheus.service <<EOF [Unit] Description=prometheus After=network.target [Service] Type=simple User=prometheus ExecStart=自己本地路徑/prometheus --config.file=/自己本地路徑/prometheus.yml --storage.tsdb.path=自己本地路徑聲明的data目錄/data Restart=on-failure [Install] WantedBy=multi-user.target EOF
啟動Prometheus,將服務設置為開機自啟動
systemctl daemon-reload
systemctl start prometheus.service
systemctl status prometheus.service
systemctl enable prometheus.service
node_exporter
換種方式啊,其實一樣的
vim /etc/systemd/system/node_exporter.service [Unit] Description=node_exporter Monitoring System Documentation=node_exporter Monitoring System [Service] ExecStart=自己本地路徑/node_exporter --web.listen-address=:9100 [Install] WantedBy=multi-user.target #設置開機自啟 systemctl daemon-reload systemctl start node_exporter.service systemctl status node_exporter.service systemctl enable node_exporter.service
