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
查看关联的主机
相关推荐
watermelonoops3 分钟前
Deepin和Windows传文件(Xftp,WinSCP)
linux·ssh·deepin·winscp·xftp
疯狂飙车的蜗牛1 小时前
从零玩转CanMV-K230(4)-小核Linux驱动开发参考
linux·运维·驱动开发
远游客07133 小时前
centos stream 8下载安装遇到的坑
linux·服务器·centos
马甲是掉不了一点的<.<3 小时前
本地电脑使用命令行上传文件至远程服务器
linux·scp·cmd·远程文件上传
jingyu飞鸟3 小时前
centos-stream9系统安装docker
linux·docker·centos
超爱吃士力架4 小时前
邀请逻辑
java·linux·后端
White_Mountain5 小时前
在Ubuntu中配置mysql,并允许外部访问数据库
数据库·mysql·ubuntu
老王笔记5 小时前
GTID下复制问题和解决
mysql
cominglately6 小时前
centos单机部署seata
linux·运维·centos
魏 无羡6 小时前
linux CentOS系统上卸载docker
linux·kubernetes·centos