prometheus之mysqld_exporter部署

mysql_exporter部署

下载解压压缩包
复制代码
mkdir /opt/mysqld_exporter/
cd /opt/mysqld_exporter/
# 修改为自己的软件下载地址
wget http://soft.download/soft/linux/prometheus/mysqld_exporter/mysqld_exporter-0.14.0.linux-amd64.tar.gz
tar -zxvf  mysqld_exporter-0.14.0.linux-amd64.tar.gz
添加mysqld_exporter配置文件
复制代码
[root@shuan-node0132 mysqld_exporter-0.14.0.linux-amd64]# cat .my.cnf
[client]
host = localhost
user = reporter #mysql账号
password = 123456yuyuyut #mysql密码
port = 3308 #mysql端口
mysql授权监控账号exporter
复制代码
CREATE USER 'reporter'@'localhost' IDENTIFIED BY '123456yuyuyut' WITH MAX_USER_CONNECTIONS 3;
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'reporter'@'localhost';
编写service服务文件
复制代码
vim /etc/systemd/system/mysqld_exporter.service

[Service]
ExecStart=/opt/mysqld_exporter/mysqld_exporter-0.14.0.linux-amd64/mysqld_exporter --config.my-cnf /opt/mysqld_exporter/mysqld_exporter-0.14.0.linux-amd64/.my.cnf
[Install]
WantedBy=multi-user.target
[Unit]
Description=mysqld_exporter
After=network.target
启动服务并设置开机自启
复制代码
systemctl start mysqld_exporter
systemctl enable mysqld_exporter
防火墙开放端口
复制代码
firewall-cmd --permanent --add-port=9104/tcp --zone=public&&firewall-cmd --reload
安装脚本
复制代码
cat install_mysqld_exporter.sh

#!/bin/bash
InstallDir='/opt/mysqld_exporter/'
FileName='mysqld_exporter-0.14.0.linux-amd64.tar.gz'

function RedFont(){
  echo -e "\033[31mError: $1 \033[0m"
}

function GreenFont(){
  echo -e "\033[32mSuccess: $1 \033[0m"
}

function YellowFont(){
  echo -e "\033[33mWarning: $1 \033[0m"
}

if [ ! -d "$InstallDir" ];then
    mkdir $InstallDir
else
    YellowFont "${InstallDir}文件夹已经存在,请删除后重新执行"
    exit
fi

#进入安装目录
cd $InstallDir

#下载安装包
wget http://soft.download/soft/linux/prometheus/mysqld_exporter/$FileName > /dev/null 2>&1

if [ $? -eq 0 ];then
   GreenFont "$FileName download success"
else
   RedFont "$FileName download faild"
   exit
fi

#解压安装包到指定目录,解压不包含压缩一级目录
tar -zxf $FileName --strip-components 1 -C $InstallDir > /dev/null 2>&1

if [ $? -eq 0 ];then
   GreenFont "$FileName decompress success"
else
   RedFont "$FileName decompress faild"
   exit
fi

#创建配置文件
cat > ${InstallDir}.my.cnf << EOF
[client]
host = localhost
user = reporter #mysql账号
password = 123456yuyuyut #mysql密码
port = 3308 #mysql端口
EOF

#设置开机自启
cat > /etc/systemd/system/mysqld_exporter.service << EOF
[Service]
ExecStart=${InstallDir}mysqld_exporter --config.my-cnf ${InstallDir}.my.cnf
[Install]
WantedBy=multi-user.target
[Unit]
Description=mysqld_exporter
After=network.target
EOF

#防火墙放行端口
firewall-cmd --permanent --add-port=9104/tcp --zone=public&&firewall-cmd --reload

#启动服务
systemctl  daemon-reload
systemctl enable mysqld_exporter
systemctl start mysqld_exporter && GreenFont "started mysqld_exporter" || RedFont "start mysqld_exporter faild"
相关推荐
Dontla2 小时前
Prometheus介绍(开源系统监控与告警工具)(时间序列数据库TSDB、标签化label-based多维分析、Pull模型、PromQL查询语言)
数据库·开源·prometheus
yunson_Liu1 天前
记一次logrotate.service处理过程
prometheus
TechWJ2 天前
Ansible 跨千台机器批量部署,Node Exporter 监控实现 Prometheus 统一采集
ansible·prometheus
却话巴山夜雨时i2 天前
互联网大厂Java面试:从Spring Boot到Kafka的业务场景深度剖析
spring boot·redis·spring cloud·微服务·kafka·prometheus·java面试
洒满阳光的午后3 天前
我做了一个“能理解业务语义”的可观测性 MCP Server:统一接入 Prometheus、OpenObserve 和 SkyWalking
人工智能·ai·prometheus·skywalking·openobserve·mcp
梵得儿SHI3 天前
SpringCloud 实战落地:可观测性建设(SkyWalking + Prometheus + Grafana)从 0 到 1 生产级部署
grafana·prometheus·springcloud·skywalking·微服务可观测性·线上问题排查
却话巴山夜雨时i4 天前
互联网大厂Java面试场景:Spring Boot、微服务与Redis实战解析
spring boot·redis·微服务·kafka·prometheus·java面试·电商场景
是店小二呀4 天前
Prometheus自定义指标实现方案:技术选型与实战评估
prometheus
南梦浅5 天前
【无标题】
prometheus
2301_旺仔5 天前
【prometheus】监控linux/windows
linux·windows·prometheus