Prometheus 安装部署
Prometheus 安装部署
- 安装版本:prometheus-2.6.1
- 百度云下载:https://pan.baidu.com/s/1w16lQZKw8PCHqlRuSK2i7A
- 提取码:lw1q
二进制安装部署
1、下载二进制包:prometheus-2.6.1.linux-amd64.tar.gz
2、解压包:tar xvzf prometheus-2.6.1.linux-amd64.tar.gz
3、移动到安装目录:mv prometheus-2.6.1.linux-amd64 /usr/local/prometheus
4、进入目录:cd /usr/local/prometheus
5、修改配置文件底部监控本机:vim prometheus.yml
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: ['server02:9090']
注:Prometheus从目标机上通过http方式拉取采样点数据, 它也可以拉取自身服务数据并监控自身的健康状况。
注:当然Prometheus服务拉取自身服务采样数据,并没有多大的用处,但是它是一个好的DEMO。
global: # 默认情况下,每15s拉取一次目标采样点数据。 scrape_interval: 15s # 我们可以附加一些指定标签到采样点度量标签列表中, 用于和第三方系统进行通信, 包括:federation, remote storage, Alertmanager external_labels: # 下面就是拉取自身服务采样点数据配置 monitor: 'codelab-monitor' scrape_configs: # job名称会增加到拉取到的所有采样点上,同时还有一个instance目标服务的host:port标签也会增加到采样点上 - job_name: 'prometheus' # 覆盖global的采样点,拉取时间间隔5s scrape_interval: 5s static_configs: - targets: ['localhost:9090'] 配置文件注解
6、启动服务
nohup ./prometheus --config.file=prometheus.yml &
# 指定配置文件 --config.file="prometheus.yml" # 指定监听地址端口 --web.listen-address="0.0.0.0:9090" # 最大连接数 --web.max-connections=512 # tsdb数据存储的目录,默认当前data/ --storage.tsdb.path="data/" # premetheus 存储数据的时间,默认保存15天 --storage.tsdb.retention=15d 启动选项了解:./prometheus --help
7、测试访问:http://localhost:9090

8、查看暴露指标:http://localhost.com:9090/metrics

9、将Prometheus配置为系统服务
1、进入systemd目录下:cd /usr/lib/systemd/system
2、创建文件:vim prometheus.service
[Unit] Description=https://prometheus.io [Service] Restart=on-failure ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml [Install] WantedBy=multi-user.target
4、生效系统system文件
systemctl daemon-reload
5、启动服务
systemctl stop prometheus.service systemctl start prometheus.service
Docker 容器安装部署
- 官方地址:https://prometheus.io/docs/prometheus/latest/installation/
一、prometheus.yml通过运行以下命令将您从主机绑定:
docker run -p 9090:9090 -v /tmp/prometheus.yml:/etc/prometheus/prometheus.yml \
prom/prometheus
二、或者为配置使用额外的卷:
docker run -p 9090:9090 -v /prometheus-data \
prom/prometheus --config.file=/prometheus-data/prometheus.yml
注:普罗米修斯的配置文件的需要指定对。

浙公网安备 33010602011771号