MySQL监控方案PMM之PMM Client的安装

2024年 1月 30日 44.0k 0

1 PMM Client介绍

PMM Client安装在每个要监视的数据库主机上。它收集服务器指标,一般系统指标和查询分析数据,以获得完整的性能概述。收集的数据发送到PMM服务器。

2 PMM Client安装

1)下载安装包

PMM Client安装的方法有两种:

  • Docker:将PMM Client作为Docker容器运行;
  • 安装包:下载安装包手动安装。

最常用的是使用二进制包进行安装,安装包在percona的首页下载:

下载哪个版本看个人喜好,推荐下载最新版本。https://www.percona.com/downloads

如果服务器能联网,也可以直接下载到服务器上:

wget https://downloads.percona.com/downloads/pmm2/2.41.0/binary/tarball/pmm2-client-2.41.0.tar.gz

2)解包并重命名

[root@mysql001 local]# cd /usr/local/
[root@mysql001 local]# tar -xvf pmm2-client-2.41.0.tar.gz

3)编译安装

[root@mysql001 local]# cd pmm2-client-2.41.0
[root@mysql001 pmm2-client-2.41.0]# export PMM_DIR=/usr/local/percona/pmm2
[root@mysql001 pmm2-client-2.41.0]# echo $PMM_DIR
/usr/local/percona/pmm2
[root@mysql001 pmm2-client-2.41.0]# ./install_tarball
Installing into /usr/local/percona/pmm2...

PMM Client的安装路径在/usr/local/percona/pmm2,目录结构如下:

[root@mysql001 pmm2]# cd /usr/local/percona/pmm2
[root@mysql001 pmm2]# ls
bin collectors config exporters tools

4)添加环境变量

[root@mysql001 pmm2]# vim /etc/profile
#添加
export PMM_DIR=/usr/local/percona/pmm2
export PATH=$PATH:$PMM_DIR/bin

[root@mysql001 pmm2]# source /etc/profile

至此,PMM Client安装完毕。

完成PMM Client安装后,需要做的事情有:

  1. 向PMM服务器注册节点;
  2. 根据类型配置和添加业务。

3 向PMM服务器注册节点

1)注册pmm-agent

[root@mysql001 ~]# pmm-agent setup --config-file=/usr/local/percona/pmm2/config/pmm-agent.yaml --server-address=192.168.131.60 --server-insecure-tls --server-username=admin --server-password=pmm123.

INFO[2024-01-29T19:10:55.365+08:00] Loading configuration file /usr/local/percona/pmm2/config/pmm-agent.yaml. component=setup
INFO[2024-01-29T19:10:55.365+08:00] Temporary directory is not configured and will be set to /usr/local/percona/pmm2/tmp component=setup
INFO[2024-01-29T19:10:55.365+08:00] Using /usr/local/percona/pmm2/exporters/node_exporter component=setup
INFO[2024-01-29T19:10:55.365+08:00] Using /usr/local/percona/pmm2/exporters/mysqld_exporter component=setup
INFO[2024-01-29T19:10:55.365+08:00] Using /usr/local/percona/pmm2/exporters/mongodb_exporter component=setup
INFO[2024-01-29T19:10:55.365+08:00] Using /usr/local/percona/pmm2/exporters/postgres_exporter component=setup
INFO[2024-01-29T19:10:55.365+08:00] Using /usr/local/percona/pmm2/exporters/proxysql_exporter component=setup
INFO[2024-01-29T19:10:55.365+08:00] Using /usr/local/percona/pmm2/exporters/rds_exporter component=setup
INFO[2024-01-29T19:10:55.365+08:00] Using /usr/local/percona/pmm2/exporters/azure_exporter component=setup
INFO[2024-01-29T19:10:55.365+08:00] Using /usr/local/percona/pmm2/exporters/vmagent component=setup
INFO[2024-01-29T19:10:55.365+08:00] Updating PMM Server address from "192.168.131.60" to "192.168.131.60:443". component=setup
Checking local pmm-agent status...
pmm-agent is not running.
Registering pmm-agent on PMM Server...
Registered.
Configuration file /usr/local/percona/pmm2/config/pmm-agent.yaml updated.
Please start pmm-agent: `pmm-agent --config-file=/usr/local/percona/pmm2/config/pmm-agent.yaml`.

看到有Registered字眼说明祖册成功。

pmm-agent setup参数说明:

  • setup: 用来启动PMM agent的setup 脚本,用于设置和启动 PMM agent。
  • –config-file:指定PMM agent的配置文件的位置。
  • –server-address: 这个参数指定了 PMM server 的地址。
  • –server-insecure-tls: 这个参数指示 PMM agent 在与 PMM server 进行 TLS 通信时忽略证书验证。
  • –server-username: 这个参数指定了用于连接到 PMM server 的用户名。
  • –server-password: 这个参数指定了用于连接到 PMM server 的密码。

2)配置pmm-agent日志

默认情况下,pmm-agent将消息发送到stderr和系统日志(Linux上的syslogd或journald)。要配置单独的日志文件,需要编辑pmm-agent启动脚本。

pmm-agent启动脚本使用systemd系统来管理,配置日志文件需要注意:

  • 脚本文件:/usr/lib/systemd/system/pmm-agent.service
  • 参数:StandardError
  • 默认值:“/var/log/pmm-agent.log”

