网络编程 
首页 > 网络编程 > 浏览文章

Prometheus的安装和配置教程详解

(编辑:jimmy 日期: 2024/9/17 浏览:3 次 )

1. 从官网选择Prometheus版本进行下载

官网地址 https://github.com/prometheus/prometheus/releases/

2. 实验安排

在主机192.168.153.137上安装prometheus监控192.168.153.138上的mysql服务和主机状态

3. 上传软件包到137服务器并配置

3.1 将软件包解压到 /usr/local 目录下

tar xzf prometheus-2.24.1.linux-amd64.tar.gz -C /usr/local/

3.2 给目录创建软链接

ln -s /usr/local/prometheus-2.24.1.linux-amd64/ /usr/local/prometheus

3.3 切换到目录下

cd /usr/local/prometheus

3.4 修改配置文件 prometheus.yml,配置要监控的项

scrape_configs:
 # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
 - job_name: 'prometheus'

 # metrics_path defaults to '/metrics'
 # scheme defaults to 'http'.

 static_configs:
 - targets: ['localhost:9090']
 #监控Linux主机状态
 - job_name: 'linux'
 static_configs:
 - targets: ['192.168.153.138:9100']
 #监控mysql服务状态
 - job_name: 'mysql'
 static_configs:
 - targets: ['192.168.153.138:9104']

3.5 启动promethus服务

./prometheus --config.file=prometheus.yml

3.6 浏览器输入 IP:9090 查看

Status->Targets页面下,我们可以看到我们配置的两个Target,它们的State为DOWN。

Prometheus的安装和配置教程详解

4. 配置138主机 4.1 下载exporter

下载地址 https://github.com/prometheus/node_exporter/releases

4.2 将软件包解压到 /usr/local 目录下

tar xzf node_exporter-1.0.1.linux-amd64.tar.gz -C /usr/local/

4.3 启动exporter

nohup /usr/local/node_exporter-1.0.1.linux-amd64/node_exporter &

4.4 下载mysqld_exporter

下载地址 https://github.com/prometheus/mysqld_exporter/releases

4.5 将软件包解压到 /usr/local 目录下

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

4.6 数据库给mysqld_exporter授权

[root@host-138 ~]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.

MariaDB [(none)]> GRANT REPLICATION CLIENT,PROCESS ON *.* TO 'mysql_monitor'@'localhost' identified by 'mysql_monitor';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> GRANT SELECT ON *.* TO 'mysql_monitor'@'localhost';
Query OK, 0 rows affected (0.00 sec)

4.7 创建 .my.cnf 配置文件

vim /usr/local/mysqld_exporter-0.12.1.linux-amd64/.my.cnf

内容为:

[client]
user=mysql_monitor
password=mysql_monitor

4.8 运行mysqld_exporter服务

nohup /usr/local/mysqld_exporter-0.12.1.linux-amd64/mysqld_exporter --config.my-cnf="/usr/local/mysqld_exporter-0.12.1.linux-amd64/.my.cnf" &

5. 在promethus页面刷新Status->Targets页面,可以看到配置的两个Target的State为UP:

Prometheus的安装和配置教程详解

5. 在137主机上安装部署grafana

安装教程链接https://www.jb51.net/article/204660.htm

5.1 添加promethus数据源 未完待续…

上一篇:grafana安装及使用教程详解
下一篇:比特币上的数独游戏合约的实现代码
一句话新闻
一文看懂荣耀MagicBook Pro 16
荣耀猎人回归!七大亮点看懂不只是轻薄本,更是游戏本的MagicBook Pro 16.
人们对于笔记本电脑有一个固有印象:要么轻薄但性能一般,要么性能强劲但笨重臃肿。然而,今年荣耀新推出的MagicBook Pro 16刷新了人们的认知——发布会上,荣耀宣布猎人游戏本正式回归,称其继承了荣耀 HUNTER 基因,并自信地为其打出“轻薄本,更是游戏本”的口号。
众所周知,寻求轻薄本的用户普遍更看重便携性、外观造型、静谧性和打字办公等用机体验,而寻求游戏本的用户则普遍更看重硬件配置、性能释放等硬核指标。把两个看似难以相干的产品融合到一起,我们不禁对它产生了强烈的好奇:作为代表荣耀猎人游戏本的跨界新物种,它究竟做了哪些平衡以兼顾不同人群的各类需求呢?
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网 SiteMap