mysql 192.168.0.%_Grafan+Prometheus 监控 MySQL

架构图

bd533115c03e5f66e72827d11b90dea7.png

环境

ip

环境

需装软件

192.168.0.237

mysql-5.7.20

node_exporter-0.15.2.linux-amd64.tar.gz

mysqld_exporter-0.10.0.linux-amd64.tar.gz

192.168.0.248

grafana+prometheus

prometheus-2.1.0.linux-amd64.tar.gz

node_exporter-0.15.2.linux-amd64.tar.gz

grafana-4.6.3.linux-x64.tar.gz

在 192.168.0.248 上安装 grafana prometheus

安装 prometheus

# 创建保存软件的目录

mkdir /data/software/ -p

cd /data/software/

# 解压 prometheus

tar xvf prometheus-2.1.0.linux-amd64.tar.gz -c /iba/

cd /iba/

mv prometheus-2.1.0.linux-amd64 prometheus

cd prometheus/

cp prometheus.yml /tmp/prometheus.yml.20181203

# 配置 prometheus.yml

cat prometheus.yml

# my global config

global:

scrape_interval: 15s # set the scrape interval to every 15 seconds. default is every 1 minute.

evaluation_interval: 15s # evaluate rules every 15 seconds. the default is every 1 minute.

# scrape_timeout is set to the global default (10s).

# a scrape configuration containing exactly one endpoint to scrape:

# here it's prometheus itself.

scrape_configs:

- job_name: 'host'

file_sd_configs:

- files:

- host.yml

metrics_path: /metrics

relabel_configs:

- source_labels: [__address__]

regex: (.*)

target_label: instance

replacement: $1

- source_labels: [__address__]

regex: (.*)

target_label: __address__

replacement: $1:9100

- job_name: 'mysql'

file_sd_configs:

- files:

- mysql.yml

metrics_path: /metrics

relabel_configs:

- source_labels: [__address__]

regex: (.*)

target_label: instance

replacement: $1

- source_labels: [__address__]

regex: (.*)

target_label: __address__

replacement: $1:9104

- job_name: 'prometheus'

static_configs:

- targets:

- localhost:9090

cat host.yml

- labels:

service: test

targets:

- 192.168.0.248

- 192.168.0.237

cat mysql.yml

- labels:

service: test

targets:

- 192.168.0.237

# 测试 prometheus 是否可以正常启动

/iba/prometheus/prometheus --storage.tsdb.retention=30d &

ps -ef|grep prometh

kill -9 14650

# 配置 prometheus.service 文件

vi /usr/lib/systemd/system/prometheus.service

# 内容为

[unit]

description=prometheus instance

wants=network-online.target

after=network-online.target

[service]

user=root

group=root

type=simple

restart=on-failure

workingdirectory=/iba/prometheus/

runtimedirectory=prometheus

runtimedirectorymode=0750

execstart=/iba/prometheus/prometheus --storage.tsdb.retention=30d --config.file=/iba/prometheus/prometheus.yml

limitnofile=10000

timeoutstopsec=20

[install]

wantedby=multi-user.target

# 启动 prometheus

systemctl start prometheus

systemctl status prometheus -l

# 开放防火墙

firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.0.0/16" accept"

firewall-cmd --reload

浏览器输入 http://192.168.0.248:9090 访问

7103d185e7da00f34a9fb8f13e4c5f91.png

prometheus.yml 文件参考:

https://prometheus.io/docs/prometheus/latest/configuration/configuration/

https://prometheus.io/docs/prometheus/latest/configuration/configuration/#%3crelabel_config%3e

https://prometheus.io/docs/prometheus/latest/configuration/configuration/#%3cfile_sd_config%3e

安装 node_exporter 获取主机信息

# 解压 node_exporter

cd /data/software/

tar xf node_exporter-0.15.2.linux-amd64.tar.gz -c /usr/local

mv node_exporter-0.15.2.linux-amd64 node_exporter

nohup ./node_exporter &

安装 grafana

cd /iba/software

# 解压

tar xf grafana-4.6.3.linux-x64.tar.gz -c /iba/prometheus/

cd /iba/prometheus/

mv grafana-4.6.3 grafana

cd grafana/

# 测试

./bin/grafana-server

# 停止

ctrl+c

cat /usr/lib/systemd/system/grafana-server.service

[unit]

description=grafana instance

documentation=http://docs.grafana.org

