首页 > 系统相关 >centos 7 Prometheus+Grafana 监控主机

centos 7 Prometheus+Grafana 监控主机

时间:2023-01-04 14:12:23浏览次数:62  
标签:node exporter centos prometheus Grafana Prometheus usr grafana local

前言:

本文介绍Prometheus 对接Grafana 对主机进行监控
Prometheus部署参考 https://www.cnblogs.com/windle/p/16932216.html

一、前置环境说明

1、关闭firewall
systemctl stop firewalld.service
systemctl disable firewalld.service
2、关闭selinux
vim /etc/selinux/config
SELINUX=disabled

使配置立即生效,重启永久生效

setenforce 0
3、系统约定

软件源代码包存放位置:/opt
源码包编译安装位置:/usr/local/软件名字

二、部署Grafana

systemctl enable grafana-server.service --now
如果图像缺失文本,请确保已安装字体包
yum install fontconfig freetype* urw-fonts
登录测试:http://x.x.x.x:3000(此处IP不公开) 登录grafana,默认用户名密码:admin/admin 修改密码 QUNA@gf123
1、grafana 安装插件
格拉法纳|的饼图插件格拉法纳实验室 (grafana.com)
grafana-cli plugins install grafana-piechart-panel

[root@qzsh32 plugins]# grafana-cli plugins install grafana-piechart-panel
✔ Downloaded grafana-piechart-panel v1.6.2 zip successfully

Please restart Grafana after installing plugins. Refer to Grafana documentation for instructions if necessary.

[root@qzsh32 plugins]# systemctl restart grafana-server.service
离线安装
Alternative installation methods
Download latest zip
wget -nv https://grafana.com/api/plugins/grafana-piechart-panel/versions/latest/download -O /tmp/grafana-piechart-panel.zip
Bash
Extract and move into place
unzip -q /tmp/grafana-piechart-panel.zip -d /tmp
mv /tmp/grafana-piechart-panel-* /var/lib/grafana/plugins/grafana-piechart-panel
sudo service grafana-server restart

三、部署node_exporter

centos 7安装

1、下载node_exporter
sudo wget https://github.com/prometheus/node_exporter/releases/download/v1.1.2/node_exporter-1.1.2.linux-amd64.tar.gz
2、解压软件
tar xf node_exporter-1.1.2.linux-amd64.tar.gz -C /usr/local/
cd /usr/local/ && mv node_exporter-1.1.2.linux-amd64/ node_exporter
3、创建用户
useradd -s /sbin/nologin prometheus
sudo chown -R prometheus:prometheus node_exporter/
4、已服务启动
cat >>/usr/lib/systemd/system/node-exporter.service<<EOF
[Unit]
Description=Prometheus server Daemon
After=network.target
[Service]
Type=simple
User=root
Group=root
ExecStart=/usr/local/prometheus/prometheus  --config.file=/usr/local/prometheus/prometheus.yml  --storage.tsdb.path=/data/prometheus  --storage.tsdb.retention=15d --web.enable-lifecycle
Restart = on-failure
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable node-exporter --now
netstat -tunlp | grep 9100

脚本:

点击查看代码
#!/bin/bash

sudo wget https://github.com/prometheus/node_exporter/releases/download/v1.1.2/node_exporter-1.1.2.linux-amd64.tar.gz


tar xf node_exporter-1.1.2.linux-amd64.tar.gz -C /usr/local/ && cd /usr/local/ && mv node_exporter-1.1.2.linux-amd64/ node_exporter && useradd -s /sbin/nologin prometheus && chown -R prometheus:prometheus node_exporter/
cd /usr/lib/systemd/system/

cat << EOF > node-exporter.service
[Unit]
Description=Prometheus node_exporter
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/node_exporter/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF

如果系统开启防火墙,需要设置防火墙规则

systemctl status firwlalld
firewall-cmd --zone=public --add-port=9100/tcp --permanent (--permanent永久生效,没有此参数重启后失效)
重新载入
firewall-cmd --reload

centos6安装

nohup ./node_exporter --web.listen-address=":9100" >/dev/null 2>&1 &

如果系统开启防火墙,需要设置防火墙规则

iptables -A INPUT -p tcp --dport 9100 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 9100 -j ACCEPT
service iptables save
vim /etc/sysconfig/iptables
service iptables restart

安装mysql_exporter

useradd -s /sbin/nologin prometheus

tar xzvf mysqld_exporter-0.12.1.linux-amd64.tar.gz -C /usr/local/

ln -s /usr/local/mysqld_exporter-0.12.1.linux-amd64/ /usr/local/mysqld_exporter

MariaDB [(none)]> grant process,replication client,select on . to 'exporter'@'localhost'
identified by 'redhat123';
MariaDB [(none)]> flush privileges;

vim /usr/local/mysqld_exporter/my.cnf

[client]
user=exporter
password=redhat123

