3.1 Prometheus环境搭建

3 篇文章 0 订阅
2 篇文章 0 订阅

 

  • 项目摘要:

本文是搭建一套prometheus环境的教程。

前期准备:准备三台虚拟机,本文以centos7为例。

  • 项目具体实施:
  1. 分别进入每台虚拟机设置hostname:

# hostnamectl set-hostname prometheus.demo

# hostnamectl set-hostname agent.demo

# hostnamectl set-hostname grafana.demo

 

  1. 在每台虚拟机的/etc/hosts文件中加入如下内容(ip改成真实的ip地址):

ip agent.demo

ip grafana.demo

ip prometheus.demo

 

  1. 每台虚拟机同步时间(前两条命令不一定需要):

# mount /dev/sr0/mnt

# yum install ntpdate -y

# ntpdate -u cn.pool.ntp.org

  1. 每台禁用SELINUX

# vim /etc/selinux/config

  将SELINUX=enforcing 修改为:SELINUX=disabled

 

  1. 每台关闭防火墙

# systemctl stop firewalld

# systemctl disable firewalld

# iptables -F

 

  1. 安装prometheus(登录到prometheus主机)

下载后,解压就能用,不需要编译。

  1. 下载:

# wget https://github.com/prometheus/prometheus/releases/download/v2.5.0/prometheus-2.5.0.linux-amd64.tar.gz

  1. 解压、移动/重命名:
  2. # tar xf prometheus-2.5.0.linux-amd64.tar.gz -C /usr/local

# mv /usr/local/prometheus-2.5.0.linux-amd64/ /usr/local/prometheus

# mkdir /etc/prometheus

# cp /usr/local/prometheus/prometheus.yml  /etc/prometheus/

  1. 启动:

# /usr/local/prometheus/prometheus --config.file=" /etc/prometheus/

/prometheus.yml" &

 解释:&:表示后台运行

  默认端口是9090

 查看端口占用情况:

# lsof -i:9090 或者 ss -naltp | grep 9090

此时,浏览器输入http://ip:9090即可访问到prometheus的主界面:

  1. 安装node_exporter监控远程Linux主机(登录到agent机器)
  1. 下载:

# wget https://github.com/prometheus/node_exporter/releases/download/v0.16.0/node_exporter-0.16.0.linux-amd64.tar.gz

  1. 解压:# tar xf node_exporter-0.16.0.linux-amd64.tar.gz -C /usr/local/
  2. 重命名: # mv  /usr/local/node_exporter-0.16.0.linux-amd64/ /usr/local/node_exporter
  3. 启动:# nohup /usr/local/node_exporter/node_exporter &
  4. 查看启动情况:# lsof -i:9100
  5. 打开浏览器输入:http://ip:9100/metrics即可看到监控信息。
  6. 将该监控添加到prometheus监控软件,登录到prometheus机器。

修改prometheus.yml

# vim /etc/prometheus/prometheus.yml

末尾添加如下内容:

 - job_name: 'agent'

  static_configs: 

  - targets: ['ip:9100']

  # ps -aux | grep prome

  # kill -HUP 进程号

去控制台查看。(选择statusàtargets查看)

  1. 在agent机器添加一个mysql监控
  1. 下载:

# wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.11.0/mysqld_exporter-0.11.0.linux-amd64.tar.gz

  1. 解压:tar xf mysqld_exporter-0.11.0.linux-amd64.tar.gz -C /usr/local/重命名:# mv /usr/local/mysqld_exporter-0.11.0.linux-amd64/ /usr/local/mysqld_exporter
  2. 安装mysql数据库:

参考:https://www.jianshu.com/p/fe476f511485

创建一个mysql配置文件,写上连接的用户名与密码(和上面的授权的用户名 和密码要对应)

# vim /usr/local/mysqld_exporter/.my.cnf

[client]

user=用户名

password=密码

# nohup /usr/local/mysqld_exporter/mysqld_exporter --config.my-cnf=/usr/local/mysqld_exporter/.my.cnf &

确认端口(9104)

# lsof -i:9104

浏览器输入:http://ip:9104/metrics即可看到监控信息。

将该监控添加到prometheus监控软件,登录到prometheus机器。

编辑如下内容:

# vim /etc/prometheus/prometheus.yml

末尾添加如下内容:

 - job_name: 'agent_mysql'

  static_configs: 

  - targets: ['ip:9104']

  # kill -HUP 进程号

再次去浏览器页面观察是否添加成功。

  1. 安装grafana
  1. 下载:# wget https://dl.grafana.com/oss/release/grafana-5.3.4-1.x86_64.rpm
  2. 安装:# rpm -ivh grafana-5.3.4-1.x86_64.rpm
  3. 启动:

# systemctl start grafana-server

# systemctl enable grafana-server

  1. 检查端口: # lsof -i:3000
  2. 打开浏览器输入:http://ip:3000查看是否成功运行。

至此,环境搭建完成。

资源下载地址(1份与本文内容一致的文档和两份讲义):https://download.csdn.net/download/qq_25337221/12437489

  • 参考链接:

1. mysqlId安:https://blog.csdn.net/an88411980/article/details/86610043

2.prometheus安装: https://www.cnblogs.com/fatyao/p/11007357.html

3.grafana安装:https://grafana.com/grafana/download/5.3.4

本内容由安康学院“雨季”原创。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值