centos7部署prometheus全过程(图解)

本文档一共需要三个包

08b17c7f723154fd6159f9efa87f13c9.png

经过测试需要使用8以上的版本,要不然模板会有问题,数据可能不显示

0b5fa12a516adc9883de23e8a10e9298.png

 时间校准

必须进行时间校准,否则后面会出问题

[root@localhost prometheus]# yum install -y ntp

[root@localhost prometheus]# systemctl start ntpd

[root@localhost prometheus]# systemctl enable ntpd
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.

[root@localhost prometheus]# ntpdate pool.ntp.org
20 Mar 13:28:42 ntpdate[11438]: the NTP socket is in use, exiting

[root@localhost prometheus]# systemctl restart ntpd

[root@localhost prometheus]# date
Wed Mar 20 13:28:55 CST 2024

 

 

安装部署node_exporter

解压文件

[root@localhost ~]# ll
total 155680
-rw-r--r--. 1 root root 25115445 Mar 15 19:48 alertmanager-0.23.0.linux-amd64.tar.gz
-rw-r--r--. 1 root root 52219308 Mar 16 12:36 grafana-7.1.0-1.x86_64.rpm
-rw-r--r--. 1 root root  8898481 Mar 15 19:59 node_exporter-1.2.2.linux-amd64.tar.gz
-rw-r--r--. 1 root root 73175122 Mar 16 12:36 prometheus-2.29.2.linux-amd64.tar.gz

[root@localhost ~]# tar -xf node_exporter-1.2.2.linux-amd64.tar.gz 


[root@localhost ~]# mv node_exporter-1.2.2.linux-amd64 node_exporter
[root@localhost ~]# ll
total 146988
-rw-r--r--. 1 root root 25115445 Mar 15 19:48 alertmanager-0.23.0.linux-amd64.tar.gz
-rw-r--r--. 1 root root 52219308 Mar 16 12:36 grafana-7.1.0-1.x86_64.rpm
drwxr-xr-x. 2 3434 3434       56 Aug  6  2021 node_exporter
-rw-r--r--. 1 root root 73175122 Mar 16 12:36 prometheus-2.29.2.linux-amd64.tar.gz

 关闭防火墙

