基于CentOS 7.9系统安装操作
参考链接🔗:Install on RPM-based Linux | Grafana Labs
本安装过程基于VMware虚拟机上进行操作。
基于CentOS 7.9系统进行搭建部署。
1️⃣Grafana: The open observability platform | Grafana Labs
2️⃣Install on RPM-based Linux | Grafana Labs
4️⃣Prometheus(一):Prometheus+Grafana 安装配置 - Aiden郭祥跃 - 博客园
此处安装步骤省略
[root@grafana ~]# hostnamectl set-hostname grafana
[root@grafana ~]# bash
[root@grafana ~]# hostnamectl
Static hostname: grafana
Icon name: computer-vm
Chassis: vm
Machine ID: 68fd3df47b4549708fadff037e734008
Boot ID: 9839e70e6c7c48c0a993a989fdd23c42
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-1160.53.1.el7.x86_64
Architecture: x86-64
[root@computer-vm ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[root@grafana ~]# vi /etc/sysconfig/network-scripts/ifcfg-ens32
[root@grafana ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens32
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens32
UUID=0cf8b554-d0e7-47d1-b2ce-73ebe8b1ecbe
DEVICE=ens32
ONBOOT=yes
IPADDR=192.168.200.60
NETWORK=24
GATEWAY=192.168.200.1
DNS1=8.8.8.8
DNS2=192.168.200.1
[root@grafana ~]# systemctl stop firewalld
[root@grafana ~]# 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@grafana ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
Jan 30 23:16:15 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
Jan 30 23:16:16 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
Jan 30 23:25:26 grafana systemd[1]: Stopping firewalld - dynamic firewall daemon...
Jan 30 23:25:27 grafana systemd[1]: Stopped firewalld - dynamic firewall daemon.
[root@grafana ~]#
[root@grafana ~]# setenforce 0
[root@grafana ~]# getenforce
Permissive
[root@grafana ~]# vi /etc/sysconfig/selinux
[root@grafana ~]# cat /etc/sysconfig/selinux
# 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 values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
[root@grafana ~]#
[root@grafana ~]# ping qq.com
PING qq.com (123.151.137.18) 56(84) bytes of data.
64 bytes from 123.151.137.18 (123.151.137.18): icmp_seq=1 ttl=128 time=31.0 ms
64 bytes from 123.151.137.18 (123.151.137.18): icmp_seq=2 ttl=128 time=32.1 ms
64 bytes from 123.151.137.18 (123.151.137.18): icmp_seq=3 ttl=128 time=31.2 ms
64 bytes from 123.151.137.18 (123.151.137.18): icmp_seq=4 ttl=128 time=32.7 ms
64 bytes from 123.151.137.18 (123.151.137.18): icmp_seq=5 ttl=128 time=32.6 ms
^C
--- qq.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4009ms
rtt min/avg/max/mdev = 31.028/31.952/32.706/0.695 ms
[root@grafana ~]#
[root@grafana ~]# cd /etc/yum.repos.d/
[root@grafana yum.repos.d]# ll
total 32
-rw-r--r--. 1 root root 1664 Nov 23 2018 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 Nov 23 2018 CentOS-CR.repo
-rw-r--r--. 1 root root 649 Nov 23 2018 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 314 Nov 23 2018 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 630 Nov 23 2018 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Nov 23 2018 CentOS-Sources.repo
-rw-r--r--. 1 root root 5701 Nov 23 2018 CentOS-Vault.repo
[root@grafana yum.repos.d]# mkdir bak
[root@grafana yum.repos.d]# cp -r CentOS-* bak/
[root@grafana yum.repos.d]# ll
total 32
drwxr-xr-x. 2 root root 187 Jan 30 23:30 bak
-rw-r--r--. 1 root root 1664 Nov 23 2018 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 Nov 23 2018 CentOS-CR.repo
-rw-r--r--. 1 root root 649 Nov 23 2018 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 314 Nov 23 2018 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 630 Nov 23 2018 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Nov 23 2018 CentOS-Sources.repo
-rw-r--r--. 1 root root 5701 Nov 23 2018 CentOS-Vault.repo
[root@grafana yum.repos.d]# cd bak/
[root@grafana bak]# ll
total 32
-rw-r--r--. 1 root root 1664 Jan 30 23:30 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 Jan 30 23:30 CentOS-CR.repo
-rw-r--r--. 1 root root 649 Jan 30 23:30 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 314 Jan 30 23:30 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 630 Jan 30 23:30 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Jan 30 23:30 CentOS-Sources.repo
-rw-r--r--. 1 root root 5701 Jan 30 23:30 CentOS-Vault.repo
[root@grafana bak]#
[root@grafana ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base extras updates
[root@grafana ~]# yum makecache
Loaded plugins: fastestmirror
Determining fastest mirrors
* base: mirrors.ustc.edu.cn
* extras: mirrors.nju.edu.cn
* updates: mirrors.nju.edu.cn
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/10): base/7/x86_64/group_gz | 153 kB 00:00:00
(2/10): extras/7/x86_64/filelists_db | 259 kB 00:00:00
(3/10): extras/7/x86_64/other_db | 145 kB 00:00:00
(4/10): updates/7/x86_64/filelists_db | 7.4 MB 00:00:00
(5/10): extras/7/x86_64/primary_db | 243 kB 00:00:00
(6/10): base/7/x86_64/other_db | 2.6 MB 00:00:00
(7/10): base/7/x86_64/filelists_db | 7.2 MB 00:00:01
(8/10): base/7/x86_64/primary_db | 6.1 MB 00:00:01
(9/10): updates/7/x86_64/primary_db | 13 MB 00:00:00
(10/10): updates/7/x86_64/other_db | 955 kB 00:00:00
Metadata Cache Created
[root@grafana ~]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.ustc.edu.cn
* extras: mirrors.nju.edu.cn
* updates: mirrors.nju.edu.cn
repo id repo name status
base/7/x86_64 CentOS-7 - Base 10,072
extras/7/x86_64 CentOS-7 - Extras 500
updates/7/x86_64 CentOS-7 - Updates 3,369
repolist: 13,941
[root@grafana ~]#
执行yum update 命令
系统 | 主机名 | IP地址 | |
---|---|---|---|
服务端/监视器/Prometheus服务端/Grafana服务端 | CentOS 7.9 | grafana | 192.168.200.30 |
客户端①/被监控主机① | CentOS 7.9 | centos7 | 192.168.200.40 |
客户端②/被监控主机② | CentOS 7.9 | Computer-VM | 192.168.200.20 |
Prometheus服务端基于服务端192.168.200.30进行操作部署。
采用源码编译安装的方式,下载最新版本的安装包地址: Downloads - The Go Programming Language
Go环境Linux版本安装包: https://go.dev/dl/go1.17.6.linux-amd64.tar.gz
[root@grafana ~]# cd /usr/local/
[root@grafana local]# curl -OL https://go.dev/dl/go1.17.6.linux-amd64.tar.gz
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 75 100 75 0 0 104 0 --:--:-- --:--:-- --:--:-- 104
100 128M 100 128M 0 0 2150k 0 0:01:01 0:01:01 --:--:-- 2228k
[root@grafana local]# ls
bin etc games go1.17.6.linux-amd64.tar.gz include lib lib64 libexec sbin share src
[root@grafana local]#
bin etc games go1.17.6.linux-amd64.tar.gz include lib lib64 libexec sbin share src
[root@grafana local]# tar -zxf go1.17.6.linux-amd64.tar.gz
[root@grafana local]# ls
bin etc games go go1.17.6.linux-amd64.tar.gz include lib lib64 libexec sbin share src
[root@grafana local]#
[root@grafana local]# vim /etc/profile
-bash: vim: command not found
//出现上述报错信息,执行yum install -y vim*命令安装Vim编辑器
[root@grafana local]# yum install -y vim*
[root@grafana local]# vim /etc/profile
[root@grafana local]# cat /etc/profile
//在profile配置文件里最后添加以下两行命令,保存并退出即可
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
[root@grafana local]# source /etc/profile
//执行此命令,使其生效
执行go version命令,查询版本号,成功显示,即安装完成。
[root@grafana local]# go version
go version go1.17.6 linux/amd64
[root@grafana local]#
Prometheus安装包下载地址: Download | Prometheus
Prometheus Linux版本压缩包下载链接: prometheus-2.33.0.linux-amd64.tar.gz
[root@grafana local]# curl -OL https://github.com/prometheus/prometheus/releases/download/v2.33.0/prometheus-2.33.0.linux-amd64.tar.gz
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 671 100 671 0 0 566 0 0:00:01 0:00:01 --:--:-- 566
100 72.3M 100 72.3M 0 0 1987k 0 0:00:37 0:00:37 --:--:-- 2188k
[root@grafana local]# ls
bin games go1.17.6.linux-amd64.tar.gz lib libexec sbin src
etc go include lib64 prometheus-2.33.0.linux-amd64.tar.gz share
[root@grafana local]#
[root@grafana local]# tar -zxf prometheus-2.33.0.linux-amd64.tar.gz
[root@grafana local]# ls
bin go lib prometheus-2.33.0.linux-amd64 share
etc go1.17.6.linux-amd64.tar.gz lib64 prometheus-2.33.0.linux-amd64.tar.gz src
games include libexec sbin
[root@grafana local]# mv prometheus-2.33.0.linux-amd64 prometheus
//修改安装包文件名称
[root@grafana local]# ls
bin games go1.17.6.linux-amd64.tar.gz lib libexec prometheus-2.33.0.linux-amd64.tar.gz share
etc go include lib64 prometheus sbin src
[root@grafana local]#
[root@grafana local]# cd prometheus
[root@grafana prometheus]# ls
console_libraries consoles LICENSE NOTICE prometheus prometheus.yml promtool
[root@grafana prometheus]# ./prometheus --config.file=/usr/local/prometheus/prometheus.yml &
验证Prometheus服务是否启动,打开浏览器输入http://192.168.200.30:9090,打开Prometheus自带的监控界面。
按CTRL+C键结束Prometheus进程。
[root@grafana prometheus]# vim /etc/systemd/system/prometheus.service
[root@grafana prometheus]# cat /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus Monitoring System
Documentation=Prometheus Monitoring System
[Service]
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --web.listen-address=:9090
Restart=on-failure
[Install]
WantedBy=multi-user.target
[root@grafana prometheus]#
[root@grafana prometheus]# systemctl start prometheus.service
[root@grafana prometheus]# systemctl enable prometheus.service
[root@grafana prometheus]# systemctl status prometheus.service
● prometheus.service - Prometheus Monitoring System
Loaded: loaded (/etc/systemd/system/prometheus.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2022-01-31 15:02:37 CST; 1s ago
Main PID: 9877 (prometheus)
CGroup: /system.slice/prometheus.service
└─9877 /usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --web.listen-address=:9090...
Jan 31 15:02:37 grafana prometheus[9877]: ts=2022-01-31T07:02:37.065Z caller=head.go:533 level=info component=tsdb msg="Re...while"
Jan 31 15:02:37 grafana prometheus[9877]: ts=2022-01-31T07:02:37.067Z caller=tls_config.go:195 level=info component=web ms...=false
Jan 31 15:02:37 grafana prometheus[9877]: ts=2022-01-31T07:02:37.480Z caller=head.go:604 level=info component=tsdb msg="WA...ment=1
Jan 31 15:02:37 grafana prometheus[9877]: ts=2022-01-31T07:02:37.481Z caller=head.go:604 level=info component=tsdb msg="WA...ment=1
Jan 31 15:02:37 grafana prometheus[9877]: ts=2022-01-31T07:02:37.481Z caller=head.go:610 level=info component=tsdb msg="WA…915309ms
Jan 31 15:02:37 grafana prometheus[9877]: ts=2022-01-31T07:02:37.484Z caller=main.go:944 level=info fs_type=XFS_SUPER_MAGIC
Jan 31 15:02:37 grafana prometheus[9877]: ts=2022-01-31T07:02:37.484Z caller=main.go:947 level=info msg="TSDB started"
Jan 31 15:02:37 grafana prometheus[9877]: ts=2022-01-31T07:02:37.484Z caller=main.go:1128 level=info msg="Loading configur...us.yml
Jan 31 15:02:37 grafana prometheus[9877]: ts=2022-01-31T07:02:37.491Z caller=main.go:1165 level=info msg="Completed loading of c…µs
Jan 31 15:02:37 grafana prometheus[9877]: ts=2022-01-31T07:02:37.491Z caller=main.go:896 level=info msg="Server is ready t...ests."
Hint: Some lines were ellipsized, use -l to show in full.
[root@grafana prometheus]#
[root@grafana prometheus]# systemctl status prometheus.service
● prometheus.service - Prometheus Monitoring System
Loaded: loaded (/etc/systemd/system/prometheus.service; enabled; vendor preset: disabled)
Active: failed (Result: start-limit) since Mon 2022-01-31 15:01:16 CST; 9s ago
Main PID: 9814 (code=exited, status=1/FAILURE)
Jan 31 15:01:16 grafana systemd[1]: prometheus.service failed.
Jan 31 15:01:16 grafana systemd[1]: prometheus.service holdoff time over, scheduling restart.
Jan 31 15:01:16 grafana systemd[1]: Stopped Prometheus Monitoring System.
Jan 31 15:01:16 grafana systemd[1]: start request repeated too quickly for prometheus.service
Jan 31 15:01:16 grafana systemd[1]: Failed to start Prometheus Monitoring System.
Jan 31 15:01:16 grafana systemd[1]: Unit prometheus.service entered failed state.
Jan 31 15:01:16 grafana systemd[1]: prometheus.service failed.
Jan 31 15:01:20 grafana systemd[1]: [/etc/systemd/system/prometheus.service:3] Invalid URL, ignoring: Prometheus
Jan 31 15:01:20 grafana systemd[1]: [/etc/systemd/system/prometheus.service:3] Invalid URL, ignoring: Monitoring
Jan 31 15:01:20 grafana systemd[1]: [/etc/systemd/system/prometheus.service:3] Invalid URL, ignoring: System
[root@grafana prometheus]# ps -aux //查看服务进程
[root@grafana prometheus]# kill 9773 //执行kill命令,结束此进程
ts=2022-01-31T07:02:05.396Z caller=main.go:775 level=warn msg="Received SIGTERM, exiting gracefully..."
ts=2022-01-31T07:02:05.396Z caller=main.go:798 level=info msg="Stopping scrape discovery manager..."
ts=2022-01-31T07:02:05.396Z caller=main.go:812 level=info msg="Stopping notify discovery manager..."
ts=2022-01-31T07:02:05.396Z caller=main.go:834 level=info msg="Stopping scrape manager..."
ts=2022-01-31T07:02:05.396Z caller=main.go:794 level=info msg="Scrape discovery manager stopped"
ts=2022-01-31T07:02:05.396Z caller=main.go:808 level=info msg="Notify discovery manager stopped"
ts=2022-01-31T07:02:05.397Z caller=manager.go:945 level=info component="rule manager" msg="Stopping rule manager..."
ts=2022-01-31T07:02:05.397Z caller=manager.go:955 level=info component="rule manager" msg="Rule manager stopped"
ts=2022-01-31T07:02:05.397Z caller=main.go:828 level=info msg="Scrape manager stopped"
ts=2022-01-31T07:02:05.398Z caller=notifier.go:600 level=info component=notifier msg="Stopping notification manager..."
ts=2022-01-31T07:02:05.398Z caller=main.go:1054 level=info msg="Notifier manager stopped"
ts=2022-01-31T07:02:05.398Z caller=main.go:1066 level=info msg="See you next time!"
[1]+ Done ./prometheus --config.file=/usr/local/prometheus/prometheus.yml
[root@grafana prometheus]#systemctl daemon-reload //重新加载再启动服务
至此,Prometheus服务配置完成。
Prometheus自带的监控页面显示的内容没有那么直观,安装Grafana监控数据看起来更加直观
💥遇到以下报错信息,执行以下命令安装vim编辑器即可。
[root@grafana ~]# vim /etc/yum.repos.d/grafana.repo
bash: vim: command not found
[root@grafana ~]# yum install -y vim*
🆗将新文件添加到 YUM 存储库
[root@grafana ~]# vim /etc/yum.repos.d/grafana.repo
[root@grafana ~]# cat /etc/yum.repos.d/grafana.repo
[grafana]
name=grafana
baseurl=https://packages.grafana.com/enterprise/rpm
repo_gpgcheck=1
enabled=1
gpgcheck=1
gpgkey=https://packages.grafana.com/gpg.key
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
[root@grafana ~]#
使用以下命令之一安装 Grafana
sudo yum install grafana
# or
sudo yum install grafana-enterprise
[root@grafana ~]# yum install grafana-enterprise
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.ustc.edu.cn
* extras: mirrors.nju.edu.cn
* updates: mirrors.nju.edu.cn
grafana/signature | 454 B 00:00:00
Retrieving key from https://packages.grafana.com/gpg.key
Importing GPG key 0x24098CB6:
Userid : "Grafana <info@grafana.com>"
Fingerprint: 4e40 ddf6 d76e 284a 4a67 80e4 8c8c 34c5 2409 8cb6
From : https://packages.grafana.com/gpg.key
Is this ok [y/N]: y
grafana/signature | 3.0 kB 00:00:17 !!!
grafana/primary_db | 92 kB 00:00:01
Resolving Dependencies
--> Running transaction check
---> Package grafana-enterprise.x86_64 0:8.3.4-1 will be installed
--> Processing Dependency: urw-fonts for package: grafana-enterprise-8.3.4-1.x86_64
--> Running transaction check
---> Package urw-base35-fonts.noarch 0:20170801-10.el7 will be installed
--> Processing Dependency: urw-base35-fonts-common = 20170801-10.el7 for package: urw-base35-fonts-20170801-10.el7.noarch
--> Processing Dependency: urw-base35-z003-fonts for package: urw-base35-fonts-20170801-10.el7.noarch
--> Processing Dependency: urw-base35-standard-symbols-ps-fonts for package: urw-base35-fonts-20170801-10.el7.noarch
--> Processing Dependency: urw-base35-p052-fonts for package: urw-base35-fonts-20170801-10.el7.noarch
--> Processing Dependency: urw-base35-nimbus-sans-fonts for package: urw-base35-fonts-20170801-10.el7.noarch
--> Processing Dependency: urw-base35-nimbus-roman-fonts for package: urw-base35-fonts-20170801-10.el7.noarch
--> Processing Dependency: urw-base35-nimbus-mono-ps-fonts for package: urw-base35-fonts-20170801-10.el7.noarch
--> Processing Dependency: urw-base35-gothic-fonts for package: urw-base35-fonts-20170801-10.el7.noarch
--> Processing Dependency: urw-base35-d050000l-fonts for package: urw-base35-fonts-20170801-10.el7.noarch
--> Processing Dependency: urw-base35-c059-fonts for package: urw-base35-fonts-20170801-10.el7.noarch
--> Processing Dependency: urw-base35-bookman-fonts for package: urw-base35-fonts-20170801-10.el7.noarch
--> Running transaction check
---> Package urw-base35-bookman-fonts.noarch 0:20170801-10.el7 will be installed
--> Processing Dependency: xorg-x11-server-utils for package: urw-base35-bookman-fonts-20170801-10.el7.noarch
--> Processing Dependency: xorg-x11-server-utils for package: urw-base35-bookman-fonts-20170801-10.el7.noarch
--> Processing Dependency: xorg-x11-font-utils for package: urw-base35-bookman-fonts-20170801-10.el7.noarch
--> Processing Dependency: xorg-x11-font-utils for package: urw-base35-bookman-fonts-20170801-10.el7.noarch
---> Package urw-base35-c059-fonts.noarch 0:20170801-10.el7 will be installed
---> Package urw-base35-d050000l-fonts.noarch 0:20170801-10.el7 will be installed
---> Package urw-base35-fonts-common.noarch 0:20170801-10.el7 will be installed
---> Package urw-base35-gothic-fonts.noarch 0:20170801-10.el7 will be installed
---> Package urw-base35-nimbus-mono-ps-fonts.noarch 0:20170801-10.el7 will be installed
---> Package urw-base35-nimbus-roman-fonts.noarch 0:20170801-10.el7 will be installed
---> Package urw-base35-nimbus-sans-fonts.noarch 0:20170801-10.el7 will be installed
---> Package urw-base35-p052-fonts.noarch 0:20170801-10.el7 will be installed
---> Package urw-base35-standard-symbols-ps-fonts.noarch 0:20170801-10.el7 will be installed
---> Package urw-base35-z003-fonts.noarch 0:20170801-10.el7 will be installed
--> Running transaction check
---> Package xorg-x11-font-utils.x86_64 1:7.5-21.el7 will be installed
--> Processing Dependency: libfontenc.so.1()(64bit) for package: 1:xorg-x11-font-utils-7.5-21.el7.x86_64
---> Package xorg-x11-server-utils.x86_64 0:7.7-20.el7 will be installed
--> Processing Dependency: libXxf86misc.so.1()(64bit) for package: xorg-x11-server-utils-7.7-20.el7.x86_64
--> Processing Dependency: libXmuu.so.1()(64bit) for package: xorg-x11-server-utils-7.7-20.el7.x86_64
--> Processing Dependency: libXmu.so.6()(64bit) for package: xorg-x11-server-utils-7.7-20.el7.x86_64
--> Running transaction check
---> Package libXmu.x86_64 0:1.1.2-2.el7 will be installed
---> Package libXxf86misc.x86_64 0:1.0.3-7.1.el7 will be installed
---> Package libfontenc.x86_64 0:1.1.3-3.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
======================================================================================================================================
Package Arch Version Repository Size
======================================================================================================================================
Installing:
grafana-enterprise x86_64 8.3.4-1 grafana 78 M
Installing for dependencies:
libXmu x86_64 1.1.2-2.el7 base 71 k
libXxf86misc x86_64 1.0.3-7.1.el7 base 19 k
libfontenc x86_64 1.1.3-3.el7 base 31 k
urw-base35-bookman-fonts noarch 20170801-10.el7 base 852 k
urw-base35-c059-fonts noarch 20170801-10.el7 base 879 k
urw-base35-d050000l-fonts noarch 20170801-10.el7 base 75 k
urw-base35-fonts noarch 20170801-10.el7 base 7.6 k
urw-base35-fonts-common noarch 20170801-10.el7 base 19 k
urw-base35-gothic-fonts noarch 20170801-10.el7 base 650 k
urw-base35-nimbus-mono-ps-fonts noarch 20170801-10.el7 base 796 k
urw-base35-nimbus-roman-fonts noarch 20170801-10.el7 base 860 k
urw-base35-nimbus-sans-fonts noarch 20170801-10.el7 base 1.3 M
urw-base35-p052-fonts noarch 20170801-10.el7 base 978 k
urw-base35-standard-symbols-ps-fonts noarch 20170801-10.el7 base 40 k
urw-base35-z003-fonts noarch 20170801-10.el7 base 275 k
xorg-x11-font-utils x86_64 1:7.5-21.el7 base 104 k
xorg-x11-server-utils x86_64 7.7-20.el7 base 178 k
Transaction Summary
======================================================================================================================================
Install 1 Package (+17 Dependent packages)
Total download size: 84 M
Installed size: 276 M
Is this ok [y/d/N]:y
************
*安装过程省略*
************
Installed:
grafana-enterprise.x86_64 0:8.3.4-1
Dependency Installed:
libXmu.x86_64 0:1.1.2-2.el7 libXxf86misc.x86_64 0:1.0.3-7.1.el7
libfontenc.x86_64 0:1.1.3-3.el7 urw-base35-bookman-fonts.noarch 0:20170801-10.el7
urw-base35-c059-fonts.noarch 0:20170801-10.el7 urw-base35-d050000l-fonts.noarch 0:20170801-10.el7
urw-base35-fonts.noarch 0:20170801-10.el7 urw-base35-fonts-common.noarch 0:20170801-10.el7
urw-base35-gothic-fonts.noarch 0:20170801-10.el7 urw-base35-nimbus-mono-ps-fonts.noarch 0:20170801-10.el7
urw-base35-nimbus-roman-fonts.noarch 0:20170801-10.el7 urw-base35-nimbus-sans-fonts.noarch 0:20170801-10.el7
urw-base35-p052-fonts.noarch 0:20170801-10.el7 urw-base35-standard-symbols-ps-fonts.noarch 0:20170801-10.el7
urw-base35-z003-fonts.noarch 0:20170801-10.el7 xorg-x11-font-utils.x86_64 1:7.5-21.el7
xorg-x11-server-utils.x86_64 0:7.7-20.el7
Complete!
详情操作步骤请自行官网浏览操作
详情操作步骤请自行官网浏览操作
参考链接:Install on RPM-based Linux | Grafana Labs
下载RPM包链接:Download Grafana | Grafana Labs
//提示未安装wget服务
[root@grafana local]# wget https://dl.grafana.com/enterprise/release/grafana-enterprise-8.3.4-1.x86_64.rpm
-bash: wget: command not found
//执行yum install -y wget命令安装即可
[root@grafana local]# yum install -y wget
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.nju.edu.cn
* extras: mirrors.njupt.edu.cn
* updates: mirrors.nju.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package wget.x86_64 0:1.14-18.el7_6.1 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=======================================================================================================================
Package Arch Version Repository Size
=======================================================================================================================
Installing:
wget x86_64 1.14-18.el7_6.1 base 547 k
Transaction Summary
=======================================================================================================================
Install 1 Package
Total download size: 547 k
Installed size: 2.0 M
Downloading packages:
wget-1.14-18.el7_6.1.x86_64.rpm | 547 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : wget-1.14-18.el7_6.1.x86_64 1/1
Verifying : wget-1.14-18.el7_6.1.x86_64 1/1
Installed:
wget.x86_64 0:1.14-18.el7_6.1
Complete!
[root@grafana local]# wget https://dl.grafana.com/enterprise/release/grafana-enterprise-8.3.4-1.x86_64.rpm
--2022-01-31 15:28:20-- https://dl.grafana.com/enterprise/release/grafana-enterprise-8.3.4-1.x86_64.rpm
Resolving dl.grafana.com (dl.grafana.com)... 199.232.194.217, 199.232.198.217, 2a04:4e42:4c::729, ...
Connecting to dl.grafana.com (dl.grafana.com)|199.232.194.217|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 81275912 (78M) [application/x-redhat-package-manager]
Saving to: ‘grafana-enterprise-8.3.4-1.x86_64.rpm’
100%[=============================================================================>] 81,275,912 2.17MB/s in 37s
2022-01-31 15:28:58 (2.12 MB/s) - ‘grafana-enterprise-8.3.4-1.x86_64.rpm’ saved [81275912/81275912]
[root@grafana local]#
[root@grafana local]# ls
bin games go1.17.6.linux-amd64.tar.gz include lib64 prometheus sbin src
etc go grafana-enterprise-8.3.4-1.x86_64.rpm lib libexec prometheus-2.33.0.linux-amd64.tar.gz share
[root@grafana local]# yum install grafana-enterprise-8.3.4-1.x86_64.rpm
[root@grafana local]# systemctl daemon-reload
[root@grafana local]# systemctl start grafana-server
[root@grafana local]# 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@grafana local]# systemctl status grafana-server
● grafana-server.service - Grafana instance
Loaded: loaded (/usr/lib/systemd/system/grafana-server.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2022-01-31 15:34:48 CST; 13s ago
Docs: http://docs.grafana.org
Main PID: 50955 (grafana-server)
CGroup: /system.slice/grafana-server.service
└─50955 /usr/sbin/grafana-server --config=/etc/grafana/grafana.ini --pidfile=/var/run/grafana/grafana-ser...
Jan 31 15:34:53 grafana systemd[1]: [/usr/lib/systemd/system/grafana-server.service:29] Unknown lvalue 'Protec...rvice'
Jan 31 15:34:53 grafana systemd[1]: [/usr/lib/systemd/system/grafana-server.service:31] Unknown lvalue 'Protec...rvice'
Jan 31 15:34:53 grafana systemd[1]: [/usr/lib/systemd/system/grafana-server.service:32] Unknown lvalue 'Protec...rvice'
Jan 31 15:34:53 grafana systemd[1]: [/usr/lib/systemd/system/grafana-server.service:33] Unknown lvalue 'Protec...rvice'
Jan 31 15:34:53 grafana systemd[1]: [/usr/lib/systemd/system/grafana-server.service:34] Unknown lvalue 'Protec...rvice'
Jan 31 15:34:53 grafana systemd[1]: [/usr/lib/systemd/system/grafana-server.service:35] Unknown lvalue 'Protec...rvice'
Jan 31 15:34:53 grafana systemd[1]: [/usr/lib/systemd/system/grafana-server.service:37] Unknown lvalue 'Remove...rvice'
Jan 31 15:34:53 grafana systemd[1]: [/usr/lib/systemd/system/grafana-server.service:39] Unknown lvalue 'Restri...rvice'
Jan 31 15:34:53 grafana systemd[1]: [/usr/lib/systemd/system/grafana-server.service:40] Unknown lvalue 'Restri...rvice'
Jan 31 15:34:53 grafana systemd[1]: [/usr/lib/systemd/system/grafana-server.service:41] Unknown lvalue 'Restri...rvice'
Hint: Some lines were ellipsized, use -l to show in full.
[root@grafana local]#
打开浏览器,输入http://192.168.200.30:3000(端口为3000),打开Grafana控制面板, 初始默认账号和密码均为 admin,初次登录需要修改密码。
设置新的登录密码
进入Web控制界面
点击Data sources
点击“Add data source”
添加Prometheus数据源
填写数据源信息
URL处填写Prometheus服务所在的IP地址,此处将Prometheus服务与Grafana安装在同一台机器上,直接填写localhost即可。
点击Save & test,保存并测试。如图所示。
Dashboards页面选择“Prometheus 2.0 Stats”
点击Dashboards选项卡,选择Prometheus 2.0 Stats
至此Prometheus服务端及Grafana配置完成。
在需要被监视的Linux主机上安装node-exporter 插件,进行安装部署监控。
注意:注意需要下载对应的版本插件,否则会启动失败!!!
插件下载链接🔗:node_exporter-1.3.1.linux-386.tar.gz
[root@centos7 ~]# cd /usr/local/
[root@centos7 local]# curl -OL https://github.com/prometheus/node_exporter/releases/download/v1.3.1/node_exporter-1.3.1.linux-386.tar.gz
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 671 100 671 0 0 327 0 0:00:02 0:00:02 --:--:-- 327
100 8422k 100 8422k 0 0 1037k 0 0:00:08 0:00:08 --:--:-- 1824k
[root@centos7 local]#
[root@centos7 local]# tar -zxf node_exporter-1.3.1.linux-386.tar.gz
[root@centos7 local]# mv node_exporter-1.3.1.linux-386 node_exporter
[root@centos7 local]# cd node_exporter
[root@centos7 node_exporter]# ./node_exporter
打开浏览器,输入http://192.168.200.40:9100
输入http://192.168.200.40:9100/metrics,出现以下数据,表示服务启动。
按CTRL+C键结束node_exporter进程
创建node_exporter服务,让node_exporter以服务的方式,开机自启。
添加node_exporter.service配置文件
vim /etc/systemd/system/node_exporter.service
[root@centos7 node_exporter]# vim /etc/systemd/system/node_exporter.service
[root@centos7 node_exporter]# cat /etc/systemd/system/node_exporter.service
[Unit]
Description=node_exporter
After=network.target
[Service]
ExecStart=/usr/local/node_exporter/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
[root@centos7 node_exporter]#
启动node_exporter,并设置开机自启动
[root@centos7 node_exporter]# systemctl daemon-reload
[root@centos7 node_exporter]# systemctl start node_exporter
[root@centos7 node_exporter]# systemctl enable node_exporter
[root@centos7 node_exporter]# systemctl status node_exporter
至此node_exporter配置完成。
进入Prometheus的安装文件夹,打开Prometheus配置文件。
在scrape_configs标签下,添加以下内容,配置监控主机信息。
[root@grafana ~]# cd /usr/local/prometheus
[root@grafana prometheus]# ll
total 196060
drwxr-xr-x 2 3434 3434 38 Jan 30 05:53 console_libraries
drwxr-xr-x 2 3434 3434 173 Jan 30 05:53 consoles
drwxr-xr-x 4 root root 58 Jan 31 15:02 data
-rw-r--r-- 1 3434 3434 11357 Jan 30 05:53 LICENSE
-rw-r--r-- 1 3434 3434 3773 Jan 30 05:53 NOTICE
-rwxr-xr-x 1 3434 3434 104419069 Jan 30 05:47 prometheus
-rw-r--r-- 1 3434 3434 934 Jan 30 05:53 prometheus.yml
-rwxr-xr-x 1 3434 3434 96325624 Jan 30 05:50 promtool
[root@grafana prometheus]# vim prometheus.yml
[root@grafana prometheus]# cat prometheus.yml
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: "prometheus"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["localhost:9090"]
- job_name: 'CentOS7.9'
static_configs:
- targets: ['192.168.56.201:9100']
labels:
instance: CentOS系统监控管理平台
[root@grafana prometheus]#
[root@grafana prometheus]# systemctl restart prometheus
打开浏览器,输入http://192.168.200.30:9090/targets,查看到主机已经显示。
至此,被监控的Linux主机已经加入。
Grafana官方为我们提供了很多dashboard页面,可直接下载使用。浏览器访问 https://grafana.com/grafana/dashboards下载所需要的dashboard页面
本示例使用的Dashboard如下图所示,链接如下:
1 Node Exporter for Prometheus Dashboard CN 20201010 dashboard for Grafana | Grafana Labs
复制 ID,并下载JSON文件,用于之后的导入。
至此Prometheus+Grafana 安装配置,并实现监控Linux主机,配置完成。
基于服务端,即监控端进行操作。
[root@grafana prometheus]# pwd
/usr/local/prometheus
[root@grafana prometheus]# vim prometheus.yml
//添加新node主机信息
- job_name: 'Computer-VM'
static_configs:
- targets: ['192.168.200.20:9100']
labels:
instance: Computer-VM
//按:wq保存退出即可
[root@grafana prometheus]# systemctl daemon-reload //重新加载
[root@grafana prometheus]# systemctl restart prometheus //重启服务
[root@grafana prometheus]# systemctl status prometheus //查看服务状态
添加完成。
至此,新添加一台被监视的Linux主机完成。
本实验采用Prometheus+Grafana的安装部署方式实现对Linux系统主机的统一监控,Prometheus自带有监控功能,但不能简洁直观的反映出被监控端的详细信息。这时,采用grafana中提供的丰富的Dashboard页面,简洁直观的显示系统的各个参数的详细情况,给人焕然一新的感觉,便于维护管理。