工具
NinGoo's blog

Gearman for MySQL

Gearman是一个开源的分布式调度框架,支持多种语言。在分布式环境中,如何管理大量的服务器,将某些任务分发到大量的机器上调度执行,是一个比较大的挑战,Gearman为该类任务提供了一个不错的思路。在未来的MySQL集群环境中,Gearman这类工具应当大有用武之地,所以它也提供了MySQL UDF的支持。
gearman_stack

一个Gearman请求的处理过程涉及三个角色:Client -> Job -> Worker。
  Client:请求的发起者,可以是 C,PHP,Perl,MySQL UDF 等等。
  Job:请求的调度者,用来负责协调把 Client 发出的请求转发给合适的 Worker。
  Worker:请求的处理者,可以是 C,PHP,Perl 等等。
因为 Client,Worker 并不限制用一样的语言,所以有利于多语言多系统之间的集成。

性能测试工具sysbench简介

sysbench是一款开源的多线程性能测试工具,可以执行CPU/内存/线程/IO/数据库等方面的性能测试。数据库目前支持MySQL/Oracle/PostgreSQL。本文只是简单演示一下几种测试的用法,后续准备利用sysbench来对MySQL进行一系列的测试。具体的一些参数设置,需要根据不同的测试要求来进行调整。

下载
http://sourceforge.net/projects/sysbench/

编译安装

默认支持MySQL,如果需要测试Oracle/PostgreSQL,则在configure时需要加上–with-oracle或者–with-pgsql参数

./configure --prefix=/u01/sysbench \
--with-mysql-includes=/opt/mysql/include/mysql \
--with-mysql-libs=/opt/mysql/lib/mysql

make && make install

参数

NinGoo:/u01/sysbench/bin>$sysbench
Missing required command argument.
Usage:
  sysbench [general-options]... --test= [test-options]... command

General options:
  --num-threads=N            number of threads to use [1]
  --max-requests=N           limit for total number of requests [10000]
  --max-time=N               limit for total execution time in seconds [0]
  --forced-shutdown=STRING   amount of time to wait after --max-time before forcing shutdown [off]
  --thread-stack-size=SIZE   size of stack per thread [32K]
  --init-rng=[on|off]        initialize random number generator [off]
  --test=STRING              test to run
  --debug=[on|off]           print more debugging info [off]
  --validate=[on|off]        perform validation checks where possible [off]
  --help=[on|off]            print help and exit
  --version=[on|off]         print version and exit

Compiled-in tests:
  fileio - File I/O test
  cpu - CPU performance test
  memory - Memory functions speed test
  threads - Threads subsystem performance test
  mutex - Mutex performance test
  oltp - OLTP test

Commands: prepare run cleanup help version
See 'sysbench --test= help' for a list of options for each test.

[继续阅读全文]

Xtrabackup 0.9发布

在我之前的文章中,介绍并演示了xtrabackup,从这段时间实际使用的情况来看,这是一个值得向所有MySQL DBA推荐的备份工具,尤其是针对使用InnoDB引擎为主的库。

现在这个开源的备份工具正处于亢奋期,刚刚发布0.8没多久,0.9版又发布了。0.9版没有引入太多的新特性,主要是对0.8版本的一些严重的bug进行修正。实际上,0.8版出来后我就试用了RPM版,但是遇到了问题无法正常备份,所以目前在生产环境中还是使用的0.7版。有同事尝试在MySQL5.1中编译xtrabackup0.8也无法成功。果然,0.9版修复的bug列表中,就有这么一个bug: Bug #394374:Can’t compile with MySQL 5.1

有兴趣尝试的,可以到这里下载。

使用Perl发送邮件

在之前的监控系统中,邮件系统配置为只能本地调用mail命令发送,这样如果要在每台数据库服务上发送邮件就比较麻烦,需要通过ssh远程调用邮件服务器上的发送脚本。如果要发送文件,还要先将文件复制到邮件服务器上。

随着机器数量的增加,这种方式越来越不灵活。因此希望能通过传统的smtp的方式在任何主机上都能发送邮件,于是花了点时间研究了一下sendmail,根据这篇文章很轻松的让sendmail跑了起来:

修改sendmail配置模板/etc/mail/sendmail.mc

define(QUEUE_DIR, `/var/spool/mqueue/q*')dnl
TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
dnl DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl
DAEMON_OPTIONS(`Port=25, Name=MTA')dnl

第一行是新增,支持多个队列
第二三行去掉注释
第四行加上注释
第五行新增

根据模板生成配置文件

m4 /etc/mail/sendmail.mc > /etc/sendmail.cf

建立多个队列的目录

cd /var/spool/mqueue/
mkdir q1 q2 q3 q4 q5 q6

启动sendmail

/etc/rc.d/init.d/sendmail start

若要随机自启动sendmail,修改一下chkconfig设置即可

chkconfig --level 35 sendmail on

测试了一下发送邮件成功:

mail -s "test mail" NinGoo@test.com < /tmp/test.log

CPAN上搜索了一下,Mail:Sender模块发送邮件比较方便,支持多附件,语法也比较简单。需要安装如下两个组件:

MIME::Base64
Mail::Sender

发送邮件的perl示例代码如下,为便于查看邮件发送的详细情况,这里开启了debug模式:

#!/usr/bin/perl -w
use Mail::Sender;
open my $DEBUG, ">> /tmp/mail.log" or die "Can't open the debug file: $!\n";
$sender = new Mail::Sender
 {smtp => 'smtp_server',
   from => 'send@mail.com'};
#发送普通邮件
$sender->MailMsg(
 {to => 'NinGoo@test.com',
 subject => 'test mail',
 msg => 'hello word',
 debug => $DEBUG
 });
#发送带附件的邮件
$sender->MailFile(
 {to => 'NinGoo@test.com',
 subject => 'test mail with attached file',
 msg => 'hello word',
 file => '/tmp/test.txt'
 debug => $DEBUG
 });

经过测试,在邮件服务器本机发送成功,但在远程主机上则失败了,通过debug的log文件,发现错误如下:

>> 550 5.7.1 < NinGoo@test.com>... Relaying denied. Proper authentication required.

因为是内部监控使用,可以配置远程发送到特定的域的邮件无须认证,修改/etc/mail/relay-domains文件,每行加入一个目标域,如taobao.com。

修改配置后注意重启sendmail

/etc/rc.d/init.d/sendmail restart

发送正常的log如下:

>> 250 2.0.0 n69DbJwt011946 Message accepted for delivery