zl程序教程

您现在的位置是:首页 >  云平台

当前栏目

prometheus监控本地主机及监控远程主机

监控 远程 本地 主机 Prometheus
2023-09-14 09:16:03 时间

文章目录

一、前期准备

 二、开始搭建prometheus监控本地主机

三、监控远程主机


一、前期准备

1)两台服务器IP

[root@localhost ~]# ifconfig ens32 | awk 'NR==2{print $2}'
192.168.157.166

[root@localhost ~]# ifconfig ens32 | awk 'NR==2{print $2}'
192.168.157.34

2)查看系统版本

[root@localhost ~]# cat /etc/redhat-release 
CentOS Linux release 7.9.2009 (Core)

3)prometheus程序下载点:Download | Prometheus 

 二、开始搭建prometheus监控本地主机

这里使用到的IP是:192.168.157.166

1)关闭防火墙,临时关闭SElinux

[root@localhost ~]# iptables -F
[root@localhost ~]# systemctl stop firewalld.service 
[root@localhost ~]# setenforce 0

2)上传程序包

使用rz命令上传

 3)解压程序包

[root@localhost ~]# ll prometheus-2.37.2.linux-amd64.tar.gz 
-rw-r--r--. 1 root root 83879445 11月  9 19:54 prometheus-2.37.2.linux-amd64.tar.gz
[root@localhost ~]# tar xf prometheus-2.37.2.linux-amd64.tar.gz 
[root@localhost ~]# mv prometheus-2.37.2.linux-amd64 prometheus

4)进入prometheus目录中

[root@localhost ~]# cd prometheus/
[root@localhost prometheus]# ll
总用量 206276
drwxr-xr-x. 2 3434 3434        38 11月  4 19:24 console_libraries
drwxr-xr-x. 2 3434 3434       173 11月  4 19:24 consoles
-rw-r--r--. 1 3434 3434     11357 11月  4 19:24 LICENSE
-rw-r--r--. 1 3434 3434      3773 11月  4 19:24 NOTICE
-rwxr-xr-x. 1 3434 3434 109691493 11月  4 19:09 prometheus
-rw-r--r--. 1 3434 3434       934 11月  4 19:24 prometheus.yml
-rwxr-xr-x. 1 3434 3434 101509420 11月  4 19:11 promtool
[root@localhost prometheus]# 

5)在后台启动程序

[root@localhost prometheus]# ./prometheus &
[1] 3509
[root@localhost prometheus]# ts=2023-02-11T02:16:56.959Z caller=main.go:491 level=info msg="No time or size retention was set so using the default time retention" duration=15d
ts=2023-02-11T02:16:56.959Z caller=main.go:535 level=info msg="Starting Prometheus Server" mode=server version="(version=2.37.2, branch=HEAD, revision=dd4b6bf1261ae67f5d4f56428f84aa462bfb63c3)"

ts=2023-02-11T02:16:56.971Z caller=manager.go:941 level=info component="rule manager" msg="Starting rule manager..."

6)查看prometheus端口号

[root@localhost ~]# netstat -antup|grep prometheus
tcp6       0      0 :::9090                 :::*                    LISTEN      3509/./prometheus   
tcp6       0      0 ::1:41868               ::1:9090                ESTABLISHED 3509/./prometheus   
tcp6       0      0 ::1:9090                ::1:41868               ESTABLISHED 3509/./prometheus   

7)使用IP加端口 192.168.157.166:9090

查看本地主机状态

 到这里本地主机的监控是已经搭建好了。

三、监控远程主机

这里使用到的IP是:192.168.157.34

1)关闭防火墙

[root@localhost ~]# iptables -F
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0

2)上传node_exporter程序包

3)解压并在后台启动

[root@localhost ~]# iptables -F
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# rz

[root@localhost ~]# tar xf node_exporter-1.4.0.linux-amd64.tar.gz 
[root@localhost ~]# mv node_exporter-1.4.0.linux-amd64 node_exporter
[root@localhost ~]# cd node_exporter/
[root@localhost node_exporter]# nohup ./node_exporter &

使用nohup表示不中断运行命令,服务器即使退出终端,也不会影响程序的进行。

4)修改prometheus主配置文件(第一台机器 192.168.157.166)

[root@localhost prometheus]# vim prometheus.yml 
[root@localhost prometheus]# tail -n 3 prometheus.yml 
  - job_name: "node34"
    static_configs:
      - targets: ["192.168.157.34:9100"]
[root@localhost prometheus]# 

5)重启启动prometheus

[root@localhost prometheus]# pkill prometheus
[root@localhost prometheus]# ./prometheus &

6)查看远程主机的状态也监控上了