快速启动一个 prometheus 和 grafana
快速创建一个可用的 prometheus 和 grafana 进行测试, 并将数据保留在当前的目录中, 在重启之后数据不会丢失:
创建一个目录.
mkdir /opt/monitor mkdir /opt/monitor/grafana mkdir /opt/monitor/grafana_data mkdir /opt/monitor/prometheus mkdir /opt/monitor/prometheus_data touch /opt/monitor/docker-compose.yaml
创建docker-compose 文件
--- version: "3" services: prometheus: container_name: prometheus image: reg.liarlee.site/docker.io/prom/prometheus:latest restart: always network_mode: host environment: - TZ=Asia/Shanghai volumes: # - /opt/monitor/prometheus/prometheus.yaml:/etc/prometheus/prometheus.yml - /opt/monitor/prometheus_data:/prometheus command: - '--config.file=/etc/prometheus/prometheus.yml' - '--storage.tsdb.path=/prometheus' - '--web.console.libraries=/usr/share/prometheus/console_libraries' - '--web.console.templates=/usr/share/prometheus/consoles' - '--storage.tsdb.retention.time=90d' grafana: container_name: grafana image: reg.liarlee.site/docker.io/grafana/grafana-oss:main-ubuntu restart: always network_mode: host environment: - TZ=Asia/Shanghai volumes: - /opt/monitor/grafana_data:/var/lib/grafana - /opt/monitor/grafana/datasource:/etc/grafana/provisioning/datasources # - /opt/monitor/grafana/grafana.ini:/etc/grafana/grafana.ini - /etc/localtime:/etc/localtime:ro user: '472'
准备基础配置文件
docker compose up -d docker cp grafana:/etc/grafana/grafana.ini /opt/monitor/grafana/grafana.ini docker cp prometheus:/etc/prometheus/prometheus.yml /opt/monitor/prometheus/prometheus.yaml chown -R 472:472 /opt/monitor/grafana_data chown -R 472:472 /opt/monitor/grafana chown -R nobody:nobody /opt/monitor/prometheus_data chown -R nobody:nobody /opt/monitor/prometheus docker compose down --remove-orphans
准备prometheus 作为默认的Datasource
touch /opt/monitor/grafana/datasource/datasource.yml --- apiVersion: 1 datasources: - name: Prometheus type: prometheus url: http://localhost:9090 isDefault: true access: proxy editable: true
修改配置文件中需要的参数, 取消配置文件中的注释, 然后重启即可。
docker compose down --remove-orphans && docker compose up -d
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Liarlee's Notebook!