Posts categorized “mysql”.

又一个sysbench for mysql监控的文摘

第一步,准备测试数据。

[root@node1 ~]# sysbench –test=oltp –oltp-table-size=1000000 –mysql-table-engine=myisam –mysql-db=test –mysql-socket=/opt/mysql1/data/mysql.sock –mysql-user=root prepare
sysbench 0.4.12:  multi-threaded system evaluation benchmarkNo DB drivers specified, using mysql
Creating table ’sbtest’…
Creating 1000000 records in table ’sbtest’…

同时,在另一个窗口使用vmstat去关注cpu idle、context switch,一些必要参数的变化,随时掌握系统的运行状况。

vmstat_sysbench1

第二步,20个用户同时并发500000条查询请求,对测试表sbtest进行只读操作。执行完成总时间大概26分钟左右,执行中最长的一次操作接近9分钟,还有结果中95%这个指标我们也会关注。

[root@node1 ~]# sysbench –num-threads=20 –max-requests=500000 –test=oltp –oltp-table-size=1000000 –mysql-db=test –mysql-socket=/opt/mysql1/data/mysql.sock –mysql-user=root –oltp-read-only run
sysbench 0.4.12:  multi-threaded system evaluation benchmarkNo DB drivers specified, using mysql
Running the test with following options:
Number of threads: 20Doing OLTP test.
Running mixed OLTP test
Doing read-only test
Using Special distribution (12 iterations,  1 pct of values are returned in 75 pct cases)
Using “LOCK TABLES READ” for starting transactions
Using auto_inc on the id column
Maximum number of requests for OLTP test is limited to 500000
Threads started!
Done.OLTP test statistics:
queries performed:
read:                            7000112
write:                           0
other:                           1000016
total:                           8000128
transactions:                        500008 (322.15 per sec.)
deadlocks:                           0      (0.00 per sec.)
read/write requests:                 7000112 (4510.14 per sec.)
other operations:                    1000016 (644.31 per sec.)Test execution summary:
total time:                          1552.0822s
total number of events:              500008
total time taken by event execution: 31034.2430
per-request statistics:
min:                                  3.56ms
avg:                                 62.07ms
max:                                521.56ms
approx.  95 percentile:              95.59msThreads fairness:
events (avg/stddev):           25000.4000/61.39
execution time (avg/stddev):   1551.7121/0.16

通过vmstat监测,会发现cpu空闲保持在34%上下,context switch的速度在每秒29000左右。

vmstat_sysbench2

下面是用strace这个工具去监测sysbench的执行,你可以看到从fd3到fd22一共20并发请求的执行状况。

strace1

********************************omit**********************************

strace2

mysqld_multi管理启动多个mysql进程

mysqlmanager的管理方式貌似在慢慢被遗忘,现流行用mysqld_multi来管理多个实例:

配置文件:  my.cnf

[mysqld_multi]
mysqld = /usr/bin/mysqld_safe
mysqladmin = /usr/bin/mysqladmin
user = root
password = defage
[mysqld1]
datadir=/opt/data1
socket=/opt/data1/mysql.sock
pid-file=/opt/data1/mysql1.pid
log=/opt/data1/mysql1.log
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1

default-character-set=utf8

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[mysqld2]
datadir=/opt/data2
socket=/opt/data2/mysql.sock
pid-file=/opt/data2/mysql2.pid
log=/opt/data2/mysql2.log
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
port=3307

default-character-set=utf8

[mysqld3]
datadir=/opt/data3
socket=/opt/data3/mysql.sock
pid-file=/opt/data3/mysql3.pid
log=/opt/data3/mysql3.log
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
port=3308

default-character-set=utf8

启动:

mysqld_multi  –config-file=/etc/my.cnf     start  1 ;只启动第一个mysql服务,相关文件由my.cnf中mysql1设定。

mysqld_multi   –config-file=/etc/my.cnf start 1-4,启动 第1至4mysql服务

sysbench 测试mysql

安装sysbench:
tar zxvf sysbench-4.12
cd sysbench-4.12
./configure –prefix=/usr/local/sysbench -with-mysql-includes=/usr/local/mysql/include/mysql –with-mysql-libs=/usr/local/mysql/lib/mysql
make && make install
出现这个错误是没有指定相应的–with-mysql-includes和–with-mysql-libs目录.找到正确的目录从新编译。
3、make的时候出现
../libtool: line 2412: Xsysbench: command not found
../libtool: line 2547: X-lmysqlclient_r: command not found
../libtool: line 2547: X-lz: command not found
../libtool: line 2547: X-lcrypt: command not found

