Docker部署配置Prometheus

创建持久卷

1
2
3
docker volume create Prometheus_Data
docker volume inspect Prometheus_Data
sudo chown -R nobody:nogroup /var/lib/docker/volumes/Prometheus_Data/_data

创建容器

1
docker run --detach --name=Prometheus_Data --restart=always --publish 9090:9090 --volume /home/user/Prometheus_Data/prometheus.yml:/etc/prometheus/prometheus.yml --volume Prometheus_Data:/prometheus prom/prometheus --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=2y

修改--storage.tsdb.retention.time配置数据保存时长,默认为15天。

允许容器访问外部网络

1
sudo ufw allow in on docker0

更新容器脚本

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#!/bin/bash
set -e

out=$(docker pull prom/prometheus)

if [[ $out != *"up to date"* ]]; then
    docker stop Prometheus_Data
    docker rm -f Prometheus_Data
    docker run --detach --name=Prometheus_Data --restart=always --publish 9090:9090 --volume /home/user/Prometheus_Data/prometheus.yml:/etc/prometheus/prometheus.yml --volume Prometheus_Data:/prometheus prom/prometheus --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=2y
    
    docker image prune -f

    echo "Upgrade Success"
fi
Licensed under CC BY-NC-SA 4.0
最后更新于 Jul 31, 2021 04:16 CST