> For the complete documentation index, see [llms.txt](https://zhangguanzhang.gitbook.io/prometheus-up-running/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://zhangguanzhang.gitbook.io/prometheus-up-running/part-i-introduction/getting-started-with-prometheus/running-prometheus.md).

# Running Prometheus

&#x20;   从Prometheus网站<https://prometheus.io/download/> 获得编译好的Prometheus和其他组件。 转到该页面，使用amd64架构的下载可以适用于Linux操作系统的最新版本的Prometheus; 下载页面如图所示，我们下载下面的release而不是rc的。

![](/files/-LWoPvDl9m9DzTHYrPSU)

这里我下载的是 prometheus-2.6.1.linux-amd64.tar.gz，任何2.x.x版本的Prometheus都足以满足本章的要求。解压文件并进入目录

```
$ wget https://github.com/prometheus/prometheus/releases/download/v2.6.1/prometheus-2.6.1.linux-amd64.tar.gz
$ tar -zxf prometheus-*.linux-amd64.tar.gz
$ cd prometheus-*.linux-amd64/
```

官方自带了个实例的配置文件，我们把它备份后用下面内容创建prometheus的配置文件`prometheus.yml` &#x20;

```yaml
global:
  scrape_interval: 10s
scrape_configs:
  - job_name: prometheus
    static_configs:
      - targets:
          - localhost:9090
```

{% hint style="info" %}
Prometheus优先使用Yet Another Markup Language（YAML）作为配置文件，因为它既易于使用 人类可以通过工具加工。 格式对空白敏感，因此请确保准确复制示例并使用空格而不是制表符，并不会阻止你使用json。
{% endhint %}

附带有promtool可以检查配置文件的错误，检查文件是否正确

```
./promtool check config prometheus.yml
Checking prometheus.yml
  SUCCESS: 0 rule files found
```

默认prometheus会监听TCP的9090端口，配置文件里每隔10秒scrape自己的metrics，下面来运行prometheus

```
$ ./prometheus
level=info ts=2019-01-22T07:35:15.200658518Z caller=main.go:243 msg="Starting Prometheus" version="(version=2.6.1, branch=HEAD, revision=b639fe140c1f71b2cbad3fc322b17efe60839e7e)"
level=info ts=2019-01-22T07:35:15.200745786Z caller=main.go:244 build_context="(go=go1.11.4, user=root@4c0e286fe2b3, date=20190115-19:12:04)"
level=info ts=2019-01-22T07:35:15.200787708Z caller=main.go:245 host_details="(Linux 4.13.0-43-generic #48~16.04.1-Ubuntu SMP Thu May 17 12:56:46 UTC 2018 x86_64 258c0505930c (none))"
level=info ts=2019-01-22T07:35:15.200858577Z caller=main.go:246 fd_limits="(soft=1048576, hard=1048576)"
level=info ts=2019-01-22T07:35:15.200886497Z caller=main.go:247 vm_limits="(soft=unlimited, hard=unlimited)"
level=info ts=2019-01-22T07:35:15.201740888Z caller=web.go:429 component=web msg="Start listening for connections" address=0.0.0.0:9090
level=info ts=2019-01-22T07:35:15.201672651Z caller=main.go:561 msg="Starting TSDB ..."
level=info ts=2019-01-22T07:35:15.215188095Z caller=main.go:571 msg="TSDB started"
level=info ts=2019-01-22T07:35:15.215264666Z caller=main.go:631 msg="Loading configuration file" filename=prometheus.yml
level=info ts=2019-01-22T07:35:15.216085652Z caller=main.go:657 msg="Completed loading of configuration file" filename=prometheus.yml
level=info ts=2019-01-22T07:35:15.216168709Z caller=main.go:530 msg="Server is ready to receive web requests."
```

如您所见，Prometheus在启动时的log里打印了各种有用的信息，包括其确切的版本和运行它的机器的详细信息。 现在，您可以在浏览器中访问<http://localhost:9090/>的Prometheus用户界面，如下所示

![](/files/-LWoWFNPMoT5PjlDnUzq)

这是表达式浏览器，您可以从中运行PromQL查询。 UI中还有其他几个页面可帮助您了解Prometheus正在执行的操作，例如Status选项卡下的Targets页面

![](/files/-LWoWg7XOa4Cy6WyZ-fX)

&#x20;   在此页面上，只有一个Prometheus服务器处于UP状态，这意味着最后一次刮擦(scrape)成功。 如果上次刮擦出现问题，则“ERROR”字段中会显示一条消息\
&#x20;   您应该看到的另一个页面是Prometheus本身的度量信息(metrics)，因为Prometheus本身也配备了Prometheus指标。 可以通过访问<http://localhost:9090/metrics查看可用的度量标准，并且是人类可读的，如图>

![](/files/-LWoXFeASCNlkf00Qolt)

请注意，不仅有Prometheus代码本身的指标，还有Go的runtimes和进程信息
