时间:2021-07-01 10:21:17 帮助过:25人阅读
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: ‘prometheus‘
# metrics_path defaults to ‘/metrics‘
# scheme defaults to ‘http‘.
static_configs:
- targets: [‘10.20.1.63:9090‘]
- job_name: ‘local_node‘
static_configs:
- targets: [‘10.20.1.63:9100‘]
labels:
instance: prometheus_node
- job_name: ‘mysql01‘
static_configs:
- targets: [‘10.20.10.18:9104‘]
labels:
instance: db1
- job_name: ‘mysql02‘
static_configs:
- targets: [‘10.20.10.19:9104‘]
labels:
instance: db2
wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
mkdir -p /opt/prometheus
tar xzvf node_exporter-0.18.1.linux-amd64.tar.gz
mv node_exporter-0.18.1.linux-amd64 /opt/prometheus/
ln -s /opt/prometheus/node_exporter-0.18.1.linux-amd64/ /opt/prometheus/node_exporter
添加系统服务启动.
先创建prometheus用户,用于启动node_exporter。
useradd -s /sbin/nologin -M prometheus
vim /usr/lib/systemd/system/node_exporter.service
[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/opt/prometheus/node_exporter/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
启动node_exporter服务
systemctl status node_exporter.service
2) 安装mysqld_exporter
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz
mkdir -p /opt/prometheus
mv /usr/local/mysqld_exporter-0.12.1.linux-amd64/ /opt/prometheus/
ln -s /opt/prometheus/mysqld_exporter-0.12.1.linux-amd64/ /opt/prometheus/mysqld_exporter
chown -R prometheus:prometheus /opt/prometheus/
添加系统服务启动.
先创建prometheus用户,用于启动mysqld_exporter。
useradd -s /sbin/nologin -M prometheus
vim /usr/lib/systemd/system/mysqld_exporter.service
[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/opt/prometheus/mysqld_exporter/mysqld_exporter --config.my-cnf=/opt/prometheus/mysqld_exporter/.my.cnf
Restart=on-failure
[Install]
WantedBy=multi-user.target
启动参数:--config.my-cnf=".my.cnf" #指定配置文件
启动mysqld_exporter服务
systemctl status mysqld_exporter.service
mysqld_exporter需要连接到Mysql,所以需Mysql的权限,创建mysql_exporter用户并赋予所需的权限。
mysql> GRANT REPLICATION CLIENT,PROCESS ON *.* TO ‘mysql_exporter‘@‘localhost‘ identified by ‘xxxxxx‘;
mysql> GRANT SELECT ON *.* TO ‘mysql_exporter‘@‘localhost‘;
创建.my.cnf文件,并重启mysqld_exporter服务。
vim /opt/prometheus/mysqld_exporter/.my.cnf
[client]
user=mysql_exporter
password=xxxxxx
Prometheus+Grafana可视化监控MySQL
标签:可视化监控 time 启动 default any 服务 mys network usr