只要先运行一次./autogen.sh,然后再configure,make就可以了.autogen.sh文件在sysbench-4.12解压目录下的.

1 、准备数据
#sysbench –debug=off –test=oltp –mysql-host=127.0.0.1 –mysql-user=root –mysql-password=defage –oltp-table-size=1000000 –mysql-db=test –oltp-table-name=stest –num-threads=20 –max-requests=10000 –oltp-auto-inc=off –mysql-engine-trx=yes –db-driver=mysql –mysql-port=3307 prepare

2、测试
# sysbench –debug=off –test=oltp –mysql-host=10.15.2.137 –mysql-user=test –mysql-password=test –oltp-table-size=1000000 –mysql-db=test –oltp-table-name=stest –num-threads=20 –max-requests=10000 –oltp-auto-inc=off –mysql-engine-trx=yes run

3、删除数据
# sysbench –debug=off –test=oltp –mysql-host=10.15.2.137 –mysql-user=test –mysql-password=test –oltp-table-size=1000000 –mysql-db=test –oltp-table-name=stest –num-threads=20 –max-requests=10000 –oltp-auto-inc=off –mysql-engine-trx=yes cleanup

提示错误:sysbench 0.4.10:  multi-threaded system evaluation benchmark

FATAL: no database driver specified
FATAL: failed to initialize database driver!

则是sysbench没有指定对应的数据库driver,在上面的命令后加参数  –db-driver=mysql即可

使用mysqlmanager管理mysql实例

需要在一个物理服务器上启用多个mysql进程(实例)的时候,mysqlmanager管理比较方便。

这里安装的是MySQL-server-percona-highperf-b16-5.0.82-0.rhel5版本,安装好之后mysqlmanager工具已经在了,其他的库文件再另外安装,客户端MySQL-client-percona-b16-5.0.82-0.rhel5肯定要装了。

默认没有/etc/my.cnf文件,可以自己建,建好之后service mysql start的时候会自动读取它。

在 /etc/my.cnf文件中配置如下类似选项:

[manager]
user=mysql
default-mysqld-path = /usr/sbin/mysqld
socket=/tmp/manager.sock
pid-file=/tmp/manager.pid
password-file = /etc/mysqlmanager.passwd
monitoring-interval = 2
port =1999
bind-address = 192.168.1.202
log = /tmp/mysqlmanager.log
run-as-service = true

[mysqld1]

……

[mysql2]

….

下一步配置mysqlmanager.passwd密码文件,使用命令:

/usr/sbin/mysqlmanager –passwd >> /etc/mysqlmanager.passwd

然后按提示输入新用户和密码

启动mysqlmanager

/usr/sbin/mysqlmanager

会自动读取/etc/my.cnf中的配置。

连接mysqlmanager进行实例状态查看:

mysql -uwills -pdefage -S /tmp/manager.sock -P1999

端口、用户和密码在/etc/my.cnf文件的[manager]字段中配置的对应

mysql错误Incorrect information in file

很郁闷,之前由于对数据库作过一个复制的操作,然后今天过来一看,select那个库的所有表都提示:Incorrect information in file: ‘./farm2/syslog.frm

在mysqld.log里看到一堆Incorrect information in file错误,

后来google了一下,将ib_logfile0 ib_logfile1 ibdata1三个文件备份后再删除,再重启了mysql,这回更加错误大了,mysqld.log里能看到一堆

[ERROR] Cannot find table farm2/shelter from the internal data dictionary

查询任何表都提示找不到表,另外使用repair table ….也提示不能打开表,看来是INNODB表日志问题
将之前备份好的3个文件再覆盖过来,然后

show variables like ‘%innodb_log_file_size%’; 比较ib_logfile0,判断可能是innodb_log_file_size设置有问题,使用盗版的办法,从别的运行正常的mysql服务器上show variables like ‘%innodb_log_file_size%’;,看到默认的大小后

再在问题mysql上,vi  /etc/my.cnf将innodb_log_file_size设置成从正常运行的mysql服务器中查到的大小,

重启mysql

o yeah!  终于能select任何表了。