centos7安装prometheus

centos7安装prometheus

  • 安装prometheus
    首先需要安装go语言环境,因为prometheus是基于go开发的,需要一些基于go的环境支持
yum install -y epel-release
yum install go -y
go version
  • 下载prometheus
wget https://github.com/prometheus/prometheus/releases/download/v2.33.0-rc.1/prometheus-2.33.0-rc.1.linux-amd64.tar.gz
tar zxvf prometheus-2.33.0-rc.1.linux-amd64.tar.gz -C /usr/local/
cd /usr/local/
mv prometheus-2.33.0-rc.1.linux-amd64 prometheus
cd prometheus
  • 修改prometheus配置文件,配置监控的主机
vim prometheus.yml

文档最后追加

 - job_name: system-status    # 每一个job_name都是一个监控项,这里代表监控操作系统状态
   static_configs:
     - targets: ['要监控的主机IP:9100']      #被监控主机Ip和端口
       labels:
         instance: hostname-system-status     # 实例名称,在grafana种表示对应的主机
 - job_name: mysql-status			# 监控mysql数据库状态
   static_configs:
     - targets: ['要监控的mysqlIP:9104']
       labels:
         instance: mysql-status
  • 添加prometheus用户用来启动prometheus
useradd -m -s /sbin/nologin prometheus
  • 配置使用systemd管理prometheus服务的启停
vim /etc/systemc/system/prometheus.service
[Unit]
Description=https://prometheus.io
[Service]
Restart=on-failure
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml
[Install]
WantedBy=multi-user.target
  • 重载systemctl
systemctl daemon-reload 
  • 启动prometheus
systemctl start prometheus

浏览器输入http://Ip:9090就可以看到关于prometheus的相关页面了,到此prometheus安装完毕

上一篇:配置cento7加入prometheus监控


下一篇:2021-12-24(剑指 Offer 12. 矩阵中的路径)