1、安装服务器
准备一台centos7服务器
安装官方文档:https://prometheus.io/docs/prometheus/latest/installation/
使用docker方式安装
先装新版docker
sudo yum install -y yum-utilssudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.reposudo yum install -y docker-cesudo systemctl start dockersudo systemctl enable docker
准备/etc/prometheus/prometheus.yml
这是一个最简单的配置:监控prometheus自身(https://prometheus.io/docs/prometheus/latest/getting_started/)
[root@centos7 etc]# cat /etc/prometheus/prometheus.ymlglobal:scrape_interval: 15s # By default, scrape targets every 15 seconds.# Attach these labels to any time series or alerts when communicating with# external systems (federation, remote storage, Alertmanager).external_labels:monitor: 'codelab-monitor'# A scrape configuration containing exactly one endpoint to scrape:# Here it's Prometheus itself.scrape_configs:# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.- job_name: 'prometheus'# Override the global default and scrape targets from this job every 5 seconds.scrape_interval: 5sstatic_configs:- targets: ['localhost:9090']
运行promtheus server
注:可以换成私有仓库地址,如192.168.37.100/devops-release-docker/prom/prometheus
docker run -d \-p 9090:9090 \--name prometheus \-v /etc/prometheus:/etc/prometheus \-v /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime \prom/prometheus
测试
docker ps 查看容器运行情况
在浏览器访问 http://ip:9090/targets
2、安装主机常用资源监控
就是安装node_exporter
https://github.com/prometheus/node_exporter
注,可以换成私有仓库地址:192.168.37.100/devops-release-docker/prom/node-exporter
docker run -d \--net="host" \--pid="host" \-v "/:/host:ro,rslave" \quay.io/prometheus/node-exporter \--path.rootfs=/host
修改server配置,增加监控项目
