1. 程式人生 > 實用技巧 >監控外掛mysqld_exporter的安裝及部署

監控外掛mysqld_exporter的安裝及部署

mysqld_exporter的安裝及部署

前提安裝mariadb

  1. 安裝命令 yum -y install mariadb mariadb-server
  2. 安裝完成MariaDB,首先啟動MariaDB systemctl start mariadb
  3. 設定開機啟動 systemctl enable mariadb
  4. 取消開機啟動 systemctl disable mariadb

在當前資料庫中增加授權

  1. 授權命令 GRANT PROCESS, REPLICATION CLIENT, SELECT ON . TO 'exporter'@'localhost' IDENTIFIED BY 'exporter123' WITH MAX_USER_CONNECTIONS 3;
  2. 重新整理 flush privileges;

安裝mysqld_exporter

  1. 進入目錄 cd /usr/local/prometheus/
  2. 下載 wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz
  3. 解壓 tar xzvf mysqld_exporter-0.12.1.linux-amd64.tar.gz
  4. 修改目錄名 mv mysqld_exporter-0.12.1.linux-amd64 mysqld_exporter
  5. 修改使用者及組 chown -R root:root /usr/local/prometheus/mysqld_exporter/mysqld_exporter
  6. 修改許可權 chmod 755 /usr/local/prometheus/mysqld_exporter/mysqld_exporter

新增mysqld_exporter為系統服務

  1. 進入目錄新建mysqld_exporter.service檔案 vim /usr/lib/systemd/system/mysqld_exporter.service
# vim /usr/lib/systemd/system/mysqld_exporter.service
[Unit]
Description=mysqld_exporter
After=network.target
[Service]
Type=simple
User=mysql
Environment=DATA_SOURCE_NAME=exporter:exporter123@(localhost:3306)/
ExecStart=/usr/local/prometheus/mysqld_exporter/mysqld_exporter --web.listen-address=0.0.0.0:9104 
  --config.my-cnf /etc/my.cnf \
  --collect.slave_status \
  --collect.slave_hosts \
  --log.level=error \
  --collect.info_schema.processlist \
  --collect.info_schema.innodb_metrics \
  --collect.info_schema.innodb_tablespaces \
  --collect.info_schema.innodb_cmp \
  --collect.info_schema.innodb_cmpmem 
Restart=on-failure
[Install]
WantedBy=multi-user.targe

啟動mysqld_exporter

  1. 修改使用者及組 chown -R root:root /usr/lib/systemd/system/mysqld_exporter.service
  2. 修改許可權 chmod 644 /usr/lib/systemd/system/mysqld_exporter.service
  3. 重新載入 systemctl daemon-reload
  4. 開機啟動服務 systemctl enable mysqld_exporter.service
  5. 啟動服務 systemctl start mysqld_exporter.service