从零开始搭建MySQL MMM架构


当前第2页 返回上一页

4. 将db02作为master,db01作为slave,重复1-3。

四、安装MMM

在管理服务器和数据库服务器上分别要运行mysql-mmm monitor和agent程序。下面分别安装:
 1. 安装监控程序
在管理服务器(192.168.84.174)上,执行下面命令:

代码如下:

# yum -y install mysql-mmm-monitor* 

与monitor依赖的所有文件也会随之安装,但是有一个例外perl-Time-HiRes,所以还需要执行下面的命令:
代码如下:

# yum -y install perl-Time-HiRes*

2. 安装代理程序

在数据库服务器上执行下面的命令:

代码如下:

# yum -y install mysql-mmm-agent* 

五、配置MMM

1. 编辑mmm_common.conf

完成安装后,所有的配置文件都放到了/etc/mysql-mmm/下面。管理服务器和数据库服务器上都要包含一个共同的文件mmm_common.conf,内容如下:

代码如下:

active_master_role      writer

<host default>
    cluster_interface       eth0

    pid_path                /var/run/mysql-mmm/mmm_agentd.pid
    bin_path                /usr/libexec/mysql-mmm/

    replication_user        replication
    replication_password    replication

    agent_user              mmm_agent
    agent_password          agent
</host>

<host db1>
    ip      192.168.85.167
    mode    master
    peer    db2
</host>

<host db2>
    ip      192.168.85.169
    mode    master
    peer    db1
</host>

<host db3>
    ip      192.168.85.171
    mode    slave
</host>

<host db4>
    ip      192.168.85.168
    mode    slave
</host>

<role writer>
    hosts   db1, db2
    ips     192.168.85.200
    mode    exclusive
</role>

<role reader>
    hosts   db2, db3, db4
    ips     192.168.85.201, 192.168.85.202, 192.168.85.203
    mode    balanced
</role>

可以在db1上编辑该文件后,通过scp命令分别复制到monitor、db2、db3和db4上。

2. 编辑mmm_agent.conf。在数据库服务器上,还有一个mmm_agent.conf需要修改,其内容是:

代码如下:

include mmm_common.conf

# The 'this' variable refers to this server.  Proper operation requires
# that 'this' server (db1 by default), as well as all other servers, have the
# proper IP addresses set in mmm_common.conf.
this db1

最后一行的db1,在不同的数据库服务器上要分别改为db2、db3和db4,否则代理就会无法启动。

3. 编辑mmm_mon.confg。在管理服务器上,修改mmm_mon.conf文件,修改后内容为:

代码如下:

include mmm_common.conf

<monitor>
    ip                  192.168.84.174
    pid_path            /var/run/mysql-mmm/mmm_mond.pid
    bin_path            /usr/libexec/mysql-mmm
    status_path         /var/lib/mysql-mmm/mmm_mond.status
    ping_ips            192.168.85.167, 192.168.85.169, 192.168.85.171, 192.168.85.168
    auto_set_online     60

    # The kill_host_bin does not exist by default, though the monitor will
    # throw a warning about it missing.  See the section 5.10 "Kill Host
    # Functionality" in the PDF documentation.
    #
    # kill_host_bin     /usr/libexec/mysql-mmm/monitor/kill_host
    #
</monitor>

<host default>
    monitor_user        mmm_monitor
    monitor_password    monitor
</host>

debug 0

六、启动MMM

1. 在数据库服务器上启动代理程序

代码如下:

# cd /etc/init.d/
# chkconfig mysql-mmm-agent on
# service mysql-mmm-agent start

2. 在管理服务器上启动监控程序

代码如下:

# cd /etc/init.d/
# chkconfig mysql-mmm-monitor on
# service mysql-mmm-monitor start

启动后,稍等几秒,可以通过mmm_control程序查看状态:

代码如下:

# mmm_control show
  db1(192.168.85.167) master/ONLINE. Roles: writer(192.168.85.200)
  db2(192.168.85.169) master/ONLINE. Roles: reader(192.168.85.202)
  db3(192.168.85.171) slave/ONLINE. Roles: reader(192.168.85.203)
  db4(192.168.85.168) slave/ONLINE. Roles: reader(192.168.85.201)

七、遇到两个问题

1. 监控程序服务器无法启动

在管理服务器上,一切都完成后,通过mmm_control查看状态,得到下面的错误信息:ERROR: Can't connect to monitor daemon! 通过编辑/etc/mysql-mmm/mmm_mon.conf文件将debug 0改为debug 1,打开监控程序的debug状态。重新启动监控程序(service mysql-mmm-monitor restart),就会看到详细的错误信息,找不到Perl Time HiRes库。执行yum -y install perl-Time-HiRes*就可以解决。

2. 防火墙问题导致Warning: agent on host db1 is not reachable.
控制台程序正确启动后,再次执行mmm_control show,却看到下面的输出:

代码如下:

# Warning: agent on host db1 is not reachable
# Warning: agent on host db2 is not reachable
# Warning: agent on host db3 is not reachable
# Warning: agent on host db4 is not reachable
  db1(192.168.85.167) master/ONLINE. Roles:
  db2(192.168.85.169) master/ONLINE. Roles:
  db3(192.168.85.171) slave/ONLINE. Roles:
  db4(192.168.85.168) slave/ONLINE. Roles:

再次打开debug,发现了下面的错误信息:

代码如下:

2011/10/07 13:38:45 DEBUG Sending command 'GET_AGENT_STATUS()' to db4 (192.168.85.167:9989)
2011/10/07 13:38:45 ERROR The status of the agent on host 'db4' could not be determined (answer was: 0).

通过telnet 192.168.85.167 9989下面检查网络连接,得到了No route to host的错误信息。登录db1,通过setup程序里的Firewall configuration关闭Firewall(这不是一个好主意)。同样,关闭db2、db3和db4上的防火墙,再次重启监控程序,一切回到正常状态!

参考文章:

MySQL MMM 官方安装文档 http://mysql-mmm.org/mmm2:guide
MMM Manual http://mysql-mmm.org/mysql-mmm.html

更多相关Mysql内容来自木庄网络博客


标签:Mysql

返回前面的内容

相关阅读 >>

mysql的内连接,左连接和右链接查询详解

mysql怎么新建数据库?

mysql详解进行jdbc编程与增删改查方法

mysql的免安装版怎么用?

mysql order by rand() 效率优化方法

mysql提示启动密码错误怎么办

解决mysql写入中文乱码问题

花式了解---mysql多表查询

mysql 基础知识小结

mysql内存不足怎么办

更多相关阅读请进入《mysql》频道 >>


数据库系统概念 第6版
书籍

数据库系统概念 第6版

机械工业出版社

本书主要讲述了数据模型、基于对象的数据库和XML、数据存储和查询、事务管理、体系结构等方面的内容。



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...