免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1910 | 回复: 1
打印 上一主题 下一主题

Maatkit install [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-05-23 20:26 |只看该作者 |倒序浏览
Mysql管理工具Maatkit详解之一(安装Maatkit) Maatkit是一个Perl写的Mysql开源管理工具,根据调查全球大约有70%多的Mysql管理员使用这个工具来管理Mysql,但我发现在国内很少有人知道这个工具,因此打算写一个系列的文章来介绍这个工具,并带上自己的心得和一些体会。
        首先安装Maatkt,需要Perl,DBI,DBD::mysql相关模块。

1.perl

perl -v
This is perl, v5.8.5 built for i386-linux-thread-multi
Copyright 1987-2004, Larry Wall
一般linux安装的时候默认安装了perl。

2.Mysql 可以到这里下载
Mysql的安装网上到处都是,就省略了。


3.DBI,可以到这里下载相应的版本

tar zxf DBI-1.58.tar.gz
cd DBI-1.58
perl Makefile.pl
make
make test
make
make install

4.data-showtable包,可以到这里下载查找相应的包

gzip -c -d Data-ShowTable-?.??.tar.gz | tar xvf -
cd Data-ShowTable-?.??
perl Makefile.PL
make
不要试make test,测试套件损坏了!
make install

5.msql-mysql-modules 可以到这里下载
gzip -c -d Msql-Mysql-modules-?.??.tar.gz | tar xvf -
将压缩文件接压缩到一个名为Msql-Mysql-modules-?.??的目录。

cd Msql-Mysql-modules-?.??
perl Makefile.PL
在 "perl Makefile.PL" 期间,会向你提出一些问题。特别是你必须选择安装驱动器(MySQL, mSQL2 and/or mSQL1)。MySQL驱动程序叫

DBD::mysql,单独的mSQL驱动程序叫DBD::mSQL。如果你想支持mSQL1和mSQL2,用DBD::mSQL1。
make
make test
make install

6.DBD-mysql 可以到这里下载

安装DBD: DBD-mysql-4.005
perl Makefile.PL --mysql_config=/usr/local/mysql/bin/mysql_config
make
make test
make
make install
如果出现以下错误,
install_driver(mysql) failed: Can't load '/usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi/auto/DBD/mysql/mysql.so' for

module DBD::mysql: libmysqlclient.so.12: cannot open shared object file: No such file or directory at

/usr/lib/perl5/5.8.5/i386-linux-thread-multi/DynaLoader.pm line 230.
at (eval 6) line 3
Compilation failed in require at (eval 6) line 3.
Perhaps a required shared library or dll isn't installed where expected
at /root/mysqlreport line 162

就做操作
cp /usr/local/mysql/include/mysql* /usr/include/
cp /usr/local/mysql/lib/* /usr/lib/ (64位的是lib64)

然后再重新安装DBD: DBD-mysql-4.005
perl Makefile.PL --mysql_config=/usr/local/mysql/bin/mysql_config
make
make test
make install

7.安装maatkit 可以到这里下载

tar zxvf   maatkit-2325.tar.gz
cd maatkit-2325
perl Makefile.PL
make install


下面分别列出这套工具,以及官方的定义,在后续的文章中,会分别对这些工具进行介绍,以及自己的测试和心得体会。
mk-archiver Archive rows from a MySQL table into another table or a file.
mk-audit Analyze, summarize and report on MySQL config, schema and operation
mk-checksum-filter Filter checksums from mk-table-checksum.
mk-deadlock-logger Extract and log MySQL deadlock information.
mk-duplicate-key-checker Find duplicate keys and foreign keys on MySQL tables.
mk-fifo-split Split files and pipe lines to a fifo without really splitting.
mk-find Find MySQL tables and execute actions, like GNU find.
mk-heartbeat Monitor MySQL replication delay.
mk-log-player Split and play MySQL slow logs.
mk-log-server Serve MySQL binary logs.
mk-parallel-dump Dump sets of MySQL tables in parallel.
mk-parallel-restore Load files into MySQL in parallel.
mk-profile-compact Compact the output from mk-query-profiler.
mk-query-digest Parses logs and more. Analyze, transform, filter, review and report on queries.
mk-query-profiler Execute SQL statements and print statistics, or measure activity caused by other processes.
mk-show-grants Canonicalize and print MySQL grants so you can effectively replicate, compare and version-control them.
mk-slave-delay Make a MySQL slave server lag behind its master.
mk-slave-find Find and print replication hierarchy tree of MySQL slaves.
mk-slave-move Move a MySQL slave around in the replication hierarchy.
mk-slave-prefetch Pipeline relay logs on a MySQL slave to pre-warm caches.
mk-slave-restart Watch and restart MySQL replication after errors.
mk-table-checksum Perform an online replication consistency check, or checksum MySQL tables efficiently on one or many servers.
mk-table-sync Synchronize MySQL tables efficiently.
mk-visual-explain Format EXPLAIN output as a tree.

论坛徽章:
0
2 [报告]
发表于 2011-05-24 18:51 |只看该作者
http://hi.baidu.com/liheng_2009/ ... 80c2eae7cd4069.html
本来打算 装的 在使用mk-table-checksum进行操作的时候,会对表加一个表级锁,所以一般这类检查最好是在业务比较闲的时候进行。-------------------------这样的情况 是不可能 容忍的 。所以放弃



但是  mk-table-checksum – 检查数据库复制模式里,master和slave的表是否一致,安装方法可以参考这里。

mysql在5.1之前,其replication都是采用的STATEMENT模式,对表的数据是否一致要求并不严格,所以对数据一致性要求比较严格的应用,定期检查数据一致性是很有必要的,mk-table-checksum 是一个很不错的检查工具。

例如:
我要检查master=192.168.0.1,slave=192.168.0.2的两台mysql的test库里的test表是否一致,命令如下:
?View Code BASH

mk-table-checksum h=192.168.0.1,u=sg,p=sg109504 h=192.168.0.2,u=sg,p=xxxx -d test -t test
DATABASE TABLE CHUNK HOST        ENGINE      COUNT         CHECKSUM TIME WAIT STAT  LAG
test     test     0  192.168.0.1 MyISAM       NULL       1592576808    0    0 NULL NULL
test     test     0  192.168.0.2 MyISAM       NULL       1592576808    0    0 NULL NULL

mk-table-checksum h=192.168.0.1,u=sg,p=sg109504 h=192.168.0.2,u=sg,p=xxxx -d test -t test -r
DATABASE TABLE CHUNK HOST        ENGINE      COUNT                         CHECKSUM TIME WAIT STAT  LAG
test     test     0  192.168.0.1 MyISAM        385 cd0abd260b2f12c95af05278c114a84b    0    0 NULL NULL
test     test     0  192.168.0.2 MyISAM        385 cd0abd260b2f12c95af05278c114a84b    0    0 NULL NULL

解释下输出的意思:
DATABASE:数据库名
TABLE:表名
CHUNK:checksum时的近似数值
HOST:MYSQL的地址
ENGINE:表引擎
COUNT:表的行数
CHECKSUM:校验值
TIME:所用时间
WAIT:等待时间
STAT:MASTER_POS_WAIT()返回值
LAG:slave的延时时间

这里需要顺带介绍下mk-table-checksum的过滤工具mk-checksum-filter,例如我只想知道上面的例子中,test库中哪些表不是一致的。只需要加一个管道符。
?View Code BASH

mk-table-checksum h=10.0.0.156,u=sg,p=sg109504 h=10.0.0.159,u=sg,p=sg109504 -d test -r|mk-checksum-filter
test login_log          0 192.168.0.1 MyISAM     133737 7336e1638a33bbc6a203a41f30b5a6fe    1    0 NULL NULL
test login_log          0 192.168.0.2 MyISAM     133735 609c44faeb584a2c1a92f0a37349a3ea    1    0 NULL NULL

需要提醒一下,在使用mk-table-checksum进行操作的时候,会对表加一个表级锁,所以一般这类检查最好是在业务比较闲的时候进行。下面给

出这2个工具的帮助。
?View Code BASH

mk-table-checksum --help
mk-table-checksum checksums MySQL tables efficiently on one or more HOSTs.  Each
HOST is specified as a DSN and missing values are inherited from the first HOST.
If you specify multiple HOSTs, the first is assumed to be the master.  For more
details, please use the --help option, or try 'perldoc mk-table-checksum' for
complete documentation.

Usage: mk-table-checksum [OPTION]... HOST [HOST...]

Options:
  --algorithm     -a  Checksum algorithm (ACCUM|CHECKSUM|BIT_XOR)
  --askpass           Prompt for a password when connecting to MySQL
  --checksum          Print checksums and table names in the style of md5sum
                      (disables --count)
  --chunksize     -C  Approximate number of rows or size of data to checksum at
                      a time. Allowable suffixes are k, M, G. Disallows -a
                      CHECKSUM.
  --columns           Checksum only this comma-separated list of columns
  --[no]count     -r  Count rows in tables. This is built into ACCUM and
                      BIT_XOR, but requires an extra query for CHECKSUM.
  --[no]crc       -c  Do a CRC (checksum) of tables (default yes)
  --databases     -d  Only checksum this comma-separated list of databases
  --defaults-file -F  Only read mysql options from the given file. You must give
                      an absolute pathname.
  --emptyrepltbl      Empty table given by --replicate before starting
  --engine        -e  Do only this comma-separated list of storage engines
  --explain           Show, but do not execute, checksum queries (disables
                      --emptyrepltbl)
  --explainhosts      Print connection information and exit
  --float-precision   Precision for FLOAT and DOUBLE column comparisons
  --function      -f  Hash function for checksums (FNV_64, SHA1, MD5, etc)
  --help              Show this help message
  --ignoredb      -g  Ignore this comma-separated list of databases
  --ignoreengine  -E  Ignore this comma-separated list of storage engines
                      (default FEDERATED,MRG_MyISAM)
  --ignoretbl     -n  Ignore this comma-separated list of tables
  --lock          -k  Lock on master until done on slaves (implies --slavelag)
  --[no]optxor    -o  Optimize BIT_XOR with user variables (default yes)
  --password      -p  Password to use when connecting
  --port          -P  Port number to use for connection
  --quiet         -q  Do not print checksum results
  --replcheck         Check results in --replicate table, to the specified depth
  --replicate     -R  Replicate checksums to slaves (disallows -a CHECKSUM)
  --separator     -s  The separator character used for CONCAT_WS() (default #)
  --setvars           Set these MySQL variables (default wait_timeout=10000)
  --slavelag      -l  Report how far slaves lag master
  --sleep             Sleep time between checksums
  --sleep-coef        Calculate --sleep as a multiple of the last checksum time
  --socket        -S  Socket file to use for connection
  --tab           -b  Print tab-separated output, not column-aligned output
  --tables        -t  Do only this comma-separated list of tables
  --trim              Trim VARCHAR columns (helps when comparing 4.1 to >= 5.0).
  --user          -u  User for login if not current user
  --[no]verify    -v  Verify checksum compatibility across servers (default yes)
  --version           Output version information and exit
  --wait          -w  Wait this long for slaves to catch up to their master
                      (implies --lock --slavelag).  Optional suffix s=seconds,
                      m=minutes, h=hours, d=days; if no suffix, s is used.
  --where         -W  Do only rows matching this WHERE clause (disallows
                      --algorithm CHECKSUM)

DSN syntax is key=value[,key=value...]  Allowable DSN keys:
  KEY  COPY  MEANING
  ===  ====  =============================================
  A    yes   Default character set
  D    yes   Database to use
  F    yes   Only read default options from the given file
  P    yes   Port number to use for connection
  S    yes   Socket file to use for connection
  h    yes   Connect to host
  p    yes   Password to use when connecting
  u    yes   User for login if not current user
  If the DSN is a bareword, the word is treated as the 'h' key.

Options and values after processing arguments:
  --algorithm         (No value)
  --askpass           FALSE
  --checksum          FALSE
  --chunksize         (No value)
  --columns           (No value)
  --count             FALSE
  --crc               TRUE
  --databases         (No value)
  --defaults-file     (No value)
  --emptyrepltbl      FALSE
  --engine            (No value)
  --explain           FALSE
  --explainhosts      FALSE
  --float-precision   (No value)
  --function          (No value)
  --help              TRUE
  --ignoredb
  --ignoreengine      FEDERATED,MRG_MyISAM
  --ignoretbl
  --lock              FALSE
  --optxor            TRUE
  --password          (No value)
  --port              (No value)
  --quiet             FALSE
  --replcheck         (No value)
  --replicate         (No value)
  --separator         #
  --setvars           wait_timeout=10000
  --slavelag          FALSE
  --sleep             (No value)
  --sleep-coef        (No value)
  --socket            (No value)
  --tab               FALSE
  --tables            (No value)
  --trim              FALSE
  --user              (No value)
  --verify            TRUE
  --version           FALSE
  --wait              (No value)
  --where             (No value)

mk-checksum-filter --help
mk-checksum-filter filters checksums from mk-table-checksum and prints those
that differ.  With no FILE, or when FILE is -, read standard input.  For more
details, please use the --help option, or try 'perldoc mk-checksum-filter' for
complete documentation.

Usage: mk-checksum-filter  FILE

Options:
  --equaldbs -d  This comma-separated list of databases are equal
  --header   -h  Preserves headers output by mk-table-checksum
  --help         Show this help message
  --ignoredb -i  Ignore the database name when comparing lines
  --master   -m  The name of the master server
  --unique   -u  Show unique differing host/db/table names
  --verbose  -v  Output all lines, even those that have no differences, except
                 for header lines
  --version      Output version information and exit
  --ignoredb and --equaldbs are mutually exclusive.

Options and values after processing arguments:
  --equaldbs
  --header       FALSE
  --help         TRUE
  --ignoredb     FALSE
  --master
  --unique       (No value)
  --verbose      FALSE
  --version      FALSE

原文来自:http://www.bigheaddba.net/
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP