prometheus 运行命令配置


#!/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的页面'

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM