log_bin = /data/mysql/sql_log/mysql-bin
server_id= 100 ##寤鸿鐢╥p鐨勬渶鍚庝竴娈
浠庢湇鍔″櫒閰嶇疆
log_bin = /data/mysql/sql_log/mysql-bin
server-id = 101
relay_log = /data/mysql/sql_log/relay-bin
read_only = on
super_read_only = on
skip_slave_sart = on
master_info_repository = TABLE
relay_log_info_repository = TABLE
create user 'repl'@`ip娈礰 identified by 'password';
grant replication slave on *.* to 'repl'@`ip娈礰;
寤鸿涓讳粠鏁版嵁搴撴湇鍔″櫒閲囩敤鐩稿悓鐨凪ySQL鐗堟湰
寤鸿浣跨敤鍏ㄥ簱澶囦唤鐨勬柟寮忓垵濮嬪寲slave鏁版嵁
mysqldump --master-data=2 -uroot-p -A --single-transcation -R --triggers --routines --all-databases > all.sql
change master to
master_host = 'master_host_ip',
master_user = 'repl',
master_password = 'password',
master_log_file = 'mysql_log_file_name',
master_log_pos = xxx;
start slave;
show slave status \G;
#鏌ョ湅SLAVE_IO_Running 鍜孲LAVE_SQL_Running鐨勭姸鎬
gtid_mode = on
enforce_gtid-consistency
log-slave-updates = on
change master to
master_host = 'master_host_ip',
master_user = 'repl',
master_password = 'password',
master_auto_position = 1
gtid澶嶅埗鐨勯檺鍒
– 鏃犳硶鍐嶄娇鐢╟reate table .. select 绠鍘嗚〃
– 鏃犳硶鍦ㄤ簨鍔′腑浣跨敤create temporary table寤虹珛涓存椂琛
– 鏃犳硶浣跨敤鍏宠仈鏇存柊鍚屾椂鏇存柊浜嬪姟琛ㄥ拰闈炰簨鍔¤〃
灏辨槸涓涓湭鍒嗛厤缁欑湡瀹炰富鏈虹殑ip锛屼篃灏辨槸璇村澶栨彁渚涙湇鍔″櫒鐨勪富鏈洪櫎浜嗘湁涓涓湡瀹瀒p澶栬繕鏈変竴涓櫄ip
淇濊瘉鍙湁涓涓富鎻愪緵鏈嶅姟 鍙︿竴涓彁渚涘彧璇荤殑鏈嶅姟
master 鏁版嵁搴撻厤缃慨鏀
auto_increment_increment = 2
auto_increment_offset = 1
1,3,5,7,9...
涓诲鏁版嵁搴撻厤缃慨鏀
auto_increment_increment = 2
auto_increment_offset = 2
2,4,6,8,10...
keeplived 鍩轰簬arrp缃戠粶鍗忚
yum install keepalived y
vim /etc/keepalived/keeplived.conf
chmod a+x /etc/keepalived/check_mysql.sh
systemctl keepalived start
鍙戣〃鍥炲