Mysql-master-master

Mysql-master-master

                                            Alvin.zeng<孤獨0-1>

環境描述:

第一組
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進行查看

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章