MySQL · 2016-10-10 0

Percona-Toolkit系列之简介安装

1.Percona Toolkit for MySQL

做过oracle的朋友再来看mysql,各种不适应,mysql没有AWR,没有RMAN,没有内部性能诊断视图,没有……这也就是为什么使用mysql的企业要求mysql dba有一定的开发能力,写一些工具或者脚本之类的减轻工作负担。可能oracle DBA最多也只需要用shell写个定时删RMAN备份的脚本(国内很多顶级大牛自己写了些工具去力挽狂澜灾难中的oracle,那也是相当了得),因为oracle已经尽可能减轻运维工作,很多工具都是直接用。可能这就是做oracle和做mysql的最大不同吧,做oracle更多的是需要你去理解内部原理,没事dump,strace,做mysql没有隐含参数需要调整,也没有内部视图来诊断性能。

既然mysql运维工具还不够完善,那么面对日益复杂的运维工作,我们如何做到从容面对呢?别担心,一群老外早都为我们准备好了mysql的运维工具套餐。注意是套餐,哈哈,很棒吧,各种工具,各种爽到爆。这个神秘套餐就是Percona Toolkit,简称pt。很多很棒的功能,比如进程跟踪,主备复制监测,主备数据一致性校验等等,三十多个工具,几乎满足mysql日常运维的所有需求。

pt (1)

2.安装工具

该工具可以二进制安装和rpm安装,我个人习惯二进制安装,下面以二进制安装为例,非常简单。

我们把二进制文件放到/u01/app下面:

[mysql@hpc02 percona-toolkit]$ pwd
/u01/app/percona-toolkit
[mysql@hpc02 percona-toolkit]$ ls -l
total 96
drwxrwxr-x 2 mysql mysql  4096 Aug 15 22:36 bin
-rw-rw-r-- 1 mysql mysql 41119 Aug 15 22:36 Changelog
-rw-rw-r-- 1 mysql mysql 18092 Aug 15 22:36 COPYING
drwxrwxr-x 2 mysql mysql  4096 Aug 15 22:36 debian
drwxrwxr-x 2 mysql mysql  4096 Aug 15 22:36 docs
-rw-rw-r-- 1 mysql mysql  1527 Aug 15 22:36 INSTALL
drwxrwxr-x 2 mysql mysql  4096 Aug 15 22:36 lib
-rw-rw-r-- 1 mysql mysql   484 Aug 15 22:36 Makefile.PL
-rw-rw-r-- 1 mysql mysql   662 Aug 15 22:36 MANIFEST
-rw-rw-r-- 1 mysql mysql  1211 Aug 15 22:36 README

将/u01/app/percona-toolkit/bin添加至环境变量PATH中

PATH=$PATH:$HOME/bin:/u01/app/percona-toolkit/bin

export PATH

安装好了直接run一把,我们测试下,pt-summary,输出数据库主机的软硬件配置信息:

[mysql@hpc02 bin]$ pt-summary 
# Percona Toolkit System Summary Report ######################
        Date | 2016-10-10 03:43:16 UTC (local TZ: CST +0800)
    Hostname | hpc02
      Uptime | 11 min,  2 users,  load average: 0.00, 0.01, 0.00
    Platform | Linux
     Release | CentOS release 6.7 (Final)
      Kernel | 2.6.32-573.el6.x86_64
Architecture | CPU = 64-bit, OS = 64-bit
   Threading | NPTL 2.12
     SELinux | Disabled
 Virtualized | KVM
# Processor ##################################################
  Processors | physical = 1, cores = 2, virtual = 2, hyperthreading = no
      Speeds | 2x2194.920
      Models | 2xIntel(R) Core(TM) i5-5200U CPU @ 2.20GHz
      Caches | 2x3072 KB
# Memory #####################################################
       Total | 996.1M
        Free | 688.2M
        Used | physical = 307.9M, swap allocated = 2.0G, swap used = 0.0, virtual = 307.9M
      Shared | 452.0k
     Buffers | 56.1M
      Caches | 75.8M
       Dirty | 48 kB
     UsedRSS | 131.0M
  Swappiness | 1
 DirtyPolicy | 20, 10
 DirtyStatus | 0, 0
  Locator   Size     Speed             Form Factor   Type          Type Detail
  ========= ======== ================= ============= ============= ===========
# Mounted Filesystems ########################################
  Filesystem                    Size Used Type  Opts Mountpoint
  /dev/mapper/vg_hpc01-lv_root   56G  62% ext4  rw   /
  /dev/sda1                     477M   9% ext4  rw   /boot
  tmpfs                         499M   0% tmpfs rw   /dev/shm
# Disk Schedulers And Queue Size #############################
        dm-0 | 128
        dm-1 | 128
         sda | [cfq] 128
         sdb | [cfq] 128
         sdc | [cfq] 128
         sr0 | [cfq] 128
         sr1 | [cfq] 128
# Disk Partioning ############################################
# Kernel Inode State #########################################
dentry-state | 86852    80968   45      0       0       0
     file-nr | 896      0       6815744
    inode-nr | 85977    235
# LVM Volumes ################################################
Unable to collect information
# LVM Volume Groups ##########################################
Unable to collect information
# RAID Controller ############################################
  Controller | No RAID controller detected
# Network Config #############################################
 FIN Timeout | 60
  Port Range | 65500
# Interface Statistics #######################################
  interface  rx_bytes rx_packets  rx_errors   tx_bytes tx_packets  tx_errors
  ========= ========= ========== ========== ========== ========== ==========
  lo                0          0          0          0          0          0
  eth0        1750000       3000          0     300000       1500          0
  eth1          12500        100          0       2500         25          0
# Network Devices ############################################
  Device    Speed     Duplex
  ========= ========= =========
  eth0                            
  eth1                            
# Network Connections ########################################
  Connections from remote IP addresses
    192.168.56.1        2
  Connections to local IP addresses
    192.168.56.103      2
  Connections to top 10 local ports
    22                  2
  States of connections
    ESTABLISHED         2
    LISTEN              8
# Top Processes ##############################################
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
    1 root      20   0 19232 1520 1232 S  0.0  0.1   0:00.76 init
    2 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kthreadd
    3 root      RT   0     0    0    0 S  0.0  0.0   0:00.32 migration/0
    4 root      20   0     0    0    0 S  0.0  0.0   0:00.01 ksoftirqd/0
    5 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 stopper/0
    6 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 watchdog/0
    7 root      RT   0     0    0    0 S  0.0  0.0   0:00.33 migration/1
    8 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 stopper/1
    9 root      20   0     0    0    0 S  0.0  0.0   0:00.00 ksoftirqd/1
# Notable Processes ##########################################
  PID    OOM    COMMAND
 1532    -17    sshd
# Simplified and fuzzy rounded vmstat (wait please) ##########
  procs  ---swap-- -----io---- ---system---- --------cpu--------
   r  b    si   so    bi    bo     ir     cs  us  sy  il  wa  st
   2  0     0    0   100    20     60     50   0   1  98   1   0
   0  0     0    0    70   175   1250   1250   5   9  83   3   0
   0  0     0    0     0     0     25     20   0   0 100   0   0
   0  0     0    0     0     0     15     20   0   0 100   0   0
   0  0     0    0     0     0     10     15   0   0 100   0   0
# The End ####################################################