MySQL promethues & grafana 配置安装手册
操作系统配置
开放防火墙端口
firewall-cmd --zone=public --add-port=9104/tcp --permanent
firewall-cmd --reload
查看某个端口
firewall-cmd --zone=public --query-port=9104/tcp
创建操作系统用户
useradd export
passwd export
创建安装目录
mkdir /app/export
chown export:export /app/export
数据库准备
GRANT REPLICATION CLIENT, PROCESS ON *.* TO 'exporter'@'localhost' identified by '123456';
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'10.253.129.79' IDENTIFIED BY 'exporter123' WITH MAX_USER_CONNECTIONS 3;
mysql> flush privileges;
GRANT SELECT ON performance_schema.* TO 'exporter'@'localhost';
创建.my.cnf文件 vi .my.cnf:
[client]
user=exporter
password=123456
安装mysqld_export
切换到export 用户下.
- 下载地址
- 解压软件.
- 准备启动脚本.
./mysqld_exporter --config.my-cnf=".my.cnf" > mysqld_export.log 2>&1 &
Note
默认端口为:9104
安装promethues
操作系统配置
开放防火墙端口
firewall-cmd --zone=public --add-port=9090/tcp --permanent
firewall-cmd --reload
查看某个端口
firewall-cmd --zone=public --query-port=9090/tcp
创建操作系统用户
[root@mysqlem ~]# mkdir -p /app/prometheusdb
[root@mysqlem ~]# userdel yh
[root@mysqlem ~]# useradd prometheus
[root@mysqlem ~]# passwd prometheus
安装promethues
- 下载promethues
- 解压程序
tar xvfz prometheus-*.tar.gz
cd prometheus-*
- 链接目录
ln -s prometheus-2.26.0.linux-amd64 prometheus
- 启动配置文件
# 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).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:9090']
- job_name: 'mysql'
static_configs:
- targets: ['192.168.10.166:9104']
labels:
instance: test
- 启动脚本
./prometheus --config.file=prometheus.yml >> prometheus.log 2>&1 &
PID=`ps -ef | grep "prometheus" | grep -v grep | awk '{print $2}'`
echo "Start suucess"
- 停止脚本
PID=`ps -ef | grep "prometheus" | grep -v grep | awk '{print $2}'`
kill -9 $PID
安装grafna
操作系统配置
开放防火墙端口
firewall-cmd --zone=public --add-port=3000/tcp --permanent
firewall-cmd --reload
查看某个端口
firewall-cmd --zone=public --query-port=3000/tcp
下载grafana-7.5.4-1.x86_64.rpm
yum localinstall grafana-7.5.4-1.x86_64.rpm
- 启动grafana
systemctl start grafana