Chinaunix首页 | 论坛 | 博客
  • 博客访问: 414532
  • 博文数量: 137
  • 博客积分: 5190
  • 博客等级: 大校
  • 技术积分: 997
  • 用 户 组: 普通用户
  • 注册时间: 2010-02-21 16:19
文章存档

2011年(17)

2010年(120)

我的朋友

分类: Mysql/postgreSQL

2010-03-19 20:49:21

mk-slave-restart - 对slave进行监控,以及在slave报错后,重启slave。安装方法查看。

其实可以理解成在slave执行了如下命令:

stop slave;
set global sql_slave_skip_counter=1;
start slave;

下面举例说明:
先模拟一个slave报错,在主库建表,然后在从库删除,再去主库删除。报错如下:

Last_SQL_Errno: 1051
Last_SQL_Error: Error 'Unknown table 'test_sg'' on query. Default database: 'test'. Query: 'drop table test_sg'

在利用mk-slave-restart去重启这个slave;

[root@mysql2 ~]# mk-slave-restart -u xxx -p xxx -h xxx --run-time 3 --skip-count 1
2010-03-09T14:01:57 h=xxx,p=...,u=xxx slave-relay-bin.000215    74173942 1051

解释下参数:
run-time:指监控slave的时间,单位是秒;
skip-count:指跳过log的数量;


解释下输出:
1、time
2、slave IP
3、user
4、passwd
5、MASTER_LOG_FILE
6、MASTER_LOG_POS
7、Last_SQL_Errno


很显然mk-slave-restart是一个很不错的slave监控工具,当salve出错后能及时报警,并直接重启slave。同时输出了报错的相关信息,方便后面查询在哪出错,是什么错。下面给出它的帮助:

[root@mysql2 ~]# mk-slave-restart --help
mk-slave-restart watches one or more MySQL replication slaves for errors, and
tries to restart replication if it stops.  For more details, please use the
--help option, or try 'perldoc /usr/bin/mk-slave-restart' for complete
documentation.
 
Usage: /usr/bin/mk-slave-restart 
 
Options:
  --always            Start slaves even when there is no error
  --ask-pass          Prompt for a password when connecting to MySQL
  --charset       -A  Default character set
  --config            Read this comma-separated list of config files; if
                      specified, this must be the first option on the command
                      line
  --daemonize         Fork to background and detach (POSIX only)
  --database      -D  Database to use
  --defaults-file -F  Only read mysql options from the given file
  --error-length      Max length of error message to print
  --error-numbers     Only restart this comma-separated list of errors
  --error-text        Only restart errors that match this pattern
  --help              Show help and exit
  --host          -h  Connect to host
  --log               Print all output to this file when daemonized
  --max-sleep         Maximum sleep seconds (default 64)
  --min-sleep         The minimum time mk-slave-restart will sleep before
                      polling the slave again (default 0.015625)
  --monitor           Whether to monitor the slave (default)
  --password      -p  Password to use when connecting
  --pid               Create the given PID file when daemonized
  --port          -P  Port number to use for connection
  --quiet         -q  Suppresses normal output (disables --verbose)
  --recurse           Watch slaves of the specified server, up to the specified
                      number of servers deep in the hierarchy
  --run-time          Time to run before exiting.  Optional suffix s=seconds,
                      m=minutes, h=hours, d=days; if no suffix, s is used.
  --sentinel          Exit if this file exists (default
                      /tmp/mk-slave-restart-sentinel)
  --set-vars          Set these MySQL variables (default wait_timeout=10000)
  --skip-count        Number of statements to skip when restarting the slave
                      (default 1)
  --sleep             Initial sleep seconds between checking the slave (default
                      1)
  --socket        -S  Socket file to use for connection
  --stop              Stop running instances by creating the sentinel file
  --until-master      Run until this master log file and position
  --until-relay       Run until this relay log file and position
  --user          -u  User for login if not current user
  --verbose       -v  Be verbose; can specify multiple times (default 1)
  --version           Show version and exit
 
Options and values after processing arguments:
  --always            FALSE
  --ask-pass          FALSE
  --charset           (No value)
  --config            /etc/maatkit/maatkit.conf,/etc/maatkit/mk-slave-restart.conf,/root/.maatkit.conf,/root/.mk-slave-
 
restart.conf
  --daemonize         FALSE
  --database          (No value)
  --defaults-file     (No value)
  --error-length      (No value)
  --error-numbers     (No value)
  --error-text        (No value)
  --help              TRUE
  --host              (No value)
  --log               (No value)
  --max-sleep         64
  --min-sleep         0.015625
  --monitor           TRUE
  --password          (No value)
  --pid               (No value)
  --port              (No value)
  --quiet             FALSE
  --recurse           (No value)
  --run-time          (No value)
  --sentinel          /tmp/mk-slave-restart-sentinel
  --set-vars          wait_timeout=10000
  --skip-count        1
  --sleep             1
  --socket            (No value)
  --stop              FALSE
  --until-master      (No value)
  --until-relay       (No value)
  --user              (No value)
  --verbose           1
  --version           FALSE
阅读(1965) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~