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;
問題解決。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章