环境

CentOS

Mysql 5.1

前提

安装了EPEL,详细安装步骤请參照

http://blog.csdn.net/robinsonmhj/article/details/36184863

机器列表

机器IP 机器名
192.168.0.135 db1
192.168.0.136 monitor
192.168.0.137 db2
虚拟IP 作用
192.168.0.138 writter
192.168.0.139 reader
192.168.0.140 reader

安装步骤

1. 在db1 和 db2 上安装mysql

yum install mysql-server

2. 改动配置文件

db1 的配置文件

[mysqld]
datadir = /data/mysql
socket=/data/mysql/mysql.sock
user=mysql
<span style="font-size:18px;"><strong>server-id=1</strong></span>
table_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 64M
thread_concurrency = 8
log-bin=mysql-bin
binlog_format = mixed
max_connections=2048
character_set_server=utf8
wait_timeout=1800
interactive_timeout=1800
skip-show-database
skip-name-resolve
tmp_table_size = 512M
max_heap_table_size = 512M
binlog-ignore-db = mysql
replicate-ignore-db = mysql
binlog-ignore-db = information_schema
replicate-ignore-db = information_schema
binlog-ignore-db = performance_schema
replicate-ignore-db = performance_schema
binlog-ignore-db = test
replicate-ignore-db = test
innodb_data_home_dir=/data/mysql/innodb
innodb_data_file_path=ibdata1:2000M;ibdata2:10M:autoextend
innodb_log_group_home_dir=/data/mysql/innodb/log
innodb_file_per_table=1
innodb_buffer_pool_size = 1000M
innodb_additional_mem_pool_size = 20M
innodb_log_file_size = 100M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 2
innodb_lock_wait_timeout = 50
default-storage-engine = MyISAM
#default-storage-engine = INNODB [mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid [mysqldump]
quick
max_allowed_packet = 16M
socket=/data/mysql/mysql.sock [mysql]
no-auto-rehash
socket=/data/mysql/mysql.sock

db2 的配置文件

[mysqld]
datadir = /data/mysql
socket=/data/mysql/mysql.sock
user=mysql
<span style="font-size:18px;"><strong>server-id=2</strong></span>
table_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size = 64M
thread_concurrency = 8
log-bin=mysql-bin
binlog_format = mixed
max_connections=2048
character_set_server=utf8
wait_timeout=1800
interactive_timeout=1800
skip-show-database
skip-name-resolve
tmp_table_size = 512M
max_heap_table_size = 512M
binlog-ignore-db = mysql
replicate-ignore-db = mysql
binlog-ignore-db = information_schema
replicate-ignore-db = information_schema
binlog-ignore-db = performance_schema
replicate-ignore-db = performance_schema
binlog-ignore-db = test
replicate-ignore-db = test
innodb_data_home_dir=/data/mysql/innodb
innodb_data_file_path=ibdata1:2000M;ibdata2:10M:autoextend
innodb_log_group_home_dir=/data/mysql/innodb/log
innodb_file_per_table=1
innodb_buffer_pool_size = 1000M
innodb_additional_mem_pool_size = 20M
innodb_log_file_size = 100M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 2
innodb_lock_wait_timeout = 50
default-storage-engine = MyISAM
#default-storage-engine = INNODB [mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid [mysqldump]
quick
max_allowed_packet = 16M
socket=/data/mysql/mysql.sock [mysql]
no-auto-rehash
socket=/data/mysql/mysql.sock

3. 在db1和db2 上分别建立复制,监控用户

    GRANT REPLICATION CLIENT                 ON *.* TO 'mmm_monitor'@'192.168.0.136' IDENTIFIED BY 'monitor';
GRANT SUPER, REPLICATION CLIENT, PROCESS ON *.* TO 'mmm_agent'@'192.168.0.%' IDENTIFIED BY 'agent';
GRANT REPLICATION SLAVE ON *.* TO 'replication'@'192.168.0.%' IDENTIFIED BY 'replication';

