代码拉取完成,页面将自动刷新
1.官网下载安装包:
```
[root@host-10-10-2-99 ~]# wget https://github.com/prometheus/prometheus/releases/download/v2.13.1/prometheus-2.13.1.linux-amd64.tar.gz
[root@host-10-10-2-99 ~]# tar -xf prometheus-2.13.1.linux-amd64.tar.gz
[root@host-10-10-2-99 ~]# mv prometheus-2.13.1.linux-amd64 /usr/local/prometheus
[root@host-10-10-2-99 ~]# cd /usr/local/prometheus/
```
2.查看相应版本,解压即可使用:
```
[root@host-10-10-2-99 prometheus]# ./prometheus --version
prometheus, version 2.13.1 (branch: HEAD, revision: 6f92ce56053866194ae5937012c1bec40f1dd1d9)
build user: root@88e419aa1676
build date: 20191017-13:15:01
go version: go1.13.1
```
3.后台启动普罗米修斯:
```
[root@host-10-10-2-99 prometheus]# ./prometheus &
```
即可完成启动,访问 http://ip:9090 端口即可,默认读取当前目录下的prometheus.yml配置文件:
![](https://s1.51cto.com/images/blog/201910/28/c58984e723f965a24da2b92b1b55f6d3.png)
4.我们把服务以系统管理的方式添加:
```
[root@host-10-10-2-99 prometheus]# cat /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus Monitoring System
Documentation=Prometheus Monitoring System
[Service]
ExecStart=/usr/local/prometheus/prometheus \
--config.file=/usr/local/prometheus/prometheus.yml \
--web.listen-address=:9090
[Install]
WantedBy=multi-user.target
```
5.启动服务,并且添加到配置文件:
```
[root@host-10-10-2-99 prometheus]# systemctl enable prometheus
Created symlink from /etc/systemd/system/multi-user.target.wants/prometheus.service to /etc/systemd/system/prometheus.service.
[root@host-10-10-2-99 prometheus]# systemctl start prometheus
```
6.当然在有Docker环境下,图方便的朋友直接启动即可:
```
docker run -p 9090:9090 -v /usr/local/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus
```
# Node Exporter 部署
在Prometheus的架构设计中,Prometheus Server并不直接服务监控特定的目标,其主要任务负责数据的收集,存储并且对外提供数据查询支持。因此为了能够能够监控到某些东西,如主机的CPU使用率,我们需要使用到Exporter。Prometheus周期性的从Exporter暴露的HTTP服务地址(通常是/metrics)拉取监控样本数据。
Node Exporter 可以采集到系统相关的信息,例如CPU、内存、硬盘等系统信息。Node Exporter采用Golang编写,并且不存在任何的第三方依赖,只需要下载,解压即可运行。
1.下载部署:
```
[root@host-10-10-2-99 ~]# wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
[root@host-10-10-2-99 ~]# tar -xf node_exporter-0.18.1.linux-amd64.tar.gz
[root@host-10-10-2-99 ~]# mv node_exporter-0.18.1.linux-amd64 /usr/local/node_exporter
```
2.添加到systemctl服务:
```
[root@host-10-10-2-99 ~]# cat /etc/systemd/system/node_exporter.service
[Unit]
Description=node exporter
Documentation=node exporter
[Service]
ExecStart=/usr/local/node_exporter/node_exporter
[Install]
WantedBy=multi-user.target
[root@host-10-10-2-99 ~]# systemctl enable node_exporter
Created symlink from /etc/systemd/system/multi-user.target.wants/node_exporter.service to /etc/systemd/system/node_exporter.service.
[root@host-10-10-2-99 ~]# systemctl start node_exporter
#查看监听端口:
[root@host-10-10-2-99 ~]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 4323/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 4527/master
tcp6 0 0 :::9100 :::* LISTEN 5206/node_exporter
tcp6 0 0 :::22 :::* LISTEN 4323/sshd
tcp6 0 0 ::1:25 :::* LISTEN 4527/master
tcp6 0 0 :::9090 :::* LISTEN 5219/prometheus
```
4.也可以和上面类似,可以直接从docker方面启动:
docker run -d -p 9100:9100 quay.io/prometheus/node-exporter
5.修改Prometheus 配置文件Prometheus.yml,增加相关监控:
```
[root@host-10-10-2-99 prometheus]# cat 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: ['localhost:9090']
- job_name: 'linux'
static_configs:
- targets: ['10.10.2.99:9100']
[root@host-10-10-2-99 prometheus]# systemctl restart prometheus
```
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。