帮助中心 >  产品文档 >  安装Prometheus Server

欢迎来到蓝队云技术小课堂,每天分享一个技术小知识。今天讲的是Prometheus Server

的安装。Prometheus是一个开放性的监控解决方案,用户可以非常方便的安装和使用Prometheus并且能够非常方便的对其进行扩展。为了能够更加直观的了解Prometheus Server,接下来我们将在本地部署并运行一个Prometheus Server实例,通过Node Exporter采集当前主机的系统资源使用情况。 并通过Grafana创建一个简单的可视化仪表盘。

 

Prometheus基于Golang编写,编译后的软件包,不依赖于任何的第三方依赖。用户只需要下载对应平台的二进制包,解压并且添加基本的配置即可正常启动Prometheus Server。

 

从二进制包安装

对于非Docker用户,可以从https://www.landui.com/download/找到最新版本的Prometheus Sevrer软件包:

export VERSION=2.13.0
curl -LO  https:
//github.com/prometheus/prometheus/releases/download/v$VERSION/prometheus-$VERSION.darwin-amd64.tar.gz

 

解压,并将Prometheus相关的命令,添加到系统环境变量路径即可:

tar -xzf prometheus-${VERSION}.darwin-amd64.tar.gz
cd prometheus-${VERSION}.darwin-amd64

 

解压后当前目录会包含默认的Prometheus配置文件promethes.yml:

# my global config
global:
  scrape_interval:    
15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval:
15s # Evaluate rules every 15 seconds. The default is every 1 minute.
 
# scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets:
     
# - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
 
# - "first_rules.yml"
 
# - "second_rules.yml"

# 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']

 

 

Promtheus作为一个时间序列数据库,其采集的数据会以文件的形似存储在本地中,默认的存储路径为data/,因此我们需要先手动创建该目录:

mkdir -p data

 

用户也可以通过参数--storage.tsdb.path="data/"修改本地数据存储的路径。

启动prometheus服务,其会默认加载当前路径下的prometheus.yaml文件:

./Prometheus

 

正常的情况下,你可以看到以下输出内容:

level=info ts=2018-10-23T14:55:14.499484Z caller=main.go:554 msg="Starting TSDB ..."
level=info ts=2018-10-23T14:55:14.499531Z caller=web.go:397 component=web msg=
"Start listening for connections" address=0.0.0.0:9090
level=info ts=2018-10-23T14:55:14.507999Z caller=main.go:564 msg=
"TSDB started"
level=info ts=2018-10-23T14:55:14.508068Z caller=main.go:624 msg=
"Loading configuration file" filename=prometheus.yml
level=info ts=2018-10-23T14:55:14.509509Z caller=main.go:650 msg=
"Completed loading of configuration file" filename=prometheus.yml
level=info ts=2018-10-23T14:55:14.509537Z caller=main.go:523 msg=
"Server is ready to receive web requests."

 

 

使用容器安装

对于Docker用户,直接使用Prometheus的镜像即可启动Prometheus Server:

docker run -p 9090:9090 -v /etc/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml prom/Prometheus

 

启动完成后,可以通过http://www.landui.com:9090访问Prometheus的UI界面:

image.png

提交成功!非常感谢您的反馈,我们会继续努力做到更好!

这条文档是否有帮助解决问题?

非常抱歉未能帮助到您。为了给您提供更好的服务,我们很需要您进一步的反馈信息:

在文档使用中是否遇到以下问题: