Prometheus监控MySQL和Linux主机结合Grafana出图

监控的命令

top
df
free
htop
uptime
cat /proc/meminfo 
iftop         流量监控工具
nethogs       查看进程占用的网络带宽
iotop

prometheus监控流程

# 携带metrics接口的服务
1、使用prometheus链接metrics获取数据

# 不携带metrics接口的服务
1、安装exporter服务(为不提供metrics的服务提供一个metrics接口)

2、使用prometheus链接metrics获取数据

部署prometheus

[root@prometheus ~]# wget https://github.com/prometheus/prometheus/releases/download/v2.30.0/prometheus-2.30.0.linux-amd64.tar.gz

[root@prometheus ~]# tar xf prometheus-2.30.0.linux-amd64.tar.gz -C /usr/local/
[root@prometheus ~]# cd /usr/local

#做软链接
[root@prometheus /usr/local]# chown -R root.root prometheus-2.30.0.linux-amd64
[root@prometheus /usr/local]# ln -s /usr/local/prometheus-2.30.0.linux-amd64 /usr/local/prometheus

#配置环境变量
[root@prometheus /usr/local]# vim /etc/profile.d/prometheus.sh
export PATH=/usr/local/prometheus:$PATH

[root@prometheus /usr/local]# source /etc/profile

# 启动(测试)
[root@promethues /usr/local/prometheus]# prometheus --config.file="/usr/local/prometheus/prometheus.yml"

#添加至system管理
[root@promethues ~]# vim /usr/lib/systemd/system/prometheus.service 
[Unit]
Description=Prometheus
[Service]
Type=simple
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --web.enable-lifecycle  
Restart=on-failure
[Install]
WantedBy=multi-user.target

[root@promethues system]# systemctl daemon-reload
[root@promethues system]# systemctl start prometheus

#目录说明
[root@promethus /usr/local/prometheus]# ls 
console_libraries       --->控制台函数库
consoles                --->控制台
data                    --->数据存放目录
 
LICENSE                 --->许可证
NOTICE                  --->通知
prometheus              --->启动脚本
prometheus.yml          --->主配置文件
promtool                --->系统工具

#主配置文件说明
[root@promethus /usr/local/prometheus]# cat prometheus.yml
 
global:                 --->全局变量
  scrape_interval:     15s # 抓取时间间隔,每隔15秒去抓取一次
  evaluation_interval: 15s # 监控数据评估间隔
 
scrape_configs:
  - job_name: 'prometheus'           --->定义job名字
 
    static_configs:
    - targets: ['localhost:9090','web01:9100','10.0.0.8:9100']    --->定义监控节点

#检测
[root@prometheus ~]# netstat -lntp | grep prometheus
tcp6       0      0 :::9090                 :::*                    LISTEN      8280/prometheus 

#浏览器访问10.0.0.72:9090

请添加图片描述

安装node_exporter

[root@promethues ~]# wget https://github.com/prometheus/node_exporter/releases/download/v1.2.2/node_exporter-1.2.2.linux-amd64.tar.gz

[root@prometheus ~]# tar xf node_exporter-1.2.2.linux-amd64.tar.gz -C /usr/local
[root@prometheus ~]# cd /usr/lcoal

[root@prometheus /usr/local]# chown -R root.root node_exporter-1.2.2.linux-amd64
[root@prometheus /usr/local]# ln -s node_exporter-1.2.2.linux-amd64 /usr/local/node_exporter

#配置环境变量
[root@prometheus /usr/local]# vim /etc/profile.d/node_exporter.sh
export PATH=/usr/local/node_exporter:$PATH

[root@prometheus /usr/local]# source /etc/profile

# 启动(测试)
[root@promethues /usr/local]# node_exporter 

#添加至system管理
[root@prometheus /usr/local]# vim /usr/lib/systemd/system/node_exporter.service
[Unit]
Description=This is prometheus node exporter
After=node_exporter.service
[Service]
Type=simple
ExecStart=/usr/local/node_exporter/node_exporter
ExecReload=/bin/kill -HUP 
KillMode=process
Restart=on-failure
[Install]
WantedBy=multi-user.target

[root@prometheus /usr/local]# systemctl daemon-reload
[root@prometheus /usr/local]# systemctl start node_exporter

#检验
[root@prometheus /usr/local]# netstat -lntp | grep node_exporter
tcp6       0      0 :::9100                 :::*                    LISTEN      8384/nod_exporter

#将node_exporter服务加入prometheus
[root@prometheus ~]# vim /usr/local/prometheus/prometheus.yml
#在结尾添加
- job_name: "node"
    static_configs:
      - targets: ["172.16.1.72:9100"]

#被监控端主机同上操作,只需添加被监控端的主机IP
  - job_name: "node"
    static_configs:
      - targets: ["172.16.1.72:9100","172.16.1.7:9100"]


[root@prometheus ~]# systemctl restart prometheus

监控MySQL

[root@prometheus ~]# wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.13.0/mysqld_exporter-0.13.0.linux-amd64.tar.gz

[root@prometheus ~]# tar xf mysqld_exporter-0.13.0.linux-amd64.tar.gz -C /usr/local
[root@prometheus ~]# cd /usr/local

[root@prometheus /usr/local]# chown -R root.root mysqld_exporter-0.13.0.linux-amd64
[root@prometheus /usr/local]# ln -s mysqld_exporter-0.13.0.linux-amd64 /usr/local/mysqld_exporter

#建立远程连接用户
[root@db01 ~]# mysql
mysql> GRANT ALL PRIVILEGES ON *.* TO 'mysql-exporter'@'%' identified by '12345';
mysql> FLUSH PRIVILEGES;

#编写mysql连接配置文件
[root@prometheus /usr/local]# cat mysqld_exporter/my.cnf
[client]
host=172.16.1.51
user=msyql-exporter
password=12345

4、启动(测试)
[root@promethues /usr/local/mysqld_exporter]# ./mysqld_exporter  --config.my-cnf="my.cnf"

#加入systemd
[root@prometheus /usr/local]# vim /usr/lib/systemd/system/mysql_exporter.service
[Unit]
Description=Prometheus
[Service]
ExecStart=/usr/local/mysqld_exporter/mysqld_exporter --config.my-cnf=/usr/local/mysqld_exporter/my.cnf --web.listen-address=:9104
Restart=on-failure
[Install]
WantedBy=multi-user.target

[root@prometheus /usr/local]# systemctl daemon-reload
[root@prometheus /usr/local]# systemctl start mysql_exporter
[root@prometheus /usr/local]# netstat -lntp | grep mysql
tcp6       0      0 :::9104                 :::*                    LISTEN      9298/mysqld_exporte 

#结尾添加
[root@prometheus /usr/local]# vim prometheus/prometheus.yml 
  - job_name: "mysqldb"
    static_configs:
      - targets: ["172.16.1.72:9104"]

[root@prometheus /usr/local]# systemctl restart prometheus

请添加图片描述
请添加图片描述

安装监控大屏(grafana)

[root@promethues ~]# wget https://dl.grafana.com/enterprise/release/grafana-enterprise-8.1.2-1.x86_64.rpm

[root@promethues ~]# yum install grafana-enterprise-8.1.2-1.x86_64.rpm 

[root@promethues ~]# systemctl start grafana-server

#浏览器访问10.0.0.72:3000
默认密码:admin /  admin

图形化监控

请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

中文监控模板

中文版Redis主机监控
中文版MySQL监控
中文版Linux主机监控1
中文版Linux主机监控2
中文版Linux主机监控3

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值