大数据集群监控配置操作指导(二)node_exporter+mysql_exporter部署
2.node_exporter监控集群服务器(所有集群服务器)
wget https://github.com/prometheus/node_exporter/releases/download/v1.3.1/node_exporter-1.3.1.linux-amd64.tar.gz
tar -zxvf node_exporter-1.3.1.linux-amd64.tar.gz -C /opt/dtstack/exporters/
mv node_exporter-1.3.1.linux-amd64 node_exporter-1.3.1
2.1可以直接启动,同样也可以配置成服务方便管理
直接启动命令
./node_exporter
2.2配置成服务
vim /etc/systemd/system/node_exporter.service
[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
User=root
ExecStart=/opt/software/exporters/node_exporter-1.3.1/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
2.3将node_exporter的目录,和node_exporter.service文件分发到其他服务器上
2.4使node_exporter 服务生效(所有服务器)
systemctl daemon-reload
2.5启动node_exporter服务,并配置开机自启(所有服务器)
systemctl start node_exporter
systemctl status node_exporter
systemctl enable node_exporter
2.6更改prometheus的配置文件
vim /opt/dtstack/prometheus-2.33.3/prometheus.yml
增加
- job_name: 'node_exporter'
static_configs:
- targets:
- 'db001:9100'
- 'db002:9100'
- 'db003:9100'
- 'db004:9100'
2.7重启prometheus
systemctl restart prometheus
2.8查看配置是否生效,要进入prometheus的web界面进入status,选择targets看到node_exporter存在,并且状态是up说明已经成功
3.mysql暴露监控指标
3.1下载监控mysql的mysql_exporter,安装在mysql服务所在服务器上,然后解压安装包
cd /opt/dtstack/exporters
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.13.0/mysqld_exporter-0.13.0.linux-amd64.tar.gz
tar -zxvf mysqld_exporter-0.13.0.linux-amd64.tar.gz -C /opt/dtstack/exporters/
mv mysqld_exporter-0.13.0.linux-amd64 mysqld_exporter-0.13
cd mysqld_exporter-0.13
3.2登录mysql,创建exporter用户
CREATE USER 'exporter'@'%' IDENTIFIED BY 'exporter';
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'%';
FLUSH PRIVILEGES;
3.3创建mysql配置文件、运行时可免密码连接数据库:
vim /opt/dtstack/exporters/mysqld_exporter-0.13/.my.cnf
[client]
user=exporter
password=exporter
3.4给mysql_exporter赋权
useradd mysql
chown -R mysql:mysql /opt/software/exporters/mysqld_exporter-0.13
3.5将mysql_exporter配置成服务
vim /etc/systemd/system/mysql_exporter.service
[Unit]
Description=mysql_exporter
Documentation=https://prometheus.io/
After=network.target
[Service]
User=mysql
Restart=on-failure
WorkingDirectory=/opt/dtstack/exporters/mysqld_exporter-0.13
ExecStart=/opt/dtstack/exporters/mysqld_exporter-0.13/mysqld_exporter \
--config.my-cnf=/opt/dtstack/exporters/mysqld_exporter-0.13/.my.cnf
[Install]
WantedBy=multi-user.target
3.6启动服务,配置开机自启
systemctl daemon-reload
systemctl start mysql_exporter
systemctl status mysql_exporter
systemctl enable mysql_exporter
3.7查看mysql_exporter的端口
netstat -ntpl | grep mysql
3.8修改prometheus的配置文件
vim /opt/dtstack/prometheus-2.33.3/prometheus.yml
- job_name: 'mysql_master'
static_configs:
- targets: ['db004:9104']
labels:
service_name: 'mysql_master'
product_name: 'mysql'
systemctl restart prometheus
systemctl status prometheus