Linux.ChinaUnix.net
ChinaUnix | Linux首页 | 新闻 | 博客 | 文章 | 专栏 | 新手 | 方案 | 图书 | 下载 | 人才 | 手册 | wiki | 搜索     
Linux论坛
  会员: 密码: 免费注册 | 忘记密码 | 会员登录 | 搜索 | 帮助 


[集群] 实践:使用MMM搭建Mysql集群

首页 » CU论坛 » Linux » 汇总贴列表 » 集群和虚拟机 »  
[打印] [订阅] [收藏] [本帖文本页] [推荐此主题给朋友,立即获积分]
sailer_sh
风云使者




UID:159553
注册:2004-5-20
最后登录: 2008-10-09
帖子:486
精华:5

可用积分:506 (稍有积蓄)
信誉积分:100
专家积分:0 (本版:0)
空间积分:0
推广积分:0

状态:...离线...

[资料] [站内短信] [Blog]


1楼 发表于 2008-1-15 18:01 
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里执行命令:

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里执行命令:

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:

*************************** 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上的结果:

*************************** 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目录下。

管理节点上的配置文件mmm_mon.conf,在这个配置文件里指定了reader和writer角色的虚拟IP:

#
# Master-Master Manager config (monitor)
#

# Debug mode
debug no

# Paths
pid_path /usr/local/mmm/var/mmmd.pid
status_path /usr/local/mmm/var/mmmd.status
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
    email root@localhost


# MMMD command socket tcp-port
bind_port 9988
agent_port 9989
monitor_ip 127.0.0.1

# Cluster interface
cluster_interface eth0

# Cluster hosts addresses and access params
host db1
    ip 192.168.20.9
    port 3306
    user rep_monitor
    password RepMonitor
    mode master
    peer db2

host db2
    ip 192.168.20.10
    port 3306
    user rep_monitor
    password RepMonitor
    mode master
    peer db1

#
# Define roles
#

active_master_role writer

# Mysql Reader role
role reader
    mode balanced
    servers db1, db2
    ip 192.168.20.27, 192.168.20.28

# Mysql Writer role
role writer
    mode exclusive
    servers db1
    ip 192.168.20.29

#
# Checks parameters
#

# Ping checker
check ping
    check_period 1
    trap_period 5
    timeout 2

# Mysql checker
# (restarts after 10000 checks to prevent memory leaks)
check mysql
    check_period 1
    trap_period  2
    timeout 2
    restart_after 10000

# Mysql replication backlog checker
# (restarts after 10000 checks to prevent memory leaks)
check rep_backlog
    check_period 5
    trap_period 10
    max_backlog 60
    timeout 2
    restart_after 10000

# Mysql replication threads checker
# (restarts after 10000 checks to prevent memory leaks)
check rep_threads
    check_period 1
    trap_period 5
    timeout 2
    restart_after 10000

db1上的配置文件mmm_agent.conf:

#
# 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:

#
# 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

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

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

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!

管理节点上相关进程的状态:

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上的相关进程:

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上的相关进程:

root      8731  0.0  3.0 100524  7980 ?        S    15:38   0:01 perl /usr/local/sbin/mmmd_agent

在管理节点上查看节点状态:
mmm_control show

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-21 10:23 编辑 ]



您对本贴的看法:鲜花[0] 臭蛋[0]
积分兑换专区 | IT节能和TPC-E活动获奖名单 | 致电800-858-2903,了解DELL如何为你量身订制笔记本 | 送2G U盘 | 站长如何获得资金?
feihulove   帅哥
骑士




UID:79756
注册:2003-8-5
最后登录: 2008-09-23
帖子:52
精华:0

可用积分:63 (白手起家)
信誉积分:100
专家积分:0 (本版:0)
空间积分:0
推广积分:0

状态:...离线...

[资料] [站内短信] [Blog]


2楼 发表于 2008-1-19 17:24 
请问192.168.20.29,192.168.20.27,192.168.20.28这些IP又是哪来的?不是只有2台数据库吗?另外,应用程序连接数据库的话,是只连接一个Monitoring Server,还是在程序里边分别连接db1,db2.

