Mysql-master-master
Alvin.zeng
环境描述:
第一组
192.168.9.11 (master)--两台master相互冗余
192.168.9.14 (master)--两台master相互冗余
一、两台master相互授权
11-master操作:
mysql> grant replication slave,file on *.* to 'admin'@'192.168.9.14' identified
by '123456';
msyql>flush privileges;
mysql>select user.host from mysql.user;
14-master操作:
mysql> grant replication slave,file on *.* to 'admin'@'192.168.9.11' identified
by '123456';
msyql>flush privileges;
mysql>select user.host from mysql.user;
二、配置文件:
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
character-set-server = utf8
replicate-ignore-db = mysql
replicate-ignore-db = test
replicate-ignore-db = information_schema
user = mysql
port = 3306
socket = /tmp/mysql.sock
basedir = /usr/local/services/mysql-5.1.49/
datadir = /data/sql
log-error = /data/sqlog/mysql_error.log
pid-file = /data/sqlog/mysql.pid
open_files_limit = 10240
back_log = 600
max_connections = 5000
max_connect_errors = 6000
table_cache = 614
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 1M
join_buffer_size = 1M
thread_cache_size = 300
query_cache_size = 512M
query_cache_limit = 2M
query_cache_min_res_unit = 2k
default-storage-engine = MyISAM
thread_stack = 192K
transaction_isolation = READ-COMMITTED
tmp_table_size = 246M
max_heap_table_size = 246M
long_query_time = 3
log-bin = /data/sqlog/binlog
binlog_cache_size = 4M
binlog_format = MIXED
max_binlog_cache_size = 8M
max_binlog_size = 1G
relay-log-index = /data/sqlog/relaylog
relay-log-info-file = /data/sqlog/relaylog
relay-log = /data/sqlog/relaylog
expire_logs_days = 30
key_buffer_size = 256M
read_buffer_size = 1M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover
interactive_timeout = 120
wait_timeout = 120
skip-name-resolve
slave-skip-errors = 1032,1062,126,1114,1146,1048,1396
server-id = 1 #注意两台master以及slave的id不能一样。
binlog-do-db=zeng #需要同步的库
sync_binlog=1 #是服务器频繁的刷新日志。这个保证了在其中一台挂掉的话,日志刷新到另外一台。从而保证了数据的同步 。
auto_increment_increment=2 #是服务器频繁的刷新日志。这个保证了在其中一台挂掉的话,日志刷新到另外一台。从而保证了数据的同步 。
auto_increment_offset=2 #是服务器频繁的刷新日志。这个保证了在其中一台挂掉的话,日志刷新到另外一台。从而保证了数据的同步 。
log-slave-updates #一个MASTER 挂掉的话,另外一个马上接管
innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 512M
innodb_data_file_path = ibdata1:256M:autoextend
innodb_file_io_threads = 4
innodb_thread_concurrency = 8
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 16M
innodb_log_file_size = 128M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = 0
[mysqldump]
quick
max_allowed_packet = 32M
第三、SQLshell同步操作
11操作:
mysql> flush tables with read lock;
mysql> show master status/G;
#:记住
File: mysql-bin.000007
Position: 528
mysql> slave stop;
mysql> change master to master_host='192.168.9.14',master_user='admin',master_password='123456', master_log_file='mysql-bin.000007',master_log_pos=728;
mysql> unlock tables;
mysql> create database zeng;
#开始在11插入数据,然后倒入表
mysql>show slave status\G;
14操作:
mysql> flush tables with read lock;
mysql> show master status/G;
#:记住
File: mysql-bin.000007
Position: 728
mysql> slave stop;
mysql> change master to master_host='192.168.9.11',master_user='admin',master_password='123456', master_log_file='mysql-bin.000007',master_log_pos=528;
mysql> unlock tables;
mysql>show slave status\G;
#开始在14进行查看