# 卸载旧版本
yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-selinux docker-engine-selinux docker-engine
# 安装依赖
yum install -y yum-utils device-mapper-persistent-data lvm2
# 添加Repo
yum-config-manager --add-repo https://mirrors.ustc.edu.cn/docker-ce/linux/centos/docker-ce.repo
# 更新并安装
yum makecache
yum install -y docker-ce
# 启动&自启动
systemctl start docker
systemctl enable docker
# 配置docker镜像加速
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io
systemctl restart docker
# 建立文件
mkdir -p /ops/prometheus-data && cd /ops/prometheus-data
vi /ops/prometheus-data/prometheus.yml
# 添加如下内容后保存
global:
scrape_interval: 15s
external_labels:
monitor: 'codelab-monitor'
scrape_configs:
- job_name: 'prometheus'
scrape_interval: 5s
static_configs:
- targets: ['localhost:9090']
# 创建文件夹
mkdir -p /ops/promerheus-data
# 取得nobody的uid
docker run --rm quay.io/prometheus/busybox cat /etc/passwd
···
nobody:x:65534:65534:nobody:/home:/bin/false
# 配置文件夹权限
chown 65534:65534 -R /ops/prometheus-data
# 启动
docker run --name prometheus -d \
-p 9090:9090 \
--restart=always \
-v /ops/prometheus-data:/prometheus-data \
quay.io/prometheus/prometheus \
--config.file=/prometheus-data/prometheus.yml \
--storage.tsdb.path=/prometheus-data/
# 如果配置文件有改动,重启Prometheus容器
docker ps | grep prometheus | awk '{print $1}' | xargs docker restart
firewall-cmd --add-port=9090/tcp --permanent
firewall-cmd --reload