也可以使用压缩包安装,但是压缩包安装实在是有点麻烦,这里便不使用压缩包安装了
第一步:查看是否安装docker
[root@localhost ~]# docker version
Client:
Version: 1.13.1
API version: 1.26
Package version:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
如果没有安装,可以查看这篇博客进行安装docker
第二步:启动docker
[root@localhost ~]# sudo systemctl start docker
第三步:安装Pushgateway
[root@localhost ~]# docker pull prom/pushgateway
Using default tag: latest
Trying to pull repository docker.io/prom/pushgateway ...
latest: Pulling from docker.io/prom/pushgateway
aa2a8d90b84c: Pull complete
b45d31ee2d7f: Pull complete
2228cb35c444: Pull complete
b896befe0244: Pull complete
Digest: sha256:a684e7c830a4b19e564a93bfc3bf713e85b04ab9dfcab5633c14cbba241f9231
Status: Downloaded newer image for docker.io/prom/pushgateway:latest
[root@localhost ~]#
第四步:启动Pushgateway
[root@localhost ~]# docker run -d \
> --name=pg \
> -p 9091:9091 \
> prom/pushgateway
796d7c215ae831016b8beacdb674e56d59736595f0d2fa4c5f2631b43e5c4c2b
[root@localhost ~]#
第五步:访问url(Pushgateway)
查看metrics数据
第六步:在prometheus中配置对应的job
要使Push Gateway正常工作,就需要配置对应的job在Prometheus里面
[root@localhost prometheus-2.6.1.linux-amd64]# vim prometheus.yml
- static_configs:
- targets:
- 192.168.156.134:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
- "/opt/prometheus/prometheus-2.6.1.linux-amd64/rules/*.rules"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:9090']
- job_name: 'agent1'
static_configs:
- targets: ['192.168.156.134:9100']
- job_name: pushgateway
static_configs:
- targets: ['192.168.156.134:9091']
labels:
instance: pushgateway
"prometheus.yml" 37L, 1212C 宸插啓鍏[?1l
[root@localhost prometheus-2.6.1.linux-amd64]#
第七步:重启Prometheus
[root@localhost prometheus-2.6.1.linux-amd64]# pkill prometheus
[root@localhost prometheus-2.6.1.linux-amd64]# level=warn ts=2022-02-10T09:00:41.205762698Z caller=main.go:405 msg="Received SIGTERM, exiting gracefully..."
level=info ts=2022-02-10T09:00:41.205814019Z caller=main.go:430 msg="Stopping scrape discovery manager..."
level=info ts=2022-02-10T09:00:41.205820974Z caller=main.go:444 msg="Stopping notify discovery manager..."
level=info ts=2022-02-10T09:00:41.205825681Z caller=main.go:466 msg="Stopping scrape manager..."
level=info ts=2022-02-10T09:00:41.205870076Z caller=main.go:426 msg="Scrape discovery manager stopped"
level=info ts=2022-02-10T09:00:41.205883045Z caller=main.go:440 msg="Notify discovery manager stopped"
level=info ts=2022-02-10T09:00:41.20589595Z caller=manager.go:664 component="rule manager" msg="Stopping rule manager..."
level=info ts=2022-02-10T09:00:41.205904859Z caller=manager.go:670 component="rule manager" msg="Rule manager stopped"
level=info ts=2022-02-10T09:00:41.206058181Z caller=main.go:460 msg="Scrape manager stopped"
level=info ts=2022-02-10T09:00:41.207038976Z caller=notifier.go:521 component=notifier msg="Stopping notification manager..."
level=info ts=2022-02-10T09:00:41.207069697Z caller=main.go:615 msg="Notifier manager stopped"
level=info ts=2022-02-10T09:00:41.207195903Z caller=main.go:627 msg="See you next time!"
[1]+ 瀹屾垚 ./prometheus --config.file=prometheus.yml
[root@localhost prometheus-2.6.1.linux-amd64]# lsof -i:9090
[root@localhost prometheus-2.6.1.linux-amd64]# ./prometheus --config.file=prometheus.yml &