4. 把db1和db2互相设置成master和slave

4.1 在db1上运行。mysql命令

CHANGE MASTER TO master_host='192.168.0.137', master_port=3306, master_user='replication',master_password='replication', master_log_file='mysql-bin.000006', master_log_pos=106;
注意:
<span></span><pre name="code" class="html">master_log_file和master_log_pos的值通过例如以下命令察看
在db2上运行例如以下mysql命令 show master status


4.2 在db2上运行,mysql命令

CHANGE MASTER TO master_host='192.168.0.135', master_port=3306, master_user='replication',master_password='replication', master_log_file='mysql-bin.000006', master_log_pos=106;
注意:
<span></span><pre name="code" class="html">master_log_file和master_log_pos的值通过例如以下命令察看
在db1上运行例如以下mysql命令 show master status


5. 在db1和db2上安装mysql-mmm-agent

yum install mysql-mmm-agent*

6. 在monitor上安装mysql-mmm-monitor

yum install mysql-mmm-monitor*



7. 改动配置文件

在db1,db2和monitor上改动

/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.0.135
mode master
peer db2
</host> <host db2>
ip 192.168.0.137
mode master
peer db1
</host> <role writer>
hosts db1,db2
ips 192.168.0.138
mode exclusive
</role> <role reader>
hosts db1,db2
ips 192.168.0.139,192.168.0.140
mode balanced
</role>

改动配置文件

/etc/mysql-mmm/mmm_agent.conf

db1上的内容例如以下

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.
<span style="font-size:18px;"><strong>this db1</strong></span>

db2上的内容例如以下

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.
<span style="font-size:18px;"><strong>this db2</strong></span>

改动配置monitor文件

/etc/mysql-mmm/mmm_mon.conf,内容例如以下

include mmm_common.conf

<monitor>
ip <span style="font-size:18px;"><strong>192.168.0.136</strong></span>
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 <span style="font-size:18px;"><strong>192.168.0.135,192.168.0.137</strong></span>
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

8.在db1。db2上启动agent

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

9. 在monitor上启动monitor

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

10. 在monitor上察看

mmm_control -show status

10.2 把一台机器上线

mmm_control set_online db1

10.3 试验

把db1上的mysql停掉 service mysqld stop

察看状态mmm_control -show status。db1上的写ip应该飘到db2上

參考

http://blog.csdn.net/mydeman/article/details/6845567

http://hi.baidu.com/viewehsoitfmyzr/item/5024bec2ef02ccd196445280

