Mysql Replication架构部署二

四、MysqlReplication性能测试

Mysql Replication性能测试采用M-MSS架构模式,即单主到多从架构模式。
(一)测试环境
Master Slave1 Slave2
OS CentOS release 5.6 (Final) CentOS release 5.4 (Final) CentOS release 5.4 (Final)
Hostname bogon repli1 repli12
IP 192.168.41.189 192.168.7.128 192.168.7.129
Mysql-Version 14.12 Distrib 5.0.77 14.12 Distrib 5.0.77 14.12 Distrib 5.0.77
(二)准备工作
1、安装apache、php
[root@bogon ~]#
yum install httpd
[root@bogon ~]#
yum install php
2、启动apache服务
[root@bogon ~]#
service httpd start
3、新建表
mysql> create table ztest(id int(4) not null primary key auto_increment,name char(30) not null default ‘Melliazia Iylizaber’,sex char(8) not null default ‘girl’,school char(50) not null default ‘Guangdong Ligong zhiye xueyuan’,degree char(20) not null default ‘MBA’,age int(8) not null default ’111′,address varchar(500) not null default ‘Room 2310 NO.1199 JinTianDaSha,Heping Road Luohu,Shenzhen City,China’,password varchar(5000) not null default ‘abcdefghijklmnopqrstuvwxyz’);
(三)测试方式
测试方式1:
通过php函数调用sql语句自动插入数据,再通过javascript实现页面自动刷新,达到不断插入数据的目的。
1、通过php函数调用sql语句自动插入数据
在站点目录下新建post.php文件,添加如下内容:
<?php
require_once(“conn.php”);//引用数据库链接文件
$uname = $_GET['n'];//GET方法为URL参数传递
$psw = $_GET['p'];
$psw=md5($psw);//直接使用MD5加密
$sql = “insert into ztest(name,password) values (‘$uname’,'$psw’)”;
mysql_query($sql);//借SQL语句插入数据
mysql_close();//关闭MySQL连接
echo “成功录入数据”;
?>
2、通过javascript实现自动刷新网页,从而实现数据的不断插入
在post.php文件末尾添加如下内容:
<html>
<head>
<title>test</title>
<script language=”javascript”>
setTimeout(“self.location.reload();”,1);
</script>
</head>
<body>
</body>
</html>
测试方式2:
通过php函数调用sql语句实现自动循环插入数据
在站点目录下新建post.php文件,添加如下内容语句:
<?php
require_once(“conn.php”);//引用数据库链接文件
$uname = $_GET['n'];//GET方法为URL参数传递
$psw = $_GET['p'];
$psw=md5($psw);//直接使用MD5加密
for ($i=0;$i<1000000;$i++) #一次往表中插入1000000条数据
{
$sql = “insert into ztest(name,password) values (‘$uname’,'$psw’)”;
mysql_query($sql);//借SQL语句插入数据
}
mysql_close();//关闭MySQL连接
echo “成功录入数据”;
?>
(四)性能测试
启动一台虚拟机,然后在主机和虚拟机里各自打开浏览器,输入http://192.168.41.189/post.php(post.php为测试页面),打开测试页面,这样可以增加每秒往数据库插入的数据,同时也可以测试mysql并发写入数据的抗压能力。
第一种测试方式插入的数据有限,1分钟才插入3000条左右的数据。
第二种测试方式是通过php循环语句控制数据的插入,经测试,单台机子1分05秒内往数据库里插入1000000条数据,即15385条/秒;两台机子并发往数据库插入2000000条数据共耗时1分35秒,平均每台10526条/秒。
(五)测试结果
通过查询两台从服务器的数据库,其数据和主服务器一致,测试过程也没有出现崩溃的情况,证明了Mysql Replication的性能的稳定性。

五、问题排除

(一)出现Slave_IO_Running: No
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Connecting to master
Master_Host: 192.168.41.189
Master_User: repli
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000014
Read_Master_Log_Pos: 399
Relay_Log_File: mysqld-relay-bin.000003
Relay_Log_Pos: 98
Relay_Master_Log_File: mysql-bin.000015
Slave_IO_Running: No
Slave_SQL_Running: Yes
Replicate_Do_DB: discuz
Replicate_Ignore_DB: mysql
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 399
Relay_Log_Space: 98
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL
1 row in set (0.00 sec)
在主服务器上查看:
mysql> show master status;
+——————+———-+————–+——————+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+——————+———-+————–+——————+
| mysql-bin.000015 | 98 | discuz | mysql |
+——————+———-+————–+——————+
1 row in set (0.00 sec)
看到master_log_file和binlog_log_pos不一致,解决方法:
在从服务器上执行:
mysql> stop slave;
Query OK, 0 rows affected (0.00 sec)
mysql> change master to master_log_file=’mysql-bin.000015′,master_log_pos=98;
Query OK, 0 rows affected (0.00 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.41.189
Master_User: repli
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000015
Read_Master_Log_Pos: 98
Relay_Log_File: mysqld-relay-bin.000002
Relay_Log_Pos: 235
Relay_Master_Log_File: mysql-bin.000015
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
…………
问题解决。
(二)出现Error: ‘Host ’192.168.7.129′ is not allowed to connect to this MySQL server’ errno: 1130 retry-time: 60 retries: 86400
查看服务器状态,发现master_log_file和master_log_pos都一致,但是Slave_IO_Running: 的状态还是No,查看日志文件:
110515 1:04:28 [ERROR] Slave I/O thread: error connecting to master ‘[email protected]:3306′: Error: ‘Host ’192.168.7.129′ is not allowed to connect to this MySQL server’ errno: 1130 retry-time: 60 retries: 86400
查看用户名和密码没错,那应该是没有对从服务器进行授权访问。
解决方法:
mysql> grant replication slave on *.* to [email protected] identified by ‘qqing99′;
(三)出现Error: ‘Host ’192.168.7.1′ is not allowed to connect to this MySQL server’
在配置测试双主架构模式(Master-Master)时,已经对从服务器进行了授权,但是Slave_IO_Running: 的状态还是No,查看日志文件:
110516 14:38:37 [ERROR] Slave I/O thread: error connecting to master ‘[email protected]:3306′: Error: ‘Host ’192.168.7.1′ is not allowed to connect to this MySQL server’ errno: 1130 retry-time: 60 retries: 86400
应该是两台服务器不同网段造成的,所以在Master1/Slave1上执行:
mysql> grant replication slave on *.* to [email protected] identified by ‘qqing99′;
问题解决。
(四)出现Could not initialize master info structure
Could not initialize master info structure; more error messages can be found in the MySQL error log
解决方法:
mysql> stop slave;
mysql> reset slave;
mysql> start salve;
问题解决。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章