systemctl启动prometheus+grafana环境

https://blog.csdn.net/qq_20042935/article/details/124324441

 

01 配置文件
在/usr/lib/systemd/system目录新增4个配置文件,分别为:

 pushgateway.service文件,内容如下:

[Unit]
Description=Prometheus Push Gateway
After=network.target

[Service]
ExecStart=/opt/prometheus_env/pushgateway-1.4.2.linux-amd64/pushgateway

User=root
[Install]
WantedBy=multi-user.target

node_exporter.service文件,内容如下:

[Unit]
Description=Prometheus Node Exporter
After=network.target

[Service]
ExecStart=/opt/prometheus_env/node_exporter-1.3.1.linux-amd64/node_exporter

User=root
[Install]
WantedBy=multi-user.target

③ prometheus.service文件,内容如下:

[Unit]
Description=Prometheus Service
After=network.target

[Service]
ExecStart=/opt/prometheus_env/prometheus-2.34.0.linux-amd64/prometheus \
--config.file=/opt/prometheus_env/prometheus-2.34.0.linux-amd64/prometheus.yml \
--web.read-timeout=5m \
--web.max-connections=10 \
--storage.tsdb.retention=15d \
--storage.tsdb.path=/prometheus/data \
--query.max-concurrency=20 \
--query.timeout=2m

User=root
[Install]
WantedBy=multi-user.target

 grafana.service文件,内容如下:

[Unit]
Description=Grafana
After=network.target

[Service]
ExecStart=/opt/prometheus_env/grafana-8.4.7/bin/grafana-server \
--config=/opt/prometheus_env/grafana-8.4.7/conf/defaults.ini \
--homepath=/opt/prometheus_env/grafana-8.4.7

[Install]
WantedBy=multi-user.target

0systemctl命令
重载配置:

systemctl daemon-reload

开启服务:

systemctl start pushgateway
systemctl start node_exporter
systemctl start prometheus
systemctl start grafana

设置开机启动:

systemctl enable pushgateway
systemctl enable node_exporter
systemctl enable prometheus
systemctl enable grafana
查看服务状态:

systemctl status pushgateway

 其它命令
开启端口,能被浏览器访问(例如开启:3000)

firewall-cmd --zone=public --add-port=3000/tcp --permanent

重启防火墙:

firewall-cmd --reload

posted @ 2022-06-22 16:09  技术颜良  阅读(317)  评论(0编辑  收藏  举报