赞
踩
目录
- 1.安装mysql
- [root@192_168_81_160 ~]# yum -y install mariadb
-
- 2.启动mysql
- [root@192_168_81_160 ~]# systemctl start mariadb
- [root@192_168_81_160 ~]# systemctl enable mariadb
-
- 3.创建用户并赋权
- [root@192_168_81_160 ~]# mysql
- MariaDB [(none)]> grant select,replication client,process on *.* to 'mysql_monitor'@'localhost' identified by '123';
- MariaDB [(none)]> flush privileges;
-
- 1.下载mysql_exporter
- [root@192_168_81_160 ~]# weget https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz
-
- 2.安装mysql_exporter
- [root@192_168_81_160 ~]# tar xf mysqld_exporter-0.12.1.linux-amd64.tar.gz -C /data/
- [root@192_168_81_160 ~]# cd /data/mysqld_exporter-0.12.1.linux-amd64/
-
- 3.创建mysql监控配置文件,填写mysql刚刚创建的用户密码
- [root@192_168_81_160 ~]# vim /data/mysqld_exporter-0.12.1.linux-amd64/my.cnf
- [client]
- user=mysql_monitor
- password=123
-
- 4.启动mysql_exporter
- [root@192_168_81_160 mysqld_exporter]# nohup /data/mysqld_exporter/mysqld_exporter --config.my-cnf="/data/mysqld_exporter/my.cnf" &
-
- 5.查看端口
- [root@192_168_81_160 mysqld_exporter]# netstat -lnpt | grep mysqld_export
- tcp6 0 0 :::9104 :::* LISTEN 14966/mysqld_export
访问http://192.168.81.160:9104/metrics
- 1.增加mysql主机的配置
- [root@prometheus-server ~]# vim /data/prometheus/prometheus.yml
- - job_name: "mysqld"
- static_configs:
- - targets: ['192.168.81.160:9104']
-
- 2.重启prometheus
- [root@prometheus-server prometheus]# ps aux | grep prometheus | awk '{print $2}' | xargs kill -9
- [root@prometheus-server prometheus]# ./prometheus --config.file="/data/prometheus/prometheus.yml" &
点击status—targets
已经添加
查看图形
查看mysql_global_status_threads_connected当前登录链接情况这个监控项的图形
- 1.修改grafana配置文件
- [root@grafana grafana]# vim /etc/grafana/grafana.ini
- [dashboard.json]
- enabled = true
- path = /var/lib/grafana/dashboards
-
- 2.下载图形模板
- [root@grafana ~]# cd /var/lib/grafana/
- [root@grafana grafana]# git clone https://github.com/percona/grafana-dashboards.git
-
- 3.复制图形json文件到dashboard目录
- [root@grafana grafana]# cp -r grafana-dashboards/dashboards/* dashboards/
-
- 4.重启grafana
- [root@grafana grafana]# systemctl restart grafana-server
虽然导入完成,但是页面没有数据
没有数据是由于图形默认的数据源是prometheus,而我们的源是prometheus-1
由于他的图形比较多,我们改起来比较麻烦,我们之间将我们的源名称修改为Prometheus即可
再次刷新就能看到监控图形
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。