wants=network-online.target

after=network-online.target

[service]

user=root

group=root

type=simple

restart=on-failure

workingdirectory=/iba/prometheus/grafana

runtimedirectory=grafana

runtimedirectorymode=0750

execstart=/iba/prometheus/grafana/bin/grafana-server

limitnofile=10000

timeoutstopsec=20

[install]

wantedby=multi-user.target

# 启动

systemctl start grafana-server

systemctl status grafana-server -l

访问 http://192.168.0.248:3000,默认用户和密码是 admin/admin

4c4fcd1fa5ad7ef1f3ee609e587f40e2.png

配置数据源

d26a1875d67e45de7bdf9e84c4a872c1.png

c71281964c845e49f42be04a1ada0cf7.png

下载 grafana-dashboards-1.6.1.tar.gz,解压,使用浏览器导入 dashboard, 下载地址:https://github.com/percona/grafana-dashboards/archive/v1.6.1.tar.gz

8b6f1f85af52c60707fd1fc6a43a21fb.png

4b896957e06276ba58136159076b03bc.png

788a5a363d3e401c4fd9afdd8e7a9924.png

4e5916cc711134093cf22e2d082e7673.png

在 192.168.0.237 安装 node_exporter 和 mysqld_exporter

cd /iba/software/

tar zxf node_exporter-0.15.2.linux-amd64.tar.gz -c /usr/local/

cd /usr/local/

mv node_exporter-0.15.2.linux-amd64 node_exporter

# 启动

cd node_exporter/

nohup ./node_exporter &

几分钟后 grafana 出现了新服务器的信息

2b2698361c170a8eb2251da77e488789.png

在mysql上配置监控使用的用户

grant replication client, process, select on *.* to 'mysql_monitor'@'%' identified by 'mysql_monitor';

flush privileges;

cd /iba/software/

tar zxf mysqld_exporter-0.10.0.linux-amd64.tar.gz -c /usr/local/

cd /usr/local/

mv mysqld_exporter-0.10.0.linux-amd64/ mysqld_exporter

cd mysqld_exporter/

# 在 mysql 上创建一个专门用于监控的用户,

cat .my.cnf

[client]

user=mysql_monitor

password=mysql_monitor

# 启动

nohup /usr/local/mysqld_exporter/mysqld_exporter -config.my-cnf="/usr/local/mysqld_exporter/.my.cnf" &

导入 dashboard: mysql_overview.json

0619951e06fd6f57287dd5b8426a2fc0.png

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
一、prometheus简介 Prometheus是一个开源的系统监控和告警系统,现在已经加入到CNCF基金会,成为继k8s之后第二个在CNCF维护管理的项目,在kubernetes容器管理系统中,通常会搭配prometheus进行监控prometheus支持多种exporter采集数据,还支持通过pushgateway进行数据上报,Prometheus再性能上可支撑上万台规模的集群。 二、prometheus架构图 三、prometheus组件介绍 1.Prometheus Server: 用于收集和存储时间序列数据。 2.Client Library: 客户端库,检测应用程序代码,当Prometheus抓取实例的HTTP端点时,客户端库会将所有跟踪的metrics指标的当前状态发送到prometheus server端。 3.Exporters: prometheus支持多种exporter,通过exporter可以采集metrics数据,然后发送到prometheus server端 4.Alertmanager: 从 Prometheus server 端接收到 alerts 后,会进行去重,分组,并路由到相应的接收方,发出报警,常见的接收方式有:电子邮件,微信,钉钉, slack等。 5.Grafana:监控仪表盘 6.pushgateway: 各个目标主机可上报数据到pushgatewy,然后prometheus server统一从pushgateway拉取数据。 四、课程亮点 五、效果图展示 六、讲师简介 先超(lucky):高级运维工程师、资深DevOps工程师,在互联网上市公司拥有多年一线运维经验,主导过亿级pv项目的架构设计和运维工作 主要研究方向: 1.云计算方向:容器 (kubernetes、docker),虚拟化(kvm、Vmware vSphere),微服务(istio),PaaS(openshift),IaaS(openstack)等2.系统/运维方向:linux系统下的常用组件(nginx,tomcat,elasticsearch,zookeeper,kafka等),DevOps(Jenkins+gitlab+sonarqube+nexus+k8s),CI/CD,监控(zabbix、prometheus、falcon)等 七、课程大纲

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值