建立一個用於mysqld_exporter鏈接到MySQL的用戶並賦予所需的權限mysql
mysql> GRANT REPLICATION CLIENT, PROCESS ON *.* TO 'mysqld_exporter'@'localhost' identified by '000000'; mysql> GRANT SELECT ON performance_schema.* TO 'mysqld_exporter'@'localhost'; mysql> flush privileges;
建立一個用於鏈接MySQL的配置文件sql
mysqld_exporter默認會讀取~/.my.cnf
文件。這裏是建立在mysqld_exporter的安裝目錄下的。vim
$ vim /usr/local/prom/mysqld_exporter_0110/.my.cnf [client] user=mysqld_exporter password=000000
建立Systemd服務ide
#vim /etc/systemd/system/mysql_exporter.service
[Unit]
Description=mysql_exporter
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/prom/exporter/mysqld_exporter_0110/mysqld_exporter --config.my-cnf=/usr/local/prom/exporter/mysqld_exporter_0110/.my.cnf
Restart=on-failure
[Install]
WantedBy=multi-user.target
啓動mysqld_exporterspa
# systemctl start mysql_exporter
# systemctl status mysql_exporter
添加prometheus相關配置code
# vi prometheus280/prometheus.yml - job_name: 'mysql' static_configs: - targets: ['localhost:9104'] labels: instance: db1
重啓prometheus便可orm