监控插件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
# 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

  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
posted @ 2020-11-16 15:23  SunFree  阅读(5935)  评论(0编辑  收藏  举报