一、环境准备
1. 准备两台虚拟机\或者购买云服务器
2. 虚拟机硬件要求
2.1 内存不得少于4G,否则项目启动会有报错
2.2 CPU2核2G
2.3 硬盘至少20G
3. 系统镜像
centos 7.9
二、部署要求
1. 两台虚拟机分别部署以下组件:
1.1 Grafana+Prometheus 部署在 192.168.44.150 机器
1.2 node_exporter监控的是 192.168.44.151 机器的操作系统
1.3 mysql_exporter监控的是 192.168.44.151 上安装的 MySQL 数据库
2. 软件包链接
链接:https://pan.baidu.com/s/1apnbxZw2ZbofeHFqOttazQ
提取码:anl8
--来自百度网盘超级会员V3的分享
二、系统时钟同步
# 安装ntp,两台虚拟机都需要执行此操作
yum install -y ntp
# 时钟同步
ntpdate pool.ntp.org
# 查看当前系统时间
date
# 两台虚拟机必须保证时间一致,因为Prometheus的时序数据库对时间要求很严格,Linux服务器的日期,时间,时区不一致会导致Grafana中监控不到数据
三、关闭防火墙
# 关闭防火墙
systemctl stop firewalld # 临时关闭,重启后开启
systemctl disable firewalld # 永久关闭
# 查看防火墙状态
systemctl status firewalld
四、部署node_exporter组件
# 下载node_exporter监控组件
https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
# 将node_exporter包上传到需要被监控的Linux服务器上任意目录下,执行解压命令
[root@localhost ~]# ls
anaconda-ks.cfg mysqld_exporter-0.12.1.linux-amd64.tar.gz node_exporter-0.18.1.linux-amd64.tar.gz
# 我这里以opt目录为例
[root@localhost ~]# mv mysqld_exporter-0.12.1.linux-amd64.tar.gz node_exporter-0.18.1.linux-amd64.tar.gz /opt/
[root@localhost ~]#
[root@localhost ~]# cd /opt/
[root@localhost opt]# ls
containerd mysqld_exporter-0.12.1.linux-amd64.tar.gz node_exporter-0.18.1.linux-amd64.tar.gz
[root@localhost opt]#
[root@localhost opt]# tar xvf node_exporter-0.18.1.linux-amd64.tar.gz
node_exporter-0.18.1.linux-amd64/
node_exporter-0.18.1.linux-amd64/node_exporter
node_exporter-0.18.1.linux-amd64/NOTICE
node_exporter-0.18.1.linux-amd64/LICENSE
[root@localhost opt]#
[root@localhost opt]# ls
containerd mysqld_exporter-0.12.1.linux-amd64.tar.gz node_exporter-0.18.1.linux-amd64 node_exporter-0.18.1.linux-amd64.tar.gz
[root@localhost opt]# cd node_exporter-0.18.1.linux-amd64
# 进入到解压完的文件夹内
[root@localhost node_exporter-0.18.1.linux-amd64]# ls
LICENSE node_exporter NOTICE
[root@localhost node_exporter-0.18.1.linux-amd64]#
# 执行启动脚本
[root@localhost node_exporter-0.18.1.linux-amd64]# nohup ./node_exporter &
[1] 1697
[root@localhost node_exporter-0.18.1.linux-amd64]# nohup: ignoring input and appending output to ‘nohup.out’
[root@localhost node_exporter-0.18.1.linux-amd64]#
# 查看nohup日志,如果出现以下回写,则安装成功
[root@localhost node_exporter-0.18.1.linux-amd64]# tail -100 nohup.out
time="2022-12-03T04:22:00+08:00" level=info msg="Starting node_exporter (version=0.18.1, branch=HEAD, revision=3db77732e925c08f675d7404a8c46466b2ece83e)" source="node_exporter.go:156"
time="2022-12-03T04:22:00+08:00" level=info msg="Build context (go=go1.12.5, user=root@b50852a1acba, date=20190604-16:41:18)" source="node_exporter.go:157"
time="2022-12-03T04:22:00+08:00" level=info msg="Enabled collectors:" source="node_exporter.go:97"
time="2022-12-03T04:22:00+08:00" level=info msg=" - arp" source="node_exporter.go:104"
time="2022-12-03T04:22:00+08:00" level=info msg=" - bcache" source="node_exporter.go:104"
time="2022-12-03T04:22:00+08:00" level=info msg=" - bonding" source="node_exporter.go:104"
time="2022-12-03T04:22:00+08:00" level=info msg=" - conntrack" source="node_exporter.go:104"
time="2022-12-03T04:22:00+08:00" level=info msg=" - cpu" source="node_exporter.go:104"
time="2022-12-03T04:22:00+08:00" level=info msg=" - cpufreq" source="node_exporter.go:104"
time="2022-12-03T04:22:00+08:00" level=info msg=" - diskstats" source="node_exporter.go:104"
time="2022-12-03T04:22:00+08:00" level=info msg=" - edac" source="node_exporter.go:104"
time="2022-12-03T04:22:00+08:00" level=info msg=" - entropy" source="node_exporter.go:104"
time="2022-12-03T04:22:00+08:00" level=info msg=" - filefd" source="node_exporter.go:104"
time="2022-12-03T04:22:00+08:00" level=info msg=" - filesystem" source="node_exporter.go:104"
time="2022-12-03T04:22:00+08:00" level=info msg=" - hwmon" source="node_exporter.go:104"
time="2022-12-03T04:22:00+08:00" level=info msg=" - infiniband" source="node_exporter.go:104"
time="2022-12-03T04:22:00+08:00" level=info msg=" - ipvs" source="node_exporter.go:104"
time="2022-12-03T04:22:00+08:00" level=info msg=" - loadavg" source="node_exporter.go:104"
time="2022-12-03T04:22:00+08:00" level=info msg=" - mdadm" source="node_exporter.go:104"
time="2022-12-03T04:22:00+08:00" level=info msg=" - meminfo" source="node_exporter.go:104"
time="2022-12-03T04:22:00+08:00" level=info msg=" - netclass" source="node_exporter.go:104"
time="2022-12-03T04:22:00+08:00" level=info msg=" - netdev" source="node_exporter.go:104"
time="2022-12-03T04:22:00+08:00" level=info msg=" - netstat" source="node_exporter.go:104"
time="2022-12-03T04:22:00+08:00" level=info msg=" - nfs" source="node_exporter.go:104"
time="2022-12-03T04:22:00+08:00" level=info msg=" - nfsd" source="node_exporter.go:104"
time="2022-12-03T04:22:00+08:00" level=info msg=" - pressure" source="node_exporter.go:104"
time="2022-12-03T04:22:00+08:00" level=info msg=" - sockstat" source="node_exporter.go:104"
time="2022-12-03T04:22:00+08:00" level=info msg=" - stat" source="node_exporter.go:104"
time="2022-12-03T04:22:00+08:00" level=info msg=" - textfile" source="node_exporter.go:104"
time="2022-12-03T04:22:00+08:00" level=info msg=" - time" source="node_exporter.go:104"
time="2022-12-03T04:22:00+08:00" level=info msg=" - timex" source="node_exporter.go:104"
time="2022-12-03T04:22:00+08:00" level=info msg=" - uname" source="node_exporter.go:104"
time="2022-12-03T04:22:00+08:00" level=info msg=" - vmstat" source="node_exporter.go:104"
time="2022-12-03T04:22:00+08:00" level=info msg=" - xfs" source="node_exporter.go:104"
time="2022-12-03T04:22:00+08:00" level=info msg=" - zfs" source="node_exporter.go:104"
time="2022-12-03T04:22:00+08:00" level=info msg="Listening on :9100" source="node_exporter.go:170"
# 在浏览器中访问node_exporter
http://192.168.44.151:9100/metrics
五、部署Prometheus
# 下载Prometheus包
https://github.com/prometheus/prometheus/releases/download/v2.15.2/prometheus-2.15.2.linux-amd64.tar.gz
# 将prometheus上传到一台单独的虚拟机上,执行解压操作
[root@localhost ~]# ls
anaconda-ks.cfg grafana-6.5.2-1.x86_64.rpm prometheus-2.15.2.linux-amd64.tar.gz
[root@localhost ~]#
[root@localhost ~]# mv grafana-6.5.2-1.x86_64.rpm prometheus-2.15.2.linux-amd64.tar.gz /opt/
[root@localhost ~]#
[root@localhost ~]# cd /opt/
[root@localhost opt]#
[root@localhost opt]# ls
grafana-6.5.2-1.x86_64.rpm prometheus-2.15.2.linux-amd64.tar.gz
[root@localhost opt]#
[root@localhost opt]# tar xvf prometheus-2.15.2.linux-amd64.tar.gz
prometheus-2.15.2.linux-amd64/
prometheus-2.15.2.linux-amd64/promtool
prometheus-2.15.2.linux-amd64/consoles/
prometheus-2.15.2.linux-amd64/consoles/node-cpu.html
prometheus-2.15.2.linux-amd64/consoles/index.html.example
prometheus-2.15.2.linux-amd64/consoles/node-overview.html
prometheus-2.15.2.linux-amd64/consoles/prometheus-overview.html
prometheus-2.15.2.linux-amd64/consoles/node-disk.html
prometheus-2.15.2.linux-amd64/consoles/node.html
prometheus-2.15.2.linux-amd64/consoles/prometheus.html
prometheus-2.15.2.linux-amd64/NOTICE
prometheus-2.15.2.linux-amd64/LICENSE
prometheus-2.15.2.linux-amd64/prometheus.yml
prometheus-2.15.2.linux-amd64/prometheus
prometheus-2.15.2.linux-amd64/tsdb
prometheus-2.15.2.linux-amd64/console_libraries/
prometheus-2.15.2.linux-amd64/console_libraries/menu.lib
prometheus-2.15.2.linux-amd64/console_libraries/prom.lib
[root@localhost opt]#
[root@localhost opt]# ls
grafana-6.5.2-1.x86_64.rpm prometheus-2.15.2.linux-amd64 prometheus-2.15.2.linux-amd64.tar.gz
# 进入到解压完的文件夹内
[root@localhost opt]# cd prometheus-2.15.2.linux-amd64
[root@localhost prometheus-2.15.2.linux-amd64]# ls
console_libraries consoles LICENSE NOTICE prometheus prometheus.yml promtool tsdb
[root@localhost prometheus-2.15.2.linux-amd64]#
[root@localhost prometheus-2.15.2.linux-amd64]# vi prometheus.yml
[root@localhost prometheus-2.15.2.linux-amd64]#
# 在配置文件中添加如下内容,注意缩进:
- job_name: 'node'
static_configs:
- targets: ['192.168.44.151:9100'] # 被监控的服务器ip和端口号
# wq保存退出
# 执行启动脚本
[root@localhost prometheus-2.15.2.linux-amd64]# nohup ./prometheus &
[1] 9963
[root@localhost prometheus-2.15.2.linux-amd64]# nohup: ignoring input and appending output to ‘nohup.out’
[root@localhost prometheus-2.15.2.linux-amd64]#
[root@localhost prometheus-2.15.2.linux-amd64]#
# 查看nohup日志,如果出现以下回写,则安装成功
[root@localhost prometheus-2.15.2.linux-amd64]# tail -100 nohup.out
level=info ts=2022-12-02T12:28:17.703Z caller=main.go:294 msg="no time or size retention was set so using the default time retention" duration=15d
level=info ts=2022-12-02T12:28:17.703Z caller=main.go:330 msg="Starting Prometheus" version="(version=2.15.2, branch=HEAD, revision=d9613e5c466c6e9de548c4dae1b9aabf9aaf7c57)"
level=info ts=2022-12-02T12:28:17.703Z caller=main.go:331 build_context="(go=go1.13.5, user=root@688433cf4ff7, date=20200106-14:50:51)"
level=info ts=2022-12-02T12:28:17.703Z caller=main.go:332 host_details="(Linux 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64 localhost.localdomain (none))"
level=info ts=2022-12-02T12:28:17.703Z caller=main.go:333 fd_limits="(soft=1024, hard=4096)"
level=info ts=2022-12-02T12:28:17.703Z caller=main.go:334 vm_limits="(soft=unlimited, hard=unlimited)"
level=info ts=2022-12-02T12:28:17.704Z caller=main.go:648 msg="Starting TSDB ..."
level=info ts=2022-12-02T12:28:17.704Z caller=web.go:506 component=web msg="Start listening for connections" address=0.0.0.0:9090
level=info ts=2022-12-02T12:28:17.705Z caller=head.go:584 component=tsdb msg="replaying WAL, this may take awhile"
level=info ts=2022-12-02T12:28:17.706Z caller=head.go:632 component=tsdb msg="WAL segment loaded" segment=0 maxSegment=0
level=info ts=2022-12-02T12:28:17.706Z caller=main.go:663 fs_type=XFS_SUPER_MAGIC
level=info ts=2022-12-02T12:28:17.706Z caller=main.go:664 msg="TSDB started"
level=info ts=2022-12-02T12:28:17.707Z caller=main.go:734 msg="Loading configuration file" filename=prometheus.yml
level=info ts=2022-12-02T12:28:17.708Z caller=main.go:762 msg="Completed loading of configuration file" filename=prometheus.yml
level=info ts=2022-12-02T12:28:17.708Z caller=main.go:617 msg="Server is ready to receive web requests."
# 在浏览器中访问promtheus
http://192.168.44.150:9090/
# 在浏览器中访问promtheus
http://192.168.44.150:9090/targets # 查看node节点是否被监控
六、部署Grafana
# 由于上面的Grafana版本过低,导致我的监控平台部分数据未显示,所以这里重新下了一个版本
wget https://wget.52liangzy.top/prom/grafana-7.5.4-1.x86_64.rpm
# 如果出现如下报错,则需要安装一个wget这个工具
[root@localhost opt]# wget https://wget.52liangzy.top/prom/grafana-7.5.4-1.x86_64.rpm
-bash: wget: command not found
# 安装wget,重新执行上述命令即可
yum install wget -y
# 安装Grafana
yum localinstall -y grafana-7.5.4-1.x86_64.rpm
# 启动Grafana
systemctl start grafana-server
# 在浏览器中访问Grafana,密码可以修改也可以跳过
http://192.168.44.150:3000/
七、监控Linux主机
# 按照下方给出的截图,依次添加主机节点,就可以实现数据的实时监控
八、导入监控模板
# 导入Grafana官方的监控模板
https://grafana.com/grafana/dashboards
标签:node,00,12,amd64,04,exporter,2022,linux,go
From: https://www.cnblogs.com/dy12138/p/16950231.html