centos7下部署 Prometheus+Grafana超炫监控
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos7下部署 Prometheus+Grafana超炫监控相关的知识,希望对你有一定的参考价值。
1.环境说明监控主机 | 被监控主机 |
---|---|
192.168.0.66 | 192.168.0.67 |
运维主机 | mysql |
2.主机安装Prometheus
下载:https://prometheus.io/download/
上传到主机[[email protected] ~]# yum -y ×××tall vim lrzsz
3.安装go
[[email protected] ~]# yum -y ×××tall epel-release
[[email protected] ~]# yum -y ×××tall go
Prometheus解压即可用
[[email protected] ~]# tar xf prometheus-2.10.0.linux-amd64.tar.gz -C /usr/local/
4.安装编辑Prometheus配置文件
[[email protected] ~]# vim /usr/local/prometheus-2.10.0.linux-amd64/prometheus.yml
追加如下内容(前方空格一定要对齐):
- job_name: system-status
static_configs:
- targets: [‘192.168.0.67:9100‘]
labels:
×××tance: 7-7
- job_name: mysql-status
static_configs:
- targets: [‘192.168.0.67:9104‘]
labels:
×××tance: 7-7-mysql
5.启动Prometheus
[[email protected] ~]# systemctl stop firewalld
[[email protected] ~]# cd /usr/local/prometheus-2.10.0.linux-amd64/
[[email protected] prometheus-2.10.0.linux-amd64]# ./prometheus --config.file=prometheus.yml & # &意为后台启动
Prometheus页面如下
6.配置被监控服务器
(1)、node_exporter 用于监控操作系统的性能和运行状态(官网自行下载)
(2)、mysqld_exporter 用于监控 mysql 服务(官网自行下载)
(3)、snmp_exporter 用于监控网络设备
更多 exporter 可在官网下载:https://prometheus.io/download/#node_exporter
7.mysql安装和授权
[[email protected] ~]# yum -y ×××tall mariadb mariadb-server
[[email protected] ~]# systemctl restart mariadb
[[email protected] ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.60-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
MariaDB [(none)]> GRANT REPLICATION CLIENT,PROCESS ON *.* TO ‘mysql_monitor‘@‘localhost‘
-> identified by ‘123456‘;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> GRANT SELECT ON *.* TO ‘mysql_monitor‘@‘localhost‘;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> exit
Bye
8.安装主机监控的node_exporter
[[email protected] ~]# tar xf node_exporter-0.17.0.linux-amd64.tar.gz -C /usr/local/
[[email protected] ~]# /usr/local/node_exporter-0.17.0.linux-amd64/node_exporter &
9.安装主机监控的mysql_exporter
[[email protected] ~]# tar xf mysqld_exporter-0.11.0.linux-amd64.tar.gz -C /usr/local/
[[email protected] ~]# vim /usr/local/mysqld_exporter-0.11.0.linux-amd64/.my.cnf
写入如下内容:
[client]
user=mysql_monitor
password= 123456
启动
[[email protected] ~]# cd /usr/local/mysqld_exporter-0.11.0.linux-amd64/
[[email protected] mysqld_exporter-0.11.0.linux-amd64]# ./mysqld_exporter --config.my-cnf=".my.cnf" &
后台启动的“ & ” 一定要写,不然推出当前操作终端后就会自动关掉
再次刷新Prometheus时,页面被监控都为up
10.安装grafana
下载:https://grafana.com/grafana/download
上传到运维主机
[[email protected] ~]# yum -y ×××tall /root/grafana-6.2.2-1.x86_64.rpm
下载饼状图插件,便于美化数据
[[email protected] ~]# grafana-cli plug××× ×××tall grafana-piechart-panel
启动grafana
[[email protected] ~]# systemctl restart grafana-server
11.登录grafana
默认端口3000,初始用户名和密码都为admin
http://192.168.0.66:3000
根据引导,登录后修改自己的密码
如上图:find dashboards on grafana.com 里可以找到需要监控的模板,查到相应的模板id
import dashboard 可以导入相应的模板id,其中8919为主机模板,9777为MySQL模板
点击load导入即可。
刷新到主页,效果如下
以上是关于centos7下部署 Prometheus+Grafana超炫监控的主要内容,如果未能解决你的问题,请参考以下文章
Centos7 docker部署监控Prometheus+Grafana