二唉地、容器方式運(yùn)行
安裝prometheus
先確保機(jī)器上已經(jīng)安裝了docker
推薦使用docker-compose嫩痰,方便管理配置
# vim /usr/local/docker/prometheus_docker/docker-compose.yml
version: '3.9'
services:
prometheus:
image: 'bitnami/prometheus:2.48.1'
user: root
container_name: prometheus
restart: always
ports:
- '9090:9090'
volumes:
- './conf/prometheus.yml:/opt/bitnami/prometheus/conf/prometheus.yml'
- './data:/opt/bitnami/prometheus/data'
command:
- '--config.file=/opt/bitnami/prometheus/conf/prometheus.yml'
- '--web.enable-lifecycle'
- '--storage.tsdb.path=/opt/bitnami/prometheus/data'
- '--storage.tsdb.retention.time=7d'
- '--web.max-connections=512'
- '--web.read-timeout=3m'
- '--query.max-concurrency=25'
- '--query.timeout=2m'
期間遇到的問題:
1遵堵、did not find expected key
docker-compose縮進(jìn)格式的問題
2晚伙、err="open /opt/bitnami/prometheus/data/queries.active: permission denied"
容器內(nèi)/data屬主是root位隶,而宿主機(jī)/data屬主是root拷窜,docker-compose.yml中指定用戶 user: root
啟動(dòng)
# docker-compose up -d
訪問ip:9090查看Web UI
node_exporter安裝
node_exporter也可以用容器運(yùn)行,映射9100端口
# vim /usr/local/docker/node_exporter_docker/docker-compose.yml
version: '3.9'
services:
node_exporter:
image: 'bitnami/node-exporter:1.7.0'
container_name: node_exporter
restart: always
network_mode: 'host'
pid: 'host'
ports:
- '9100:9100'
volumes:
- '/proc:/host/proc:ro'
- '/sys:/host/sys:ro'
- '/:/rootfs:ro'
需要將宿主機(jī)的 /proc涧黄、/sys 等目錄掛載到容器內(nèi)篮昧,從而讓node_exporter能夠訪問到宿主機(jī)的信息
不然只是對(duì)容器的信息進(jìn)行采集
啟動(dòng)
# docker-compose up -d
在prometheus機(jī)器上prometheus.yml添加
# vim /usr/local/docker/prometheus_docker/data/prometheus.yml
添加
- job_name: "docker_node_exporter"
static_configs:
- targets: ["ip:9100"]
重啟prometheus容器
# docker restart 容器ID
訪問prometheus的ip:9090 Status-->Targets中看到監(jiān)控的對(duì)象多了docker_node_exporter
安裝grafana
# vim /usr/local/docker/grafana_docker/docker-compose.yml
version: '3.9'
services:
grafana:
image: 'grafana/grafana:10.2.2'
container_name: grafana
restart: always
ports:
- '3000:3000'
volumes:
- 'grafana_data:/var/lib/grafana'
volumes:
grafana_data:
需要?jiǎng)?chuàng)建一個(gè)volumes,將grafana數(shù)據(jù)目錄掛載進(jìn)去,實(shí)現(xiàn)持久化笋妥。
訪問ip:3000
默認(rèn)admin/admin
進(jìn)入后add your fiirst data source
選擇prometheus
根據(jù)需求填寫