監控外掛mysqld_exporter的安裝及部署
阿新 • • 發佈:2020-11-16
mysqld_exporter的安裝及部署
前提安裝mariadb
- 安裝命令 yum -y install mariadb mariadb-server
- 安裝完成MariaDB,首先啟動MariaDB systemctl start mariadb
- 設定開機啟動 systemctl enable mariadb
- 取消開機啟動 systemctl disable mariadb
在當前資料庫中增加授權
- 授權命令 GRANT PROCESS, REPLICATION CLIENT, SELECT ON . TO 'exporter'@'localhost' IDENTIFIED BY 'exporter123' WITH MAX_USER_CONNECTIONS 3;
- 重新整理 flush privileges;
安裝mysqld_exporter
- 進入目錄 cd /usr/local/prometheus/
- 下載 wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz
- 解壓 tar xzvf mysqld_exporter-0.12.1.linux-amd64.tar.gz
- 修改目錄名 mv mysqld_exporter-0.12.1.linux-amd64 mysqld_exporter
- 修改使用者及組 chown -R root:root /usr/local/prometheus/mysqld_exporter/mysqld_exporter
- 修改許可權 chmod 755 /usr/local/prometheus/mysqld_exporter/mysqld_exporter
新增mysqld_exporter為系統服務
- 進入目錄新建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
- 修改使用者及組 chown -R root:root /usr/lib/systemd/system/mysqld_exporter.service
- 修改許可權 chmod 644 /usr/lib/systemd/system/mysqld_exporter.service
- 重新載入 systemctl daemon-reload
- 開機啟動服務 systemctl enable mysqld_exporter.service
- 啟動服務 systemctl start mysqld_exporter.service