美文网首页收藏
Prometheus+Grafana(更新中)

Prometheus+Grafana(更新中)

作者: 这货不是王马勺 | 来源:发表于2022-06-24 17:57 被阅读0次

参考https://www.cnblogs.com/jinanxiaolaohu/p/15154049.html

Prometheus环境配置

除了网络配置、host文件配置之外,尤其重要的是进行时间同步的配置;
时间同步:

mount /dev/sr0 /mnt
yum install ntpdate -y
ntpdate cn.ntp.org.cn

部署

下载软件:
https://prometheus.io/download/
下载压缩包(.tar.gz)
上传并解压:

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/

直接使用默认配置文件启动:

/usr/local/prometheus/prometheus --config.file="/usr/local/prometheus/prometheus.yml"&

其中可执行文件prometheus就是启动文件,prometheus.yml是配置文件。
&连接符代表后台运行,不占用终端窗口。
确认端口9090:

lsof -i:9090
ss -naltp |grep 9090

注意lsof(list open files)工具需要自行安装。
访问:
浏览器访问http://服务器ip:9090即可

设置监控目标:



采集的数据:


监控Linux主机

1.在被监控端安装node_exporter组件
下载地址:https://prometheus.io/download/
(监控不同的东西都需要不同组件)
上传解压:

tar xf node_exporter-0.16.0.linux-amd64.tar.gz -C  /usr/local/
mv  /usr/local/node_exporter-0.16.0.linux-amd64/  /usr/local/node_exporter/

里面就一个启动命令node_exporter,可以直接使用此命令启动

ls /usr/local/node_exporter/
nohup /usr/local/node_exporter/node_exporter &

nohup避免了终端关闭导致进程关闭。
确认端口(9100)
一般下载界面都有端口说明

lsof -i:9100
ss -naltp |grep 9100

查看搜集的信息http://被监控端的ip地址:9100/metrics

然后让Prometheus可以拉取node节点信息,
回到Prometheus服务器的配置文件,添加被监控机器的配置段,
在配置文件最后加上下面三行:

vim /usr/local/prometheus/prometheus.yml
- job_name: 'agent1'  #起个job名来代表被监控的机器
  static_configs:
  - targets: ['10.1.1.14:9100']  #此处改成被监控机器的ip,端口是9100

改完配置之后重启服务:

pkill prometheus
lsof -i:9090
/usr/local/prometheus/prometheus --config.file="/usr/local/prometheus/prometheus.yml"&
lsof -i:9090

回到web管理界面,status, targets可以看到多了一些监控目标


监控MySQL服务

在被管理机器上安装mysqld_exporter组件

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/

创建mysql的专用用户,并授予select、replication client、process的权限。

在mysqld_exporter组件中配置mysql信息,手工创建.my.cnf文件并添加如下内容:

vim /usr/local/mysqld_exporter/.my.cnf
[client]
user=prometheus
password=prometheus

启动mysqld_exporter

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

确认端口(9104)

回到Prometheus服务器的配置文件里添加被监控的mysql配置段:
在主配置文件的最后再添加下面三行

vim /usr/local/prometheus/prometheus.yml
- job_name:'agent1_mysql'  #取一个job名称来代表被监控的mysql
static_configs:
- targets: ['10.10.1.220:9104']   #这里改成被监控机器的ip,后面端口接9104

配置完成后重启服务:

pkill prometheus
lsof -i:9090
/usr/local/prometheus/prometheus --config.file="/usr/local/prometheus/prometheus.yml"&
lsof -i:9090

回到web管理界面,status, targets可以看到多了一些监控目标.

Grafana安装和配置

官网https://grafana.com/
下载地址:https://grafana.com/grafana/download
可直接下载rpm包安装即可,然后启动

rpm -ivh /grafana-5.3.4-1.x86_64.rpm
systemctl start grafana-server
systemctl enable grafana-server

确认端口3000

ss -naltp |grep 3000

注:有两个依赖包需要安装,可直接yum安装grafana解决依赖

yum install grafana-5.3.4-1.x86_64.rpm -y

通过浏览器方位http://grafana服务器ip:3000即可登录界面,使用默认的admin,密码也是admin,第一次登录的时候需要修改admin密码。

添加Prometheus的数据源:
在图形界面中选择add data source,设置数据源、类型、ip地址、端口号等信息;


相关文章

网友评论

    本文标题:Prometheus+Grafana(更新中)

    本文链接:https://www.haomeiwen.com/subject/gbtmvrtx.html