[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

[root@localhost ~]# vi /etc/selinux/config 
[root@localhost ~]# cat /etc/selinux/config 

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 

进行安装

[root@localhost ~]# mv node_exporter /usr/local/
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ls
bin  etc  games  include  lib  lib64  libexec  node_exporter  sbin  share  src
[root@localhost local]# cd node_exporter/
[root@localhost node_exporter]# ls
LICENSE  node_exporter  NOTICE

 

创建服务

不能直接运行程序,默认是运行在前台,所以需要一个服务来开启

2cbaff232fbf1d88768d7f4cbc2b437e.png

[root@localhost node_exporter]# vim /etc/systemd/system/node_exporter.service
[root@localhost node_exporter]# cat /etc/systemd/system/node_exporter.service 
[Unit]
Description=node_exporter
After=network.target

[Service]
Restart=on-failure
ExecStart=/usr/local/node_exporter/node_exporter

[Install]
WantedBy=multi-user.target

开启服务并设置开机自启

[root@localhost node_exporter]# systemctl start node_exporter
[root@localhost node_exporter]# systemctl enable node_exporter
Created symlink from /etc/systemd/system/multi-user.target.wants/node_exporter.service to /etc/systemd/system/node_exporter.service.
[root@localhost node_exporter]# systemctl status node_exporter
● node_exporter.service - node_exporter
   Loaded: loaded (/etc/systemd/system/node_exporter.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2024-03-20 19:01:20 CST; 10s ago
 Main PID: 1640 (node_exporter)
   CGroup: /system.slice/node_exporter.service
           └─1640 /usr/local/node_exporter/node_exporter

Mar 20 19:01:20 localhost.localdomain node_exporter[1640]: level=info ts=2024-03-20T11:01:20.275...ne
Mar 20 19:01:20 localhost.localdomain node_exporter[1640]: level=info ts=2024-03-20T11:01:20.275...me
Mar 20 19:01:20 localhost.localdomain node_exporter[1640]: level=info ts=2024-03-20T11:01:20.275...ex
Mar 20 19:01:20 localhost.localdomain node_exporter[1640]: level=info ts=2024-03-20T11:01:20.275...es
Mar 20 19:01:20 localhost.localdomain node_exporter[1640]: level=info ts=2024-03-20T11:01:20.275...me
Mar 20 19:01:20 localhost.localdomain node_exporter[1640]: level=info ts=2024-03-20T11:01:20.275...at
Mar 20 19:01:20 localhost.localdomain node_exporter[1640]: level=info ts=2024-03-20T11:01:20.275...fs
Mar 20 19:01:20 localhost.localdomain node_exporter[1640]: level=info ts=2024-03-20T11:01:20.275...fs
Mar 20 19:01:20 localhost.localdomain node_exporter[1640]: level=info ts=2024-03-20T11:01:20.275...00
Mar 20 19:01:20 localhost.localdomain node_exporter[1640]: level=info ts=2024-03-20T11:01:20.276...se
Hint: Some lines were ellipsized, use -l to show in full.

add6f11a27bfa365db80208c8ed09cf1.png

 

 浏览器访问 ip:9100

58175557ad03cdfb853fe1ef96636b19.png

 显示的是当前主机的指标信息

0f193feac5f271e1dadfdc162e4b5ced.png

 

 

部署prometheus

解压文件

[root@localhost node_exporter]# cd 
[root@localhost ~]# 
[root@localhost ~]# ll
total 146988
-rw-r--r--. 1 root root 25115445 Mar 15 19:48 alertmanager-0.23.0.linux-amd64.tar.gz
-rw-r--r--. 1 root root 52219308 Mar 16 12:36 grafana-7.1.0-1.x86_64.rpm
-rw-r--r--. 1 root root 73175122 Mar 16 12:36 prometheus-2.29.2.linux-amd64.tar.gz
[root@localhost ~]# tar -xf prometheus-2.29.2.linux-amd64.tar.gz 
[root@localhost ~]# ls
alertmanager-0.23.0.linux-amd64.tar.gz  prometheus-2.29.2.linux-amd64
grafana-7.1.0-1.x86_64.rpm              prometheus-2.29.2.linux-amd64.tar.gz
[root@localhost ~]# mv prometheus-2.29.2.linux-amd64 prometheus
[root@localhost ~]# ls
alertmanager-0.23.0.linux-amd64.tar.gz  prometheus
grafana-7.1.0-1.x86_64.rpm              prometheus-2.29.2.linux-amd64.tar.gz
[root@localhost ~]# mv prometheus /usr/local/
[root@localhost ~]# ls /usr/local/
bin  etc  games  include  lib  lib64  libexec  node_exporter  prometheus  sbin  share  src

2c5e168da1c493b86fa8560ee9125c1f.png

 

 

修改配置文件

[root@localhost ~]# cd /usr/local/prometheus/
[root@localhost prometheus]# vim prometheus.yml 

50534decf35ebfa0e79641ef3f14477a.png

9e564f709c736e15ce85f97f315b91ca.png

 

创建服务

不能直接运行程序,默认是运行在前台,所以需要一个服务来开启

[root@localhost prometheus]# cat  /etc/systemd/system/prometheus.service
[Unit]
Desciption=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network-online.target

[Service]
Restart=on-failure
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --storage.tsdb.path=/var/lib/prometheus --web.external-url=http://0.0.0.0:9090

[Install]
WantedBy=multi-user.target

开启服务

[root@localhost prometheus]# systemctl start prometheus
[root@localhost prometheus]# systemctl enable prometheus
Created symlink from /etc/systemd/system/multi-user.target.wants/prometheus.service to /etc/systemd/system/prometheus.service.
[root@localhost prometheus]# ssytemctl status prometheus

c92b6f7f7ee7665128516e5b5a24f951.png

 

浏览器访问ip:9090

1e25ef2db1d9558753a8e283fb7b4cfa.png

部署grafana

安装

[root@localhost ~]# ls
grafana-7.1.0-1.x86_64.rpm              prometheus-2.29.2.linux-amd64.tar.gz
node_exporter-1.2.2.linux-amd64.tar.gz
[root@localhost ~]# yum install grafana-7.1.0-1.x86_64.rpm -y

开启服务

[root@localhost ~]# systemctl start grafana-server
[root@localhost ~]# systemctl enable grafana-server
Created symlink from /etc/systemd/system/multi-user.target.wants/grafana-server.service to /usr/lib/systemd/system/grafana-server.service.

[root@localhost ~]# netstat -ntpl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1000/sshd           
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1235/master         
tcp6       0      0 :::9090                 :::*                    LISTEN      11461/prometheus    
tcp6       0      0 :::9100                 :::*                    LISTEN      1640/node_exporter  
tcp6       0      0 :::22                   :::*                    LISTEN      1000/sshd           
tcp6       0      0 :::3000                 :::*                    LISTEN      11682/grafana-serve 
tcp6       0      0 ::1:25                  :::*                    LISTEN      1235/master  

浏览器访问ip:3000

默认账号密码都是admin

然后输入新密码

9d3c802a0e7cad43341793d41750360b.png

 

d99a3a45b0d818adbb68e1042e3b410f.png

a9b28fa86a7a29faa5e41fc6255c5c15.png

 7ab9d1c53ee401ec4dcdc28aeac1593d.png

5c3addcb9aeafbb982cced07b6d2d4c4.png

出现这个提示,就是说数据源添加成功了

a813d7791d96865ea9bc55cecb989bbe.png

出现绿色提示就是成功

ef893bff4d1f992766a6587ca1698c58.png

817075f448ef67c874b7f507d7ec51b1.png

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

SKY慕雪

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值