本文档一共需要三个包
经过测试需要使用8以上的版本,要不然模板会有问题,数据可能不显示
时间校准
必须进行时间校准,否则后面会出问题
[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
创建服务
不能直接运行程序,默认是运行在前台,所以需要一个服务来开启
[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.
浏览器访问 ip:9100
显示的是当前主机的指标信息
部署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
修改配置文件
[root@localhost ~]# cd /usr/local/prometheus/
[root@localhost prometheus]# vim prometheus.yml
创建服务
不能直接运行程序,默认是运行在前台,所以需要一个服务来开启
[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
浏览器访问ip:9090
部署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
然后输入新密码
出现这个提示,就是说数据源添加成功了
出现绿色提示就是成功