机器预配置修改IP为静态IP(自由配置)
BOOTPROTO=static
IPADDR=192.168.223.9
NETMASK=255.255.255.0
DNS1=8.8.8.8
DNS2=114.114.114.114
GATEWAY=192.168.223.2
重启network
systmctl restart network
1.Prometheus包下载
wget https://github.com/prometheus/prometheus/releases/download/v2.5.0/prometheus-2.5.0.linux-amd64.tar.gz
2.解压
3.启动Prometheus(要进入解压缩后的文件夹里)
./prometheus --config.file="prometheus.yml" &
4.检查端口查看是否启动
ss -naltp | grep 9090
或者
lsof -i:9090
5.检查防火墙状态
systemctl status firewalld.service
5.如果是启动状态就关闭防火墙
systemctl stop firewalld.service
6.访问Prometheus服务,安装完毕
http://localhost:9090
7.下载被监控主机所需的node包
wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
8.解压node包
tar xf node_exporter-0.18.1.linux-amd64.tar.gz
9.启动node服务,nohup持续运行,&后台运行,后台持续运行
nohup node_exporter-1.0.0-rc.0.linux-amd64/node_exporter &
10.检查端口占用确定是否启动
lsof -i:9100
11.查看node节点收集到的本机数据
http://node节点IP:9100/metrics
12.去prometheus机器添加node机器配置,从而可以拉取到node收集到的数据(注意yml文件格式一定要正确)
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: 'agent'
static_configs:
- targets: ['192.168.223.7:9100']
13.agent机器安装mysql_exporter组件监控mysql服务,并安装mysql服务
MariaDB [(none)]> grant select,replication client,process ON *.* to 'mysql_monitor'@'localhost' identified by '123';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit
先下载好rpm包
sudo yum install grafana-6.7.0-1.x86_64.rpm // 下载包
rpm -ivh grafana-6.7.0-1.x86_64.rpm //安装
systemctl start grafana-server.service //启动
lsof -i:3000 // 查看端口占用
访问web页
http://prometheus机器ip:3000/
json文件导入后点import完成到处,就能查看到数据了
ntpdate cn.ntp.org.cn // 同步时间
date // 查看当前时间
设置告警提示