摘要:架构 grafana和prometheus之前安装配置过,见:Grafana+Prometheus打造全方位立体监控系统 MySql安装 MySql的地位和重要性就不言而喻了,作为开源产品深受广大中小企业以及互联网企业喜爱,所以这里我们也有必要对其进行相应的监控。
架构
grafana和prometheus之前安装配置过,见:Grafana+Prometheus打造全方位立体监控系统
MySql安装
MySql的地位和重要性就不言而喻了,作为开源产品深受广大中小企业以及互联网企业喜爱,所以这里我们也有必要对其进行相应的监控。
由于最近更换了CentOS7,这里对MySql重新安装一遍,顺便做个记录,CentOS7的yum源中默认好像是没有mysql的。为了解决这个问题,我们要先下载mysql的repo源。
列出所有版本信息:
lsb_release -a
下载mysql的repo源:
wgethttp://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
安装mysql-community-release-el7-5.noarch.rpm包:
rpm -ivh mysql-community-release-el7-5.noarch.rpm
安装mysql:
yuminstallmysql-server-y
修改权限,否则会报错:
chown -Rroot:root /var/lib/mysql
重启mysql服务:
service mysqld restart
登录并重置密码:
## 直接回车进入mysql控制台mysql -u rootmysql > use mysql;mysql > update user set password=password('123456') where user='root';mysql >exit;
mysqld_exporter安装
下载并解压:
https://github.com/prometheus/mysqld_exporter/releases/download/v0.10.0/mysqld_exporter-0.10.0.linux-amd64.tar.gztar -xvf mysqld_exporter-0.10.0.linux-amd64.tar.gz
mysqld_exporter需要连接Mysql,首先为它创建用户并赋予所需的权限:
GRANTREPLICATIONCLIENT, PROCESSON.TO'exporter'@'localhost'identifiedby'123456';GRANTSELECTONperformance_schema.*TO'exporter'@'localhost';flushprivileges;
创建.my.cnf文件 vi .my.cnf:
[client]user=exporterpassword=123456
运行mysqld_exporter:
./mysqld_exporter -config.my-cnf=".my.cnf"&
Prometheus配置
修改prometheus.yml加入MySql节点:
global:scrape_interval:15sevaluation_interval:15sscrape_configs: -job_name: prometheusstatic_configs: -targets: ['localhost:9090']labels:instance: prometheus -job_name: linux1static_configs: -targets: ['192.168.1.120:9100']labels:instance: sys1 -job_name: linux2static_configs: -targets: ['192.168.1.130:9100']labels:instance: sys2 -job_name: redis1static_configs: -targets: ['192.168.1.120:9121']labels:instance: redis1 -job_name: mysqlstatic_configs: -targets: ['192.168.1.120:9104']labels:instance: db1
保存以后重启Prometheus,查看targets:
最后登录grafana查看MySql监控信息:
参考文档:
https://github.com/prometheus/mysqld_exporter
本文为云栖社区原创内容,未经允许不得转载,如需转载请发送邮件至yqeditor@list.alibaba-inc.com;如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件至:yqgroup@service.aliyun.com 进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容。