mysql-mmm的作用很简单就是读和写以ip的形式分离出来,并且可以全自动对mysql主从配置进行故障切换。
整个架构如下图:
操作系统全部为centos5.5 32bit
mysql版本为mysql-5.1.59
mysql-mmm版本为mysql-mmm-2.2.1
另外还需要4个虚拟IP,,作用为:
192.168.93.141 数据库写入ip
192.168.93.142 数据库读取ip
192.168.93.143 数据库读取ip
192.168.93.144 数据库读取ip
一、安装mysql
useradd mysqltar zxvf mysql-5.1.59.tar.gzcd mysql-5.1.59./configure –prefix=/usr/local/mysql –without-debug –enable-thread-safe-client –enable-assembler –enable-profiling –with-mysqld-ldflags=-all-static –with-client-ldflags=-all-static –with-charset=utf8 –with-extra-charsets=all –with-big-tables –enable-largefile –without-ndb-debug –with-plugins=partition –localstatedir=/home/varmakemake install
vi /etc/my.cnf
[client]port = 3306socket = /tmp/mysql.sock
[mysqld]port = 3306socket = /tmp/mysql.sock
skip-external-locking#skip-bdbskip-name-resolve#skip-innodbmax_allowed_packet = 8Mtable_cache = 2048sort_buffer_size = 2Mread_buffer_size = 2Mquery_cache_limit = 2Mmyisam_sort_buffer_size = 128Mthread_cache_size = 256query_cache_size = 128Mthread_concurrency = 8
log-bin=mysql-binslow_query_log=slowquery.loglong_query_time = 60
character-set-server=utf8max_user_connections=5000max_connections=8000wait_timeout=31536000tmp_table_size = 384Mbulk_insert_buffer_size = 512Mconcurrent_insert = 2back_log = 512
[mysqldump]quickmax_allowed_packet = 16M
[isamchk]key_buffer = 512Msort_buffer_size = 512Mread_buffer = 2Mwrite_buffer = 2M
[myisamchk]key_buffer = 512Msort_buffer_size = 512Mread_buffer = 2Mwrite_buffer = 2M
[mysqlhotcopy]interactive-timeoutdatadir=/home/var
[mysqld_safe]open_files_limit = 65535
保存退出!
继续安装Mysql
/usr/local/mysql/bin/mysql_install_db –user=mysqlchown -R mysql:mysql /home/var/usr/local/mysql/bin/mysqld_safe –user=mysql &cp ./support-files/mysql.server /etc/rc.d/init.d/mysql
chmod +x /etc/rc.d/init.d/mysql
chkconfig –add mysqlservice mysql start/usr/local/mysql/bin/mysqladmin -u root password 123456
vi ~/.bash_profile
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin/
追加蓝色部分,然后保存退出
使配置立即生效
source ~/.bash_profile
二、配置主从关系
DB1:编辑/etc/my.cnf,加入以下内容:
server-id=1log-bin=mysql-binbinlog_format=ROWlog-slave-updatessync_binlog=1auto_increment_increment=2auto_increment_offset=1skip_slave_start
DB2:编辑/etc/my.cnf,加入以下内容:
server-id=2log-bin=mysql-binbinlog_format=ROWlog-slave-updatessync_binlog=1auto_increment_increment=2auto_increment_offset=2
DB3:编辑/etc/my.cnf,加入以下内容:
server-id=3log-bin=mysql-binlog-slave-updates
然后重启mysql服务!
接下创建一个同步用的帐号并授权:
DB1授权:
mysql -uroot -p123456 -e "GRANT REPLICATION SLAVE ON *.* TO’slave’@’192.168.93.138’IDENTIFIED BY ‘slave’; "mysql -uroot -p123456 -e "GRANT REPLICATION SLAVE ON *.* TO’slave’@’192.168.93.139’IDENTIFIED BY ‘slave’; "
DB2授权:
mysql -uroot -p123456 -e "GRANT REPLICATION SLAVE ON *.* TO’slave’@’192.168.93.137’IDENTIFIED BY ‘slave’; "mysql -uroot -p123456 -e "GRANT REPLICATION SLAVE ON *.* TO’slave’@’192.168.93.139’IDENTIFIED BY ‘slave’; "
DB3的话以谁为主都无所谓,当主出现故障的时候,mmm会自动切换主的,我这里就以DB2为主,配置方从的步骤:锁表——(主)导出数据——(主)查看指针位置——(主)解锁——(从)导入数据——(从)导入主服务器的指针位置——(双方)开启主从线程
DB2:(PS我这里是新的数据库,所以省了导出数据这一步!)
mysql> flush tables with read lock;mysql> show master status;+——————+———-+————–+——————+| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |+——————+———-+————–+——————+| mysql-bin.000004 | 586 | | |+——————+———-+————–+——————+1 row in set (0.00 sec)mysql> unlock tables;
得出指针位置之后在DB1和DB3上操作:
没有了爱的语言,所有的文字都是乏味的