# 安装Prometheus

官网给出了很多种安装方法（`https://prometheus.io/docs/prometheus/latest/installation/`），最常用的就是二进制与docker镜像，这里我们使用已经编译好的二进制进行安装。

从官网（`https://prometheus.io/download/`）\
下载最新版本（`2.15.2`）的二进制包，解压，然后查看prometheus版本信息

```
$ wget https://github.com/prometheus/prometheus/releases/download/v2.15.2/prometheus-2.15.2.linux-amd64.tar.gz
$ tar xzvf prometheus-2.15.2.linux-amd64.tar.gz
$ cd prometheus-2.15.2.linux-amd64
$ ./prometheus --version
```

当使用二进制进行安装时，最好用systemd来管理。我们把整个`prometheus-2.15.2.linux-amd64`文件夹移动到`/usr/local/`目录下，并重命名为`prometheus`

```
$ mv ./prometheus-2.15.2.linux-amd64 /usr/local/prometheus
```

然后创建文件`/usr/lib/systemd/system/prometheus.service`，内容如下

```
[Unit]
Description=prometheus
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --storage.tsdb.path=/var/lib/prometheus
Restart=on-failure

[Install]
WantedBy=multi-user.target
```

关于启动参数可以使用命令`/usr/local/prometheus/prometheus --help`查看。这里我们把数据的存储目录指定到`/var/lib/prometheus`

然后启动prometheus，并查看prometheus是否启动成功

```
$ systemctl daemon-reload && systemctl enable prometheus
$ systemctl start prometheus && systemctl status prometheus
```

如果启动失败，则可以通过`journalctl -xeu prometheus --no-pager`查看错误日志（因为systemd管理的service的stdout日志都由journald接管）。如果成功，此时我们可以通过`http://ip:9090`访问prometheus自带的UI

![](/files/-MA1FeDpcFZMquD6h-8A)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://pshizhsysu.gitbook.io/prometheus/kuai-su-kai-shi/an-zhuang-prometheus.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
