在Ubuntu 20.04/18.04 LTS上安装和使用Percona Toolkit

时间:2020-02-23 14:32:08  来源:igfitidea点击:

在这篇文章中,我们将介绍如何在Ubuntu 20.04/18.04上安装和使用Percona Toolkit。
Percona Toolkit是由Percona创建的高级命令行工具集合,以执行可以手动进行复杂的MongoDB和MySQL管理任务。

Percona Toolkit的安装附带了许多脚本,这些脚本被记录得很好,易于使用,并且不依赖于任何外部库。
Percona Toolkit由Percona开发和支持。

在Ubuntu 20.04/18.04 LTS上安装Percona Toolkit

Percona Toolkit可在Percona APT存储库上使用,可以将其添加到Ubuntu 20.04/18.04 LTS服务器。
按照以下步骤在Ubuntu 20.04/18.04上安装Percona Toolkit。

第1步:下载percona存储库文件

使用命令下载存储库文件:

sudo apt update
sudo apt -y install gnupg2 wget
wget https://repo.percona.com/apt/percona-release_latest.$(lsb_release -sc)_all.deb

第2步:安装percona存储库包

下载存储库文件后,将其安装 dpkg命令:

sudo dpkg -i percona-release_latest.$(lsb_release -sc)_all.deb

我们应该获得类似于以下的输出:

Selecting previously unselected package percona-release.
(Reading database ... 194365 files and directories currently installed.)
Preparing to unpack percona-release_latest.focal_all.deb ...
Unpacking percona-release (1.0-17.generic) ...
Setting up percona-release (1.0-17.generic) ...
* Enabling the Percona Original repository
<*> All done!
==> Please run "apt-get update" to apply changes
The percona-release package now contains a percona-release script that can enable additional repositories for our newer products.
For example, to enable the Percona Server 8.0 repository use:
  percona-release setup ps80
Note: To avoid conflicts with older product versions, the percona-release setup command Jan disable our original repository for some products.
For more information, please visit:
  https://www.percona.com/doc/percona-repo-config/percona-release.html

第3步:在Ubuntu 20.04/18.04上安装Percona Toolkit

最后,更新本地APT缓存并安装Percona Toolkit:

sudo apt update
sudo apt install percona-toolkit

同意软件安装:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  geoip-database gsfonts libapt-pkg5.90 libbind9-161 libcroco3
  libdns-export1107 libdns1107 libdns1109 libgeoip1 libicu65 libirs161
  libisc-export1104 libisc1104 libisc1105 libisccc161 libisccfg163 liblwres161
  libmozjs-60-0 liboauth0 libpoppler95 linux-modules-extra-5.4.0-14-generic
  ubuntu-system-service
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  libdbd-mysql-perl libdbi-perl libterm-readkey-perl
Suggested packages:
  libclone-perl libmldbm-perl libnet-daemon-perl libsql-statement-perl
The following NEW packages will be installed:
  libdbd-mysql-perl libdbi-perl libterm-readkey-perl percona-toolkit
0 upgraded, 4 newly installed, 0 to remove and 0 not upgraded.
Need to get 1,732 kB of archives.
After this operation, 10.3 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

下面是pt-alignpt-archiverpt-config-diffpt-deadlock-loggerpt-diskstatspt-duplicate-key-checkerpt-fifo-splitpt-findpt-fingerprintpt-fk-error-loggerpt-heartbeatpt-index-usagept-alignpt-archiverpt-config-diffpt-deadlock-loggerpt-diskstatspt-duplicate-key-checkerpt-fifo-splitpt-findpt-fingerprintpt-fk-error-loggerpt-heartbeatpt-index-usagept-ioprofilept-killpt-mextpt-mongodb-query-digestpt-mongodb-summarypt-mysql-summarypt-online-schema-changept-pmppt-query-digestpt-secure-collectpt-show-grantspt-siftpt-slave-delaypt-slave-findpt-slave-restartpt-stalkpt-summarypt-table-checksumpt-table-syncpt-table-usagept-upgradept-variable-advisorpt-visual-explainpt-slave-findpt-slave-restartpt-stalkpt-summarypt-table-checksumpt-table-syncpt-table-usagept-upgradept-variable-advisorpt-visual-explain

示例:拉动MySQL性能摘要

PT-MySQL-摘要方便总结了MySQL数据库服务器的状态和配置,以便可以一目了然地了解它。

pt-mysql-summary --host localhost --user root --ask-pass

在提示输入MySQL root用户密码时,请提供统计数据。
我们可以将输出重定向到文件。

pt-mysql-summary --host localhost --user root --ask-pass > mysql-summary.txt

请参阅下面的示例输出:

# Percona Toolkit MySQL Summary Report #######################
              System time | 2016-12-09 07:10:54 UTC (local TZ: EAT +0300)
# Instances ##################################################
  Port  Data Directory             Nice OOM Socket
  ===== ========================== ==== === ======
# MySQL Executable ###########################################
       Path to executable | /usr/sbin/mysqld
              Has symbols | Yes
# Slave Hosts ################################################
No slaves found
# Report On Port 3306 ########################################
                     User | Hyman@theitroad
                     Time | 2016-12-09 10:10:54 (EAT)
                 Hostname | centos-db
                  Version | 10.3.10-MariaDB MariaDB Server
                 Built On | Linux x86_64
                  Started | 2016-12-02 02:01 (up 7+08:08:58)
                Databases | 8
                  Datadir | /var/lib/mysql/
                Processes | 1 connected, 6 running
              Replication | Is not a slave, has 0 slaves connected
                  Pidfile | /var/lib/mysql/cnetos-db.pid (exists)
# Processlist ################################################
  Command                        COUNT(*) Working SUM(Time) MAX(Time)
  ------------------------------ -------- ------- --------- --------
  Daemon                                5       5         0         0
  Query                                 1       1         0         0
  User                           COUNT(*) Working SUM(Time) MAX(Time)
  ------------------------------ -------- ------- --------- --------
  root                                  1       1         0         0
  system user                           5       5         0         0
  Host                           COUNT(*) Working SUM(Time) MAX(Time)
  ------------------------------ -------- ------- --------- --------
                                        5       5         0         0
  localhost                             1       1         0         0
  db                             COUNT(*) Working SUM(Time) MAX(Time)
  ------------------------------ -------- ------- --------- --------
  NULL                                  6       6         0         0
  State                          COUNT(*) Working SUM(Time) MAX(Time)
  ------------------------------ -------- ------- --------- --------
  Init                                  1       1         0         0
  InnoDB purge coordinator              1       1         0         0
  InnoDB purge worker                   3       3         0         0
  InnoDB shutdown handler               1       1         0         0
# Status Counters (Wait 10 Seconds) ##########################
.....