[ 本帖最后由 feihulove 于 2008-1-19 17:27 编辑 ]



您对本贴的看法:鲜花[0] 臭蛋[0]

__________________________________

www.kankantu.com
积分兑换专区 | IT节能和TPC-E活动获奖名单 | 致电800-858-2903,了解DELL如何为你量身订制笔记本 | 送2G U盘 | 站长如何获得资金?
sailer_sh
风云使者




UID:159553
注册:2004-5-20
最后登录: 2008-10-09
帖子:486
精华:5

可用积分:506 (稍有积蓄)
信誉积分:100
专家积分:0 (本版:0)
空间积分:0
推广积分:0

状态:...离线...

[资料] [站内短信] [Blog]


3楼 发表于 2008-1-21 10:36 


QUOTE:
原帖由 feihulove 于 2008-1-19 17:24 发表
请问192.168.20.29,192.168.20.27,192.168.20.28这些IP又是哪来的?不是只有2台数据库吗?另外,应用程序连接数据库的话,是只连接一个Monitoring Server,还是在程序里边分别连接db1,db2.

Sorry我漏掉了管理节点上的配置文件mmm_mon.conf,这个文件里定义了读、写角色的IP,这些IP是虚拟的。按照MMM作者的说法,应用连接数据库的时候,连接的是这些虚拟IP,但是必须手工指定分别去连接所有的读写IP(这一点感觉不太爽),他并没有做到像LVS那样去访问一个IP,后台自动分配任务,我在考虑自己实现这个功能,我这里有一个写节点和多个读节点,打算在读节点上部署LVS,使读角色对应用的透明化。
Monitoring只是实现HA功能,可以放在其他服务器上,它本身不提供读写数据的功能。



您对本贴的看法:鲜花[0] 臭蛋[0]
积分兑换专区 | IT节能和TPC-E活动获奖名单 | 致电800-858-2903,了解DELL如何为你量身订制笔记本 | 送2G U盘 | 站长如何获得资金?
wuruichang   帅哥
侠客



UID:227917
注册:2005-2-22
最后登录: 2008-09-16
帖子:39
精华:0

可用积分:47 (白手起家)
信誉积分:100
专家积分:0 (本版:0)
空间积分:0
推广积分:0

状态:...离线...

[资料] [站内短信] [Blog]


4楼 发表于 2008-1-29 16:55 
可通过在db1,db2服务器绑定虚拟IP(192.168.20.29),实现往writer(192.168.20.29) 写数据,在一台挂了后,另一台接替写操作。
http://code.google.com/p/mysql-master-master/wiki/FAQ

You just need to configure the IP address, for each computer, specified at your Cluster Hosts Addresses section on your Configuration File. As soon as MMM Agent start and communicate with MMM Monitor, it will setup the additional IPs for the roles.

Using Configuration Example as reference, you will ONLY need to setup IPs 192.168.1.8 at master 1 and 192.168.1.9 at master2.

Using Configuration Example as reference you will write to IP 192.168.1.200 and read from 192.168.1.100, 192.168.1.101.

If master1 fails MMM Monitor will move IP address 192.168.1.200 to master2 automatically.



您对本贴的看法:鲜花[0] 臭蛋[0]

__________________________________

某天深夜,偶起来上厕所,见一透明状东西左忽右闪~
吾问:你是鬼?
鬼曰:恩那
吾  :怕我吗??
鬼  : ........
积分兑换专区 | IT节能和TPC-E活动获奖名单 | 致电800-858-2903,了解DELL如何为你量身订制笔记本 | 送2G U盘 | 站长如何获得资金?
wwdwwd   帅哥
圣骑士




UID:328728
注册:2005-10-28
最后登录: 2008-08-10
帖子:92
精华:0

可用积分:309 (白手起家)
信誉积分:100
专家积分:5 (本版:0)
空间积分:823
推广积分:0

状态:...离线...

[资料] [站内短信] [Blog]


