1. 下载 Prometheus
https://prometheus.io/download/
1 | yum install net-tools vim superviosr wget -y |
2 | cd /opt/ |
3 | useradd -s /usr/sbin/nologin prometheus |
4 | wget https://github.com/prometheus/prometheus/releases/download/v2.4.3/prometheus-2.4.3.linux-amd64.tar.gz |
5 | tar -xvf prometheus-2.4.3.linux-amd64.tar.gz |
6 | ln -s prometheus-2.4.3.linux-amd64 prometheus |
7 | |
8 | cat > /etc/supervisord.d/prometheus.ini << EOF |
9 | command=/opt/prometheus/prometheus --storage.tsdb.retention=90d --config.file=/opt/prometheus/prometheus.yml |
10 | user=prometheus |
11 | autostart = true |
12 | autorestart=true |
13 | redirect_stderr=true |
14 | directory=/opt/prometheus |
15 | stdout_logfile=/opt/prometheus/sprometheus.log |
16 | stdout_logfile_maxbytes=20MB |
17 | EOF |
2. node
1 | cd /opt/ |
2 | wget https://github.com/prometheus/node_exporter/releases/download/v0.16.0/node_exporter-0.16.0.linux-amd64.tar.gz |
3 | tar -xvf node_exporter-0.16.0.linux-amd64.tar.gz |
4 | ln -s node_exporter-0.16.0.linux-amd64 node_exporter |
https://github.com/percona/grafana-dashboards
3. 监控 MySQL
https://prometheus.io/docs/visualization/grafana/
1 | wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.11.0/mysqld_exporter-0.11.0.linux-amd64.tar.gz |
授权
1 | CREATE USER 'exporter'@'127.0.0.1' IDENTIFIED BY '3Xporter' WITH MAX_USER_CONNECTIONS 3; |
2 | GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'127.0.0.1'; |
1 | |
2 | cat > /etc/supervisord.d/prometheus_export.ini << EOF |
3 | [program:p_mysql] |
4 | command=/opt/mysqld_exporter/mysqld_exporter |
5 | autostart = true |
6 | autorestart=true |
7 | redirect_stderr=true |
8 | stdout_logfile=/dev/stdout |
9 | stdout_logfile_maxbytes=0 |
10 | environment=DATA_SOURCE_NAME='exporter:3Xporter@(localhost:3306)/' |
11 | [program:p_os] |
12 | command=/opt/node_exporter/node_exporter |
13 | autostart = true |
14 | autorestart=true |
15 | redirect_stderr=true |
16 | stdout_logfile=/dev/stdout |
17 | stdout_logfile_maxbytes=0 |
18 | EOF |
19 | |
20 | |
21 | |
22 | supervisorctl reload |
23 | supervisorctl status |