CentOS 搭建 Mysql MMM 高可用架构的更多相关文章

  1. Oracle Compute云快速搭建MySQL Keepalived高可用架构

    最近有个客户在测试Oracle Compute云,他们的应用需要使用MySQL数据库,由于是企业级应用一定要考虑高可用架构,因此有需求要在Oracle Compute云上搭建MySQL高可用集群.客户 ...

  2. MySQL集群搭建(3)-MMM高可用架构

    1 MMM 介绍 1.1 简介 MMM 是一套支持双主故障切换以及双主日常管理的第三方软件.MMM 由 Perl 开发,用来管理和监控双主复制,虽然是双主架构,但是业务上同一时间只允许一个节点进行写入 ...

  3. 搭建MySQL MMM高可用

    搭建MMM: 1,安装 agent 节点执行 yum install -y mysql-mmm-agent 2, monitor 节点执行 yum install -y mysql-mmm-monit ...

  4. centos6.6部署mysql mmm高可用架构

    一.环境简述 1.工作逻辑图 2.MySQL-MMM优缺点 优点:高可用性,扩展性好,出现故障自动切换,对于主主同步,在同一时间只提供一台数据库写操作,保证的数据的一致性. 缺点:Monitor节点是 ...

  5. mysql mmm高可用架构设计

    项目概述:搭建主从,双主,安装Perl模块  安装配置mmm软件  测试 硬件环境:4台虚拟PC 软件环境:rehl6.5 MySQL-5.6.26 percona-xtrabackup-2.3.4 ...

  6. 美团点评MySQL数据库高可用架构从MMM到MHA+Zebra以及MHA+Proxy的演进

    本文介绍最近几年美团点评MySQL数据库高可用架构的演进过程,以及我们在开源技术基础上做的一些创新.同时,也和业界其它方案进行综合对比,了解业界在高可用方面的进展,和未来我们的一些规划和展望. MMM ...

  7. (转)基于keepalived搭建MySQL的高可用集群

    基于keepalived搭建MySQL的高可用集群  原文:http://www.cnblogs.com/ivictor/p/5522383.html MySQL的高可用方案一般有如下几种: keep ...

  8. mysql复制(高可用架构方案的基础)

    mysql复制:把一个数据库实例上所有改变复制到另外一个数据库库服务器实例的过程特点:1.没有改变就无所谓复制 ;改变是复制的根本与数据源2.所有的改变:是指可以复制全部改变,也可以复制部分改变 可以 ...

  9. Mysql MMM 高可用

    一.Mysql MMM 高可用概况: mmm_mond  负责所有的监控工作的监控守护进程,决定节点的移除等: mmm_agentd  运行在mysql服务器上的代理守护进程,通过简单远程服务集提供给 ...

随机推荐

  1. grant 命令

    创建拥有所有权限账户.可以远程连接.并且允许用户再将该权限授予其它用户: grant all privileges on *.* to root @"%" identified b ...

  2. WordPress开启伪静态

    一.NGINX 的话在 domain.conf 的 server 增加代码: location / { try_files $uri $uri/ /index.php?$args; } 如果使用的是 ...

  3. 洛谷 P1005 矩阵取数游戏 (区间dp+高精度)

    这道题大部分时间都在弄高精度-- 还是先讲讲dp吧 这道题是一个区间dp,不过我还是第一次遇到这种类型的区间dp f[i][j]表示取了数之后剩下i到j这个区间的最优值 注意这里是取了i之前和j之后的 ...

  4. Qt之根据扩展名获取文件图标、类型

    简述 在C++根据扩展名获取文件图标.类型一节中我们分享了如何根据扩展名来获取对应的文件图标.类型,下面.我们在Qt中使用它. 简述 示例 效果 源码 更多参考 示例 如下,我们根据扩展名来获取对应的 ...

  5. [iOS]iOS获取设备信息经常用法

    郝萌主倾心贡献.尊重作者的劳动成果.请勿转载. 假设文章对您有所帮助.欢迎给作者捐赠.支持郝萌主.捐赠数额任意,重在心意^_^ 我要捐赠: 点击捐赠 Cocos2d-X源代码下载:点我传送 游戏官方下 ...

  6. echarts 地图 动态 展示 结合css+js

    echarts地图展示功能非常强大,官网上静态展示的样例非常多了,动态的资料少.研究了下.我眼下实现的通过ajax从server获取数据动态展示地图. 另外,我们有时候希望在地图之上做些自己定义的东西 ...

  7. List methods

    Python provides methods that operate on lists. For example, append adds a new element to the end of ...

  8. AngularJs轻松入门(八)Cookies读写

    虽然使用JavaScript创建和获取Cookie很简单,AngularJs还是把它作为一个单独的模块进行了封装,模块名为ngCookies,和前面的教程中做法一样,先引入angular-cookie ...

  9. <Sicily>Tiling a Grid With Dominoes

    一.题目描述 We wish to tile a grid 4 units high and N units long with rectangles (dominoes) 2 units by on ...

  10. sql排名函数--四个

    1 row_number 2 rank 3 dense_rank 4 ntile 例子如下: select * into #MyTablefrom(select '语文' as 课程,70 as 成绩 ...