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
# exporter对应授权账号,exporter123对应授权密码,localhost对应授权账号密码所在的地址
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