MMM是 mysql-master-master的縮寫,MMM在多台mysql server之間以主-主的形式復制數據,達到並發訪問,提高性能的目的。
MMM項目來自Google:
http://code.google.com/p/mysql-master-master/
我的安裝過程參考了文檔
http://blog.kovyrin.net/2007/04/ ... -example-using-mmm/
以下是我搭建的過程。
我使用三台RHEL5U1 server,其中一台是Monitoring Server,另兩台Mysql server用來讀寫數據。
192.168.20.5做為Monitoring Server,
192.168.20.9做為db1,
192.168.20.10做為db2。
三台服務器先安裝mysql,我安裝的是mysql 5.1.22的社區版本。
先安裝3個perl的包:
Algorithm-Diff-1.1902.tar.gz
Proc-Daemon-0.03.tar.gz
DBD-mysql-4.006.tar.gz(依賴於mysql-devel包)
perl包的安裝過程都是:
perl Makefile.PL
make
make test
make install
DBD-mysql包的安裝(本地mysql server必須處於運行狀態):
perl Makefile.PL --testuser=root --testpassword=abcdefg (後面的參數是本地mysql server登錄的用戶名和密碼)
make
make test
make install
安裝DBD-mysql的時候提示找不到mysql_config,需要安裝mysql-devel包。
安裝mmm:
./install.pl
先配置Master-Master replication:
在db1的/etc/my.cnf增加:
server-id = 1
log-bin = mysql-bin
在db2的/etc/my.cnf增加:
server-id = 2
log-bin = mysql-bin
為了保證replication能正常啟動,我在啟動mysql服務以前以前把/var/lib/mysql目錄下與二進制日志相關的文件全部刪除,包括log-bin、 relaybin、mysql-bin.index、mysql_ndb-1-relay-bin.index、relay-log.info等文件,又刪除test庫裡的表。
啟動mysql以後在db1上的mysql裡執行命令:
[ - ]CODE:grant replication slave on *.* to 'replication'@'%' identified by 'slave';
change master to master_host='192.168.20.10', master_port=3306, master_user='replication', master_password='slave';
slave start;
在db2上的mysql裡執行命令:
[ - ]CODE:grant replication slave on *.* to 'replication'@'%' identified by 'slave';
change master to master_host='192.168.20.9', master_port=3306, master_user='replication', master_password='slave';
slave start;
show slave status\G;的結果:
db1:
[ - ]CODE:*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.20.10
Master_User: replication
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 106
Relay_Log_File: mysql_ndb-1-relay-bin.000002
Relay_Log_Pos: 251
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
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: 106
Relay_Log_Space: 412
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: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
1 row in set (0.00 sec)
ERROR:
No query specified
db2上的結果:
[ - ]CODE:*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.20.9
Master_User: replication
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 106
Relay_Log_File: mysql_ndb-2-relay-bin.000002
Relay_Log_Pos: 251
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
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: 106
Relay_Log_Space: 412
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: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
1 row in set (0.00 sec)
ERROR:
No query specified
MMM所有配置文件都放在/usr/local/mmm/etc目錄下。
db1上的配置文件mmm_agent.conf:
[ - ]CODE:#
# Master-Master Manager config (agent)
#
# Debug mode
debug no
# Paths
pid_path /usr/local/mmm/var/mmmd_agent.pid
bin_path /usr/local/mmm/bin
# Logging setup
log mydebug
file /usr/local/mmm/var/mmm-debug.log
level debug
log mytraps
file /usr/local/mmm/var/mmm-traps.log
level trap
# MMMD command socket tcp-port and ip
bind_port 9989
# Cluster interface
cluster_interface eth1
# Define current server id
this db1
mode slave
# For masters
peer db2
# Cluster hosts addresses and access params
host db1
ip 192.168.20.9
port 3306
user rep_agent
password RepAgent
host db2
ip 192.168.20.10
port 3306
user rep_agent
password RepAgent
db2上的配置文件mmm_agent.conf:
[ - ]CODE:#
# Master-Master Manager config (agent)
#
# Debug mode
debug no
# Paths
pid_path /usr/local/mmm/var/mmmd_agent.pid
bin_path /usr/local/mmm/bin
# Logging setup
log mydebug
file /usr/local/mmm/var/mmm-debug.log
level debug
log mytraps
file /usr/local/mmm/var/mmm-traps.log
level trap
# MMMD command socket tcp-port and ip
bind_port 9989
# Cluster interface
cluster_interface eth1
# Define current server id
this db2
mode slave
# For masters
peer db1
# Cluster hosts addresses and access params
host db1
ip 192.168.20.9
port 3306
user rep_agent
password RepAgent
host db2
ip 192.168.20.10
port 3306
user rep_agent
password RepAgent
在db1和db2上建立新用戶,用於管理節點訪問db節點:
GRANT ALL PRIVILEGES on *.* to 'rep_monitor'@'192.168.20.5' identified by 'RepMonitor';
在db1和db2節點上啟動agent:
mmmd_agent
在管理節點上啟動管理進程:
mmmd_mon
[ - ]CODE:Reading config file: 'mmm_mon.conf'
$VAR1 = {
'db2' => {
'roles' => [],
'version' => '0',
'state' => 'AWAITING_RECOVERY'
},
'db1' => {
'roles' => [
'reader(192.168.20.27;)',
'reader(192.168.20.28;)',
'writer(192.168.20.29;)'
],
'version' => '0',
'state' => 'ONLINE'
}
};
Role: 'reader(192.168.20.27;)'
Adding role: 'reader' with ip '192.168.20.27'
Role: 'reader(192.168.20.28;)'
Adding role: 'reader' with ip '192.168.20.28'
Role: 'writer(192.168.20.29;)'
Adding role: 'writer' with ip '192.168.20.29'
在管理節點上啟動db節點
mmm_control set_online db1
[ - ]CODE:Config file: mmm_mon.conf
Daemon is running!
Command sent to monitoring host. Result: OK: State of 'db1' changed to ONLINE. Now you can wait some time and check its new roles!
mmm_control set_online db2
[ - ]CODE:Config file: mmm_mon.conf
Daemon is running!
Command sent to monitoring host. Result: OK: State of 'db2' changed to ONLINE. Now you can wait some time and check its new roles!
管理節點上相關進程的狀態:
[ - ]CODE:root 8653 0.6 14.9 256856 39192 ? Sl 15:51 0:01 perl /usr/local/sbin/mmmd_mon
root 8656 0.1 3.1 99868 8160 ? S 15:51 0:00 \_ perl /usr/local/mmm/bin/check/checker rep_backlog
root 8658 0.1 3.1 99856 8144 ? S 15:51 0:00 \_ perl /usr/local/mmm/bin/check/checker mysql
root 8661 0.1 1.8 87004 4932 ? S 15:51 0:00 \_ perl /usr/local/mmm/bin/check/checker ping
root 8926 0.0 0.1 1612 508 ? S 15:55 0:00 | \_ /usr/local/mmm/bin/sys/fping -q -u -t 500 -C 1 192.168.20.10
root 8662 0.1 3.1 99868 8168 ? S 15:51 0:00 \_ perl /usr/local/mmm/bin/check/checker rep_threads
db1上的相關進程:
[ - ]CODE:root 8769 0.3 3.0 100520 7988 ? S 15:38 0:04 perl /usr/local/sbin/mmmd_agent
root 11824 15.0 2.5 94764 6588 ? S 15:56 0:00 \_ perl /usr/local/mmm/bin/agent/check_role writer(192.168.20.29;)
root 11825 17.0 2.9 101824 7776 ? S 15:56 0:00 \_ perl /usr/local/mmm/bin/mysql_allow_write
db2上的相關進程:
[ - ]CODE:root 8731 0.0 3.0 100524 7980 ? S 15:38 0:01 perl /usr/local/sbin/mmmd_agent
在管理節點上查看節點狀態:
mmm_control show
[ - ]CODE:Config file: mmm_mon.conf
Daemon is running!
Servers status:
db1(192.168.20.9): master/ONLINE. Roles: writer(192.168.20.29;)
db2(192.168.20.10): master/ONLINE. Roles: reader(192.168.20.27;), reader(192.168.20.28;)
到這裡集群搭好了,db1負責讀數據,db2負責讀和寫數據,讀寫性能應該比單台mysql server高,對於類似read 90% + write 10%這樣的應用來說,增加讀節點以後,整體性能會有很大提高。
接下來用sysbench和super-smack測它的性能。
[ 本帖最後由 sailer_sh 於 2008-1-15 18:05 編輯 ]