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
02 systemctl命令
重载配置:
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
03 其它命令
开启端口,能被浏览器访问(例如开启:3000)
firewall-cmd --zone=public --add-port=3000/tcp --permanent
重启防火墙:
firewall-cmd --reload