文章目录
- 一、Prometheus的安装和运行
- 1、使用docker拉取镜像
- 2、创建prometheus.yml文件
- 3、启动容器
- 4、查看启动是否成功
- 5、记录安装过程中出现的错误
- 二、Grafana的安装和运行
- 1、使用docker拉取镜像
- 2、创建grafana
- 3、运行grafana
- 4、查看grafana运行日志
- 5、登录grafana
一、Prometheus的安装和运行
1、使用docker拉取镜像
sudo docker pull prom/prometheus
2、创建prometheus.yml文件
vim /etc/prometheus/prometheus.yml
编写yml文件
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
3、启动容器
sudo docker run -d --name prometheus -p 9090:9090 -v /home/ubuntu/promdata/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus
4、查看启动是否成功
5、记录安装过程中出现的错误
错误原因:yaml格式不正确,yaml有自己严格的格式要求
ubuntu@VM-24-12-ubuntu:~/promdata$ sudo docker logs prometheus
ts=2023-04-04T04:14:49.067Z caller=main.go:468 level=error msg="Error loading config (--config.file=/etc/prometheus/prometheus.yml)" file=/etc/prometheus/prometheus.yml err="parsing YAML file /etc/prometheus/prometheus.yml: yaml: line 5: did not find expected '-' indicator"
二、Grafana的安装和运行
1、使用docker拉取镜像
docker pull grafana/grafana
2、创建grafana
mkdir /home/ubuntu/grafana/
chmod 777 /home/ubuntu/grafana/
3、运行grafana
sudo docker run -d -p 3000:3000 --name=grafana -v /home/ubuntu/grafana:/var/lib/grafana grafana/grafana
ubuntu@VM-24-12-ubuntu:~$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2033249700e7 grafana/grafana "/run.sh" 6 seconds ago Up 6 seconds 0.0.0.0:3000->3000/tcp, :::3000->3000/tcp grafana
1a85fed12fda prom/prometheus "/bin/prometheus --c…" 10 hours ago Up 10 hours 0.0.0.0:9090->9090/tcp, :::9090->9090/tcp prometheus
08b43ae8cdc6 redis:alpine "docker-entrypoint.s…" 3 months ago Up 3 months 6379/tcp myredis
30c5b2ac7355 mariadb:latest "docker-entrypoint.s…" 3 months ago Up 3 months 0.0.0.0:8011->3306/tcp, :::8011->3306/tcp mydb
4、查看grafana运行日志
sudo docker logs -f grafana
5、登录grafana
http://82.156.178.xxx:3000/
输入用户名密码: admin admin