vim /usr/lib/systemd/system/mysql_exporter.service

[Unit]
Description=Prometheus mysqld_exporter
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/mysqld_exporter/mysqld_exporter --config.my-cnf=/usr/local/mysqld_exporter/my.cnf
Restart=on-failure
[Install]
WantedBy=multi-user.target

systemctl daemon-reload

systemctl enable mysql_exporter --now

安装 blackbox_exporter

tar xf blackbox_exporter-0.19.0.linux-amd64.tar.gz -C /usr/local/
cd /usr/local/
mv blackbox_exporter-0.19.0.linux-amd64/ blackbox_exporter
chown -R prometheus:prometheus blackbox_exporter/

vim /usr/lib/systemd/system/blackbox_exporter.service
[Unit]
Description=blackbox_exporter
After=network.target

[Service]
User=prometheus
Type=simple
ExecStart=/usr/local/blackbox_exporter/blackbox_exporter --config.file=/usr/local/blackbox_exporter/blackbox.yml
Restart=on-failure

[Install]
WantedBy=multi-user.target

systemctl start blackbox_exporter.service
systemctl enable blackbox_exporter.service

安装Alertmanager
tar xf alertmanager-0.22.2.linux-amd64.tar.gz -C /usr/local/
cd /usr/local/
mv alertmanager-0.22.2.linux-amd64/ alertmanager
chown -R prometheus:prometheus alertmanager/

vim /usr/lib/systemd/system/alertmanager.service
[Unit]
Description=alertmanager
After=network.target

[Service]
User=prometheus
Type=simple
ExecStart=/usr/local/alertmanager/alertmanager --config.file=/usr/local/alertmanager/alertmanager.yml
Restart=on-failure

[Install]
WantedBy=multi-user.target

systemctl daemon-reload
systemctl start alertmanager.service
systemctl enable alertmanager.service

四、配置Prometheus

vim /usr/local/prometheus/prometheus.yml

cd /usr/local/prometheus/ && ./promtool check config prometheus.yml
curl -X POST http://192.168.1.160:9090/-/reload

标签:node,exporter,centos,prometheus,Grafana,Prometheus,usr,grafana,local
From: https://www.cnblogs.com/windle/p/17024671.html

相关文章

  • centos.7.6.1810
    最近在玩国产化系统,采用华为国产服务器,但是系统依旧采用centos,费劲找了很多网址都没有想用的版本我这里是用centos7.6.1810版本,提供下载地址,可以参考下:https://archive.k......
  • CentOS7重启selinux
    1查看selinux状态[root@localhost~]#sestatusSELinuxstatus:disabled2关闭零时关闭[root@localhost~]#setenforcesetenforce:SELinuxisdisabled永久关闭......
  • Linux(centos7)开机命令行字符欢迎界面修改显示IP
    Linux有两个公告栏:1.登录前显示的“公告栏”配置文件/etc/issue ;2.登录后显示的“布告栏”文件 /etc/motd即messageoftoday(布告栏信息)这两个是普通文件,是程序,所......
  • 面对Centos7系统的openssl版本升级
    CentOS7的版本系统,默认的OpenSSL的版本为OpenSSL1.0.2k-fips26Jan2017。但是openssl需要的版本需要较高的版本。通过下载最新的openssl版本。对openssl进行升级。1.查......
  • go get / go install 配置系统代理(centos 7)
    在goget或者goinstall时,代理报错,比如proxyconnecttcp:dialtcp:lookup3128:nosuchhostdialtcp:lookup proxy.golang.com.cn on8.8.4.4:53:readudp192......
  • Centos7离线安装Mysql8(rpm安装)
    1.下载:        官网下载: MySQL::DownloadMySQLCommunityServer2.解压将下载好的tar文件放到centos中,目录文件夹名称自定义,解压后得到:[root@localhost......
  • CentOS7源码安装redis6
    CentOS7源码安装redis61.下载源码包[root@localhost~]#wgethttps://download.redis.io/releases/redis-6.2.8.tar.gz2.安装依赖 redis6需要gcc高版本[root@lo......
  • Window下安装centos虚拟机
    1.下载virtualbox软件,安装virtualbox(一直下一步就行)。官网下载地址:https://www.virtualbox.org/wiki/Downloads   安装时可能提示”MicrosoftVisualC++“版本......
  • Centos 6.5 iptables 端口白名单设置
     iptables-IINPUT-ptcp--dport8888-jDROPiptables-IINPUT-s10.9.145.101-ptcp--dport8888-jACCEPTserviceiptablessave参考文章:https://www.cnblo......
  • centos root用户自动登录
    1.切换至管理员通过su指令切换至root用户2.打开/etc/gdm/custom.confvi/etc/gdm/custom.conf 在文件[daemon]下写入:AutomaticLoginEnable=TrueAutomaticLogin=root......