云原生监控平台 Prometheus 从部署到监控

首先要有三台虚拟机,xshell(有更方便,没有也可以)
第一台虚拟机ip 192.168.213.168
第二台虚拟机ip 192.168.213.167
第三台虚拟机ip 192.168.213.166
然后将这个三台虚拟机连接到xshell软件

三台虚拟机都要关闭防火墙,命令是:systemctl stop firewalld

下面是所需要用到的工具链接

链接: https://pan.baidu.com/s/1yyyoFD-nRQ7HCMl-4IvTZQ?pwd=ly52 提取码: ly52 复制这段内容后打开百度网盘手机App,操作更方便哦

 

 

 

(第一台虚拟机上做)

 

 

 

#安装docker
yum install docker -y
systemctl enable --now docker

#将prometheus镜像包上传到linux系统中
#导入镜像
#docker load -i prometheus.tar

 

二进制安装 prometheus

 下载二进制包并解压

[root@master1 ~]#wget https://github.com/prometheus/prometheus/releases/download/v2.35.0/prometheus-2.35.0.linux-amd64.tar.gz

[root@master1 ~]#ls -l prometheus-2.35.0.linux-amd64.tar.gz 
-rw-r--r-- 1 root root 80620181 Apr 21 10:07 prometheus-2.35.0.linux-amd64.tar.gz

[root@master1 ~]#tar xf prometheus-2.35.0.linux-amd64.tar.gz 

[root@master1 ~]#ln -s /root/prometheus-2.35.0.linux-amd64 /usr/local/prometheus

[root@master1 ~]#cd /usr/local/prometheus

[root@master1 /usr/local/prometheus]#ls
console_libraries  consoles  LICENSE  NOTICE  prometheus  prometheus.yml  promtool

[root@master1 /usr/local/prometheus]#mkdir bin conf data

[root@master1 /usr/local/prometheus]#mv prometheus promtool bin/

[root@master1 /usr/local/prometheus]#mv prometheus.yml conf/

[root@master1 /usr/local/prometheus]#useradd -r -s /sbin/nologin prometheus

[root@master1 /usr/local/prometheus]#chown -R prometheus.prometheus /usr/local/prometheus/

[root@master1 /usr/local/prometheus]#cd

[root@master1 ~]#vim /etc/profile.d/prometheus.sh
export PROMETHEUS_HOME=/usr/local/prometheus
export PATH=${PROMETHEUS_HOME}/bin:$PATH

[root@master1 ~]#source /etc/profile.d/prometheus.sh

#查看配置文件,默认可不修改
[root@master1 ~]#grep -Ev "^ *#|^$" /usr/local/prometheus/conf/prometheus.yml
global:
  scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
alerting:
  alertmanagers:
    - static_configs:
        - targets:
rule_files:
scrape_configs:
  - job_name: "prometheus"
    static_configs:
      - targets: ["localhost:9090"]
     
#属性解析:主要是global和 scrape_configs 两部分的配置,在这里目前我们保持默认即可

#检查配置文件是否正确
[root@master1 ~]#promtool check config /usr/local/prometheus/conf/prometheus.yml
Checking /usr/local/prometheus/conf/prometheus.yml
 SUCCESS: /usr/local/prometheus/conf/prometheus.yml is valid prometheus config file syntax


创建service文件

[root@master1 ~]#vim /lib/systemd/system/prometheus.service
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network.target

[Service]
Restart=on-failure
User=root
WorkingDirectory=/usr/local/prometheus/
ExecStart=/usr/local/prometheus/bin/prometheus --config.file=/usr/local/prometheus/conf/prometheus.yml
ExecReload=/bin/kill -HUP $MAINPID
LimitNOFILE=65535
[Install]
WantedBy=multi-user.target

#配置解析:
#我们需要将定制的prometheus的配置文件和数据目录作为启动参数配置好
#其它的参数,可以基于prometheus --help 查看更多

[root@master1 ~]#systemctl daemon-reload

[root@master1 ~]#systemctl restart prometheus

[root@master1 ~]#systemctl status prometheus

[root@master1 ~]#ss -tnlp |grep prometheus
LISTEN 0      4096               *:9090            *:*    users:(("prometheus",pid=6488,fd=8))

#结果显示:可以看到当前主机上可以看到一个端口9090,可通过下面地址看到prometheus的服务页面

测试访问

