Implantação e uso do Prometheus
1. Implantar em modo binário
1.1. Instale o prometheus
1.下载软件包
[root@prometheus-server ~]# wget https://github.com/prometheus/prometheus/releases/download/v2.23.0/prometheus-2.23.0.linux-amd64.tar.gz
2.安装
[root@prometheus-server ~]# mkdir /data/ -p
[root@prometheus-server ~]# tar xf prometheus-2.23.0.linux-amd64.tar.gz -C /data/
[root@prometheus-server ~]# mv /data/prometheus-2.23.0.linux-amd64 /data/prometheus
3.将可执行程序移动到/usr/bin
[root@prometheus-server ~]# lscd /data/prometheus
[root@prometheus-server prometheus]# cp prom* /usr/bin/
[root@prometheus-server prometheus]# prometheus --version
prometheus, version 2.23.0 (branch: HEAD, revision: 26d89b4b0776fe4cd5a3656dfa520f119a375273)
build user: root@37609b3a0a21
build date: 20201126-10:56:17
go version: go1.15.5
platform: linux/amd64
1.2. Inicie o prometheus
Parâmetros de inicialização comuns
-config.file = "/ data / prometheus / prometheus.yml" // Especifique o caminho do arquivo de configuração--Web.enable-lifecycle // Habilita a configuração do hot reload da web
--Storage.tsdb.path = // Especifique o caminho do banco de dados tsdb, o padrão é data /
--Storage.tsdb.retention.time = // Especifique por quanto tempo o tsdb retém os dados, o padrão é 15d
启动prometheus
[root@prometheus-server ~]# prometheus --config.file="/data/prometheus/prometheus.yml" --web.enable-lifecycle &
1.3. Use systemctl para iniciar o Prometheus
Grave o arquivo systemctl, especifique o caminho de tsdb ao gravar o comando de inicialização
1.编写文件
[root@prometheus-server system]# cd /usr/lib/systemd/system
[root@prometheus-server system]# vim prometheus.service
[Unit]
Description=https://prometheus.io
[Service]
Restart=on-failure
ExecStart=/data/prometheus/prometheus --config.file=/data/prometheus/prometheus.yml --web.enable-lifecycle --storage.tsdb.path=/data/prometheus/data
[Install]
WantedBy=multi-user.target
2.加载system配置以及启动服务
[root@prometheus-server system]# systemctl daemon-reload
[root@prometheus-server system]# systemctl start prometheus.service
[root@prometheus-server system]# systemctl enable prometheus.service
3.查看进程
[root@prometheus-server system]# ps aux | grep prome
1.4. Acessar prometheus
Visite: http: // loclahost: 9090
Visualize a página do host de monitoramento
status—> alvos
1.5. Modifique o endereço prometheus da página do host de monitoramento para o endereço IP real
1.修改配置,找到targets一行,将localhost修改为真实地址即可
[root@prometheus-server ~]# vim /data/prometheus/prometheus.yml
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['192.168.81.210:9090']
2.加载配置
由于启动增加了--web.enable-lifecycle,因此可以使用配置加载功能
[root@prometheus-server ~]# curl -XPOST 192.168.81.210:9090/-/reload
Clique no link abaixo do endpoint para ver a métrica da metris
2. Docker implanta prometheus
2.1. Instale o docker
1.获取镜像源
[root@prometheus-server ~]# wget -O /etc/yum.repos.d/docker-ce.repo https://download.docker.com/linux/centos/docker-ce.repo
[root@prometheus-server ~]# sed -i 's#download.docker.com#mirrors.tuna.tsinghua.edu.cn/docker-ce#' /etc/yum.repos.d/docker-ce.repo
[root@prometheus-server ~]# yum makecache fast
2.安装docker
[root@prometheus-server ~]# yum -y install docker-ce
3.配置镜像加速器
[root@prometheus-server ~]# tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://zggyaen3.mirror.aliyuncs.com"]
}
EOF
4.启动docker
[root@prometheus-server ~]# systemctl restart docker
2.2. Executar o contêiner prometheus
Montamos o arquivo de configuração do prometheus recém-instalado no contêiner e o mapeamos para a porta 7090
[root@prometheus-server ~]# docker run -d -p7090:9090 -v /data/prom/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus:latest
517523d6da1d4135bbd5d6bb2714576f20b7da832b6d75ce7dc88f1844c1d5f4
[root@prometheus-server ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
517523d6da1d prom/prometheus:latest "/bin/prometheus --c…" 16 seconds ago Up 10 seconds 0.0.0.0:7090->9090/tcp hopeful_tharp