5楼 发表于 2008-5-18 21:54 
楼上的兄弟们,为什么我按你的配置就不成功呢?
db1,db2可以起来,但是一旦把monitor起来之后,db1,db2就自动关闭了。
db1,db2上的提示信息是:
Can't locate object method "new" via package "Algorithmiff" at /usr/local/mmm/lib/agent_commands.pm line 131


我总共使用了6个ip,全是内网的ip,我用来测试的:
db1:172.16.0.101,172.16.0.111,172.16.0.110
db2:172.16.0.102,172.16.0.112
monitor:172.16.0.103





我的配置文件如下:


db1:

#
# Master-Master Manager config (agent)
#

# Debug mode
debug yes

# 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 eth0

# Define current server id
this db1
mode slave

# For masters
peer db2

# Cluster hosts addresses and access params
host db1
    ip 172.16.0.101
    port 3306
    user rep_agent
    password RepAgent

host db2
    ip 172.16.0.102
    port 3306
    user rep_agent
    password RepAgent

db2:

# Master-Master Manager config (agent)
#

# Debug mode
debug yes

# 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 eth0

# Define current server id
this db2
mode slave

# For masters
peer db1

# Cluster hosts addresses and access params
host db1
    ip 172.16.0.101
    port 3306
    user rep_agent
    password RepAgent

host db2
    ip 172.16.0.102
    port 3306
    user rep_agent
    password RepAgent

monitor:

# Debug mode
debug no

# Paths
pid_path /usr/local/mmm/var/mmmd.pid
status_path /usr/local/mmm/var/mmmd.status
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
bind_port 9988
agent_port 9989
monitor_ip 127.0.0.1

# Cluster interface
cluster_interface eth0

# Cluster hosts addresses and access params
host db1
    ip 172.16.0.101
    port 3306
    user rep_monitor
    password RepMonitor
    mode master
    peer db2

host db2
    ip 172.16.0.102
    port 3306
    user rep_monitor
    password RepMonitor
    mode master
    peer db1

#
# Define roles
#

active_master_role writer

# Mysql Reader role
role reader
    mode balanced
    servers db1, db2
    ip 172.16.0.111, 172.16.0.112

# Mysql Writer role
role writer
    mode exclusive
    servers db1
    ip 172.16.0.110

#
# Checks parameters
#

# Ping checker
check ping
    check_period 1
    trap_period 5
    timeout 2

# Mysql checker
check mysql
    check_period 1
    trap_period  2
    timeout 2
    restart_after 10000
# Mysql replication backlog checker
check rep_backlog
    check_period 5
    trap_period 10
    max_backlog 60
    timeout 2
    restart_after 10000

# Mysql replication threads checker
check rep_threads
    check_period 1
    trap_period 5
    timeout 2
    restart_after 10000

[ 本帖最后由 wwdwwd 于 2008-5-18 21:58 编辑 ]



您对本贴的看法:鲜花[0] 臭蛋[0]
积分兑换专区 | IT节能和TPC-E活动获奖名单 | 致电800-858-2903,了解DELL如何为你量身订制笔记本 | 送2G U盘 | 站长如何获得资金?
wwdwwd   帅哥
圣骑士




UID:328728
注册:2005-10-28
最后登录: 2008-08-10
帖子:92
精华:0

可用积分:309 (白手起家)
信誉积分:100
专家积分:5 (本版:0)
空间积分:823
推广积分:0

状态:...离线...

[资料] [站内短信] [Blog]


6楼 发表于 2008-5-21 15:18 
顶上来接着求助,各位朋友们请帮帮忙啊



您对本贴的看法:鲜花[0] 臭蛋[0]
积分兑换专区 | IT节能和TPC-E活动获奖名单 | 致电800-858-2903,了解DELL如何为你量身订制笔记本 | 送2G U盘 | 站长如何获得资金?

首页 » CU论坛 » Linux » 汇总贴列表 » 集群和虚拟机 »

 


Copyright © 2001-2008 ChinaUnix.net All Rights Reserved     联系我们:

感谢所有关心和支持过ChinaUnix的朋友们    转载本站内容请注明原作者名及出处

京ICP证041476号


清除 Cookies - Linux时代 - Archiver - WAP - TOP

Processed in 0.065966 second(s), 5 queries , Gzip enabled