docker-compose.yml 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. services:
  2. prometheus:
  3. image: registry.cn-chengdu.aliyuncs.com/reghao/prometheus:2.54.1
  4. container_name: prometheus
  5. restart: always
  6. ports:
  7. - "9090:9090"
  8. command:
  9. - '--config.file=/etc/prometheus/prometheus.yml'
  10. # 极致内存优化参数:控制内存中缓存的数据块数量
  11. - '--storage.tsdb.min-block-duration=2h'
  12. - '--storage.tsdb.max-block-duration=2h'
  13. # 减少历史保留时间,节省资源
  14. - '--storage.tsdb.retention.time=7d'
  15. - '--web.enable-admin-api'
  16. - '--web.enable-lifecycle'
  17. volumes:
  18. - /etc/localtime:/etc/localtime:ro
  19. - /opt/docker/prometheus/conf/prometheus.yml:/etc/prometheus/prometheus.yml
  20. - /opt/docker/prometheus/rules:/etc/prometheus/rules
  21. - /opt/docker/prometheus/data:/prometheus
  22. # 限制资源使用
  23. deploy:
  24. resources:
  25. limits:
  26. cpus: '0.5' # 最高使用 0.5 核
  27. memory: 512M # 强制上限
  28. reservations:
  29. memory: 128M # 启动预留
  30. logging:
  31. driver: "json-file"
  32. options:
  33. max-size: "10m" # 单个日志文件最大 10MB
  34. max-file: "3" # 最多保留 3 个归档文件
  35. grafana:
  36. image: registry.cn-chengdu.aliyuncs.com/reghao/grafana_grafana-oss:11.2.2
  37. container_name: grafana
  38. user: root # 相当于 -u root
  39. privileged: true
  40. restart: always
  41. ports:
  42. - "3000:3000"
  43. volumes:
  44. - /etc/localtime:/etc/localtime:ro
  45. - /opt/docker/grafana/data:/var/lib/grafana
  46. # --- 资源限制 ---
  47. deploy:
  48. resources:
  49. limits:
  50. cpus: '0.5'
  51. memory: 256M
  52. reservations:
  53. memory: 128M
  54. # --- 日志限制 ---
  55. logging:
  56. driver: "json-file"
  57. options:
  58. max-size: "10m"
  59. max-file: "2"