Centos系统安装grafana+prometheus+node_exporter详细步骤

一:环境准备

准备可用的两台centos7服务器:
服务器一(看板服务器)ip:119.1.1.1
服务器二(被监控的服务器)ip:119.1.1.2
备注:也可只准备一台服务器,将看板服务器和监控服务器放在一台服务器上

二:grafana和prometheus登录地址:

grafana登录地址:http://119.1.1.1:3000
prometheus登录地址:http://119.1.1.1:9090/targets

三:安装grafana(服务器ip:119.1.1.1)

1:新建grafana目录:

[root@prometheus src]#mkdir grafana

2:进入grafana目录:`

[root@prometheus src]#cd grafana

3:下载:

[root@prometheus src]#wget https://dl.grafana.com/oss/release/grafana-7.3.7-1.x86_64.rpm

4:安装(如服务器没有yun需先安装yun):

[root@prometheus src]#yum localinstall grafana-7.3.7-1.x86_64.rpm

5:查看是否安装成功:

[root@prometheus src]#grafana-cli -version

如成功出现如下界面:
在这里插入图片描述
6:设置开机启动

[root@prometheus src]# systemctl enable grafana-server
[root@prometheus src]# systemctl start grafana-server
  1. 设置iptables
[root@prometheus src]# vi /etc/sysconfig/iptables
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3000 -j ACCEPT
[root@prometheus src]# service iptables restart

8.远程登陆
浏览器访问:http://119.1.1.1:3000/login,默认账号/密码:admin/admin(如访问不了需把服务器的防火墙关闭,再确定3000端口是否开放)
出现如下界面则安装成功:
在这里插入图片描述

四:安装prometheus(服务器ip:119.1.1.1)

1:新建目录prometheus:

[root@prometheus src]#mkdir prometheus

2:进入目录

[root@prometheus src]#cd prometheus

3:下载:

[root@prometheus src]#wget https://github.com/prometheus/prometheus/releases/download/v2.20.1/prometheus-2.20.1.linux-amd64.tar.gz

5:解压:

[root@prometheus src]#tar -zxf prometheus-2.20.1.linux-amd64.tar.gz(解压后路径:/usr/zzbtest/grafana/prometheus/prometheus-2.20.1.linux-amd64)

6:进入解压目录

[root@prometheus src]#cd prometheus-2.20.1.linux-amd64

7:修改prometheus.yml配置并保存:

global:
  # 默认情况下,每15s拉取一次目标采样点数据。
  scrape_interval:     15s 
  external_labels:
    monitor: 'codelab-monitor'
scrape_configs:
  - job_name: 'prometheus'
    scrape_interval: 5s    # 拉取时间间隔5s
    static_configs:
      - targets: ['119.1.1.1:9090']#修改为prometheus安装服务器,9090为prometheus端口号

8:进入prometheus.yml文件存放目录:
如第一次启动:

[root@prometheus src]#./prometheus --config.file=prometheus.yml

如之前启动成功过,直接后台启动:

[root@prometheus src]#nohup ./prometheus --config.file=prometheus.yml --web.enable-admin-api &

注意:之前启动过,重启需要杀掉之前的进程,步骤如下:
查找进程:

[root@prometheus src]#ps -ef | grep prometheus

杀掉进程:

[root@prometheus src]#kill -9  进程号

9:浏览器访问:http://119.1.1.1:9090/targets

五:安装node_exporter 采集器(服务器ip:119.1.1.2 )

1:创建文件夹:

[root@prometheus src]#mkdir node_exporter

2:进入文件夹:

[root@prometheus src]#cd node_exporter

3:下载文件:

[root@prometheus src]#wget https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz

4:解压文件:

[root@prometheus src]#sudo tar -zxf node_exporter-1.0.1.linux-amd64.tar.gz

5:进入解压目录:

[root@prometheus src]#cd node_exporter-1.0.1.linux-amd64

6:进入/node_exporter-1.0.1.linux-amd64目录启动node_exporter:
第一次建议调试启动:

[root@prometheus src]#./node_exporter

在这里插入图片描述

如启动成功,直接后台启动:

[root@prometheus src]#nohup ./node_exporter --web.listen-address=":9200"   & 

7:查看是否启动成功:被监听的服务器:

[root@prometheus src]#curl localhost:9200/metrics|wc -l

在这里插入图片描述

8:进入119.1.1.1服务器,修改prometheus.yml配置并保存

global:
  # 默认情况下,每15s拉取一次目标采样点数据。
  scrape_interval:     15s 
  external_labels:
    monitor: 'codelab-monitor'
scrape_configs:
  - job_name: 'prometheus'
    scrape_interval: 5s    # 拉取时间间隔5s
    static_configs:
      - targets: ['119.1.1.1:9090']#修改为prometheus安装服务器,9090为prometheus端口号
#安装node_exporter修改如下内容
  - job_name: '119.1.1.2服务器'
    scrape_interval: 5s
    static_configs:
      - targets: ['119.1.1.2:9200']#后面node_exporter安装后需配置该内容
9:重启prometheus:
```bash
[root@prometheus src]#nohup ./prometheus --config.file=prometheus.yml --web.enable-admin-api &

注意:之前启动过,重启需要杀掉之前的进程,步骤如下:
查找进程:

[root@prometheus src]#ps -ef | grep prometheus

杀掉进程:

[root@prometheus src]#kill -9  进程号

10:浏览器访问:http://119.1.1.1:9090/targets
up状态:成功
down状态:失败
失败需检查node_exporter进程是否存在,对应的9200端口是否开放
在这里插入图片描述

六:grafana配置prometheus数据源

1:浏览器:http://119.1.1.1:3000 进入图形界面,默认账户密码:admin/admin
在这里插入图片描述
2:配置 Grafana 添加 Prometheus 数据源
在这里插入图片描述
3:然后点击 add data source,点击prometheus
在这里插入图片描述
4:输入好 prometheus 的服务端地址和端口
在这里插入图片描述
5:然后点击完成,查看信息是否成功
在这里插入图片描述

七:grafana配置node_exporter看板

在这里插入图片描述
  1:去官网:https://grafana.com/grafana/dashboards
  在这里插入图片描述
可以筛选
在这里插入图片描述
2:如果可以联网,就可以用 ID 来导入,如果服务器网络不好或没有外网就可以下载json(默认使用8919模板)
在这里插入图片描述
3:然后点击manage里面import,点击load:
在这里插入图片描述
最后,起个名字,然后选择好数据源,点击也没下方的 蓝色 import 按钮
在这里插入图片描述
最终,仪表盘导入成功
在这里插入图片描述

  • 2
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值