5 Node exporter 部署(第二台虚拟机上做)

在需要监控的所有节点主机上进行安装

 在第二台虚拟机上下图安装包

[root@centos7 ~]#wget -P /usr/local/  https://github.com/prometheus/node_exporter/releases/download/v1.2.2/node_exporter-1.2.2.linux-amd64.tar.gz

[root@centos7 ~]#cd /usr/local/

[root@centos7 /usr/local]#tar xf node_exporter-1.2.2.linux-amd64.tar.gz

[root@centos7 /usr/local]#ln -s node_exporter-1.2.2.linux-amd64 node_exporter

[root@centos7 /usr/local]#cd node_exporter

[root@centos7 /usr/local/node_exporter]#mkdir bin

[root@centos7 /usr/local/node_exporter]#mv node_exporter bin/



有些可能不一样,如果出现没有这个文件的情况,不要完全粘贴,粘贴一部分按tab键补全即可解决

5.2 准备 service 文件

[root@centos7 ~]#vim /lib/systemd/system/node_exporter.service
[Unit]
Description=Prometheus Node Exporter
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/node_exporter/bin/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target

5.3 启动 node exporter 服务

[root@centos7 ~]#systemctl daemon-reload

[root@centos7 ~]#systemctl enable --now node_exporter.service
Created symlink from /etc/systemd/system/multi-user.target.wants/node_exporter.service to /usr/lib/systemd/system/node_exporter.service.

[root@centos7 ~]#systemctl is-active node_exporter.service
active

[root@centos7 ~]#ss -ntlp|grep node_exporter
LISTEN     0      128       [::]:9100                  [::]:*                   users:(("node_exporter",pid=1766,fd=3))

#结果显示:可以看到当前主机上可以看到一个端口9100

5.4 访问 node exporter web 界面

6 Prometheus 采集监控数据(第一台虚拟机上做)

6.1 修改prometheus 配置文件

[root@master1 ~]#vim /usr/local/prometheus/conf/prometheus.yml 
 23   - job_name: "prometheus"
 24     static_configs:
 25       - targets: ["localhost:9090"]
 26   - job_name: "node_exporter"
 27     static_configs:
 28       - targets: ["192.168.213.167:9100"]

#属性解析:
#新增一个job_name 和 static_configs的属性
#targets 就是前面基本概念中提到的instance,格式就是"ip:port"

#重启prometheus服务:
[root@master1 ~]#systemctl restart prometheus
[root@master1 ~]#systemctl status prometheus

6.2 Prometheus 验证 node 节点状态

http://192.168.213.168:9090/targets
#结果显示:当我们把鼠标放到Labels部位的时候,就会将改target的属性信息标识出来,其中"__*"开头的就是该对象的私有属性,当我们点击Endpoint的时候,就可以看到该node节点上的所有定制好的监控项。

7 Grafana 展示监控数据(第三台虚拟机上做)

7.2 Grafana 部署

将如下安装包放入如下图位置

#安装软件
[root@master1 ~]#ls -l grafana-enterprise-8.2.2-1.x86_64.rpm
-rw-r--r-- 1 root root 69875374 Apr 25 14:37 grafana-enterprise-8.2.2-1.x86_64.rpm
[root@master1 ~]#yum -y install ./grafana-enterprise-8.2.2-1.x86_64.rpm
#注意:这里安装的是本地文件,所以要加文件路径

#启动服务
[root@master1 ~]#systemctl daemon-reload

[root@master1 ~]#systemctl enable --now grafana-server.service

#检查结果
[root@master1 ~]#ss -ntulp|grep grafana
tcp   LISTEN 0      4096                   *:3000            *:*    users:(("grafana-server",pid=7805,fd=8))
#结果显示:当前主机上出现了一个端口3000

7.3 登录并配置

#浏览器访问 http://192.168.213.166:3000/,查看效果
#输入用户名和密码:admin/admin,就会进入到更改密码的页面,查看效果

 然后修改密码,并登录

 

 

 

 

 

 

 

 

7.4 导入指定模板

上面内置的模板不太理想,导入指定的网络上比较合适的dashboard模板

点击"import",将"https://grafana.com/dashboards/8919或1860"添加到如下位置,点 Load 后效果如下

 

在Prometheus Data Source右侧选择刚才配置的Prometheus数据源即可,然后点击"Import",查看效果

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值