Promtheus实战系列(一)之环境部署与搭建

Johnny21
• 阅读 1505

一、部署prometheus,grafana和node_exporter

Prometheus开始教程:https://github.com/Alrights/prometheus/blob/master/introductions/FirstSteps.md

1.1 环境(centos7)

[root@localhost prometheus]# uname -a
Linux localhost.localdomain 3.10.0-957.10.1.el7.x86_64 #1 SMP Mon Mar 18 15:06:45 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux 

1.2 环境部署与服务启动

// 安装prometheus
wget  https://github.com/prometheus/prometheus/releases/download/v2.9.2/prometheus-2.9.2.linux-amd64.tar.gz
tar xzvf prometheus-2.9.2.linux-amd64.tar.gz
mv prometheus-2.9.2.linux-amd64 /usr/local/prometheus 

// 添加prometheus用户,非必须 groupadd prometheus useradd -g prometheus -m -d /var/lib/prometheus -s /sbin/nologin prometheus


对systemctl不熟的可以了解[鸟哥的Linux私房菜](https://links.jianshu.com/go?to=http%3A%2F%2Flinux.vbird.org%2Flinux_basic%2F0560daemons.php%23daemon)

// prometheus系统服务配置 vim /etc/systemd/system/prometheus.service

[Unit] Description=prometheus After=network.target [Service] Type=simple User=prometheus ExecStart=/usr/local/prometheus/prometheus -config.file=/usr/local/prometheus/prometheus.yml -storage.local.path=/var/lib/prometheus Restart=on-failure [Install] WantedBy=multi-user.target

// 启动prometheus
systemctl start prometheus
systemctl status prometheus 
```

![](https://img-hello-world.oss-cn-beijing.aliyuncs.com/1724e8f3fe630e5b0eb01c9d31955e3c.png)

systemctl\_prometheus.png

2.  node\_exporter setup

```
// 安装node_exporter
wget https://github.com/prometheus/node_exporter/releases/download/v0.18.0/node_exporter-0.18.0.linux-amd64.tar.gz
tar -zxvf node_exporter-0.18.0.linux-amd64.tar.gz
mv node_exporter-0.18.0.linux-amd64 /usr/local/node_exporter 

// 系统服务配置node_exporter vim /etc/systemd/system/node_exporter.service

[Unit] Description=node_exporter After=network.target [Service] Type=simple User=prometheus ExecStart=/usr/local/node_exporter/node_exporter Restart=on-failure [Install] WantedBy=multi-user.target

systemctl start node_exporter
systemctl status node_exporter 
```

![](https://img-hello-world.oss-cn-beijing.aliyuncs.com/3ea07e0c25982e1bd7bf180aa2b98753.png)

systemctl\_node\_exporter.png

3.  add node\_exporter to prometheus.yaml

```
vim  /usr/local/prometheus/prometheus.yml

  - job_name: 'linux'
    static_configs:
      - targets: ['localhost:9100']
        labels:
          instance: node1 

systemctl restart prometheus systemctl status prometheus


4.  grafana setup

// 安装grafana wget https://dl.grafana.com/oss/release/grafana-6.1.6-1.x86_64.rpm yum localinstall grafana-6.1.6-1.x86_64.rpm // 启动grafana-server systemctl start grafana-server systemctl status grafana-server


![](https://img-hello-world.oss-cn-beijing.aliyuncs.com/7a65df055e0a6c9b8a20cbe5e65f3945.png)

systemctl\_grafana\_server.png

二、仪表化
-----

### 2.1 prometheus

prometheus默认端口为9090,可以在浏览器中输入[http://localhost:9090/](https://links.jianshu.com/go?to=http%3A%2F%2Flocalhost%3A9090%2F)  

![](https://img-hello-world.oss-cn-beijing.aliyuncs.com/082565e1e0e21fa4d9a5b5dd7dfefac8.png)

prometheus\_first\_start.png

### 2.2 granafa

granafa默认端口为3000,可以在浏览器中输入[http://localhost:3000/](https://links.jianshu.com/go?to=http%3A%2F%2Flocalhost%3A3000%2F)

*   granafa首次登录账户名和密码`admin/admin`,可以修改
*   配置数据源`Data sources->Add data source -> Prometheus`,输入prometheus数据源的信息,主要是输入`name`和`url`  

    ![](https://img-hello-world.oss-cn-beijing.aliyuncs.com/be6feb002f5eaec8634945934bc8e1d2.png)

    grafana\_prometheus\_datasource.png

*   添加Dashboard`New Dashboard->Import Dashboard->输入8919`,配置数据源为Prometheus,即上一步中的`name`  

    ![](https://img-hello-world.oss-cn-beijing.aliyuncs.com/e91722b93b249c3abcb4381f62f04bd8.png)

    grafana\_dashboard\_node\_exporter.png

*   配置完保存后即可看到逼格非常高的系统主机节点监控信息,包括CPU、IO、网络等信息。



    ![](https://img-hello-world.oss-cn-beijing.aliyuncs.com/a7a740743d18b92f43025eff67d82a65.png)

    grafana\_first\_dashboard.png


三、tips
------

1.  iptables(端口不通)

/sbin/iptables -I INPUT -p tcp --dport 9090 -j ACCEPT


2.  datetime(设置时区)

timedatectl list-timezones timedatectl set-timezone Asia/Shanghai

```

本文转自 https://www.jianshu.com/p/65fcff832ad7,如有侵权,请联系删除。

点赞
收藏
评论区
推荐文章
blmius blmius
2年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
Jacquelyn38 Jacquelyn38
2年前
2020年前端实用代码段,为你的工作保驾护航
有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
Stella981 Stella981
2年前
KVM调整cpu和内存
一.修改kvm虚拟机的配置1、virsheditcentos7找到“memory”和“vcpu”标签,将<namecentos7</name<uuid2220a6d1a36a4fbb8523e078b3dfe795</uuid
Wesley13 Wesley13
2年前
mysql设置时区
mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0
Wesley13 Wesley13
2年前
00:Java简单了解
浅谈Java之概述Java是SUN(StanfordUniversityNetwork),斯坦福大学网络公司)1995年推出的一门高级编程语言。Java是一种面向Internet的编程语言。随着Java技术在web方面的不断成熟,已经成为Web应用程序的首选开发语言。Java是简单易学,完全面向对象,安全可靠,与平台无关的编程语言。
Stella981 Stella981
2年前
Android蓝牙连接汽车OBD设备
//设备连接public class BluetoothConnect implements Runnable {    private static final UUID CONNECT_UUID  UUID.fromString("0000110100001000800000805F9B34FB");
Stella981 Stella981
2年前
Django中Admin中的一些参数配置
设置在列表中显示的字段,id为django模型默认的主键list_display('id','name','sex','profession','email','qq','phone','status','create_time')设置在列表可编辑字段list_editable
Wesley13 Wesley13
2年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Python进阶者 Python进阶者
3个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这