#!/bin/bash echo '開始下載------node_exporter' wget https://github.com/prometheus/node_exporter/releases/download/v0.17.0/node_exporter-0.17.0.linux-amd64.tar.gz echo '下載完成,開始解壓 ------node_exporter' tar zxvf node_exporter-0.17.0.linux-amd64.tar.gz echo '解壓完成,把文件轉移到 /opt目錄下並把名稱改為 node_exporter' mv node_exporter-0.17.0.linux-amd64 /opt/node_exporter echo '進入/opt/node_exporter目錄' cd /opt/node_exporter echo '啟動node_exporter' nohup ./node_exporter & echo '開始下載------mysqld_exporter' wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.11.0/mysqld_exporter-0.11.0.linux-amd64.tar.gz echo '下載完成,開始解壓 ------mysqld_exporter' tar zxvf mysqld_exporter-0.11.0.linux-amd64.tar.gz echo '解壓完成,把文件轉移到 /opt目錄下並把名稱改為 mysqld_exporter' mv mysqld_exporter-0.11.0.linux-amd64 /opt/mysqld_exporter echo '運行mysqld_exporter需要連接到MySQL,需要授權' echo '需要提供mysql的賬號密碼' echo '先用root 賬號登錄mysql ' mysql -u root -p echo '輸入密碼登錄成功執行授權sql語句' grant replication client, process on *.* to user@"localhost" identified by "password"; grant select on performance_schema.* to mysql_monitor@"localhost"; echo '授權后進入mysqld_exporter安裝目錄創建.my.cnf配置文件,並運行mysqld_exporter ' cd /opt/mysqld_exporter echo '創建.my.cnf配置文件' vi .my.cnf < EOF i [client] user=user password=password ^[ :wq EOF echo '運行mysqld_exporter' nohup ./mysqld_exporter --config.my-cnf=.my.cnf & echo '開始下載------/prometheus' wget https://github.com/prometheus/prometheus/releases/download/v2.8.1/prometheus-2.8.1.linux-amd64.tar.gz echo '下載完成,開始解壓 ------/prometheus' tar zxvf prometheus-2.8.1.linux-amd64.tar.gz echo '解壓完成,把文件轉移到 /opt目錄下並把名稱改為 prometheus' mv prometheus-2.8.1.linux-amd64 /opt/prometheus echo '進入 /opt/prometheus目錄' cd /opt/prometheus echo '開始修改prometheus.yml文件' vim prometheus.yml < EOF i # my global config global: scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. # scrape_timeout is set to the global default (10s). # Alertmanager configuration alerting: alertmanagers: - static_configs: - targets: # - alertmanager:9093 # Load rules once and periodically evaluate them according to the global 'evaluation_interval'. rule_files: # - "first_rules.yml" # - "second_rules.yml" # A scrape configuration containing exactly one endpoint to scrape: # Here it's Prometheus itself. 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: ['localhost:9090'] - job_name: 'mysql' static_configs: - targets: ['localhost:9104'] labels: instance: 'db1' - job_name: 'node' static_configs: - targets: ['localhost:9100'] labels: instance: 'nd1' ^[ :wq EOF echo '配置文件修改完成,開始運行prometheus系統' nohup ./prometheus --config.file=./prometheus.yml & echo '瀏覽器訪問 服務器的9090端口可以訪問prometheus的頁面'