Prometheus安装部署

Prometheus 安装部署

一、监控简介

二、环境准备

1、服务器配置情况
服务器 ip 配置 内核版本 软件安装情况
node-01-server 192.168.163.130 2核4G 3.10 prometheus node_exporter grafana go
node-02-client 192.168.163.131 2核4G 3.10 node_exporter
2、软件下载地址

​ Prometheus:https://prometheus.io/download/#prometheus.

​ Go:https://studygolang.com/dl/golang/go1.17.5.linux-amd64.tar.gz

​ Grafana:https://dl.grafana.com/oss/release/grafana-5.4.2-1.x86_64.rpm

​ node_exporter:https://prometheus.io/download/#prometheus

3、环境准备
# 设置主机名
$ hostnamectl set-hostname node-01-server
$ hostnamectl set-hostname node-02-client 
# systecmctl stop firewalld && systemctl disable firewalld  # 防火墙关闭
# setenforce && sed -i 's/enforcing/disabled/' /etc/selinux/config # selinus关闭

三、具体安装

1、安装go环境
[root@node-01-server ~]# tar -xf go1.17.5.linux-amd64.tar.gz -C /usr/local/
[root@node-01-server ~]# ll /usr/local/ | grep go 
drwxr-xr-x  10 root root 257 Dec  9 21:50 go
[root@node-01-server ~]# vim /etc/profile
export PATH=$PATH:/usr/local/go/bin/  # 为了方便调用,我们在/etc/profile下对其进行定义路径,添加在最后一行。
[root@node-01-server ~]# source /etc/profile
[root@node-01-server ~]# go version 
go version go1.17.5 linux/amd64
2、安装prometheus
[root@node-01-server ~]# tar -xf prometheus-2.32.1.linux-amd64.tar.gz -C /usr/local/
[root@node-01-server ~]# mv /usr/local/prometheus-* /usr/local/Prometheus
[root@node-01-server ~]# ll /usr/local/Prometheus/
total 193448
drwxr-xr-x 2 3434 3434        38 Dec 18 06:18 console_libraries
drwxr-xr-x 2 3434 3434       173 Dec 18 06:18 consoles
drwxr-xr-x 4 root root        70 Jan  6 16:58 data
-rw-r--r-- 1 3434 3434     11357 Dec 18 06:18 LICENSE
-rw-r--r-- 1 3434 3434      3646 Dec 18 06:18 NOTICE
-rwxr-xr-x 1 3434 3434 103070626 Dec 18 06:10 prometheus
-rw-r--r-- 1 3434 3434      1028 Jan  6 16:58 prometheus.yml
-rwxr-xr-x 1 3434 3434  94996583 Dec 18 06:13 promtool
[root@node-01-server ~]# vim /usr/local/Prometheus/prometheus.yml
    static_configs:
      - targets: ["localhost:9090"]
  - job_name: "node-02-client"             # 新增job,会在界面上显示的
    static_configs:
      - targets: ["192.168.163.131:9100"]
# 本节重点在安装部署,运行一个监控架构,配置文件及更多玩法还会不定期更新,敬请期待。
[root@node-01-server ~]# ./prometheus
ts=2022-01-06T08:58:44.370Z caller=main.go:521 level=info host_details="(Linux 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 node-01-server (none))"
ts=2022-01-06T08:58:44.370Z caller=main.go:522 level=info fd_limits="(soft=1024, hard=4096)"
ts=2022-01-06T08:58:44.370Z caller=main.go:523 level=info vm_limits="(soft=unlimited, hard=unlimited)"
ts=2022-01-06T08:58:44.372Z caller=web.go:570 level=info component=web msg="Start listening for connections" address=0.0.0.0:9090
ts=2022-01-06T08:58:44.372Z caller=main.go:924 level=info msg="Starting TSDB ..."
ts=2022-01-06T08:58:44.386Z caller=head.go:488 level=info component=tsdb msg="Replaying on-disk memory mappable chunks if any"
ts=2022-01-06T08:58:44.386Z caller=head.go:522 level=info component=tsdb msg="On-disk memory mappable chunks replay completed" duration=6.914µs
...
# 不要关闭,在网页端进行验证查看。

Prometheus安装部署

3、安装export监控主机
[root@node-02-client Prometheus]# cd
[root@node-02-client ~]# tar -xf node_exporter-1.3.1.linux-amd64.tar.gz -C /usr/local/
[root@node-02-client ~]# cd /usr/local/node_exporter-1.3.1.linux-amd64/
[root@node-02-client ~]# ll
total 17820
-rw-r--r-- 1 3434 3434    11357 Dec  5 19:15 LICENSE
-rwxr-xr-x 1 3434 3434 18228926 Dec  5 19:10 node_exporter
-rw-r--r-- 1 3434 3434      463 Dec  5 19:15 NOTICE
[root@node-02-client ~]# ./node_exporter 
ts=2022-01-06T09:26:33.333Z caller=node_exporter.go:115 level=info collector=arp
ts=2022-01-06T09:26:33.333Z caller=node_exporter.go:115 level=info collector=bcache
ts=2022-01-06T09:26:33.333Z caller=node_exporter.go:115 level=info collector=bonding
ts=2022-01-06T09:26:33.333Z caller=node_exporter.go:115 level=info collector=btrfs
...
## 通过server端的普鲁米修斯的界面,我们看到原本是红色down状态的node-02,变成up状态

Prometheus安装部署

4、安装grafana
[root@node-01-server ~]# yum -y install grafana-5.4.2-1.x86_64.rpm 
[root@node-01-server ~]# systemctl start grafana-server.service
[root@node-01-server ~]# systemctl enable grafana-server.service
[root@node-01-server ~]# ss -anptu  | grep grafana
tcp    LISTEN   0    128   :::3000              :::*      users:(("grafana-server",pid=11263,fd=6))
tcp    ESTAB    0    0     ::ffff:192.168.163.130:3000    ::ffff:192.168.163.1:59662    users:(("grafana-server",pid=11263,fd=12))
tcp    ESTAB    0    0     ::ffff:192.168.163.130:3000    ::ffff:192.168.163.1:59656    users:(("grafana-server",pid=11263,fd=9))
tcp    ESTAB    0    0     ::ffff:192.168.163.130:3000    ::ffff:192.168.163.1:59657    users:(("grafana-server",pid=11263,fd=10))
tcp    ESTAB    0    0     ::ffff:192.168.163.130:3000    ::ffff:192.168.163.1:59661    users:(("grafana-server",pid=11263,fd=13))
# 通过server的ip:3000进行访问,第一次登陆账号密码为admin,admin。

Prometheus安装部署
Prometheus安装部署
Prometheus安装部署
Prometheus安装部署
Prometheus安装部署
Prometheus安装部署
Prometheus安装部署

​ 这是Prometheus监控系统资源使用情况的样例,9726是grafana监控模板的代码,更多的模板代码大家可以在grafana的官网进行查询,复制代码,这里的代码不是指任何开发语言,而只是简单的数字结合,比如9726。

上一篇:Javascript中的字符串链接和Array.join()方法时间效率对比


下一篇:Prometheus 监控体系、部署