[root@mysql001 config]# vim /usr/local/pmm2-client-2.41.0/config/pmm-agent.service

根据自己的环境修改ExecStart,添加StandardError

修改后的内容如下:

[Unit]
Description=pmm-agent
After=time-sync.target network.target

[Service]
Type=simple
ExecStart=/usr/local/percona/pmm2/bin/pmm-agent --config-file=/usr/local/percona/pmm2/config/pmm-agent.yaml
Restart=always
RestartSec=2s
StandardError=file:/var/log/pmm-agent.log

[Install]
WantedBy=multi-user.target

重新加载systemd管理器配置:

[root@mysql001 config]# cp /usr/local/pmm2-client-2.41.0/config/pmm-agent.service /usr/lib/systemd/system/
[root@mysql001 config]# systemctl daemon-reload

3)启动pmmagent

[root@mysql001 config]# systemctl start pmm-agent
[root@mysql001 config]# systemctl status pmm-agent
● pmm-agent.service - pmm-agent
Loaded: loaded (/usr/lib/systemd/system/pmm-agent.service; disabled; vendor preset: disabled)
Active: active (running) since Mon 2024-01-29 20:27:53 CST; 1s ago
Main PID: 16665 (pmm-agent)
CGroup: /system.slice/pmm-agent.service
├─16665 /usr/local/percona/pmm2/bin/pmm-agent --config-file=/usr/local/percona/pmm2/config/pmm-agent.yaml
├─16676 /usr/local/percona/pmm2/exporters/node_exporter --collector.bonding --collector.buddyinfo --collector.cpu --colle...
└─16682 /usr/local/percona/pmm2/exporters/vmagent -envflag.enable=true -envflag.prefix=VMAGENT_ -httpListenAddr=127.0.0.1...

Jan 29 20:27:54 mysql001 pmm-agent[16665]: time="2024-01-29T20:27:54.208+08:00" level=info msg="ts=2024-01-29T12:27:54.208Z c...xporter
Jan 29 20:27:54 mysql001 pmm-agent[16665]: time="2024-01-29T20:27:54.215+08:00" level=info msg="2024-01-29T12:27:54.209ZtinfotVict...
Jan 29 20:27:54 mysql001 pmm-agent[16665]: time="2024-01-29T20:27:54.222+08:00" level=info msg="2024-01-29T12:27:54.222ZtinfotVict...
Jan 29 20:27:54 mysql001 pmm-agent[16665]: time="2024-01-29T20:27:54.238+08:00" level=info msg="2024-01-29T12:27:54.238Ztinf...m_agent
Jan 29 20:27:54 mysql001 pmm-agent[16665]: time="2024-01-29T20:27:54.238+08:00" level=info msg="2024-01-29T12:27:54.238Ztinf...m_agent
Jan 29 20:27:54 mysql001 pmm-agent[16665]: time="2024-01-29T20:27:54.238+08:00" level=info msg="2024-01-29T12:27:54.238Ztinf...m_agent
Jan 29 20:27:54 mysql001 pmm-agent[16665]: time="2024-01-29T20:27:54.238+08:00" level=info msg="2024-01-29T12:27:54.238Ztinf...m_agent
Jan 29 20:27:54 mysql001 pmm-agent[16665]: time="2024-01-29T20:27:54.239+08:00" level=info msg="2024-01-29T12:27:54.238ZtinfotVict...
Jan 29 20:27:54 mysql001 pmm-agent[16665]: time="2024-01-29T20:27:54.239+08:00" level=info msg="2024-01-29T12:27:54.239Ztinf...m_agent
Jan 29 20:27:54 mysql001 pmm-agent[16665]: time="2024-01-29T20:27:54.239+08:00" level=info msg="2024-01-29T12:27:54.239Ztinf...m_agent
Hint: Some lines were ellipsized, use -l to show in full.

4)设置开机自启

[root@mysql001 config]# systemctl enable pmm-agent
Created symlink from /etc/systemd/system/multi-user.target.wants/pmm-agent.service to /usr/lib/systemd/system/pmm-agent.service.

4 查看pmm-agent监控

1)检查pmm-agent状态

[root@mysql001 config]# pmm-admin status
Agent ID : /agent_id/4de14939-751a-46b6-812b-3ad4cd0f970f
Node ID : /node_id/2d9b4c14-c4c5-4432-9a2d-fce35a0633ac
Node name: mysql001

PMM Server:
URL : https://192.168.131.60:443/
Version: 2.41.0

PMM Client:
Connected : true
Time drift : -53.076956ms
Latency : 403.674µs
Connection uptime: 100
pmm-admin version: 2.41.0
pmm-agent version: 2.41.0
Agents:
/agent_id/2d3b82ae-94be-43e5-b372-049a99a18b68 node_exporter Running 42000
/agent_id/53f78922-dc94-412e-abbc-f5bda5e368b5 vmagent Running 42001

2)查看监控数据

Node Names为主机名hostname。

如果想观察操作系统的详细监控数据,在以下面板查看:

相关文章

Oracle如何使用授予和撤销权限的语法和示例
Awesome Project: 探索 MatrixOrigin 云原生分布式数据库
下载丨66页PDF,云和恩墨技术通讯(2024年7月刊)
社区版oceanbase安装
Oracle 导出CSV工具-sqluldr2
ETL数据集成丨快速将MySQL数据迁移至Doris数据库

发布评论