Centos7 安装Prometheus2.31.1监控安装

Centos7 安装Prometheus2.31.1监控安装,第1张

一、系统换华为云和安装插件

备份源:mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

一步换源:

wget -O /etc/yum.repos.d/CentOS-Base.repo https://repo.huaweicloud.com/repository/conf/CentOS-7-reg.repo

清理缓存:sudo yum clean all

生成新缓存:sudo yum makecache

yum  update -y
yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
yum install libffi-devel -y
yum install -y gcc gcc-c++ openssl-devel zlib-devel
yum -y install  gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel firewalld autoconf automake

二、安装golang环境

golang安装
wget https://dl.google.com/go/go1.17.5.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.17.5.linux-amd64.tar.gz
vi /etc/profile
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
export GOPATH=/root/go
export PATH=$PATH:$GOPATH/BIN

source /etc/profile

vi /etc/profile.d/golang.sh
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin
export GOPATH=/root/go
export PATH=$PATH:$GOPATH/BIN

source /etc/profile.d/golang.sh

测试golang执行文件
vim Hello.go

package main
import "fmt"

func main() {

    fmt.Println("hello world")
    var str string = "hello agin"
    fmt.Println(str)

}

保存
go run ./Hello.go

三、安装Prometheus2.31.1监控

1、安装
wget https://github.com/prometheus/prometheus/releases/download/v2.31.1/prometheus-2.31.1.linux-amd64.tar.gz
tar xf prometheus-2.31.1.linux-amd64.tar.gz -C /usr/local/
cd /usr/local/
mv prometheus-2.31.1.linux-amd64/ prometheus
useradd -M -s /sbin/nologin prometheus
mkdir -p /data/prometheus
chown -R prometheus.prometheus /usr/local/prometheus /data/prometheus
2、配置
vim /usr/local/prometheus/prometheus.yml
#全局配置
global:
  scrape_interval: 15s #每隔15秒向目标抓取一次数,默认为一分钟
  evaluation_interval: 15s #每隔15秒执行一次告警规则,默认为一分钟
  # scrape_timeout: 600s  #抓取数据的超时时间,默认为10s

#告警配置
alerting:
  alertmanagers:
    - static_configs:
        - targets:
          # - alertmanager:9093     #alertmanager所部署机器的ip和端口

#定义告警规则和阈值的yml文件
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

#收集数据配置
#以下是Prometheus自身的一个配置.
scrape_configs:
  #这个配置是表示在这个配置内的时间序例,每一条都会自动添加上这个{job_name:"prometheus"}的标签.
  - job_name: "prometheus"
    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.
    static_configs:            #静态配置
      - targets: ["localhost:9090"]

配置service文件
vim /usr/lib/systemd/system/prometheus.service
[Unit]
Description=The Prometheus Server
After=network.target

[Service]
Restart=on-failure

Type=simple
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml
RestartSec=15s

[Install]
WantedBy=multi-user.target
保存
systemctl daemon-reload

3、启动参数介绍
--config.file             #加载prometheus的配置文件
--web.listen-address   #监听prometheus的web地址和端口
--web.enable-lifecycle #热启动参数,可以在不中断服务的情况下重启加载配置文件
--storage.tsdb.retention   #数据持久化的时间                         
--storage.tsdb.path        #数据持久化的保存路径

设置开机启动:systemctl enable prometheus

启动服务:systemctl start prometheus
重启服务:systemctl restart prometheus
ss -anlt

4、访问:IP地址+9090端口号进行访问

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/994946.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存