侧边栏壁纸
博主头像
平凡的运维之路博主等级

行动起来,活在当下

  • 累计撰写 49 篇文章
  • 累计创建 25 个标签
  • 累计收到 3 条评论

目 录CONTENT

文章目录

基础篇-Docker安装Prometheus

平凡的运维之路
2024-08-01 / 0 评论 / 0 点赞 / 66 阅读 / 7173 字

Docker安装Prometheus

详细操作

  • 安装docker服务
yum -y install gcc gcc-c++ yum-utils
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum -y install docker-ce docker-ce-cli containerd.io

systemctl start docker
systemctl status docker
docker --version

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://cz1numin.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
  • 下载相关镜像
docker pull prom/node-exporter
docker pull prom/mysqld-exporter
docker pull prom/alertmanager
docker pull oliver006/redis_exporter 
docker pull prom/prometheus
docker pull grafana/grafana
  • 启动相关容器
docker run -d --name node-exporter \
--restart=always -p 9100:9100 \
-v /proc:/host/proc:ro \
-v /sys:/host/sys:ro \
-v /:/rootfs:ro prom/node-exporter

docker run -d --name mysqld_exporter \
--restart=always -p 9104:9104 \
-e DATA_SOURCE_NAME="ucds:ucds@(192.168.27.52:3306)/"  \
prom/mysqld-exporter

#不带密码
docker run -d --name redis_exporter -p 9121:9121 oliver006/redis_exporter --redis.addr redis://192.168.27.44:27001
 
# 带密码
docker run -d --name redis_exporter -p 9121:9121 oliver006/redis_exporter --redis.addr redis://192.168.27.44:27001 --redis.password 'abc123'


docker network inspect      bridge|grep IPv4Address
                "IPv4Address": "172.17.0.3/16",
                "IPv4Address": "172.17.0.4/16",
                "IPv4Address": "172.17.0.2/16",

mkdir /opt/prometheus
cd /opt/prometheus/
vim prometheus.yml
global:
  scrape_interval:     60s
  evaluation_interval: 60s
 
scrape_configs:
 
  - job_name: prometheus
    static_configs:
      - targets: ['localhost:9090']
        labels:
          instance: prometheus
 
  - job_name: node
    static_configs:
      - targets: ['172.17.0.2:9100']
        labels:
          instance: node-exporter
 
  - job_name: redis
    static_configs:
      - targets: ['172.17.0.4:9121']
        labels:
          instance: redis_exporter
 
  - job_name: mysqld
    static_configs:
      - targets: ['172.17.0.3:9104']
        labels:
          instance: mysql-exporter

docker run  -d --name prometheus --restart=always -p 9090:9090 -v /opt/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus


mkdir /opt/grafana-storage
chmod 777 -R /opt/grafana-storage
docker run -d --name grafana --restart=always  \
 -p 3000:3000 --name=grafana  \
 -v /opt/grafana-storage:/var/lib/grafana grafana/grafana
 
 
mkdir /opt/alertmanager-storage
vim /opt/alertmanager-storage/alertmanager.yml
# 相关路由规则
route:
  group_by: [...] # 分组, ... 表示不分组
  group_wait: 60s # 同一组 告警 需要等待多少s才能发出
  group_interval: 5m # 同一组的多批次告警间隔多少秒后,才能发出
  repeat_interval: 1h  # 重复告警要等待多久后才能再次发出去,目的是为了避免重复的消息发送多次
  receiver: 'web.hook' # receiver名称,对应 receivers.name
 
# 配置报警方式
receivers:
  - name: 'web.hook'
    webhook_configs:
      # 通知url
      - url: 'http://192.168.1.30:9094/alert/card'

docker run -d --name alertmanager \
-p 9093:9093 \
-m 200m \
-v /etc/localtime:/etc/localtime \
-v /opt/alertmanager-storage:/data \
-v /opt/alertmanager-storage/alertmanager.yml:/etc/alertmanager/alertmanager.yml \
prom/alertmanager

访问Grafana

导入模版,常用Grafana Dashboard ID

  • 常用Grafana Dashboard ID
应用名称 Dashboard ID
Redis 11835
Node 12884
Elasticsearch 14191
rabbitmq 4371
kafka 7589
blackbox 13230 域名证书到期监控
postgres 9628
mysql 7362
process exporter 249
blackbox_exporter 13659 黑盒探针
0

评论区