mysqld_exporter的搭建

1、创建/data/apps目录,并且下载mysql_exporte

复制代码
mkdir -p /data/apps
​
cd /data/apps
​
wget https://githubfast.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz
或者
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz

2、解压压缩包到/usr/local,并且重创建软链接

复制代码
tar -zxvf mysqld_exporter-0.12.1.linux-amd64.tar.gz -C /usr/local
​
cd /usr/local
​
ln -s mysqld_exporter-0.12.1.linux-amd64 mysqld_exporter
​

3、使用systemctl管理mysqld_exporter

复制代码
vi /usr/lib/systemd/system/mysqld_exporter.service
​
[Unit]
​
Description=Prometheus
​
[Service]
​
Environment=DATA_SOURCE_NAME=exporter:Prometheus@(localhost:3306)/
ExecStart=/usr/local/mysqld_exporter/mysqld_exporter --config.my-cnf=/usr/local/mysqld_exporter/.my.cnf --web.listen-address=:9104
Restart=on-failure
​
[Install]
​
WantedBy=multi-user.target
​

4、设置开机自启并且开启mysqld_exporter服务,数据库进行添加用户和放开权限

复制代码
systemctl enable mysqld_exporter && systemctl start mysqld_exporter && systemctl status mysqld_exporter
​
iptables -I INPUT -p tcp --dport 9104 -j ACCEPT &&
iptables-save
​
数据库的操作
​
cd /usr/local/mysqld_exporter
​
cat > .my.cnf <<EOF
[client]
user=exporter
password=Prometheus
EOF
​
mysql -u root -p
​
set global validate_password_policy=LOW;  
​
CREATE USER 'exporter'@'localhost' IDENTIFIED BY 'Prometheus' WITH MAX_USER_CONNECTIONS 5;
​
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'localhost';
​

5、在prometheus服务器添加mysqld_exporter节点监控

复制代码
vi /usr/local/prometheus/prometheus.yml
​
  - job_name: "mysqld_exporter"
    static_configs:
      - targets: ['被监控设备的IP:9104']
        labels:
          app: mysqld_exporter
          role: mysqld_exporter
      
或者以file_sd_configs方式添加node
vi /usr/local/prometheus/prometheus.yml
​
  - job_name: "mysqld_exporter"
    file_sd_configs:
      - files:
        - /usr/local/prometheus/target/mysqld_exporter.yml
        
# pwd
/usr/local/prometheus/target
# cat mysqld_exporter.yml 
- targets:
  - "被监控设备的IP:9104"
  labels:
    app: mysqld_exporter
    role: mysqld_exporter
​

6、热加载prometheus配置

复制代码
curl  -X POST http://127.0.0.1:9090/-/reload
​
复制代码
脚本方式部署
----------------------------------------------------------------------------
mysqld_exporter节点

vi mysqld_exporter.sh
​
#!/bin/bash
​
setenforce 0 &&
iptables -I INPUT -p tcp --dport 9104 -j ACCEPT &&
iptables-save > /dev/null  &&
mkdir -p /data/apps > /dev/null &&
cd /data/apps &&
wget https://githubfast.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz > /dev/null &&
echo "下载mysqld_exporter压缩包完成" &&
tar -zxvf mysqld_exporter-0.12.1.linux-amd64.tar.gz -C /usr/local > /dev/null &&
cd /usr/local &&
ln -s mysqld_exporter-0.12.1.linux-amd64 mysqld_exporter &&
echo "[Unit]
​
Description=Prometheus
​
[Service]
​
Environment=DATA_SOURCE_NAME=exporter:Prometheus@(localhost:3306)/
ExecStart=/usr/local/mysqld_exporter/mysqld_exporter --config.my-cnf=/usr/local/mysqld_exporter/.my.cnf --web.listen-address=:9104
Restart=on-failure
​
[Install]
​
WantedBy=multi-user.target" | tee -i /usr/lib/systemd/system/mysqld_exporter.service > /dev/null &&
systemctl enable mysqld_exporter && 
systemctl start mysqld_exporter && 
systemctl status mysqld_exporter 
​
sh ./mysqld_exporter.sh

​进行上面4的数据库的操作

卸载mysqld_exporter节点

vi mysqld_exporter_uninstall.sh
​
#!/bin/bash
​
systemctl disable mysqld_exporter && 
systemctl stop mysqld_exporter && 
rm -rf /usr/lib/systemd/system/mysqld_exporter.service &&
setenforce 1 &&
iptables -D INPUT -p tcp --dport 9104 -j ACCEPT &&
iptables-save > /dev/null  &&
cd /usr/local &&
unlink mysqld_exporter &&
rm -rf mysqld_exporter-0.12.1.linux-amd64 &&
rm -rf /data/apps/mysqld_exporter-0.12.1.linux-amd64.tar.gz > /dev/null &&
echo "删除mysqld_exporter压缩包完成" 
​
sh ./mysqld_exporter_uninstall.sh
​

​prometheus节点

vi mysqld_exporter_join.sh
​
#!/bin/bash
​
#对应被监控的node名称
NODENAME=$1
#对应被监控的IP地址
IPADDRESS=$2
echo "
  - job_name: "$NODENAME"
    static_configs:
      - targets: ["$IPADDRESS:9104"]
    " | tee -a /usr/local/prometheus/prometheus.yml > /dev/null &&
/usr/local/prometheus/promtool check config /usr/local/prometheus/prometheus.yml &&
curl  -X POST http://127.0.0.1:9090/-/reload
​
sh ./mysqld_exporter_join.sh NODENAME(对应被监控的node名称) IPADDRESS(对应被监控的IP地址)
​
相关推荐
JavaGuide4 小时前
公司来的新人用字符串存储日期,被组长怒怼了...
后端·mysql
怒放吧德德7 小时前
MySQL篇:MySQL主从集群同步延迟问题
后端·mysql·面试
Eip不易也不e8 小时前
教程之同时安装两个版本的 mysql
mysql
Kagol9 小时前
macOS 和 Windows 操作系统下如何安装和启动 MySQL / Redis 数据库
redis·后端·mysql
Qi妙代码11 小时前
MYSQL基础
数据库·mysql·oracle
llzcxdb11 小时前
【MySQL】理解MySQL的双重缓冲机制:Buffer Pool与Redo Log的协同之道
数据库·mysql
Allen Bright12 小时前
【MySQL基础-20】MySQL条件函数全面解析:提升查询逻辑的利器
数据库·mysql
dleei14 小时前
MySql安装及SQL语句
数据库·后端·mysql
信徒_14 小时前
Mysql 在什么样的情况下会产生死锁?
android·数据库·mysql
苹果酱056716 小时前
Golang标准库——runtime
java·vue.js·spring boot·mysql·课程设计