Prometheus+Grafana监控方案

tech2024-11-10  8

标题虚拟机安装centos7:

1、网络配置:

cd /etc/sysconfig/network-scripts vi ifcfg-ens33

      TYPE=Ethernet       PROXY_METHOD=none       BROWSER_ONLY=no       BOOTPROTO=static       DEFROUTE=yes       IPV4_FAILURE_FATAL=no       IPV6INIT=yes       IPV6_AUTOCONF=yes       IPV6_DEFROUTE=yes       IPV6_FAILURE_FATAL=no       IPV6_ADDR_GEN_MODE=stable-privacy       NAME=ens33       UUID=fb1029c5-4987-44c7-b535-0816c3805129       DEVICE=ens33       ONBOOT=yes       IPADDR=192.168.2.88       NETMASK=255.255.255.0       GATEWAY=192.168.2.1       DNS1=114.114.114.114       标黑的改变

2、永久关闭防火墙

命令描述systemctl status firewalld.service查看firewall状态systemctl start firewalld启动firewallsystemctl stop firewalld停止firewallsystemctl enable firewalld开机启动firewallsystemctl disable firewalld开机禁止firewall

一、安装grafana

1、命令安装

# 下载grafana安装包 wget https://dl.grafana.com/oss/release/grafana-6.5.2-1.x86_64.rpm # 本地安装 sudo yum localinstall grafana-6.5.2-1.x86_64.rpm

2、启动服务

# 开启grafana systemctl start grafana-server 设为开机启动 systemctl enable grafana-server

3、访问ip     访问IP加端口http://192.168.2.88:3000 ,输入用户名,密码登录系统。用户名与密码都是"admin"

二、安装Prometheus

1、解压

cd /usr/local tar -zxvf prometheus-2.6.1.linux-amd64.tar.gz

2、重命名

mv prometheus-2.6.1.linux-amd64 prometheus

3、配置

cd prometheus vi prometheus.yml

添加mysql的配置信息

# 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']

4、启动

# 从配置文件启动 ./prometheus --config.file=prometheus.yml &

然后访问:http://192.168.2.88:9090/,点击导航栏Status>Targets,即可看到刚才配置的mysql信息,因为还没安装mysql_exporter环境,所以存在错误

三、安装mysqld_exporter

1、解压

cd /usr/local tar zxvf mysqld_exporter-0.12.1.linux-amd64.tar.gz

2、重命名

mv mysqld_exporter-0.12.1.linux-amd64 mysqld_exporter

3、配置 在/usr/local/mysql_exporter 下创建一个.my.cnf 配置文件,写上创建的用户名和密码

[client] user=root password=root

4、启动

./mysqld_exporter --config.my-cnf=.my.cnf

再次访问Prometheus,刷新http://192.168.2.88:9090/targets,原先mysql的错误已经消失

四、node_exporter监控Linux

1、解压

tar zxvf node_exporter-0.18.1.linux-amd64.tar.gz

2、重命名

mv node_exporter-0.18.1.linux-amd64 node_exporter

3、启动

./node_exporter
最新回复(0)