How to realize Master and Master replication in MySQL
Today, I will talk to you about how to achieve master-master replication in MySQL. Many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.
1 Machine Planning 192.168.6.119keepalive+ipvsadm (Lvs)
192.168.6.121keepalive+ipvsadm (Lvs)
192.168.6.66VIP
192.168.6.114 real machine (testing httpd load balancing), lvs client
192.168.6.115 real machine (testing httpd load balancing), lvs client
It's needed on 114.115.
[root@node1 ~] # more / usr/local/bin/lvs_real
#! / bin/bash
# description: start realserver
VIP=192.168.6.66
/ etc/rc.d/init.d/functions
Case "$1" in
Start)
Echo "start LVS of REALServer"
/ sbin/ifconfig lo:0$ VIP broadcast $VIP netmask 255.255.255.255 up
Echo "1" > / proc/sys/net/ipv4/conf/lo/arp_ignore
Echo "2" > / proc/sys/net/ipv4/conf/lo/arp_announce
Echo "1" > / proc/sys/net/ipv4/conf/all/arp_ignore
Echo "2" > / proc/sys/net/ipv4/conf/all/arp_announce
Stop)
/ sbin/ifconfig lo:0 down
Echo "close LVS Directorserver"
Echo "0" > / proc/sys/net/ipv4/conf/lo/arp_ignore
Echo "0" > / proc/sys/net/ipv4/conf/lo/arp_announce
Echo "0" > / proc/sys/net/ipv4/conf/all/arp_ignore
Echo "0" > / proc/sys/net/ipv4/conf/all/arp_announce
*)
Echo "Usage: $0 {start | stop}"
Exit 1
Esac
Start client script
[root@node1 ~] # sh / usr/local/bin/lvs_real start
4 the server keepalive configuration file is as follows
119 121 machines (master / slave modify key points are fine)
[root@localhost keepalived] # more keepalived.conf
# writed by sery, contact sery@163.com
# guration File for keepalived
# global define
Global_defs {
Router_id LVS_CNC_1
}
Vrrp_sync_group VGM {
Group {
VI_CACHE
}
}
#
# vvrp_instance define #
#
Vrrp_instance VI_CACHE {
State MASTER
Interface eth0
Lvs_sync_daemon_inteface eth0
Virtual_router_id 51
Priority 180
Advert_int 5
Authentication {
Auth_type PASS
Auth_pass 1111
}
Virtual_ipaddress {
192.168.6.66
}
}
# # #
# virtual machine setting #
# # #
# setting port 80 forward
Virtual_server 192.168.6.66 80 {
Delay_loop 6
Lb_algo wlc
Lb_kind DR
# persistence_timeout 20
Protocol TCP
Real_server 192.168.6.114 80 {
Weight 100
TCP_CHECK {
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
Connect_port 80
}
}
Real_server 192.168.6.115 80 {
Weight 100
TCP_CHECK {
Connect_timeout 3
Nb_get_retry 3
Delay_before_retry 3
Connect_port 80
}
}
}
Start keepalive
[root@localhost ~] # / etc/init.d/keepalived start
Check the ipvsadm situation
[root@localhost keepalived] # ipvsadm-ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.6.66:80 wlc
-> 192.168.6.115 Route 80 100
-> 192.168.6.114 Route 80 100
After reading the above, do you have any further understanding of how to achieve master-master replication in MySQL? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.