Prometheus部署,即服务发现(二)

目录

一、Prometheus部署

1、前期准备,主机分配、防火墙、基础环境等

2、准备安装包

3、prometheus主机服务部署

 4、部署监控其他节点

 5、修改配置,加入其他节点监控

 6、prometheusUI控制台,表达式浏览器

 二、部署service discovery服务发现

1、Prometheus的服务发现

2、prometheus 服务发现机制

3、静态配置发现

4、动态发现

◆◆◆基于文件服务发现

◆◆◆基于DNS自动发现

◆◆◆基于consul发现

◆◆◆基于K8S API的服务发现

总结


一、Prometheus部署

1、前期准备,主机分配、防火墙、基础环境等

服务器分配主机名

地址

安装包

prometheus

192.168.110.130

prometheus-2.27.1.linux-amd64.tar.gz

server1

192.168.110.131

node_exporter-1.1.2.linux-amd64.tar.gz

server2

192.168.110.132

server3

192.168.110.133

 

hostnamectl set-hostname prometheus		#其他主机分别设置server1.2.3
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
vim /etc/reslove.conf
nameserver 114.114.114.114
ntpdate ntp1.aliyun.com 		#时间同步;时间同步必须要做,不然会报错

2、准备安装包

#同步源的方式下载
cat > /etc/yum.repos.d/prometheus.repo <<EOF
[prometheus] 
name=prometheus
baseurl=https://packagecloud.io/prometheus-rpm/release/el/basearch
repo gpgcheck=1 
enabled-1
gpgkey=https://packagecloud.io/prometheus-rpm/release/gpgkeyhttps://raw.githubusercontent.com/lest/prometheus-rpm/master/RPM-GPG-KEY-prometheus-rpmgpgcheck=1 metadata_expire=300
EOF

3、prometheus主机服务部署

#上传包,并解压
tar -zxvf prometheus-2.27.1.linux-amd64.tar.gz -C /usr/local
#启动服务
[root@prometheus ~]# cd /usr/local/prometheus-2.27.1.linux-amd64/
[root@prometheus prometheus-2.27.1.linux-amd64]# ./prometheus
#重新开会话终端,查看9090端口,检测服务是否启动
[root@prometheus prometheus-2.27.1.linux-amd64]# ss -natp | grep 9090
LISTEN     0      128         :::9090                    :::*                   users:(("prometheus",pid=85118,fd=7))
[root@prometheus prometheus-2.27.1.linux-amd64]#

#浏览器访问http://192.168.110.130:9090/

 #访问http://192.168.110.130:9090/metrics:查看prometheus自带的内键指标。

#查看采集数据。Prometheus会进行周期性的采集数据(完整的),多次周期性(在一个时间区间内)

采集的数据集合,形成时间序列数据。

 4、部署监控其他节点

server1、server2、server3,prometheus想要监控其他节点,则需要借助node_exporter组件,下

载地:https://prometheus.io/docs/concepts/data_model/,腾讯云盘prometheus安装包。

[root@server1 ~]# rz -E   #上传安装包
rz waiting to receive.
[root@server1 ~]# ls
anaconda-ks.cfg                         original-ks.cfg  模板  图片  下载  桌面
node_exporter-1.1.2.linux-amd64.tar.gz  公共             视频  文档  音乐
[root@server1 ~]# tar -zxvf node_exporter-1.1.2.linux-amd64.tar.gz -C /opt/
node_exporter-1.1.2.linux-amd64/
node_exporter-1.1.2.linux-amd64/LICENSE
node_exporter-1.1.2.linux-amd64/NOTICE
node_exporter-1.1.2.linux-amd64/node_exporter
[root@server1 ~]# cd /opt/node_exporter-1.1.2.linux-amd64/
[root@server1 node_exporter-1.1.2.linux-amd64]# ls
LICENSE  node_exporter  NOTICE
[root@server1 node_exporter-1.1.2.linux-amd64]# cp node_exporter /usr/local/bin/
[root@server1 node_exporter-1.1.2.linux-amd64]# ./node_exporter   #启动node_exporter,在/usr/local/bin/目录下
###添加系统管理,使用systemctl管理工具管理此服务
服务管理方式utilfile(文件读取工具)
[Unit]
Description=node_exporter
Documentation=https:/prometheus.io/
After=network.targets
[serveice]
Type=simple
User=prometheus
ExecStart=/usr/local/bin/node_exporter \
    --collector.ntp \
    --collector.mountstats \
    --collector.systemd \
    --collertor.tcpstat
ExecReload=/bin/kill -HUP $MAINPID
TimeoutStopSec=20s
Restart=always
[Install]
WantedBy=multi-user.target

#启动服务这边的会话窗口查看动态变化

 #在开一个会话终端,查看服务是否启动

[root@server1 ~]# netstat -antp | grep 9100
tcp6       0      0 :::9100                 :::*                    LISTEN      86943/./node_export 
[root@server1 ~]#

#我们访问http://192.168.110.130:9090/targets,访问http://192.168.110.130:9090/ 点击—>status

—>targets

 5、修改配置,加入其他节点监控

需要在192.168.110.130 prometheus服务端停止prometheus,并修改配置文件添加静态targets才

能使得server节点可以被发现。

[root@prometheus ~]# cd /usr/local/prometheus/
[root@prometheus prometheus]# vim prometheus.yml
……  #在文件末尾添加target静态配置如下
  - job_name: 'nodes'
    static_configs:
    - targets:
      - 192.168.110.130:9100
      - 192.168.110.131:9100
      - 192.168.110.132:9100
      - 192.168.110.133:9100

[root@prometheus prometheus]# ./prometheus

#访问http://192.168.110.130:9090/targets#pool-nodes,查看

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值