项目所需工具:
链接:https://pan.baidu.com/s/1sIa8nninf2Fz6YqE3vUpqQ?pwd=5wr3
提取码:5wr3
–来自百度网盘超级会员V4的分享
目标:实现node_exporter插件的安装监控Linux指标
实施
上传安装
cd ~
rz
tar zxvf node_exporter-1.1.2.linux-amd64.tar.gz -C /opt/prometheus-2.26/
mv /opt/prometheus-2.26/node_exporter-1.1.2.linux-amd64 /opt/prometheus-2.26/node_exporter
注册
# 创建并编辑文件
vim /etc/systemd/system/node_exporter.service
[Unit]
Description=node_exporter
Documentation=Prometheus node_exporter plugin
[Service]
ExecStart=/opt/prometheus-2.26/node_exporter/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
启动
# 设置开机自启动
systemctl enable node_exporter
# 启动服务
systemctl start node_exporter
# 查看服务状态
systemctl status node_exporter
配置Prometheus
vim /opt/prometheus-2.26/prometheus.yml
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
# 增加以下内容
- job_name: 'linux'
static_configs:
- targets: ['localhost:9100']
labels:
instance: node1
重启prometheus
systemctl restart prometheus.service
验证:http://node1:9090
查看当前主机的CPU使用情况:node_cpu_seconds_total
查看当前主机的CPU负载情况 :node_load15
小结
目标:实现mysqld_exportor插件的安装监控MySQL指标
实施
上传安装
cd ~
rz
tar zxvf mysqld_exporter-0.13.0-rc.0.linux-amd64.tar.gz -C /opt/prometheus-2.26/
mv /opt/prometheus-2.26/mysqld_exporter-0.13.0-rc.0.linux-amd64/ /opt/prometheus-2.26/mysqld_exporter/
配置MySQL用户授权
mysql -uroot -p
SHOW VARIABLES LIKE 'validate_password%';
set global validate_password_policy=LOW;
set global validate_password_length=6;
# 授权
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'mysql_exporter'@'localhost' IDENTIFIED BY '123456' WITH MAX_USER_CONNECTIONS 3;
flush privileges;
注册服务
vim /etc/systemd/system/mysqld_exporter.service
[Unit]
Description=mysqld_exporter
Documentation=Prometheus mysql exporter plugin
[Service]
Type=simple
User=mysql
Environment=DATA_SOURCE_NAME=mysql_exporter:123456@(localhost:3306)/
ExecStart=/opt/prometheus-2.26/mysqld_exporter/mysqld_exporter --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.target
启动服务
# 设置开机自启动
systemctl enable mysqld_exporter
# 启动服务
systemctl start mysqld_exporter
# 查看服务状态
systemctl status mysqld_exporter
配置Prometheus
vim /opt/prometheus-2.26/prometheus.yml
scrape_configs:
# 增加以下内容
- job_name: 'mysql'
scrape_interval: 1s
static_configs:
- targets: ['localhost:9104']
labels:
instance: 'mysqld_exporter'
重启prometheus
systemctl restart prometheus.service
验证
mysql_exporter_collector_duration_seconds
小结