linux系统监控工具prometheus的安装以及监控mysql

prometheus

安装

复制代码
https://prometheus.io/download/

下载客户端和服务端以及需要监控的所有的包

服务端

复制代码
官网下载下载prometheus

tar -xf prometheus-2.47.2.linux-amd64.tar.gz -C /usr/local/
cd /usr/local/
mv prometheus-2.47.2.linux-amd64 prometheus
cd prometheus
./prometheus --config.file=prometheus.yml &     //启动prometheus

将Prometheus配置为systemd管理

vim /usr/lib/systemd/system/prometheus.service

[Unit]
Description=https://prometheus.io

[Service]
Restart=on-failure
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --web.listen-address=:9090

[Install]                      
WantedBy=multi-user.target


systemctl daemon-reload
systemctl start prometheus

客户端

复制代码
官网下载安装node_exporter

tar -xf node_exporter-1.7.0.linux-amd64.tar.gz -C /usr/local/
cd /usr/local/
mv node_exporter-1.7.0.linux-amd64/ node_exporter
cd node_exporter/
./node_exporter &

默认端口9100

将node_exporter配置为systemd管理

vim /usr/lib/systemd/system/node_exporter.service

[Unit]
Description=node_exporter
After=network.target 

[Service]
ExecStart=/usr/local/node_exporter/node_exporter
Restart=on-failure

[Install]
WantedBy=multi-user.target


systemctl daemon-reload
systemctl start node_exporter

服务端配置数据
vim 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"]
  # 添加以下内容
  - job_name: "node_exporter"
    static_configs:
    # 如果有多个机器,用','分开
    - targets: ['ip:端口']

# 重启prometheus服务
systemctl restart prometheus

监控mysql

ini 复制代码
# 官网下载安装mysqld-exporter
tar xf mysqld_exporter-0.15.0.linux-amd64.tar.gz -C /usr/local/
cd /usr/local
mv mysqld_exporter-0.15.0.linux-amd64 mysqld_exporter
cd mysqld_exporter/

vim .my.cnf

[client]
user=用户名
password=密码


./mysqld_exporter --config.my-cnf="/usr/local/mysqld_exporter/.my.cnf" &           //启动mysqld-exporter


ps -ef |grep mysqld_exporter    //查看进程
ss -lntp |grep 4647             //过滤进程号,查看端口
默认端口:9104
复制代码
将mysqld-exporter配置为systemd管理

vim /usr/lib/systemd/system/mysqld_exporter.service

[Unit]
Description=Prometheus
[Service]
ExecStart=/usr/local/mysqld_exporter/mysqld_exporter --config.my-cnf=/usr/local/mysqld_exporter/.my.cnf
Restart=on-failure
[Install]
WantedBy=multi-user.target


systemctl daemon-reload
systemctl start mysqld_exporter

服务端配置
vim prometheus.yml                  //prometheus配置文件添加
  - job_name: 'mysql'
    static_configs:
      - targets: ['ip:端口']


systemctl restart prometheus   //重启prometheus

prometheus浏览器查看

复制代码
浏览器访问
ip:9090
复制代码
status=》Targets
查看关联的主机
相关推荐
喆星时瑜8 分钟前
MySQL【8.0.41版】安装详细教程--无需手动配置环境
数据库·mysql·安装教程
菜就多练吧18 分钟前
Redis与Mysql双写一致性如何保证?
数据库·redis·mysql
喵喵帕斯1 小时前
MySQL索引优化-索引可见性
后端·sql·mysql
kfepiza1 小时前
`use_tempaddr` 和 `temp_valid_lft ` 和 `temp_prefered_lft ` 笔记250405
linux·网络·笔记·tcp/ip·ip·tcp
流星白龙2 小时前
【Linux】39.一个基础的HTTP Web服务器
linux·服务器·http
菜鸟康2 小时前
Linux网络编程——TCP协议格式、可靠性分析
linux·网络·tcp/ip
共享家95272 小时前
Linux权限管理:从入门到实践
linux·运维·服务器
霖檬ing2 小时前
PXE远程安装服务器
linux·运维
monster - r2 小时前
MySQL【sql之DML】
数据库·sql·mysql
Starry_hello world3 小时前
Linux 入门指令(1)
linux·笔记·有问必答