前言:
软件环境准备好:两台centos 7虚机(一个安装promethus、一个安装agent)
# 常用liunx命令
# 查看ip
ip a
# xshell拖拽上传文件
yum install -y lrzsz
# 安装git
yum install -y git
# 安装java环境
yum -y install java java-devel
# 安装 maven
yum -y install maven
# 安装 docker
yum -y install docker
yum install -y net-tools
1. 安装promethus
docker拉镜像
docker pull prom/node-exporter
docker pull prom/prometheus
docker pull grafana/grafana
启动node-exporter
docker run -d -p 9100:9100 \
-v "/proc:/host/proc:ro" \
-v "/sys:/host/sys:ro" \
-v "/:/rootfs:ro" \
--net="host" \
prom/node-exporter
netstat -anpt命令,查看端口起来没
访问 http://192.168.27.25:9100/
↓
如上所示,promethus搭建成功一半了
新建目录prometheus,编辑配置文件prometheus.yml
mkdir /opt/prometheus
cd /opt/prometheus/
vim prometheus.yml
prometheus.yml如下
global:
scrape_interval: 60s
evaluation_interval: 60s
scrape_configs:
- job_name: prometheus
static_configs:
- targets: ['localhost:9090']
labels:
instance: prometheus
- job_name: linux
static_configs:
- targets: ['192.168.27.25:9100']
labels:
instance: localhost
prometheus.yml
注意:修改IP地址,这里的192.168.27.25就是本机地址
启动 prometheus
docker run -d \
-p 9090:9090 \
-v /opt/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml \
prom/prometheus
访问:http://192.168.27.25:9090/graph
访问:http://192.168.27.25:9090/targets
2. 搭建grafana
新建空文件夹grafana-storage,用来存储数据
mkdir /opt/grafana-storage
设置权限 因为grafana用户会在这个目录写入文件,直接设置777,比较简单粗暴!
chmod 777 -R /opt/grafana-storage
chmod 777 /var/lib
启动grafana
docker run -d \
--privileged=true \
-p 3000:3000 \
--name=grafana \
-v /opt/grafana-storage:/var/lib/grafana \
grafana/grafana
访问 http://192.168.27.25:3000/ admin admin
后续步骤
点击下面的Save & Test,如果出现绿色的,说明ok了
3.监控java应用
准备:新虚机;jar包;test-remote-0.0.1-SNAPSHOT-exec.jar